This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgc bug when using Gnu C nested functions


/*
This small program causes a libgc error when compiled and run in Cygwin:

$ gcc gcerror.c -lgc -o x.exe
$ ./x.exe
42
GC Warning: Thread stack pointer 0x22aa98 out of range, pushing everything
*/


#include <gc/gc.h>
#include <stdio.h>

void *dummy;

void f (void (*x)())
{
    x();
}

int main ()
{
    int i;

    void g ()
    {
        printf("%i\n", i);
    }

    i = 42;
    f(g);
    dummy = GC_MALLOC(10);

    return 0;
}

/*
The presence of a function call that is passed a pointer to
a Gnu C nested function with a closure seems to cause the problem:

* There is no error if:

        - i is global;
        - i is not used in g;
        - g is called normally (not passed to f);
        - f is not called;
        - GC_MALLOC is not called;
        - GC_MALLOC is replaced with malloc.

* There is still an error if:

        - f does not call g;
        - GC_MALLOC is called before f.

The bug also causes memory corruption when it occurs larger programs.

Programs with libgc and this construct always work correctly in Debian Stable.
*/


Attachment: cygcheck.out
Description: Text document

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]