Fix mixed include of GC public header and gc_priv.h in disclaim bench/test
authorIvan Maidanski <ivmai@mail.ru>
Thu, 30 Mar 2017 19:06:09 +0000 (22:06 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 30 Mar 2017 19:06:09 +0000 (22:06 +0300)
Include gc_priv.h should be avoided in tests (if possible) or, at
least, this include should not precede include of the public GC
headers (because, e.g., gc_priv.h define GC_BUILD which influences
declspec of the GC public symbols in case of a shared library).

* tests/disclaim_bench.c: Move include gc_priv.h to be after
gc_disclaim.h; add comment .
* tests/disclaim_bench.c [HAVE_CONFIG_H]: Include "config.h" (before
include gc_disclaim.h).
* tests/disclaim_test.c [LINT2]: Do not include gc_priv.h; include
config.h instead.
* tests/disclaim_test.c [LINT2] (GC_API_PRIV): Define.
* tests/disclaim_test.c [LINT2] (GC_random): Declare the function
(instead of including gc_priv.h to get the prototype).

tests/disclaim_bench.c
tests/disclaim_test.c

index 298bac6..7ae1f3e 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-#include "private/gc_priv.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "gc_disclaim.h"
 
+/* Include gc_priv.h is done after including GC public headers, so      */
+/* that GC_BUILD has no effect on the public prototypes.                */
+#include "private/gc_priv.h" /* for CLOCK_TYPE and GC_random */
+
 #ifdef LINT2
 # undef rand
 # define rand() (int)GC_random()
index 73f82c5..b7c9201 100644 (file)
 #include <stdio.h>
 #include <string.h>
 
-#ifdef LINT2
-  /* For GC_random() */
-# include "private/gc_priv.h"
-# undef rand
-# define rand() (int)GC_random()
-#elif defined(HAVE_CONFIG_H)
+#ifdef HAVE_CONFIG_H
   /* For GC_[P]THREADS */
 # include "config.h"
 #endif
 #undef GC_NO_THREAD_REDIRECTS
 #include "gc_disclaim.h"
 
+#ifdef LINT2
+  /* Avoid include gc_priv.h. */
+# ifndef GC_API_PRIV
+#   define GC_API_PRIV GC_API
+# endif
+  GC_API_PRIV long GC_random(void);
+# undef rand
+# define rand() (int)GC_random()
+#endif /* LINT2 */
+
 #define my_assert(e) \
     if (!(e)) { \
         fflush(stdout); \