]> granicus.if.org Git - gc/commitdiff
Replace conditional extern 'C' blocks begin/end with EXTERN_C_BEGIN/END
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Feb 2018 18:39:04 +0000 (21:39 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Feb 2018 18:39:04 +0000 (21:39 +0300)
(code refactoring)

Issue #206 (bdwgc).

Note: EXTERN_C_BEGIN and EXTERN_C_END are not available in the GC
public headers.

* include/private/darwin_stop_world.h: Replace the conditional
extern "C" block begin/end with EXTERN_C_BEGIN and EXTERN_C_END,
respectively.
* include/private/dbg_mlc.h: Likewise.
* include/private/gc_hdrs.h: Likewise.
* include/private/gc_locks.h: Likewise.
* include/private/gc_pmark.h: Likewise.
* include/private/gc_priv.h: Likewise.
* include/private/gcconfig.h: Likewise.
* include/private/pthread_stop_world.h: Likewise.
* include/private/pthread_support.h: Likewise.
* include/private/specific.h: Likewise.
* include/private/thread_local_alloc.h: Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN]: Likewise.
* tests/test.c [GC_AMIGA_FASTALLOC && AMIGA]: Likewise.
* include/private/gcconfig.h (EXTERN_C_BEGIN, EXTERN_C_END): Define
macro.

13 files changed:
include/private/darwin_stop_world.h
include/private/dbg_mlc.h
include/private/gc_hdrs.h
include/private/gc_locks.h
include/private/gc_pmark.h
include/private/gc_priv.h
include/private/gcconfig.h
include/private/pthread_stop_world.h
include/private/pthread_support.h
include/private/specific.h
include/private/thread_local_alloc.h
os_dep.c
tests/test.c

index ca8ef9edadf14dfc91354e8db0bc97d7d38140aa..ee97cbf66c48c1affd70c4774de9fee3476a0dc1 100644 (file)
@@ -25,9 +25,7 @@
 #include <mach/mach.h>
 #include <mach/thread_act.h>
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 struct thread_stop_info {
   mach_port_t mach_thread;
@@ -50,8 +48,6 @@ struct thread_stop_info {
   GC_INNER GC_bool GC_is_mach_marker(thread_act_t);
 #endif
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif
index 2ba8f9cb852f6e07c561a02516d610434962dac4..4283bdac9eea0592ffc456a33b920605038de7df 100644 (file)
@@ -30,9 +30,7 @@
 # include "gc_backptr.h"
 #endif
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 #if CPP_WORDSZ == 32
 # define START_FLAG (word)0xfedcedcb
@@ -171,8 +169,6 @@ typedef struct {
 # define GC_HAS_DEBUG_INFO(p) (GC_has_other_debug_info(p) > 0)
 #endif
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* _DBG_MLC_H */
index d44b5998752ec4acb479b986f72f28d286a6c3f7..03889febfd782d75f7ab0f4c2b39e686d14ecc6d 100644 (file)
 #ifndef GC_HEADERS_H
 #define GC_HEADERS_H
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
-
-typedef struct hblkhdr hdr;
-
 #if CPP_WORDSZ != 32 && CPP_WORDSZ < 36
 # error Get a real machine
 #endif
 
+EXTERN_C_BEGIN
+
+typedef struct hblkhdr hdr;
+
 /*
  * The 2 level tree data structure that is used to find block headers.
  * If there are more than 32 bits in a pointer, the top level is a hash
@@ -211,8 +209,6 @@ typedef struct bi {
 /* h.  Assumes hhdr == HDR(h) and IS_FORWARDING_ADDR(hhdr).             */
 #define FORWARDED_ADDR(h, hhdr) ((struct hblk *)(h) - (size_t)(hhdr))
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* GC_HEADERS_H */
index fad4ad2d9909e5d73f0b293ea0f1770ff8f13456..15da91bb2a3ebee5c316aaf684c587170c812392 100644 (file)
@@ -33,9 +33,7 @@
 #    include <th/PCR_Th.h>
 #  endif
 
-#  ifdef __cplusplus
-     extern "C" {
-#  endif
+   EXTERN_C_BEGIN
 
 #  ifdef PCR
      GC_EXTERN PCR_Th_ML GC_allocate_ml;
 #  endif
 
 #  if defined(GC_WIN32_THREADS) && !defined(USE_PTHREAD_LOCKS)
-#    ifdef __cplusplus
-       } /* extern "C" */
-#    endif
 #    ifndef WIN32_LEAN_AND_MEAN
 #      define WIN32_LEAN_AND_MEAN 1
 #    endif
 #    define NOSERVICE
+     EXTERN_C_END
 #    include <windows.h>
-#    ifdef __cplusplus
-       extern "C" {
-#    endif
+     EXTERN_C_BEGIN
 #    define NO_THREAD (DWORD)(-1)
      GC_EXTERN CRITICAL_SECTION GC_allocate_ml;
 #    ifdef GC_ASSERTIONS
 #      define UNCOND_UNLOCK() LeaveCriticalSection(&GC_allocate_ml)
 #    endif /* !GC_ASSERTIONS */
 #  elif defined(GC_PTHREADS)
-#    ifdef __cplusplus
-       } /* extern "C" */
-#    endif
+     EXTERN_C_END
 #    include <pthread.h>
-#    ifdef __cplusplus
-       extern "C" {
-#    endif
+     EXTERN_C_BEGIN
      /* Posix allows pthread_t to be a struct, though it rarely is.     */
      /* Unfortunately, we need to use a pthread_t to index a data       */
      /* structure.  It also helps if comparisons don't involve a        */
                 /* != NUMERIC_THREAD_ID(pthread_self()) for any thread */
 
 #    ifdef SN_TARGET_PSP2
-#      ifdef __cplusplus
-         } /* extern "C" */
-#      endif
+       EXTERN_C_END
 #      include "psp2-support.h"
-#      ifdef __cplusplus
-         extern "C" {
-#      endif
+       EXTERN_C_BEGIN
        GC_EXTERN WapiMutex GC_allocate_ml_PSP2;
 #      define UNCOND_LOCK() { int res; GC_ASSERT(I_DONT_HOLD_LOCK()); \
                               res = PSP2_MutexLock(&GC_allocate_ml_PSP2); \
 #      endif
 #    endif /* THREAD_LOCAL_ALLOC || USE_PTHREAD_LOCKS */
 #    ifdef USE_PTHREAD_LOCKS
-#      ifdef __cplusplus
-         } /* extern "C" */
-#      endif
+       EXTERN_C_END
 #      include <pthread.h>
-#      ifdef __cplusplus
-         extern "C" {
-#      endif
+       EXTERN_C_BEGIN
        GC_EXTERN pthread_mutex_t GC_allocate_ml;
 #      ifdef GC_ASSERTIONS
 #        define UNCOND_LOCK() { GC_ASSERT(I_DONT_HOLD_LOCK()); \
 #    endif
 #  endif
 
-#  ifdef __cplusplus
-     } /* extern "C" */
-#  endif
+   EXTERN_C_END
 
 # else /* !THREADS */
 #   define LOCK() (void)0
index aad245c884fc79be6299604c00d2649f62db6831..1a8841dfeef9ee67f186301fabdf33d75aab90b2 100644 (file)
@@ -48,9 +48,7 @@
 # include "gc_priv.h"
 #endif
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /* The real declarations of the following is in gc_priv.h, so that      */
 /* we can avoid scanning the following table.                           */
@@ -482,8 +480,6 @@ typedef int mark_state_t;       /* Current state of marking, as follows:*/
 
 GC_EXTERN mark_state_t GC_mark_state;
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif  /* GC_PMARK_H */
index 393aec525c1bdf7a13a7eff8d6f7ac4c5e923b5a..002945c1e29be6840b19e121565e29978b7066cd 100644 (file)
@@ -326,10 +326,7 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
                     /* This is now really controlled at startup,        */
                     /* through GC_all_interior_pointers.                */
 
-/* Note: never put extern "C" around an #include.                       */
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 #ifndef GC_NO_FINALIZATION
 # define GC_INVOKE_FINALIZERS() GC_notify_or_invoke_finalizers()
@@ -420,9 +417,7 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
   GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]);
 #endif
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 /*********************************/
 /*                               */
@@ -460,14 +455,10 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
 # define MS_TIME_DIFF(a,b) ((long)((a)-(b)))
 #elif defined(NN_PLATFORM_CTR)
 # define CLOCK_TYPE long long
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
   CLOCK_TYPE n3ds_get_system_tick(void);
   CLOCK_TYPE n3ds_convert_tick_to_ms(CLOCK_TYPE tick);
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 # define GET_TIME(x) (void)(x = n3ds_get_system_tick())
 # define MS_TIME_DIFF(a,b) ((long)n3ds_convert_tick_to_ms((a)-(b)))
 #else /* !BSD_TIME && !NN_PLATFORM_CTR && !MSWIN32 && !MSWINCE */
@@ -525,9 +516,7 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
 # include "th/PCR_ThCtl.h"
 #endif
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /*
  * Stop and restart mutator threads.
@@ -673,9 +662,7 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc;
 # define GETENV(name) getenv(name)
 #endif
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #if defined(DARWIN)
 # include <mach/thread_status.h>
@@ -762,9 +749,7 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc;
 
 #include <setjmp.h>
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /*********************************/
 /*                               */
@@ -2627,13 +2612,9 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
 #if (defined(UNIX_LIKE) || (defined(NEED_FIND_LIMIT) && defined(CYGWIN32))) \
     && !defined(GC_NO_SIGSETJMP)
 # if defined(SUNOS5SIGS) && !defined(FREEBSD) && !defined(LINUX)
-#   ifdef __cplusplus
-      } /* extern "C" */
-#   endif
+    EXTERN_C_END
 #   include <sys/siginfo.h>
-#   ifdef __cplusplus
-      extern "C" {
-#   endif
+    EXTERN_C_BEGIN
 # endif
   /* Define SETJMP and friends to be the version that restores  */
   /* the signal mask.                                           */
@@ -2660,13 +2641,9 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
 #endif
 
 #if defined(DATASTART_USES_BSDGETDATASTART)
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 # include <machine/trap.h>
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
 # if !defined(PCR)
 #   define NEED_FIND_LIMIT
 # endif
@@ -2725,8 +2702,6 @@ GC_INNER ptr_t GC_store_debug_info(ptr_t p, word sz, const char *str,
 # define ASSERT_CANCEL_DISABLED() (void)0
 #endif /* !CANCEL_SAFE */
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* GC_PRIVATE_H */
index bd4867f7c0415722f9672b26fae9de73a995aa35..408318c3654f9fddddf0b1598da74fe014584299 100644 (file)
 /* around #includes.  Types and macros do not need such wrapping, only  */
 /* the declared global data and functions.                              */
 #ifdef __cplusplus
-  extern "C" {
+# define EXTERN_C_BEGIN extern "C" {
+# define EXTERN_C_END } /* extern "C" */
+#else
+# define EXTERN_C_BEGIN /* empty */
+# define EXTERN_C_END /* empty */
 #endif
 
+EXTERN_C_BEGIN
+
 /* Convenient internal macro to test version of Clang.  */
 #if defined(__clang__) && defined(__clang_major__)
 # define GC_CLANG_PREREQ(major, minor) \
 /* And one for Darwin: */
 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
 #   define DARWIN
-#   ifdef __cplusplus
-      } /* extern "C" */
-#   endif
+    EXTERN_C_END
 #   include <TargetConditionals.h>
-#   ifdef __cplusplus
-      extern "C" {
-#   endif
+    EXTERN_C_BEGIN
 # endif
 
 /* Determine the machine type: */
 # endif
 # if (defined(sun) || defined(__sun)) && (defined(sparc) || defined(__sparc))
             /* Test for SunOS 5.x */
-#   ifdef __cplusplus
-      } /* extern "C" */
-#   endif
+    EXTERN_C_END
 #   include <errno.h>
-#   ifdef __cplusplus
-      extern "C" {
-#   endif
+    EXTERN_C_BEGIN
 #   define SPARC
 #   define SOLARIS
 #   define mach_type_known
 #       define MPROTECT_VDB
 #       ifdef __ELF__
 #         define DYNAMIC_LOADING
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <features.h>
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #         if defined(__GLIBC__) && __GLIBC__ >= 2
 #           define SEARCH_FOR_DATA_START
 #         else /* !GLIBC2 */
 #   endif
 #   ifdef MACOS
 #     ifndef __LOWMEM__
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <LowMem.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #     endif
 #     define OS_TYPE "MACOS"
                 /* see os_dep.c for details of global data segments. */
 #   ifdef MACOS
 #     define ALIGNMENT 2  /* Still necessary?  Could it be 4?   */
 #     ifndef __LOWMEM__
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <LowMem.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #     endif
 #     define OS_TYPE "MACOS"
                         /* see os_dep.c for details of global data segments. */
 #     define DATAEND   ((ptr_t)get_end())
 #     define USE_MMAP_ANON
 #     define MPROTECT_VDB
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)getpagesize()
 #     if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
         /* The performance impact of prefetches is untested */
 #     define OS_TYPE "OPENBSD"
 #     define ALIGNMENT 4
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
         /* USRSTACK is defined in <machine/vmparam.h> but that is       */
         /* protected by _KERNEL in <uvm/uvm_param.h> file.              */
 #       ifdef USRSTACK
         /* Apparently USRSTACK is defined to be USERLIMIT, but in some  */
         /* installations that's undefined.  We work around this with a  */
         /* gross hack:                                                  */
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/vmparam.h>
 #       include <unistd.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USERLIMIT
           /* This should work everywhere, but doesn't.  */
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #   ifdef OPENBSD
 #     define OS_TYPE "OPENBSD"
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USRSTACK
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       else
 #   endif
 #   ifdef HAIKU
 #     define OS_TYPE "HAIKU"
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <OS.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)B_PAGE_SIZE
       extern int etext[];
 #     define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
         /* Apparently USRSTACK is defined to be USERLIMIT, but in some  */
         /* installations that's undefined.  We work around this with a  */
         /* gross hack:                                                  */
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/vmparam.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USERLIMIT
           /* This should work everywhere, but doesn't.  */
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       define DATAEND ((ptr_t)(&_end))
 #       define STACK_GROWS_DOWN
 #       define HEURISTIC2
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <unistd.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE)
 #       define DYNAMIC_LOADING
 #       ifndef USE_MMAP
                 /* thus allowing the heap to grow to ~3GB               */
 #       ifdef __ELF__
 #           define DYNAMIC_LOADING
-#           ifdef __cplusplus
-              } /* extern "C" */
-#           endif
+            EXTERN_C_END
 #           include <features.h>
-#           ifdef __cplusplus
-              extern "C" {
-#           endif
+            EXTERN_C_BEGIN
 #            if defined(__GLIBC__) && __GLIBC__ >= 2 \
                 || defined(HOST_ANDROID) || defined(HOST_TIZEN)
 #                define SEARCH_FOR_DATA_START
 #       if defined(__GLIBC__) && !defined(__UCLIBC__)
           /* Workaround lock elision implementation for some glibc.     */
 #         define GLIBC_2_19_TSX_BUG
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <gnu/libc-version.h> /* for gnu_get_libc_version() */
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #       endif
 #   endif
 #   ifdef CYGWIN32
 #   endif
 #   ifdef DJGPP
 #       define OS_TYPE "DJGPP"
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include "stubinfo.h"
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
         extern int etext[];
         extern int _stklen;
         extern int __djgpp_stack_limit;
 #   ifdef OPENBSD
 #       define OS_TYPE "OPENBSD"
 #       ifndef GC_OPENBSD_THREADS
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <sys/param.h>
 #         include <uvm/uvm_extern.h>
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #         ifdef USRSTACK
 #           define STACKBOTTOM ((ptr_t)USRSTACK)
 #         else
 #   endif
 #   ifdef RTEMS
 #       define OS_TYPE "RTEMS"
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/unistd.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
         extern int etext[];
         extern int end[];
         void *rtems_get_stack_bottom(void);
 #     define STACKBOTTOM ((ptr_t)0xc0000000)
 #     define USE_MMAP_ANON
 #     define MPROTECT_VDB
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)getpagesize()
       /* There seems to be some issues with trylock hanging on darwin.  */
       /* This should be looked into some more.                          */
 #     define OS_TYPE "OPENBSD"
 #     define ALIGNMENT 4
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USRSTACK
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       else
 #       define STACKBOTTOM ((ptr_t)environ)
 #     endif
 #     define DYNAMIC_LOADING
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)sysconf(_SC_PAGE_SIZE)
 #     ifndef __GNUC__
 #       define PREFETCH(x)  do { \
 #  ifdef OPENBSD
 #     define OS_TYPE "OPENBSD"
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USRSTACK
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       else
 #       define OS_TYPE "OPENBSD"
 #       define ELF_CLASS ELFCLASS64
 #       ifndef GC_OPENBSD_THREADS
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <sys/param.h>
 #         include <uvm/uvm_extern.h>
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #         ifdef USRSTACK
 #           define STACKBOTTOM ((ptr_t)USRSTACK)
 #         else
 #       define STACKBOTTOM ((ptr_t)environ)
 #       define HPUX_STACKBOTTOM
 #       define DYNAMIC_LOADING
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <unistd.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       define GETPAGESIZE() (unsigned)sysconf(_SC_PAGE_SIZE)
         /* The following was empirically determined, and is probably    */
         /* not very robust.                                             */
 #           define CLEAR_DOUBLE(x) \
               __asm__ ("        stf.spill       [%0]=f0": : "r"((void *)(x)))
 #         else
-#           ifdef __cplusplus
-              } /* extern "C" */
-#           endif
+            EXTERN_C_END
 #           include <ia64intrin.h>
-#           ifdef __cplusplus
-              extern "C" {
-#           endif
+            EXTERN_C_BEGIN
 #           define PREFETCH(x) __lfetch(__lfhint_none, (x))
 #           define GC_PREFETCH_FOR_WRITE(x) __lfetch(__lfhint_nta, (x))
 #           define CLEAR_DOUBLE(x) __stf_spill((void *)(x), 0)
 #     define STACKBOTTOM ((ptr_t)0x16fdfffff)
 #     define USE_MMAP_ANON
 #     define MPROTECT_VDB
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)getpagesize()
       /* FIXME: There seems to be some issues with trylock hanging on   */
       /* darwin. This should be looked into some more.                  */
 #       define STACK_GRAN 0x10000000
 #       ifdef __ELF__
 #           define DYNAMIC_LOADING
-#           ifdef __cplusplus
-              } /* extern "C" */
-#           endif
+            EXTERN_C_END
 #           include <features.h>
-#           ifdef __cplusplus
-              extern "C" {
-#           endif
-#            if defined(__GLIBC__) && __GLIBC__ >= 2 \
+            EXTERN_C_BEGIN
+#           if defined(__GLIBC__) && __GLIBC__ >= 2 \
                 || defined(HOST_ANDROID) || defined(HOST_TIZEN)
 #                define SEARCH_FOR_DATA_START
-#            else
+#           else
                  extern char **__environ;
 #                define DATASTART ((ptr_t)(&__environ))
                               /* hideous kludge: __environ is the first */
                               /* would include .rodata, which may       */
                               /* contain large read-only data tables    */
                               /* that we'd rather not scan.             */
-#            endif
-             extern int _end[];
-#            define DATAEND ((ptr_t)(_end))
+#           endif
+            extern int _end[];
+#           define DATAEND ((ptr_t)(_end))
 #       else
-             extern int etext[];
-#            define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
+            extern int etext[];
+#           define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
 #       endif
 #   endif
 #   ifdef MSWINCE
 #     define STACKBOTTOM ((ptr_t)0x30000000)
 #     define USE_MMAP_ANON
 #     define MPROTECT_VDB
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)getpagesize()
       /* FIXME: There seems to be some issues with trylock hanging on   */
       /* darwin. This should be looked into some more.                  */
 #   ifdef OPENBSD
 #     define OS_TYPE "OPENBSD"
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USRSTACK
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       else
 #   ifdef OPENBSD
 #     define OS_TYPE "OPENBSD"
 #     ifndef GC_OPENBSD_THREADS
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/param.h>
 #       include <uvm/uvm_extern.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USRSTACK
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       else
 #   ifdef SN_TARGET_ORBIS
 #     define DATASTART (ptr_t)ALIGNMENT
 #     define DATAEND (ptr_t)ALIGNMENT
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <pthread.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
       void *ps4_get_stack_bottom(void);
 #     define STACKBOTTOM ((ptr_t)ps4_get_stack_bottom())
 #   endif
 #       define OS_TYPE "OPENBSD"
 #       define ELF_CLASS ELFCLASS64
 #       ifndef GC_OPENBSD_THREADS
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <sys/param.h>
 #         include <uvm/uvm_extern.h>
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #         ifdef USRSTACK
 #           define STACKBOTTOM ((ptr_t)USRSTACK)
 #         else
 #       endif
 #       ifdef __ELF__
 #           define DYNAMIC_LOADING
-#           ifdef __cplusplus
-              } /* extern "C" */
-#           endif
+            EXTERN_C_END
 #           include <features.h>
-#           ifdef __cplusplus
-              extern "C" {
-#           endif
+            EXTERN_C_BEGIN
 #           define SEARCH_FOR_DATA_START
             extern int _end[];
 #           define DATAEND ((ptr_t)(_end))
 #       if defined(__GLIBC__) && !defined(__UCLIBC__)
           /* Workaround lock elision implementation for some glibc.     */
 #         define GLIBC_2_19_TSX_BUG
-#         ifdef __cplusplus
-            } /* extern "C" */
-#         endif
+          EXTERN_C_END
 #         include <gnu/libc-version.h> /* for gnu_get_libc_version() */
-#         ifdef __cplusplus
-            extern "C" {
-#         endif
+          EXTERN_C_BEGIN
 #       endif
 #   endif
 #   ifdef DARWIN
 #     define STACKBOTTOM ((ptr_t)0x7fff5fc00000)
 #     define USE_MMAP_ANON
 #     define MPROTECT_VDB
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <unistd.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)getpagesize()
       /* There seems to be some issues with trylock hanging on darwin.  */
       /* This should be looked into some more.                          */
 #   endif
 #   ifdef HAIKU
 #     define OS_TYPE "HAIKU"
-#     ifdef __cplusplus
-        } /* extern "C" */
-#     endif
+      EXTERN_C_END
 #     include <OS.h>
-#     ifdef __cplusplus
-        extern "C" {
-#     endif
+      EXTERN_C_BEGIN
 #     define GETPAGESIZE() (unsigned)B_PAGE_SIZE
 #     define HEURISTIC2
 #     define SEARCH_FOR_DATA_START
         /* Apparently USRSTACK is defined to be USERLIMIT, but in some  */
         /* installations that's undefined.  We work around this with a  */
         /* gross hack:                                                  */
-#       ifdef __cplusplus
-          } /* extern "C" */
-#       endif
+        EXTERN_C_END
 #       include <sys/vmparam.h>
-#       ifdef __cplusplus
-          extern "C" {
-#       endif
+        EXTERN_C_BEGIN
 #       ifdef USERLIMIT
           /* This should work everywhere, but doesn't.  */
 #         define STACKBOTTOM ((ptr_t)USRSTACK)
 #       define MPROTECT_VDB
 #       ifdef __ELF__
 #           define DYNAMIC_LOADING
-#           ifdef __cplusplus
-              } /* extern "C" */
-#           endif
+            EXTERN_C_END
 #           include <features.h>
-#           ifdef __cplusplus
-              extern "C" {
+            EXTERN_C_BEGIN
+#           if defined(__GLIBC__) && __GLIBC__ >= 2
+#               define SEARCH_FOR_DATA_START
+#           else
+#               error --> unknown Hexagon libc configuration
 #           endif
-#            if defined(__GLIBC__) && __GLIBC__ >= 2
-#                define SEARCH_FOR_DATA_START
-#            else
-#                error --> unknown Hexagon libc configuration
-#            endif
-             extern int _end[];
-#            define DATAEND ((ptr_t)(_end))
+            extern int _end[];
+#           define DATAEND ((ptr_t)(_end))
 #       elif !defined(CPPCHECK)
-#            error --> bad Hexagon Linux configuration
+#           error --> bad Hexagon Linux configuration
 #       endif
 #   else
 #       error --> unknown Hexagon OS configuration
 
 #if (defined(SVR4) || defined(HOST_ANDROID) || defined(HOST_TIZEN)) \
     && !defined(GETPAGESIZE)
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 # include <unistd.h>
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE)
 #endif
 
 #ifndef GETPAGESIZE
 # if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
      || defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
-#   ifdef __cplusplus
-      } /* extern "C" */
-#   endif
+    EXTERN_C_END
 #   include <unistd.h>
-#   ifdef __cplusplus
-      extern "C" {
-#   endif
+    EXTERN_C_BEGIN
 # endif
 # define GETPAGESIZE() (unsigned)getpagesize()
 #endif
 #endif
 
 #ifdef GC_OPENBSD_THREADS
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 # include <sys/param.h>
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
   /* Prior to 5.2 release, OpenBSD had user threads and required        */
   /* special handling.                                                  */
 # if OpenBSD < 201211
 # endif
 #endif /* GC_PRIVATE_H */
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* GCCONFIG_H */
index 2293aada0f8de83a78e7f49ba6b74ca02d5496a5..080b682c49a7cdfd09385fcfd11ca035a6ac4955 100644 (file)
 #ifndef GC_PTHREAD_STOP_WORLD_H
 #define GC_PTHREAD_STOP_WORLD_H
 
-/* Note: never put extern "C" around an #include.                       */
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 struct thread_stop_info {
 #   if !defined(GC_OPENBSD_UTHREADS) && !defined(NACL)
@@ -51,8 +48,6 @@ struct thread_stop_info {
 
 GC_INNER void GC_stop_init(void);
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif
index 57a6cd90606a1a177ef2dc2f621562138dedb037..8df6bc21f9d6b1b487bcf2f81183aad96dd0342e 100644 (file)
 # include "dbg_mlc.h" /* for oh type */
 #endif
 
-/* Note: never put extern "C" around an #include.                       */
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /* We use the allocation lock to protect thread-related data structures. */
 
@@ -184,9 +181,7 @@ GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread(
                                         struct GC_stack_base *sb, void *arg);
 GC_INNER_PTHRSTART void GC_thread_exit_proc(void *);
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* GC_PTHREADS && !GC_WIN32_THREADS */
 
index 1367a25218eac80b24c417c0e6a20ea4232752d5..1cc1f6b00fe091f93c34c425f70f2fd77e378abc 100644 (file)
 
 #include <errno.h>
 
-/* Note: never put extern "C" around an #include.       */
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /* Called during key creation or setspecific.           */
 /* For the GC we already hold lock.                     */
@@ -103,6 +100,4 @@ GC_INLINE void * GC_getspecific(tsd * key)
     return GC_slow_getspecific(key, qtid, entry_ptr);
 }
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
index 268e3ec2e7c0fc2e28176625fac201bab07ab685..e01133dea3e929d48a639f83b9648c6afabea2f4 100644 (file)
 
 #include <stdlib.h>
 
-/* Note: never put extern "C" around an #include.               */
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 #if !defined(USE_PTHREAD_SPECIFIC) && !defined(USE_WIN32_SPECIFIC) \
     && !defined(USE_WIN32_COMPILER_TLS) && !defined(USE_COMPILER_TLS) \
@@ -134,17 +131,13 @@ typedef struct thread_local_freelists {
 # define GC_remove_specific_after_fork(key, t) (void)0
   typedef void * GC_key_t;
 #elif defined(USE_WIN32_SPECIFIC)
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
 # ifndef WIN32_LEAN_AND_MEAN
 #   define WIN32_LEAN_AND_MEAN 1
 # endif
 # define NOSERVICE
+  EXTERN_C_END
 # include <windows.h>
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
 # define GC_getspecific TlsGetValue
 # define GC_setspecific(key, v) !TlsSetValue(key, v)
         /* We assume 0 == success, msft does the opposite.      */
@@ -159,13 +152,9 @@ typedef struct thread_local_freelists {
 # define GC_remove_specific_after_fork(key, t) (void)0
   typedef DWORD GC_key_t;
 #elif defined(USE_CUSTOM_SPECIFIC)
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 # include "private/specific.h"
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
 #else
 # error implement me
 #endif
@@ -208,9 +197,7 @@ extern
 /* for cleanup on thread exit.  But the thread support layer makes sure */
 /* that GC_thread_key is traced, if necessary.                          */
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 #endif /* THREAD_LOCAL_ALLOC */
 
index f7369ac26138e95d5e8deb2e2a63148f29c018f1..1cd4e89048a66ebddf9e1455f81bd8c6cdc97221 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -3914,9 +3914,7 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
 #include <mach/task.h>
 #include <pthread.h>
 
-#ifdef __cplusplus
-  extern "C" {
-#endif
+EXTERN_C_BEGIN
 
 /* Some of the following prototypes are missing in any header, although */
 /* they are documented.  Some are in mach/exc.h file.                   */
@@ -3961,9 +3959,7 @@ catch_exception_raise_state_identity(mach_port_name_t exception_port,
                 int flavor, thread_state_t old_state, int old_stateCnt,
                 thread_state_t new_state, int new_stateCnt);
 
-#ifdef __cplusplus
-  } /* extern "C" */
-#endif
+EXTERN_C_END
 
 /* These should never be called, but just in case...  */
 GC_API_OSCALL kern_return_t
index 452ad7200fe922b81cc9f357fb5ff6d6117efd96..a05358fe9a6ac8ad5a2abd39e2b3333d92edbee6 100644 (file)
@@ -213,14 +213,9 @@ volatile AO_t extra_count = 0;  /* Amount of space wasted in cons node; */
                                 /* chktree (for other purposes).        */
 
 #if defined(GC_AMIGA_FASTALLOC) && defined(AMIGA)
-
-# ifdef __cplusplus
-    extern "C" {
-# endif
+  EXTERN_C_BEGIN
   void GC_amiga_free_all_mem(void);
-# ifdef __cplusplus
-    } /* extern "C" */
-# endif
+  EXTERN_C_END
 
   void Amiga_Fail(void){GC_amiga_free_all_mem();abort();}
 # define FAIL Amiga_Fail()