diff options
author | Zack Weinberg <zackw@panix.com> | 2017-03-21 16:30:53 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-06-14 08:14:34 -0400 |
commit | fd860eaaa8757b221d9169e460c9ec41ea51f317 (patch) | |
tree | 5e5037486db89c12cd4a7dc89a545767481aff29 /sysdeps/mach/hurd/errnos.awk | |
parent | 37f802f86400684c8d13403958b2c598721d6360 (diff) | |
download | glibc-fd860eaaa8757b221d9169e460c9ec41ea51f317.tar.gz glibc-fd860eaaa8757b221d9169e460c9ec41ea51f317.tar.xz glibc-fd860eaaa8757b221d9169e460c9ec41ea51f317.zip |
Remove __need macros from errno.h (__need_Emath, __need_error_t).
This is fairly complicated, not because the users of __need_Emath and __need_error_t have complicated requirements, but because the core changes had a lot of fallout. __need_error_t exists for gnulib compatibility in argz.h and argp.h. error_t itself is a Hurdism, an enum containing all the E-constants, so you can do 'p (error_t) errno' in gdb and get a symbolic value. argz.h and argp.h use it for function return values, and they want to fall back to 'int' when that's not available. There is no reason why these nonstandard headers cannot just go ahead and include all of errno.h; so we do that. __need_Emath is defined only by .S files; what they _really_ need is for errno.h to avoid declaring anything other than the E-constants (e.g. 'extern int __errno_location(void);' is a syntax error in assembly language). This is replaced with a check for __ASSEMBLER__ in errno.h, plus a carefully documented requirement for bits/errno.h not to define anything other than macros. That in turn has the consequence that bits/errno.h must not define errno - fortunately, all live ports use the same definition of errno, so I've moved it to errno.h. The Hurd bits/errno.h must also take care not to define error_t when __ASSEMBLER__ is defined, which involves repeating all of the definitions twice, but it's a generated file so that's okay. * stdlib/errno.h: Remove __need_Emath and __need_error_t logic. Reorganize file. Declare errno here. When __ASSEMBLER__ is defined, don't declare anything other than the E-constants. * include/errno.h: Change conditional for exposing internal declarations to (not _ISOMAC and not __ASSEMBLER__). * bits/errno.h: Remove logic for __need_Emath. Document requirements for a port-specific bits/errno.h. * sysdeps/unix/sysv/linux/bits/errno.h * sysdeps/unix/sysv/linux/alpha/bits/errno.h * sysdeps/unix/sysv/linux/hppa/bits/errno.h * sysdeps/unix/sysv/linux/mips/bits/errno.h * sysdeps/unix/sysv/linux/sparc/bits/errno.h: Add multiple-include guard and check against improper inclusion. Remove __need_Emath logic. Don't declare errno here. Ensure all constants are defined as simple integer literals. Consistent formatting. * sysdeps/mach/hurd/errnos.awk: Likewise. Only define error_t and enum __error_t_codes if __ASSEMBLER__ is not defined. * sysdeps/mach/hurd/bits/errno.h: Regenerate. * argp/argp.h, string/argz.h: Don't define __need_error_t before including errno.h. * sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S * sysdeps/x86_64/fpu/s_cosf.S * sysdeps/x86_64/fpu/s_sincosf.S * sysdeps/x86_64/fpu/s_sinf.S: Just include errno.h; don't define __need_Emath or include bits/errno.h directly.
Diffstat (limited to 'sysdeps/mach/hurd/errnos.awk')
-rw-r--r-- | sysdeps/mach/hurd/errnos.awk | 206 |
1 files changed, 130 insertions, 76 deletions
diff --git a/sysdeps/mach/hurd/errnos.awk b/sysdeps/mach/hurd/errnos.awk index 1cd2a0ac96..1fdca40d38 100644 --- a/sysdeps/mach/hurd/errnos.awk +++ b/sysdeps/mach/hurd/errnos.awk @@ -19,71 +19,74 @@ # @errno{ENOSYS, 123, Function not implemented} BEGIN { - print "/* This file generated by errnos.awk. */"; - print ""; - print "/* The Hurd uses Mach error system 0x10, currently only subsystem 0. */"; - print "#ifndef _HURD_ERRNO"; - print "#define _HURD_ERRNO(n)\t((0x10 << 26) | ((n) & 0x3fff))"; - print "#endif"; + print "/* This file generated by errnos.awk from"; + for (i = 1; i < ARGC; i++) + { + arg = ARGV[i]; + sub(/.*(manual|include)\//, "", arg) + print " " arg; + } + print " Do not edit this file; edit errnos.awk and regenerate it. */"; print ""; - print "#ifdef _ERRNO_H\n"; - print "enum __error_t_codes\n{"; - print "\t/* The value zero always means success and it is perfectly fine for"; - print "\t code to use 0 explicitly (or implicitly, e.g. via Boolean coercion)."; - print "\t Having an enum entry for zero both makes the debugger print the name"; - print "\t for error_t-typed zero values, and prevents the compiler from"; - print "\t issuing warnings about 'case 0:' in a switch on an error_t-typed"; - print "\t value. */"; - print "\tESUCCESS = 0," + print "#ifndef _BITS_ERRNO_H"; + print "#define _BITS_ERRNO_H 1"; print ""; + print "#if !defined _ERRNO_H"; + print "# error \"Never include <bits/errno.h> directly; use <errno.h> instead.\""; + print "#endif"; + maxerrno = 0; + maxerrlen = 0; in_mach_errors = ""; - in_math = 0; - edom = erange = ""; - print "#undef EDOM\n#undef ERANGE"; - lno = 0; + seq = 0; } /^@errno\{/ \ { - etext = ""; - for (i = 3; i <= NF; ++i) - etext = etext " " $i; - etext = substr(etext, 1, length(etext)-1) - e = substr($1, 8, length($1)-8) + if (length(e) > maxerrlen) + maxerrlen = length(e); if (e == "EWOULDBLOCK") { - lines[lno++]="#define EWOULDBLOCK EAGAIN /* Operation would block */"; + econsts[seq] = e; + errnos[seq] = "EAGAIN"; + seq++; next; } - errno = substr($2, 1, length($2)-1) + 0 + errno = substr($2, 1, length($2)-1) + 0; if (errno == 0) next; - if (errno > maxerrno) maxerrno = errno; - x = sprintf ("%-40s/*%s */", sprintf ("%-24s%s", "#define\t" e, - "_HURD_ERRNO (" errno ")"), - etext); - if (e == "EDOM") - edom = x; - else if (e == "ERANGE") - erange = x; - comma[lno] = 1; - lines[lno++] = sprintf("\t%-16s= _HURD_ERRNO (%d)", e, errno); - lines[lno++] = x; + if (errno > 0x3ffff) + { + printf("%s:%d: errno value %d too large for the Hurd\n", + FILENAME, NR, errno) >> "/dev/stderr"; + exit 1; + } + if (errno > maxerrno) + maxerrno = errno; + + etext = ""; + for (i = 3; i <= NF; ++i) + etext = etext " " $i; + etext = substr(etext, 2, length(etext)-2); + + econsts[seq] = e; + errnos[seq] = sprintf("0x%08x", 0x40000000 + errno); + etexts[seq] = etext; + seq++; next; } NF == 3 && $1 == "#define" && $2 == "MACH_SEND_IN_PROGRESS" \ { in_mach_errors = FILENAME; - lines[lno++] = "\n\t/* Errors from <mach/message.h>. */"; + annot[seq++] = "\n/* Errors from <mach/message.h>. */"; } NF == 3 && $1 == "#define" && $2 == "KERN_SUCCESS" \ { in_mach_errors = FILENAME; - lines[lno++] = "\n\t/* Errors from <mach/kern_return.h>. */"; + annot[seq++] = "\n/* Errors from <mach/kern_return.h>. */"; next; } @@ -92,16 +95,24 @@ in_mach_errors != "" && $2 == "MACH_IPC_COMPAT" \ in_mach_errors = ""; } +# FIXME: mach/message.h and mach/kern_return.h do include error +# descriptions which we could slurp, but some of them are very long, +# we would need to word-wrap them. in_mach_errors == FILENAME && NF == 3 && $1 == "#define" \ { - comma[lno] = 1; - lines[lno++] = sprintf("\t%-32s= %s", "E" $2, $3); + e = "E" $2; + if (length(e) > maxerrlen) + maxerrlen = length(e); + econsts[seq] = e; + errnos[seq] = $3; + etexts[seq] = ""; + seq++; } $1 == "#define" && $2 == "_MACH_MIG_ERRORS_H_" \ { in_mig_errors = 1; - lines[lno++] = "\n\t/* Errors from <mach/mig_errors.h>. */"; + annot[seq++] = "\n/* Errors from <mach/mig_errors.h>. */"; next; } in_mig_errors && $1 == "#endif" && $3 == "_MACH_MIG_ERRORS_H_" \ @@ -112,17 +123,23 @@ in_mig_errors && $1 == "#endif" && $3 == "_MACH_MIG_ERRORS_H_" \ (in_mig_errors && $1 == "#define" && $3 <= -300) || \ (in_device_errors && $1 == "#define" && /D_/ && NF > 3) \ { - comment = ""; - for (i = 4; i <= NF; ++i) - comment = comment " " $i; - comma[lno] = 1; - lines[lno++] = sprintf("%-32s", sprintf ("\t%-24s= %s", "E" $2, $3)) comment; + etext = ""; + for (i = 5; i < NF; ++i) + etext = etext " " $i; + + e = "E" $2; + if (length(e) > maxerrlen) + maxerrlen = length(e); + econsts[seq] = e; + errnos[seq] = $3; + etexts[seq] = substr(etext, 2, length(etext)-1); + seq++; } $1 == "#define" && $2 == "D_SUCCESS" \ { in_device_errors = 1; - lines[lno++] = "\n\t/* Errors from <device/device_types.h>. */"; + annot[seq++] = "\n/* Errors from <device/device_types.h>. */"; next; } in_device_errors && $1 == "#endif" \ @@ -130,36 +147,73 @@ in_device_errors && $1 == "#endif" \ in_device_errors = 0; } +function print_errno_enum(maxseq) +{ + print ""; + print "#ifndef __ASSEMBLER__"; + print ""; + print "enum __error_t_codes"; + print "{"; + print " /* The value zero always means success and it is perfectly fine"; + print " for code to use 0 explicitly (or implicitly, e.g. via Boolean"; + print " coercion.) Having an enum entry for zero both makes the"; + print " debugger print the name for error_t-typed zero values, and"; + print " prevents the compiler from issuing warnings about 'case 0:'"; + print " in a switch on an error_t-typed value. */"; + printf(" %-*s = 0,\n", maxerrlen, "ESUCCESS"); + + print ""; + print " /* The Hurd uses Mach error system 0x10, subsystem 0. */"; + for (i = 0; i < maxseq; i++) + { + if (i in annot) + print annot[i]; + else if (i in etexts && etexts[i] != "") + printf(" %-*s = %s,\t/* %s */\n", + maxerrlen, econsts[i], errnos[i], etexts[i]); + else if (errnos[i] != "EAGAIN") + printf(" %-*s = %s,\n", maxerrlen, econsts[i], errnos[i]); + } + + print ""; + print " /* Because the C standard requires that errno have type 'int'," + print " this enumeration must be a signed type. */"; + print " __FORCE_ERROR_T_CODES_SIGNED = -1"; + print "};"; + print ""; + print "/* User-visible type of error codes. It is ok to use 'int' or"; + print " 'kern_return_t' for these, but with 'error_t' the debugger prints"; + print " symbolic values. */"; + print "# if !defined __error_t_defined && defined __USE_GNU"; + print "# define __error_t_defined 1"; + print "typedef enum __error_t_codes error_t;" + print "# endif"; + print ""; + print "#endif /* not __ASSEMBLER__ */"; +} + +function print_errno_defines(maxseq) +{ + print ""; + print "/* The C standard requires that all of the E-constants be" + print " defined as macros. */" + print ""; + for (i = 0; i < maxseq; i++) + { + if (i in annot) + print annot[i]; + else + printf("#define %-*s %s\n", maxerrlen, econsts[i], errnos[i]); + } + print ""; + printf("#define _HURD_ERRNOS %d\n", maxerrno+1); +} END \ { - for (i = 0; i < lno - 1; ++i) - printf "%s%s\n", lines[i], (comma[i] ? "," : ""); - print lines[i]; - print ""; - print "};"; - print ""; - printf "#define\t_HURD_ERRNOS\t%d\n", maxerrno+1; - print ""; - print "\ -/* User-visible type of error codes. It is ok to use `int' or\n\ - `kern_return_t' for these, but with `error_t' the debugger prints\n\ - symbolic values. */"; - print "#ifdef __USE_GNU"; - print "typedef enum __error_t_codes error_t;" - print "#define __error_t_defined\t1" - print "#endif"; - print ""; - print "\ -/* Return the current thread's location for `errno'.\n\ - The syntax of this function allows redeclarations like `int errno'. */\n\ -extern int *__errno_location (void) __THROW __attribute__ ((__const__));\n\ -\n\ -#define errno (*__errno_location ())\n\ -"; - print "#endif /* <errno.h> included. */"; + print_errno_enum(seq); + print_errno_defines(seq); + print ""; - print "#if !defined (_ERRNO_H) && defined (__need_Emath)"; - print edom; print erange; - print "#endif /* <errno.h> not included and need math error codes. */"; + print "#endif /* bits/errno.h. */"; } |