This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch zack/more-obsolete-typedefs created. glibc-2.29.9000-82-g2fcf4d7
- From: zack at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 19 Feb 2019 14:35:51 -0000
- Subject: GNU C Library master sources branch zack/more-obsolete-typedefs created. glibc-2.29.9000-82-g2fcf4d7
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, zack/more-obsolete-typedefs has been created
at 2fcf4d7af2979be199ed2db171392555032933e4 (commit)
- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=2fcf4d7af2979be199ed2db171392555032933e4
commit 2fcf4d7af2979be199ed2db171392555032933e4
Author: Zack Weinberg <zackw@panix.com>
Date: Tue Feb 19 08:45:22 2019 -0500
Define register_t using bits/typesizes.h macros.
Currently register_t is, unlike all other types in sys/types.h,
defined using a GCC extension (__attribute__((mode(word)))), falling
back to â??intâ?? if the extension is unavailable. This is a potential
ABI compatibility hazard for people using non-GNU compilers with
glibc. Itâ??s also unnecessary; the bits/typesizes.h mechanism can
handle all of the existing variation in the definition.
Tested using build-many-glibcs. The c++-types test confirms that the
physical type of register_t does not change on any supported platform.
* posix/sys/types.h: Typedef register_t as __register_t.
* posix/bits/types.h: Typedef __register_t using __REGISTER_T_TYPE.
* bits/typesizes.h
* sysdeps/mach/hurd/bits/typesizes.h
* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
* sysdeps/unix/sysv/linux/s390/bits/typesizes.h
* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h:
Define __REGISTER_T_TYPE as __SWORD_TYPE.
* sysdeps/unix/sysv/linux/x86/bits/typesizes.h:
Define __REGISTER_T_TYPE as __SWORD_TYPE for o32 and n64.
Define __REGISTER_T_TYPE as __SQUAD_TYPE for n32.
* scripts/check-obsolete-constructs.py
(ObsoletePublicDefinitionsAllowed): Remove special handling
for register_t.
(ObsoletePrivateDefinitionsAllowed): Understand __STD_TYPE as
introducing a typedef.
diff --git a/bits/typesizes.h b/bits/typesizes.h
index 41c8924..4541013 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -60,6 +60,7 @@
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
#ifdef __LP64__
/* Tell the libc code that off_t and off64_t are actually the same type
diff --git a/posix/bits/types.h b/posix/bits/types.h
index 0de6c59..4521d9d 100644
--- a/posix/bits/types.h
+++ b/posix/bits/types.h
@@ -219,6 +219,9 @@ typedef int __sig_atomic_t;
__STD_TYPE __TIME64_T_TYPE __time64_t; /* Seconds since the Epoch. */
#endif
+/* BSD: Size of a general-purpose integer register. */
+__STD_TYPE __REGISTER_T_TYPE __register_t;
+
#undef __STD_TYPE
#endif /* bits/types.h */
diff --git a/posix/sys/types.h b/posix/sys/types.h
index 29a7e9e..7327904 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -162,11 +162,8 @@ typedef __uint16_t u_int16_t;
typedef __uint32_t u_int32_t;
typedef __uint64_t u_int64_t;
-#if __GNUC_PREREQ (2, 7)
-typedef int register_t __attribute__ ((__mode__ (__word__)));
-#else
-typedef int register_t;
-#endif
+/* Type of a general-purpose integer register (BSD). */
+typedef __register_t register_t;
/* Some code from BIND tests this macro to see if the types above are
defined. */
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index c118585..a06a5fa 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -190,7 +190,8 @@ class ObsoletePrivateDefinitionsAllowed(ConstructChecker):
self.reporter.error(self.prev_token, "use of {!r}")
def examine(self, tok):
- if tok.kind == 'IDENT' and tok.text == 'typedef':
+ # bits/types.h hides 'typedef' in a macro sometimes.
+ if tok.kind == 'IDENT' and tok.text in ('typedef', '__STD_TYPE'):
self.in_typedef = True
elif tok.kind == 'PUNCTUATOR' and tok.text == ';' and self.in_typedef:
self.in_typedef = False
@@ -216,8 +217,6 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
- typedef int register_t;
- typedef int register_t __attribute__ ((__mode__ (__word__)));
"""
def __init__(self, reporter):
super().__init__(reporter)
@@ -252,15 +251,12 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
def _finish(self):
if self.typedef_tokens[-1].kind == 'IDENT':
m = OBSOLETE_TYPE_RE_.match(self.typedef_tokens[-1].text)
- if m:
- if self._permissible_public_definition(m):
- self.typedef_tokens.clear()
- elif self.typedef_tokens[-1].kind == 'PUNCTUATOR':
- if self._is_register_t_with_attribute():
+ if self._permissible_public_definition(m):
self.typedef_tokens.clear()
self._reset()
def _permissible_public_definition(self, m):
+ if not m: return False
if m.group(1) == '__': return False
name = m.group(2)
tk = self.typedef_tokens
@@ -276,9 +272,6 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
and name[5:-2] == defn[6:-2]):
return True
- if name == 'register_t' and defn == 'int':
- return True
-
return False
if (name == 'ulong' and ntok == 5
@@ -300,23 +293,6 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
return False
- def _is_register_t_with_attribute(self):
- tk = self.typedef_tokens
- ntok = len(tk)
- return (
- ntok == 12
- and tk[ 1].kind == 'IDENT' and tk[ 1].text == 'int'
- and tk[ 2].kind == 'IDENT' and tk[ 2].text == 'register_t'
- and tk[ 3].kind == 'IDENT' and tk[ 3].text == '__attribute__'
- and tk[ 4].kind == 'PUNCTUATOR' and tk[ 4].text == '('
- and tk[ 5].kind == 'PUNCTUATOR' and tk[ 5].text == '('
- and tk[ 6].kind == 'IDENT' and tk[ 6].text == '__mode__'
- and tk[ 7].kind == 'PUNCTUATOR' and tk[ 7].text == '('
- and tk[ 8].kind == 'IDENT' and tk[ 8].text == '__word__'
- and tk[ 9].kind == 'PUNCTUATOR' and tk[ 9].text == ')'
- and tk[10].kind == 'PUNCTUATOR' and tk[10].text == ')'
- and tk[11].kind == 'PUNCTUATOR' and tk[11].text == ')')
-
def ObsoleteTypedefChecker(reporter, fname):
"""Factory: produce an instance of the appropriate
obsolete-typedef checker for FNAME."""
diff --git a/sysdeps/mach/hurd/bits/typesizes.h b/sysdeps/mach/hurd/bits/typesizes.h
index 6bd9b43..94b0afc 100644
--- a/sysdeps/mach/hurd/bits/typesizes.h
+++ b/sysdeps/mach/hurd/bits/typesizes.h
@@ -60,6 +60,7 @@
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
/* Number of descriptors that can fit in an `fd_set'. */
#define __FD_SETSIZE 256
diff --git a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
index cde275d..0485dd1 100644
--- a/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
@@ -60,6 +60,7 @@
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
#define __FSWORD_T_TYPE __S32_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
/* Tell the libc code that off_t and off64_t are actually the same type
for all ABI purposes, even if possibly expressed as different base types
diff --git a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
index 3ef1281..c738ff5 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -61,6 +61,7 @@
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
#ifdef __LP64__
/* Tell the libc code that off_t and off64_t are actually the same type
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index e421057..c578237 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -66,6 +66,7 @@
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
#ifdef __s390x__
/* Tell the libc code that off_t and off64_t are actually the same type
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
index 115cc19..0db18f4 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -60,6 +60,7 @@
#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+#define __REGISTER_T_TYPE __SWORD_TYPE
#if defined __arch64__ || defined __sparcv9
/* Tell the libc code that off_t and off64_t are actually the same type
diff --git a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
index 18d2c63..0a71e30 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
@@ -30,9 +30,11 @@
#if defined __x86_64__ && defined __ILP32__
# define __SYSCALL_SLONG_TYPE __SQUAD_TYPE
# define __SYSCALL_ULONG_TYPE __UQUAD_TYPE
+# define __REGISTER_T_TYPE __SQUAD_TYPE
#else
# define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
# define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+# define __REGISTER_T_TYPE __SWORD_TYPE
#endif
#define __DEV_T_TYPE __UQUAD_TYPE
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c3861d93da7c1a4d288e8e1ed31b663944f07152
commit c3861d93da7c1a4d288e8e1ed31b663944f07152
Author: Zack Weinberg <zackw@panix.com>
Date: Mon Feb 18 21:00:34 2019 -0500
Donâ??t define u_intN_t or register_t unless __USE_MISC.
sys/types.h unconditionally defines u_int8_t, u_int16_t, u_int32_t,
u_int64_t, and register_t. These are not part of POSIX. The
u_intXX_t types are superseded by C99â??s uintXX_t types. Iâ??m not aware
of a standardized exact equivalent of register_t, but also Iâ??ve never
seen anyone use it for anything. I could be persuaded to leave that
one alone.
* posix/sys/types.h (u_int8_t, u_int16_t, u_int32_t, u_int64_t)
(register_t): Move under #ifdef __USE_MISC.
Consolidate adjacent #ifdef __USE_MISC blocks.
* scripts/check_obsolete_constructs.py: Add register_t to the
set of obsolete typedefs that our headers should not use
(but sys/types.h may still define).
diff --git a/NEWS b/NEWS
index 0a3b6c7..d951cf0 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,14 @@ Deprecated and removed features, and other changes affecting compatibility:
definitions in libc will be used automatically, which have been available
since glibc 2.17.
+* The typedefs u_int8_t, u_int16_t, u_int32_t, u_int64_t, and register_t
+ are no longer defined by <sys/types.h> in strict conformance modes.
+ These types were historically provided by <sys/types.h> on BSD systems,
+ but are not part of the POSIX specification for that header. Applications
+ requiring fixed-width unsigned integer types should use the similarly
+ named uint8_t, uint16_t, etc. from <stdint.h>. There is no standardized
+ replacement for register_t.
+
Changes to build and runtime requirements:
* GCC 6.2 or later is required to build the GNU C Library.
diff --git a/posix/sys/types.h b/posix/sys/types.h
index 0e37b1c..29a7e9e 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -143,18 +143,20 @@ typedef __suseconds_t suseconds_t;
#define __need_size_t
#include <stddef.h>
+/* POSIX does not require intN_t to be defined in this header, so
+ technically this ought to be under __USE_MISC, but it doesn't
+ forbid them to be defined here either, and much existing code
+ expects them to be defined here. */
+#include <bits/stdint-intn.h>
+
#ifdef __USE_MISC
/* Old compatibility names for C types. */
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
-#endif
-
-/* These size-specific names are used by some of the inet code. */
-#include <bits/stdint-intn.h>
-
-/* These were defined by ISO C without the first `_'. */
+/* These size-specific names are used by some of the inet code.
+ They were defined by ISO C without the first `_'. */
typedef __uint8_t u_int8_t;
typedef __uint16_t u_int16_t;
typedef __uint32_t u_int32_t;
@@ -170,8 +172,6 @@ typedef int register_t;
defined. */
#define __BIT_TYPES_DEFINED__ 1
-
-#ifdef __USE_MISC
/* In BSD <sys/types.h> is expected to define BYTE_ORDER. */
# include <endian.h>
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index b370904..c118585 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -163,6 +163,7 @@ class NoCheck(ConstructChecker):
OBSOLETE_TYPE_RE_ = re.compile(r'''\A
(__)?
( quad_t
+ | register_t
| u(?: short | int | long
| _(?: char | short | int(?:[0-9]+_t)? | long | quad_t )))
\Z''', re.VERBOSE)
@@ -215,6 +216,8 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
+ typedef int register_t;
+ typedef int register_t __attribute__ ((__mode__ (__word__)));
"""
def __init__(self, reporter):
super().__init__(reporter)
@@ -237,6 +240,9 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
elif self.typedef_tokens:
self.typedef_tokens.append(tok)
+ def eof(self):
+ self._reset()
+
def _reset(self):
while self.typedef_tokens:
tok = self.typedef_tokens.pop(0)
@@ -249,15 +255,18 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
if m:
if self._permissible_public_definition(m):
self.typedef_tokens.clear()
+ elif self.typedef_tokens[-1].kind == 'PUNCTUATOR':
+ if self._is_register_t_with_attribute():
+ self.typedef_tokens.clear()
self._reset()
def _permissible_public_definition(self, m):
if m.group(1) == '__': return False
name = m.group(2)
- toks = self.typedef_tokens
- ntok = len(toks)
- if ntok == 3 and toks[1].kind == 'IDENT':
- defn = toks[1].text
+ tk = self.typedef_tokens
+ ntok = len(tk)
+ if ntok == 3 and tk[1].kind == 'IDENT':
+ defn = tk[1].text
n = OBSOLETE_TYPE_RE_.match(defn)
if n and n.group(1) == '__' and n.group(2) == name:
return True
@@ -267,29 +276,46 @@ class ObsoletePublicDefinitionsAllowed(ConstructChecker):
and name[5:-2] == defn[6:-2]):
return True
+ if name == 'register_t' and defn == 'int':
+ return True
+
return False
if (name == 'ulong' and ntok == 5
- and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
- and toks[2].kind == 'IDENT' and toks[2].text == 'long'
- and toks[3].kind == 'IDENT' and toks[3].text == 'int'):
+ and tk[1].kind == 'IDENT' and tk[1].text == 'unsigned'
+ and tk[2].kind == 'IDENT' and tk[2].text == 'long'
+ and tk[3].kind == 'IDENT' and tk[3].text == 'int'):
return True
if (name == 'ushort' and ntok == 5
- and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
- and toks[2].kind == 'IDENT' and toks[2].text == 'short'
- and toks[3].kind == 'IDENT' and toks[3].text == 'int'):
+ and tk[1].kind == 'IDENT' and tk[1].text == 'unsigned'
+ and tk[2].kind == 'IDENT' and tk[2].text == 'short'
+ and tk[3].kind == 'IDENT' and tk[3].text == 'int'):
return True
if (name == 'uint' and ntok == 4
- and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
- and toks[2].kind == 'IDENT' and toks[2].text == 'int'):
+ and tk[1].kind == 'IDENT' and tk[1].text == 'unsigned'
+ and tk[2].kind == 'IDENT' and tk[2].text == 'int'):
return True
return False
- def eof(self):
- self._reset()
+ def _is_register_t_with_attribute(self):
+ tk = self.typedef_tokens
+ ntok = len(tk)
+ return (
+ ntok == 12
+ and tk[ 1].kind == 'IDENT' and tk[ 1].text == 'int'
+ and tk[ 2].kind == 'IDENT' and tk[ 2].text == 'register_t'
+ and tk[ 3].kind == 'IDENT' and tk[ 3].text == '__attribute__'
+ and tk[ 4].kind == 'PUNCTUATOR' and tk[ 4].text == '('
+ and tk[ 5].kind == 'PUNCTUATOR' and tk[ 5].text == '('
+ and tk[ 6].kind == 'IDENT' and tk[ 6].text == '__mode__'
+ and tk[ 7].kind == 'PUNCTUATOR' and tk[ 7].text == '('
+ and tk[ 8].kind == 'IDENT' and tk[ 8].text == '__word__'
+ and tk[ 9].kind == 'PUNCTUATOR' and tk[ 9].text == ')'
+ and tk[10].kind == 'PUNCTUATOR' and tk[10].text == ')'
+ and tk[11].kind == 'PUNCTUATOR' and tk[11].text == ')')
def ObsoleteTypedefChecker(reporter, fname):
"""Factory: produce an instance of the appropriate
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=9b73aabc5aa2e94b7835a4705f94dc845e590401
commit 9b73aabc5aa2e94b7835a4705f94dc845e590401
Author: Zack Weinberg <zackw@panix.com>
Date: Mon Feb 18 16:05:58 2019 -0500
Make the test for obsolete typedefs pickier.
Only bits/types.h is allowed to define __-prefixed obsolete typedefs.
Only sys/types.h is allowed to define unprefixed obsolete typedefs.
Definitions of unprefixed obsolete typedefs must have one of three
specific forms.
No new errors are detected.
In addition, check-obsolete-constructs.py is refactored to make it
easier to add checks for other obsolete constructs in the future.
(I do not have any current plans for such checks.)
* scripts/check-obsolete-constructs.py: Reorganize obsolete-
typedef checks for maintainability and to make it easier to
add checks for other obsolete constructs in the future.
Only allow bits/types.h to define __-prefixed obsolete typedefs.
Only allow sys/types.h to define unprefixed obsolete typedefs.
Require unprefixed obsolete typedefs to be defined in one of
three specific ways.
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index a0af229..b370904 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -119,29 +119,224 @@ def tokenize_c(file_contents):
line_start = mo.start() + adj_line_start
yield Token(kind, text, line, column + 1)
+#
+# Base and generic classes for individual checks.
+#
+
+class ConstructChecker:
+ """Scan a stream of C preprocessing tokens and possibly report
+ problems with them. The REPORTER object passed to __init__ has
+ one method, reporter.error(token, message), which should be
+ called to indicate a problem detected at the position of TOKEN.
+ If MESSAGE contains the four-character sequence '{!r}' then that
+ will be replaced with a textual representation of TOKEN.
+ """
+ def __init__(self, reporter):
+ self.reporter = reporter
+
+ def examine(self, tok):
+ """Called once for each token in a header file. Comments, whitespace,
+ and \-newline *are* included. Syntactically invalid tokens
+ (BAD_STRING, BAD_CHARCONST, BAD_BLOCK_COM, and OTHER) are *not*
+ included. Call self.reporter.error if a problem is detected.
+ """
+ raise NotImplementedError
+
+ def eof(self):
+ """Called once at the end of the stream. Subclasses need only
+ override this if it might have something to do."""
+ pass
+
+class NoCheck(ConstructChecker):
+ """Generic checker class which doesn't do anything. Substitute this
+ class for a real checker when a particular check should be skipped
+ for some file."""
+
+ def examine(self, tok):
+ pass
+
+#
+# Check for obsolete type names.
+#
+
+# The obsolete type names we're looking for:
+OBSOLETE_TYPE_RE_ = re.compile(r'''\A
+ (__)?
+ ( quad_t
+ | u(?: short | int | long
+ | _(?: char | short | int(?:[0-9]+_t)? | long | quad_t )))
+\Z''', re.VERBOSE)
+
+class ObsoleteNotAllowed(ConstructChecker):
+ """Don't allow any use of the obsolete typedefs."""
+ def examine(self, tok):
+ if OBSOLETE_TYPE_RE_.match(tok.text):
+ self.reporter.error(tok, "use of {!r}")
+
+class ObsoletePrivateDefinitionsAllowed(ConstructChecker):
+ """Allow definitions of the private versions of the
+ obsolete typedefs; that is, 'typedef [anything] __obsolete;'
+ """
+ def __init__(self, reporter):
+ super().__init__(reporter)
+ self.in_typedef = False
+ self.prev_token = None
+
+ def _check_prev(self):
+ if (self.prev_token is not None
+ and self.prev_token.kind == 'IDENT'
+ and OBSOLETE_TYPE_RE_.match(self.prev_token.text)):
+ self.reporter.error(self.prev_token, "use of {!r}")
+
+ def examine(self, tok):
+ if tok.kind == 'IDENT' and tok.text == 'typedef':
+ self.in_typedef = True
+ elif tok.kind == 'PUNCTUATOR' and tok.text == ';' and self.in_typedef:
+ self.in_typedef = False
+ if self.prev_token.kind == 'IDENT':
+ m = OBSOLETE_TYPE_RE_.match(self.prev_token.text)
+ if m and m.group(1) != '__':
+ self.reporter.error(self.prev_token, "use of {!r}")
+ self.prev_token = None
+ else:
+ self._check_prev()
+
+ self.prev_token = tok
+
+ def eof(self):
+ self._check_prev()
+
+class ObsoletePublicDefinitionsAllowed(ConstructChecker):
+ """Allow definitions of the public versions of the obsolete
+ typedefs. Only specific forms of definition are allowed:
+
+ typedef __obsolete obsolete; // identifiers must agree
+ typedef __uintN_t u_intN_t; // N must agree
+ typedef unsigned long int ulong;
+ typedef unsigned short int ushort;
+ typedef unsigned int uint;
+ """
+ def __init__(self, reporter):
+ super().__init__(reporter)
+ self.typedef_tokens = []
+
+ def examine(self, tok):
+ if tok.kind in ('WHITESPACE', 'BLOCK_COMMENT',
+ 'LINE_COMMENT', 'ESCNL'):
+ pass
+
+ elif tok.kind == 'IDENT' and tok.text == 'typedef':
+ if self.typedef_tokens:
+ self.reporter.error(tok, "typedef inside typedef")
+ self._reset()
+ self.typedef_tokens.append(tok)
+
+ elif tok.kind == 'PUNCTUATOR' and tok.text == ';':
+ self._finish()
-class Checker:
+ elif self.typedef_tokens:
+ self.typedef_tokens.append(tok)
+
+ def _reset(self):
+ while self.typedef_tokens:
+ tok = self.typedef_tokens.pop(0)
+ if tok.kind == 'IDENT' and OBSOLETE_TYPE_RE_.match(tok.text):
+ self.reporter.error(tok, "use of {!r}")
+
+ def _finish(self):
+ if self.typedef_tokens[-1].kind == 'IDENT':
+ m = OBSOLETE_TYPE_RE_.match(self.typedef_tokens[-1].text)
+ if m:
+ if self._permissible_public_definition(m):
+ self.typedef_tokens.clear()
+ self._reset()
+
+ def _permissible_public_definition(self, m):
+ if m.group(1) == '__': return False
+ name = m.group(2)
+ toks = self.typedef_tokens
+ ntok = len(toks)
+ if ntok == 3 and toks[1].kind == 'IDENT':
+ defn = toks[1].text
+ n = OBSOLETE_TYPE_RE_.match(defn)
+ if n and n.group(1) == '__' and n.group(2) == name:
+ return True
+
+ if (name[:5] == 'u_int' and name[-2:] == '_t'
+ and defn[:6] == '__uint' and defn[-2:] == '_t'
+ and name[5:-2] == defn[6:-2]):
+ return True
+
+ return False
+
+ if (name == 'ulong' and ntok == 5
+ and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
+ and toks[2].kind == 'IDENT' and toks[2].text == 'long'
+ and toks[3].kind == 'IDENT' and toks[3].text == 'int'):
+ return True
+
+ if (name == 'ushort' and ntok == 5
+ and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
+ and toks[2].kind == 'IDENT' and toks[2].text == 'short'
+ and toks[3].kind == 'IDENT' and toks[3].text == 'int'):
+ return True
+
+ if (name == 'uint' and ntok == 4
+ and toks[1].kind == 'IDENT' and toks[1].text == 'unsigned'
+ and toks[2].kind == 'IDENT' and toks[2].text == 'int'):
+ return True
+
+ return False
+
+ def eof(self):
+ self._reset()
+
+def ObsoleteTypedefChecker(reporter, fname):
+ """Factory: produce an instance of the appropriate
+ obsolete-typedef checker for FNAME."""
+
+ # The obsolete rpc/ and rpcsvc/ headers are allowed to use the
+ # obsolete types, because it would be more trouble than it's
+ # worth to remove them from headers that we intend to stop
+ # installing eventually anyway.
+ if (fname.startswith("rpc/")
+ or fname.startswith("rpcsvc/")
+ or "/rpc/" in fname
+ or "/rpcsvc/" in fname):
+ return NoCheck(reporter)
+
+ # bits/types.h is allowed to define the __-versions of the
+ # obsolete types.
+ if (fname == "bits/types.h"
+ or fname.endswith("/bits/types.h")):
+ return ObsoletePrivateDefinitionsAllowed(reporter)
+
+ # sys/types.h is allowed to use the __-versions of the
+ # obsolete types, but only to define the unprefixed versions.
+ if (fname == "sys/types.h"
+ or fname.endswith("/sys/types.h")):
+ return ObsoletePublicDefinitionsAllowed(reporter)
+
+ return ObsoleteNotAllowed(reporter)
+
+#
+# Master control
+#
+
+class HeaderChecker:
def __init__(self):
+ self.fname = None
self.status = 0
- def error(self, fname, tok, message):
+ def error(self, tok, message):
self.status = 1
if '{!r}' in message:
message = message.format(tok.text)
sys.stderr.write("{}:{}:{}: error: {}\n".format(
- fname, tok.line, tok.column, message))
-
- # The obsolete type names we're looking for:
- OBSOLETE_TYPE_RE_ = re.compile(r'''\A
- (__)?
- (?: quad_t
- | u(?: short | int | long
- | _(?: char | short | int([0-9]+_t)? | long | quad_t )))
- \Z''', re.VERBOSE)
-
- def check_file(self, fname):
- OBSOLETE_TYPE_RE = self.OBSOLETE_TYPE_RE_
+ self.fname, tok.line, tok.column, message))
+ def check(self, fname):
+ self.fname = fname
try:
with open(fname, "rt") as fp:
contents = fp.read()
@@ -150,66 +345,22 @@ class Checker:
self.status = 1
return
- # The obsolete rpc/ and rpcsvc/ headers are allowed to use the
- # obsolete types, because it would be more trouble than it's
- # worth to remove them from headers that we intend to stop
- # installing eventually anyway.
- uses_ok = (fname.startswith("rpc/") or
- fname.startswith("rpcsvc/") or
- "/rpc/" in fname or
- "/rpcsvc/" in fname)
-
- # sys/types.h and bits/types.h are allowed to define the
- # obsolete types, and they're allowed to use the __-versions
- # of the obsolete types to define the unprefixed versions of
- # the obsolete types.
- typedefs_ok = (fname == "sys/types.h" or
- fname == "bits/types.h" or
- fname.endswith("/sys/types.h") or
- fname.endswith("/bits/types.h"))
- in_typedef = False
- delayed_error_token = None
+ typedef_checker = ObsoleteTypedefChecker(self, self.fname)
for tok in tokenize_c(contents):
+ # Report and discard ill-formed tokens so the checkers don't
+ # have to worry about them.
kind = tok.kind
if kind == 'BAD_STRING':
- self.error(fname, tok, "unclosed string")
+ self.error(tok, "unclosed string")
elif kind == 'BAD_CHARCONST':
- self.error(fname, tok, "unclosed char constant")
+ self.error(tok, "unclosed char constant")
elif kind == 'BAD_BLOCK_COM':
- self.error(fname, tok, "unclosed block comment")
+ self.error(tok, "unclosed block comment")
elif kind == 'OTHER':
- self.error(fname, tok, "stray {!r} in program")
-
- elif kind == 'IDENT':
- if tok.text == 'typedef':
- in_typedef = True
- continue
-
- mo = OBSOLETE_TYPE_RE.match(tok.text)
- if mo:
- if uses_ok:
- continue
-
- if typedefs_ok and in_typedef:
- # inside a typedef, the underscore versions
- # are allowed unconditionally, and the
- # non-underscore versions are allowed as the
- # final identifier (the one being defined).
- if mo.group(1) != '__':
- delayed_error_token = tok
- continue
-
- self.error(fname, tok, "use of {!r}")
-
- elif kind == 'PUNCTUATOR':
- if in_typedef and tok.text == ';':
- delayed_error_token = None
- in_typedef = False
-
- if delayed_error_token is not None:
- self.error(fname, delayed_error_token, "use of {!r}")
- delayed_error_token = None
+ self.error(tok, "stray {!r} in program")
+ else:
+ typedef_checker.examine(tok)
def main():
ap = argparse.ArgumentParser(description=__doc__)
@@ -217,9 +368,9 @@ def main():
help="one or more headers to scan for obsolete constructs")
args = ap.parse_args()
- checker = Checker()
+ checker = HeaderChecker()
for fname in args.headers:
- checker.check_file(fname)
+ checker.check(fname)
sys.exit(checker.status)
main()
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=e79c2239ff1a97cc5127a29b6b8b53c63326acdb
commit e79c2239ff1a97cc5127a29b6b8b53c63326acdb
Author: Zack Weinberg <zackw@panix.com>
Date: Sat Jan 19 11:17:22 2019 -0500
Use a proper C tokenizer to implement the obsolete typedefs test.
The test for obsolete typedefs in installed headers was implemented
using â??grepâ?? and could therefore get false positives on e.g. â??ulongâ??
in a comment. It was also scanning all of the headers included by our
headers, and therefore testing headers we donâ??t control, e.g. Linux
kernel headers.
This patch splits the obsolete-typedef test from
scripts/check-installed-headers.sh to a separate program,
scripts/check-obsolete-constructs.py. Being implemented in Python,
it is feasible to make it tokenize C accurately enough to avoid false
positives on the contents of comments and strings. It also only
examines $(headers) in each subdirectory--all the headers we install,
but not any external dependencies of those headers.
It is also feasible to make the new test understand the difference
between _defining_ the obsolete typedefs and _using_ the obsolete
typedefs, which means posix/{bits,sys}/types.h no longer need to be
exempted. This uncovered an actual bug in bits/types.h: __quad_t and
__u_quad_t were being used to define __S64_TYPE, __U64_TYPE,
__SQUAD_TYPE and __UQUAD_TYPE. These are changed to __int64_t and
__uint64_t respectively. (__SQUAD_TYPE and __UQUAD_TYPE should be
considered obsolete as well, but that is more of a change than I feel
is safe during the freeze. Note that the comments in bits/types.h
claiming a difference between *QUAD_TYPE and *64_TYPE were also in
error: supposedly QUAD_TYPE is â??long longâ?? in all ABIs whereas 64_TYPE
is â??longâ?? in LP64 ABIs, but that appears never to have been true; both
are defined as â??longâ?? in LP64 ABIs. I made a minimal change to make
the comments not completely wrong and will revisit this whole area for
the next release.)
The change to sys/types.h removes a construct that was too complicated
for the new script (which lexes C but does not attempt to parse it) to
understand. It should have absolutely no functional effect. We might
want to consider limiting sys/types.hâ??s definition of intN_t and
u_intN_t to __USE_MISC, and we might also want to consider adding
register_t to the set of obsolete typedefs, but those changes are much
too risky during the freeze (even within our own headers there are
places where we assume sys/types.h defines intN_t unconditionally).
* scripts/check-obsolete-constructs.py: New test script.
* scripts/check-installed-headers.sh: Donâ??t test for obsolete
typedefs.
* Rules: Run scripts/check-obsolete-constructs.py over $(headers)
as a special test. Update commentary.
* bits/types.h (__SQUAD_TYPE, __S64_TYPE): Define as __int64_t.
(__UQUAD_TYPE, __U64_TYPE): Define as __uint64_t.
Update commentary.
* sys/types.h (__u_intN_t): Remove.
(u_int8_t): Typedef using __uint8_t.
(u_int16_t): Typedef using __uint16_t.
(u_int32_t): Typedef using __uint32_t.
(u_int64_t): Typedef using __uint64_t.
diff --git a/Rules b/Rules
index e08a28d..222dba6 100644
--- a/Rules
+++ b/Rules
@@ -82,7 +82,8 @@ $(common-objpfx)dummy.c:
common-generated += dummy.o dummy.c
ifneq "$(headers)" ""
-# Special test of all the installed headers in this directory.
+# Test that all of the headers installed by this directory can be compiled
+# in isolation.
tests-special += $(objpfx)check-installed-headers-c.out
libof-check-installed-headers-c := testsuite
$(objpfx)check-installed-headers-c.out: \
@@ -93,6 +94,8 @@ $(objpfx)check-installed-headers-c.out: \
$(evaluate-test)
ifneq "$(CXX)" ""
+# If a C++ compiler is available, also test that they can be compiled
+# in isolation as C++.
tests-special += $(objpfx)check-installed-headers-cxx.out
libof-check-installed-headers-cxx := testsuite
$(objpfx)check-installed-headers-cxx.out: \
@@ -103,12 +106,24 @@ $(objpfx)check-installed-headers-cxx.out: \
$(evaluate-test)
endif # $(CXX)
+# Test that a wrapper header exists in include/ for each non-sysdeps header.
+# This script does not need $(py-env).
tests-special += $(objpfx)check-wrapper-headers.out
$(objpfx)check-wrapper-headers.out: \
$(..)scripts/check-wrapper-headers.py $(headers)
$(PYTHON) $< --root=$(..) --subdir=$(subdir) $(headers) > $@; \
$(evaluate-test)
+# Test that none of the headers installed by this directory use certain
+# obsolete constructs (e.g. legacy BSD typedefs superseded by stdint.h).
+# This script does not need $(py-env).
+tests-special += $(objpfx)check-obsolete-constructs.out
+libof-check-obsolete-constructs := testsuite
+$(objpfx)check-obsolete-constructs.out: \
+ $(..)scripts/check-obsolete-constructs.py $(headers)
+ $(PYTHON) $^ > $@ 2>&1; \
+ $(evaluate-test)
+
endif # $(headers)
# This makes all the auxiliary and test programs.
diff --git a/posix/bits/types.h b/posix/bits/types.h
index 27e065c..0de6c59 100644
--- a/posix/bits/types.h
+++ b/posix/bits/types.h
@@ -87,7 +87,7 @@ __extension__ typedef unsigned long long int __uintmax_t;
32 -- "natural" 32-bit type (always int)
64 -- "natural" 64-bit type (long or long long)
LONG32 -- 32-bit type, traditionally long
- QUAD -- 64-bit type, always long long
+ QUAD -- 64-bit type, traditionally long long
WORD -- natural type of __WORDSIZE bits (int or long)
LONGWORD -- type of __WORDSIZE bits, traditionally long
@@ -113,14 +113,14 @@ __extension__ typedef unsigned long long int __uintmax_t;
#define __SLONGWORD_TYPE long int
#define __ULONGWORD_TYPE unsigned long int
#if __WORDSIZE == 32
-# define __SQUAD_TYPE __quad_t
-# define __UQUAD_TYPE __u_quad_t
+# define __SQUAD_TYPE __int64_t
+# define __UQUAD_TYPE __uint64_t
# define __SWORD_TYPE int
# define __UWORD_TYPE unsigned int
# define __SLONG32_TYPE long int
# define __ULONG32_TYPE unsigned long int
-# define __S64_TYPE __quad_t
-# define __U64_TYPE __u_quad_t
+# define __S64_TYPE __int64_t
+# define __U64_TYPE __uint64_t
/* We want __extension__ before typedef's that use nonstandard base types
such as `long long' in C89 mode. */
# define __STD_TYPE __extension__ typedef
diff --git a/posix/sys/types.h b/posix/sys/types.h
index 27129c5..0e37b1c 100644
--- a/posix/sys/types.h
+++ b/posix/sys/types.h
@@ -154,37 +154,20 @@ typedef unsigned int uint;
#include <bits/stdint-intn.h>
-#if !__GNUC_PREREQ (2, 7)
-
/* These were defined by ISO C without the first `_'. */
-typedef unsigned char u_int8_t;
-typedef unsigned short int u_int16_t;
-typedef unsigned int u_int32_t;
-# if __WORDSIZE == 64
-typedef unsigned long int u_int64_t;
-# else
-__extension__ typedef unsigned long long int u_int64_t;
-# endif
-
-typedef int register_t;
-
-#else
-
-/* For GCC 2.7 and later, we can use specific type-size attributes. */
-# define __u_intN_t(N, MODE) \
- typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE)))
-
-__u_intN_t (8, __QI__);
-__u_intN_t (16, __HI__);
-__u_intN_t (32, __SI__);
-__u_intN_t (64, __DI__);
+typedef __uint8_t u_int8_t;
+typedef __uint16_t u_int16_t;
+typedef __uint32_t u_int32_t;
+typedef __uint64_t u_int64_t;
+#if __GNUC_PREREQ (2, 7)
typedef int register_t __attribute__ ((__mode__ (__word__)));
-
+#else
+typedef int register_t;
+#endif
/* Some code from BIND tests this macro to see if the types above are
defined. */
-#endif
#define __BIT_TYPES_DEFINED__ 1
diff --git a/scripts/check-installed-headers.sh b/scripts/check-installed-headers.sh
index 8e7beff..63bc8d4 100644
--- a/scripts/check-installed-headers.sh
+++ b/scripts/check-installed-headers.sh
@@ -16,11 +16,9 @@
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
-# Check installed headers for cleanliness. For each header, confirm
-# that it's possible to compile a file that includes that header and
-# does nothing else, in several different compilation modes. Also,
-# scan the header for a set of obsolete typedefs that should no longer
-# appear.
+# For each installed header, confirm that it's possible to compile a
+# file that includes that header and does nothing else, in several
+# different compilation modes.
# These compilation switches assume GCC or compatible, which is probably
# fine since we also assume that when _building_ glibc.
@@ -31,13 +29,6 @@ cxx_modes="-std=c++98 -std=gnu++98 -std=c++11 -std=gnu++11"
# These are probably the most commonly used three.
lib_modes="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700"
-# sys/types.h+bits/types.h have to define the obsolete types.
-# rpc(svc)/* have the obsolete types too deeply embedded in their API
-# to remove.
-skip_obsolete_type_check='*/sys/types.h|*/bits/types.h|*/rpc/*|*/rpcsvc/*'
-obsolete_type_re=\
-'\<((__)?(quad_t|u(short|int|long|_(char|short|int([0-9]+_t)?|long|quad_t))))\>'
-
if [ $# -lt 3 ]; then
echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
exit 2
@@ -46,14 +37,10 @@ case "$1" in
(c)
lang_modes="$c_modes"
cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.c)
- already="$skip_obsolete_type_check"
;;
(c++)
lang_modes="$cxx_modes"
cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.cc)
- # The obsolete-type check can be skipped for C++; it is
- # sufficient to do it for C.
- already="*"
;;
(*)
echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
@@ -151,22 +138,8 @@ $expanded_lib_mode
int avoid_empty_translation_unit;
EOF
if $cc_cmd -fsyntax-only $lang_mode "$cih_test_c" 2>&1
- then
- includes=$($cc_cmd -fsyntax-only -H $lang_mode \
- "$cih_test_c" 2>&1 | sed -ne 's/^[.][.]* //p')
- for h in $includes; do
- # Don't repeat work.
- eval 'case "$h" in ('"$already"') continue;; esac'
-
- if grep -qE "$obsolete_type_re" "$h"; then
- echo "*** Obsolete types detected:"
- grep -HE "$obsolete_type_re" "$h"
- failed=1
- fi
- already="$already|$h"
- done
- else
- failed=1
+ then :
+ else failed=1
fi
done
done
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
new file mode 100755
index 0000000..a0af229
--- /dev/null
+++ b/scripts/check-obsolete-constructs.py
@@ -0,0 +1,225 @@
+#! /usr/bin/python3
+# Copyright (C) 2019 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+#
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <http://www.gnu.org/licenses/>.
+
+"""Verifies that installed headers do not use any obsolete constructs:
+ * legacy BSD typedefs superseded by <stdint.h>:
+ ushort uint ulong u_short u_int u_long u_intNN_t quad_t u_quad_t
+ (sys/types.h is allowed to _define_ these types, but not to use them
+ to define anything else).
+"""
+
+import argparse
+import collections
+import os
+import re
+import sys
+
+# Simplified lexical analyzer for C preprocessing tokens.
+# Does not implement trigraphs.
+# Does not implement backslash-newline in the middle of any lexical
+# item other than a string literal.
+# Does not implement universal-character-names in identifiers.
+# Does not implement header-names.
+# Treats prefixed strings (e.g. L"...") as two tokens (L and "...")
+# Accepts non-ASCII characters only within comments and strings.
+
+# Caution: The order of the outermost alternation matters.
+# STRING must be before BAD_STRING, CHARCONST before BAD_CHARCONST,
+# BLOCK_COMMENT before BAD_BLOCK_COM before PUNCTUATOR, and OTHER must
+# be last.
+# Caution: There should be no capturing groups other than the named
+# captures in the outermost alternation.
+
+# For reference, these are all of the C punctuators as of C11:
+# [ ] ( ) { } , ; ? ~
+# ! != * *= / /= ^ ^= = ==
+# # ##
+# % %= %> %: %:%:
+# & &= &&
+# | |= ||
+# + += ++
+# - -= -- ->
+# . ...
+# : :>
+# < <% <: << <<= <=
+# > >= >> >>=
+
+# The BAD_* tokens are not part of the official definition of pp-tokens;
+# they match unclosed strings, character constants, and block comments,
+# so that the regex engine doesn't have to backtrack all the way to the
+# beginning of a broken construct and then emit dozens of junk tokens.
+
+PP_TOKEN_RE_ = re.compile(r'''
+ (?P<STRING> \"(?:[^\"\\\r\n]|\\(?:[\r\n -~]|\r\n))*\")
+ |(?P<BAD_STRING> \"(?:[^\"\\\r\n]|\\[ -~])*)
+ |(?P<CHARCONST> \'(?:[^\'\\\r\n]|\\(?:[\r\n -~]|\r\n))*\')
+ |(?P<BAD_CHARCONST> \'(?:[^\'\\\r\n]|\\[ -~])*)
+ |(?P<BLOCK_COMMENT> /\*(?:\*(?!/)|[^*])*\*/)
+ |(?P<BAD_BLOCK_COM> /\*(?:\*(?!/)|[^*])*\*?)
+ |(?P<LINE_COMMENT> //[^\r\n]*)
+ |(?P<IDENT> [_a-zA-Z][_a-zA-Z0-9]*)
+ |(?P<PP_NUMBER> \.?[0-9](?:[0-9a-df-oq-zA-DF-OQ-Z_.]|[eEpP][+-]?)*)
+ |(?P<PUNCTUATOR>
+ [,;?~(){}\[\]]
+ | [!*/^=]=?
+ | \#\#?
+ | %(?:[=>]|:(?:%:)?)?
+ | &[=&]?
+ |\|[=|]?
+ |\+[=+]?
+ | -[=->]?
+ |\.(?:\.\.)?
+ | :>?
+ | <(?:[%:]|<(?:=|<=?)?)?
+ | >(?:=|>=?)?)
+ |(?P<ESCNL> \\(?=[\r\n]))
+ |(?P<WHITESPACE> [ \t\n\r\v\f]+)
+ |(?P<OTHER> .)
+''', re.DOTALL | re.VERBOSE)
+ENDLINE_RE_ = re.compile(r'\r|\n|\r\n')
+
+# based on the sample code in the Python re documentation
+Token_ = collections.namedtuple('Token', (
+ 'kind', 'text', 'line', 'column'))
+def tokenize_c(file_contents):
+ Token = Token_
+ PP_TOKEN_RE = PP_TOKEN_RE_
+ ENDLINE_RE = ENDLINE_RE_
+
+ line_num = 1
+ line_start = 0
+ for mo in PP_TOKEN_RE.finditer(file_contents):
+ kind = mo.lastgroup
+ text = mo.group()
+ line = line_num
+ column = mo.start() - line_start
+ # only these kinds can contain a newline
+ if kind in ('WHITESPACE', 'BLOCK_COMMENT', 'LINE_COMMENT',
+ 'STRING', 'CHARCONST', 'BAD_BLOCK_COM'):
+ adj_line_start = 0
+ for tmo in ENDLINE_RE.finditer(text):
+ line_num += 1
+ adj_line_start = tmo.end()
+ if adj_line_start:
+ line_start = mo.start() + adj_line_start
+ yield Token(kind, text, line, column + 1)
+
+
+class Checker:
+ def __init__(self):
+ self.status = 0
+
+ def error(self, fname, tok, message):
+ self.status = 1
+ if '{!r}' in message:
+ message = message.format(tok.text)
+ sys.stderr.write("{}:{}:{}: error: {}\n".format(
+ fname, tok.line, tok.column, message))
+
+ # The obsolete type names we're looking for:
+ OBSOLETE_TYPE_RE_ = re.compile(r'''\A
+ (__)?
+ (?: quad_t
+ | u(?: short | int | long
+ | _(?: char | short | int([0-9]+_t)? | long | quad_t )))
+ \Z''', re.VERBOSE)
+
+ def check_file(self, fname):
+ OBSOLETE_TYPE_RE = self.OBSOLETE_TYPE_RE_
+
+ try:
+ with open(fname, "rt") as fp:
+ contents = fp.read()
+ except OSError as e:
+ sys.stderr.write("{}: {}\n".format(fname, e.strerror))
+ self.status = 1
+ return
+
+ # The obsolete rpc/ and rpcsvc/ headers are allowed to use the
+ # obsolete types, because it would be more trouble than it's
+ # worth to remove them from headers that we intend to stop
+ # installing eventually anyway.
+ uses_ok = (fname.startswith("rpc/") or
+ fname.startswith("rpcsvc/") or
+ "/rpc/" in fname or
+ "/rpcsvc/" in fname)
+
+ # sys/types.h and bits/types.h are allowed to define the
+ # obsolete types, and they're allowed to use the __-versions
+ # of the obsolete types to define the unprefixed versions of
+ # the obsolete types.
+ typedefs_ok = (fname == "sys/types.h" or
+ fname == "bits/types.h" or
+ fname.endswith("/sys/types.h") or
+ fname.endswith("/bits/types.h"))
+ in_typedef = False
+ delayed_error_token = None
+
+ for tok in tokenize_c(contents):
+ kind = tok.kind
+ if kind == 'BAD_STRING':
+ self.error(fname, tok, "unclosed string")
+ elif kind == 'BAD_CHARCONST':
+ self.error(fname, tok, "unclosed char constant")
+ elif kind == 'BAD_BLOCK_COM':
+ self.error(fname, tok, "unclosed block comment")
+ elif kind == 'OTHER':
+ self.error(fname, tok, "stray {!r} in program")
+
+ elif kind == 'IDENT':
+ if tok.text == 'typedef':
+ in_typedef = True
+ continue
+
+ mo = OBSOLETE_TYPE_RE.match(tok.text)
+ if mo:
+ if uses_ok:
+ continue
+
+ if typedefs_ok and in_typedef:
+ # inside a typedef, the underscore versions
+ # are allowed unconditionally, and the
+ # non-underscore versions are allowed as the
+ # final identifier (the one being defined).
+ if mo.group(1) != '__':
+ delayed_error_token = tok
+ continue
+
+ self.error(fname, tok, "use of {!r}")
+
+ elif kind == 'PUNCTUATOR':
+ if in_typedef and tok.text == ';':
+ delayed_error_token = None
+ in_typedef = False
+
+ if delayed_error_token is not None:
+ self.error(fname, delayed_error_token, "use of {!r}")
+ delayed_error_token = None
+
+def main():
+ ap = argparse.ArgumentParser(description=__doc__)
+ ap.add_argument("headers", metavar="header", nargs="+",
+ help="one or more headers to scan for obsolete constructs")
+ args = ap.parse_args()
+
+ checker = Checker()
+ for fname in args.headers:
+ checker.check_file(fname)
+ sys.exit(checker.status)
+
+main()
-----------------------------------------------------------------------
hooks/post-receive
--
GNU C Library master sources