Subject: Conflicting declarations of GC_is_heap_ptr

From: Sören Jonsson <[email-masked]>
Date: Thu, 25 Apr 2019 08:20:31 +0200

Hello,

I'm working on building guile 2.2.4 for Cygwin/Windows. I have now 
resolved a couple of library issues, and have run into a problem with 
conflicting declarations.

Environment:

    Cygwin

    $ gcc --version
    gcc (GCC) 7.4.0
    Copyright © 2017 Free Software Foundation, Inc.

    guile-2.2.4

    gc-8.0.4

Error message:

    make  all-am
    make[3]: Entering directory '/tmp/guile-2.2.4/libguile'
       CC       guile-guile.o
    In file included from ../libguile.h:81:0,
                      from guile.c:34:
    ../libguile/pairs.h:182:1: error: conflicting types for 'GC_is_heap_ptr'
      GC_is_heap_ptr (void *ptr)
      ^~~~~~~~~~~~~~
    In file included from ../libguile/bdw-gc.h:47:0,
                      from ../libguile/gc.h:156,
                      from ../libguile/atomic.h:25,
                      from ../libguile.h:37,
                      from guile.c:34:
    /usr/local/include/gc/gc.h:551:20: note: previous declaration of
    'GC_is_heap_ptr' was here
      GC_API int GC_CALL GC_is_heap_ptr(const void *);
                         ^~~~~~~~~~~~~~
    make[3]: *** [Makefile:3575: guile-guile.o] Error 1
    make[3]: Leaving directory '/tmp/guile-2.2.4/libguile'

Analysis:

    This appears to be a simple problem with the the function
    GC_is_heap_ptr declared in two different ways in two different
    files: /usr/local/include/gc/gc.h.156 and
    /tmp/guile/2.2.4/libguile/pairs.h. The first file declares it as
    "GC_API int GC_CALL GC_is_heap_ptr(const void *);", and the second
    as "static int
    GC_is_heap_ptr (void *ptr)
    {
       return GC_base (ptr) != NULL;
    }
    ".

Proposed solution:

    The obvious solution would be to surround the definition in
    libguile/pairs.h with a conditional #ifndef HAVE_GC_IS_HEAP_PTR, but
    i get the impression that libguile/pairs.h is auto-generated, so I
    might brake your code.  What would be your preferred solution?

With my best regards,

-- 
Sören Jonsson
Kärnvägen 237
906 27 UMEÅ
SWEDEN
Tel: 090-180 339, 070-603 3896