]> granicus.if.org Git - gc/commitdiff
Enable staticrootstest for the case of GC shared library build
authorIvan Maidanski <ivmai@mail.ru>
Sat, 4 May 2013 09:56:34 +0000 (13:56 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 4 May 2013 09:56:34 +0000 (13:56 +0400)
* tests/staticrootslib.c (GC_TEST_EXPORT_API): New macro (defined to
set GCC default visibility attribute if GC_VISIBILITY_HIDDEN_SET
unless Win32).
* tests/staticrootslib.c (root): Remove unused global variable.
* tests/staticrootslib.c (libsrl_mktree, libsrl_init): Decorate with
GC_TEST_EXPORT_API.
* tests/staticrootstest.c (GC_VISIBILITY_HIDDEN_SET): Do not check (do
not skip the test).
* tests/staticrootstest.c (GC_TEST_IMPORT_API): New macro.
* tests/staticrootstest.c (root): Explicitly specify zero initializer.
* tests/staticrootstest.c (libsrl_mktree, libsrl_init): Decorate with
GC_TEST_IMPORT_API.
* tests/staticrootstest.c (mktree, main): Remove commented out code.
* tests/staticrootstest.c (main): Avoid code duplication.
* tests/tests.am (staticrootstest_LDADD, check_LTLIBRARIES,
libstaticrootslib_la): Rename libstaticrootslib to
libstaticrootslib_test.

tests/staticrootslib.c
tests/staticrootstest.c
tests/tests.am

index 2a8fcd49cd5f8ccd170fe789ed8074a8996defcd..c80d79ccbbf2316c0802a1d64e0d8d93b0aba12a 100644 (file)
@@ -9,12 +9,22 @@
 
 #include "gc.h"
 
+#ifndef GC_TEST_EXPORT_API
+# if defined(GC_VISIBILITY_HIDDEN_SET) \
+     && !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+#   define GC_TEST_EXPORT_API \
+                        extern __attribute__((__visibility__("default")))
+# else
+#   define GC_TEST_EXPORT_API extern
+# endif
+#endif
+
 struct treenode {
     struct treenode *x;
     struct treenode *y;
-} * root[10];
+};
 
-struct treenode * libsrl_mktree(int i)
+GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i)
 {
   struct treenode * r = GC_MALLOC(sizeof(struct treenode));
   if (0 == i) return 0;
@@ -26,7 +36,7 @@ struct treenode * libsrl_mktree(int i)
   return r;
 }
 
-void * libsrl_init(void)
+GC_TEST_EXPORT_API void * libsrl_init(void)
 {
   GC_INIT();
   return GC_MALLOC(sizeof(struct treenode));
index 5d5cb3ebb755c039bcedda7d05c37622717ad13a..162f02b27258b8ce251d9d04a8ca2473d8577180 100644 (file)
@@ -9,33 +9,27 @@
 #include "gc.h"
 #include "gc_backptr.h"
 
-#ifndef GC_VISIBILITY_HIDDEN_SET
+#ifndef GC_TEST_IMPORT_API
+# define GC_TEST_IMPORT_API extern
+#endif
 
+/* Should match that in staticrootslib.c.       */
 struct treenode {
     struct treenode *x;
     struct treenode *y;
-} * root[10];
+};
 
-static char *staticroot = 0;
+struct treenode *root[10] = { NULL };
 
-extern struct treenode * libsrl_mktree(int i);
-extern void * libsrl_init(void);
+static char *staticroot = 0;
 
-/*
-struct treenode * mktree(int i) {
-  struct treenode * r = GC_MALLOC(sizeof(struct treenode));
-  if (0 == i) return 0;
-  if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
-  r -> x = mktree(i-1);
-  r -> y = mktree(i-1);
-  return r;
-}*/
+GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i);
+GC_TEST_IMPORT_API void * libsrl_init(void);
 
 int main(void)
 {
-  int i;
-  /*GC_INIT();
-  staticroot = GC_MALLOC(sizeof(struct treenode));*/
+  int i, j;
+
   staticroot = libsrl_init();
   if (NULL == staticroot) {
     fprintf(stderr, "GC_malloc returned NULL\n");
@@ -43,37 +37,17 @@ int main(void)
   }
   memset(staticroot, 0x42, sizeof(struct treenode));
   GC_gcollect();
-  for (i = 0; i < 10; ++i) {
-    root[i] = libsrl_mktree(12);
-    GC_gcollect();
+  for (j = 0; j < 2; j++) {
+      for (i = 0; i < 10; ++i) {
+        root[i] = libsrl_mktree(12);
+        GC_gcollect();
+      }
+      for (i = 0; i < (int)sizeof(struct treenode); ++i) {
+        if (staticroot[i] != 0x42) {
+          fprintf(stderr, "Memory check failed\n");
+          return -1;
+        }
+      }
   }
-  for (i = 0; i < (int)sizeof(struct treenode); ++i) {
-    if (staticroot[i] != 0x42) {
-      fprintf(stderr, "Memory check failed\n");
-      return -1;
-    }
-  }
-  for (i = 0; i < 10; ++i) {
-    root[i] = libsrl_mktree(12);
-    GC_gcollect();
-  }
-  for (i = 0; i < (int)sizeof(struct treenode); ++i) {
-    if (staticroot[i] != 0x42) {
-      fprintf(stderr, "Memory check failed\n");
-      return -1;
-    }
-  }
-  return 0;
-}
-
-#else
-
-/* Skip since symbols defined in staticrootslib are not visible */
-
-int main(void)
-{
-  printf("staticrootstest skipped\n");
   return 0;
 }
-
-#endif
index 85999ecdb90673de231a4b96a1ae17b30ac62970..b63e0b3070628ee666070dac255ddc51ebfd743b 100644 (file)
@@ -48,12 +48,13 @@ realloc_test_LDADD = $(test_ldadd)
 TESTS += staticrootstest$(EXEEXT)
 check_PROGRAMS += staticrootstest
 staticrootstest_SOURCES = tests/staticrootstest.c
-staticrootstest_LDADD = $(test_ldadd) libstaticrootslib.la
-check_LTLIBRARIES += libstaticrootslib.la
-libstaticrootslib_la_SOURCES = tests/staticrootslib.c
-libstaticrootslib_la_LIBADD = $(test_ldadd)
-libstaticrootslib_la_LDFLAGS = -version-info 1:3:0 -no-undefined -rpath /nowhere
-libstaticrootslib_la_DEPENDENCIES = $(top_builddir)/libgc.la
+staticrootstest_LDADD = $(test_ldadd) libstaticrootslib_test.la
+check_LTLIBRARIES += libstaticrootslib_test.la
+libstaticrootslib_test_la_SOURCES = tests/staticrootslib.c
+libstaticrootslib_test_la_LIBADD = $(test_ldadd)
+libstaticrootslib_test_la_LDFLAGS = -version-info 1:3:0 -no-undefined \
+                                    -rpath /nowhere
+libstaticrootslib_test_la_DEPENDENCIES = $(top_builddir)/libgc.la
 
 if KEEP_BACK_PTRS
 TESTS += tracetest$(EXEEXT)