Permalink
Browse files

Reorganize the way we handle reserved C macro names.

RESERVED_MACRO_NAMES:
*/RESERVED_MACRO_NAMES:
    Add a macro, _FORTIFY_SOURCE, that gcc defines by default on some recent
    versions of Linux.

    I could have added it in SIX separate RESERVED_MACRO_NAMES files.
    Instead, I moved the content common to all these files to a
    RESERVED_MACRO_NAMES file in the top directory, leaving the
    RESERVED_MACRO_NAMES files of the subdirectories containing only
    macros that *don't* occur in all those subdirectories.

tools/bootcheck:
   Copy the top-level RESERVED_MACRO_NAMES names to the stage 2 directory.

Mmake.common.in:
   Filter out the contents of the top level RESERVED_MACRO_NAMES file,
   as well as the RESERVED_MACRO_NAMES file in the current directory.
  • Loading branch information...
1 parent e94af1a commit ba57f4a5df1aa1d9ff71c412c64871e9eec3b20a @zsomogyi zsomogyi committed Jan 21, 2014
View
@@ -302,7 +302,8 @@ OBJ_CHECKS = $(CHECK_OBJS:%=%.obj_check)
# is in a separate CVS module and is not included in the
# normal Mercury source distributions)
# Exceptions to this policy must be listed in the RESERVED_MACRO_NAMES file
-# in the relevant directory.
+# in the top directory (if applicable to all C source directories) or in
+# the relevant directory (if applicable only to some C source directories).
#
# XXX The base_typeclass_info prefix is allowed only temporarily; it should
# be fixed by adding a prefix giving the name of the module defining the
@@ -368,7 +369,9 @@ OBJ_PREFIX_EXPRS = \
$(SSDB_OBJ_PREFIX_EXPRS)
HEADER_CLEAN_FILTER = \
- grep -v $(MACRO_PREFIX_EXPRS) | fgrep -v -x -f RESERVED_MACRO_NAMES
+ grep -v $(MACRO_PREFIX_EXPRS) | \
+ fgrep -v -x -f ../RESERVED_MACRO_NAMES | \
+ fgrep -v -x -f RESERVED_MACRO_NAMES
# This rule checks that object files are properly namespace-clean, with
# regard to the global symbols that they define.
View
@@ -0,0 +1,90 @@
+#-----------------------------------------------------------------------------#
+# Copyright (C) 2014 The Mercury team
+# This file may only be copied under the terms of the GNU General
+# Public License - see the file COPYING in the Mercury distribution.
+#-----------------------------------------------------------------------------#
+#
+# RESERVED_MACRO_NAMES
+#
+# We want all macros defined by the Mercury header files to start with a prefix
+# that indicates their origin, leaving the rest of the namespace available
+# to users to use as they wish. However, we do have to define some macros
+# that do not conform to this naming scheme. This file, and the other files
+# of the same name in the lower directories that contain C header files
+# list all these exceptions. The purpose of this is to enable the
+# Mmakefile target `check_headers' in each of those directories
+# to check whether we have accidentally defined any other macros that
+# encroach on users' namespace.
+#
+# This file, and the other files with the same name, are used as arguments
+# to `fgrep -f'. Lines starting with `#' will not match anything in the input,
+# and can thus be used as comments. Other lines are treated as strings
+# to match against.
+#
+# This file contains the namespace-unclean macros that are defined
+# in all of the directories that have hand-written .h files.
+#
+# Any macros that are *not* defined in all those directories should be listed
+# in the RESERVED_MACRO_NAMES file in the relevant directory or directories.
+#
+#-----------------------------------------------------------------------------#
+# This is documented in the Mercury language reference manual
+# and defined by mercury_types.h.
+SUCCESS_INDICATOR
+#-----------------------------------------------------------------------------#
+# pid_t is only defined in mercury_conf.h if it is not present
+# in the system headers. I don't think there is a nice way to
+# prefix this without requiring a later version of autoconf (e.g. 2.52).
+pid_t
+#-----------------------------------------------------------------------------#
+# These are defined by boehm_gc/gc.h.
+__GC
+_GC_H
+HIDE_POINTER
+REVEAL_POINTER
+#-----------------------------------------------------------------------------#
+# These are defined by boehm_gc/include/gc_pthread_redirects.h
+dlopen
+pthread_create
+pthread_detach
+pthread_join
+pthread_sigmask
+#-----------------------------------------------------------------------------#
+# This is defined by mps_gc/code/mercury_mps.h,
+# which uses this macro for its header guard.
+# Normally it would be better to use uppercase for header guard macro names,
+# but that would be inconsistent with the coding style used in mps_gc/code.
+mercury_mps_h
+#-----------------------------------------------------------------------------#
+# This is defined by the mgnuc script in some grades.
+# It is used for configuring the Boehm collector.
+# XXX it should have a GC_ prefix.
+NO_SIGNALS
+#-----------------------------------------------------------------------------#
+# These are defined automatically by GCC -- gcc optionally passes them
+# on the command line when calling cc1, depending on the exact options
+# that gcc was invoked with. These are not namespace pollution, since they are
+# in the _[A-Z]* namespace which is reserved for the C implementation,
+# and they *are* being defined by the C implementation.
+_GNU_SOURCE
+_FORTIFY_SOURCE
+__EXTENSIONS__
+__OPTIMIZE__
+__STRICT_ANSI__
+__GCC_HAVE_DWARF2_CFI_ASM
+__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+__i686
+__i686__
+__pentiumpro
+__pentiumpro__
+#-----------------------------------------------------------------------------#
+# These are defined in when threads are enabled.
+_REENTRANT
+_THREAD_SAFE
+#-----------------------------------------------------------------------------#
+# This is defined on MinGW64 to workaround limitations in the Windows libc.
+__USE_MINGW_ANSI_STDIO
+#-----------------------------------------------------------------------------#
@@ -6,74 +6,7 @@
#
# RESERVED_MACRO_NAMES
#
-# This file lists the macro names, other than the ones starting with a
-# certain set of allowed prefixes that are defined by the Mercury header files.
-# The Mmakefile target `check_headers' automatically checks that no other
-# macro names are defined. This is done to keep our headers namespace-clean,
-# i.e. ensure that we don't invade the user's namespace.
+# For the purpose of this file, see the top of RESERVED_MACRO_NAMES in the top
+# directory.
#
-# This file is used as the argument to `fgrep -f'.
-# Lines starting with `#' will not match anything in the input,
-# and can thus be used as comments.
-# Other lines are treated as strings to match against.
-#
-#-----------------------------------------------------------------------------#
-# This is documented in the Mercury language reference manual
-# and defined by mercury_types.h.
-SUCCESS_INDICATOR
-#-----------------------------------------------------------------------------#
-# pid_t is only defined in mercury_conf.h if it is not present
-# in the system headers. I don't think there is a nice way to
-# prefix this without requiring a later version of autoconf (e.g. 2.52).
-pid_t
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/gc.h.
-__GC
-_GC_H
-HIDE_POINTER
-REVEAL_POINTER
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/include/gc_pthread_redirects.h
-dlopen
-pthread_create
-pthread_detach
-pthread_join
-pthread_sigmask
-#-----------------------------------------------------------------------------#
-# This is defined by mps_gc/code/mercury_mps.h,
-# which uses this macro for its header guard.
-# Normally it would be better to use uppercase for header guard macro names,
-# but that would be inconsistent with the coding style used in mps_gc/code.
-mercury_mps_h
-#-----------------------------------------------------------------------------#
-# This is defined by the mgnuc script in some grades.
-# It is used for configuring the Boehm collector.
-# XXX it should have a GC_ prefix.
-NO_SIGNALS
-#-----------------------------------------------------------------------------#
-# These are defined automatically by GCC -- gcc optionally passes
-# them on the command line when calling cc1, depending on the
-# exact options which gcc was invoked with. These are not
-# namespace pollution, since they are in the _[A-Z]* namespace
-# which is reserved for the C implementation, and they are being
-# defined by the C implementation.
-_GNU_SOURCE
-__EXTENSIONS__
-__OPTIMIZE__
-__STRICT_ANSI__
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
-__i686
-__i686__
-__pentiumpro
-__pentiumpro__
-#-----------------------------------------------------------------------------#
-# These are defined in when threads are enabled.
-_REENTRANT
-_THREAD_SAFE
-#-----------------------------------------------------------------------------#
-# This is defined on MinGW64 to workaround limitations in the Windows libc.
-__USE_MINGW_ANSI_STDIO
#-----------------------------------------------------------------------------#
@@ -6,69 +6,9 @@
#
# RESERVED_MACRO_NAMES
#
-# This file lists the macro names, other than the ones starting with a
-# certain set of allowed prefixes that are defined by the Mercury header files.
-# The Mmakefile target `check_headers' automatically checks that no other
-# macro names are defined. This is done to keep our headers namespace-clean,
-# i.e. ensure that we don't invade the user's namespace.
+# For the purpose of this file, see the top of RESERVED_MACRO_NAMES in the top
+# directory.
#
-# This file is used as the argument to `fgrep -f'.
-# Lines starting with `#' will not match anything in the input,
-# and can thus be used as comments.
-# Other lines are treated as strings to match against.
-#
-#-----------------------------------------------------------------------------#
-# This is documented in the Mercury language reference manual
-# and defined by mercury_types.h.
-SUCCESS_INDICATOR
-#-----------------------------------------------------------------------------#
-# pid_t is only defined in mercury_conf.h if it is not present
-# in the system headers. I don't think there is a nice way to
-# prefix this without requiring a later version of autoconf (e.g. 2.52).
-pid_t
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/gc.h.
-__GC
-_GC_H
-HIDE_POINTER
-REVEAL_POINTER
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/include/gc_pthread_redirects.h
-dlopen
-pthread_create
-pthread_detach
-pthread_join
-pthread_sigmask
-#-----------------------------------------------------------------------------#
-# This is defined by mps_gc/code/mercury_mps.h,
-# which uses this macro for its header guard.
-# Normally it would be better to use uppercase for header guard macro names,
-# but that would be inconsistent with the coding style used in mps_gc/code.
-mercury_mps_h
-#-----------------------------------------------------------------------------#
-# This is defined by the mgnuc script in some grades.
-# It is used for configuring the Boehm collector.
-# XXX it should have a GC_ prefix.
-NO_SIGNALS
-#-----------------------------------------------------------------------------#
-# These are defined automatically by GCC -- gcc optionally passes
-# them on the command line when calling cc1, depending on the
-# exact options which gcc was invoked with. These are not
-# namespace polution, since they are in the _[A-Z]* namespace
-# which is reserved for the C implementation, and they are being
-# defined by the C implementation.
-_GNU_SOURCE
-__EXTENSIONS__
-__OPTIMIZE__
-__STRICT_ANSI__
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
-__i686
-__i686__
-__pentiumpro
-__pentiumpro__
#-----------------------------------------------------------------------------#
# These are defined in exception.m. They are used to map this set of six
# names, one for each declared mode of builtin.catch/3, down to the three
@@ -82,10 +22,3 @@ mercury__exception__builtin_catch_3_p_3
mercury__exception__builtin_catch_3_p_4
mercury__exception__builtin_catch_3_p_5
#-----------------------------------------------------------------------------#
-# These are defined in when threads are enabled.
-_REENTRANT
-_THREAD_SAFE
-#-----------------------------------------------------------------------------#
-# This is defined on MinGW64 to workaround limitations in the Windows libc.
-__USE_MINGW_ANSI_STDIO
-#-----------------------------------------------------------------------------#
@@ -6,74 +6,7 @@
#
# RESERVED_MACRO_NAMES
#
-# This file lists the macro names, other than the ones starting with a
-# certain set of allowed prefixes that are defined by the Mercury header files.
-# The Mmakefile target `check_headers' automatically checks that no other
-# macro names are defined. This is done to keep our headers namespace-clean,
-# i.e. ensure that we don't invade the user's namespace.
+# For the purpose of this file, see the top of RESERVED_MACRO_NAMES in the top
+# directory.
#
-# This file is used as the argument to `fgrep -f'.
-# Lines starting with `#' will not match anything in the input,
-# and can thus be used as comments.
-# Other lines are treated as strings to match against.
-#
-#-----------------------------------------------------------------------------#
-# This is documented in the Mercury language reference manual
-# and defined by mercury_types.h.
-SUCCESS_INDICATOR
-#-----------------------------------------------------------------------------#
-# pid_t is only defined in mercury_conf.h if it is not present
-# in the system headers. I don't think there is a nice way to
-# prefix this without requiring a later version of autoconf (e.g. 2.52).
-pid_t
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/gc.h.
-__GC
-_GC_H
-HIDE_POINTER
-REVEAL_POINTER
-#-----------------------------------------------------------------------------#
-# These are defined by boehm_gc/include/gc_pthread_redirects.h
-dlopen
-pthread_create
-pthread_detach
-pthread_join
-pthread_sigmask
-#-----------------------------------------------------------------------------#
-# This is defined by mps_gc/code/mercury_mps.h,
-# which uses this macro for its header guard.
-# Normally it would be better to use uppercase for header guard macro names,
-# but that would be inconsistent with the coding style used in mps_gc/code.
-mercury_mps_h
-#-----------------------------------------------------------------------------#
-# This is defined by the mgnuc script in some grades.
-# It is used for configuring the Boehm collector.
-# XXX it should have a GC_ prefix.
-NO_SIGNALS
-#-----------------------------------------------------------------------------#
-# These are defined automatically by GCC -- gcc optionally passes
-# them on the command line when calling cc1, depending on the
-# exact options which gcc was invoked with. These are not
-# namespace pollution, since they are in the _[A-Z]* namespace
-# which is reserved for the C implementation, and they are being
-# defined by the C implementation.
-_GNU_SOURCE
-__EXTENSIONS__
-__OPTIMIZE__
-__STRICT_ANSI__
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
-__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
-__i686
-__i686__
-__pentiumpro
-__pentiumpro__
-#-----------------------------------------------------------------------------#
-# These are defined in when threads are enabled.
-_REENTRANT
-_THREAD_SAFE
-#-----------------------------------------------------------------------------#
-# This is defined on MinGW64 to workaround limitations in the Windows libc.
-__USE_MINGW_ANSI_STDIO
#-----------------------------------------------------------------------------#
Oops, something went wrong.

0 comments on commit ba57f4a

Please sign in to comment.