[mercury-users] Problem with linking bigger project (Mercury and C++)

Roy Ward rward at infoscience.otago.ac.nz
Mon Jan 7 11:46:29 AEDT 2002


>
>
>>TLinMem komplexne_inicializuj(int DBSTATE) {
>>    /* Inicializuje Mercury a pak Lingvistickou cast enta. */
>>    char dummy;
>>    TLinMem linmem;
>>
>>    printf("komplexne_inicializuj: spoustim Mercury\n");
>>
>>    /* Inicializace enginu Mercury */
>>    mercury_init(0, NULL, &dummy);
>>
>
>Declaring `char dummy' here is wrong.  `char dummy', whose address
>indicates the top-of-the-stack, should not be declared in a function
>which returns before the Mercury procedures are called.
>
>`char dummy' should be declared in main() [or some other function whose
>stack frame sticks around while the Mercury procedures are being called]
>and should be passed down to komplexne_inicializuj(), perhaps via a global
>variable.
>
OK, it's good to know what the dummy is used for.

How important are the other arguments to mercury_init? I don't have
the option of having Mercury at the top level for what I'm doing.

I'm trying to call Mercury from Java (going through C as glue), and I 
also get
a segmentation violation in mercury_init.

    /* lets get really paranoid about setting up some command line 
arguments */
    char* argvv[2];
    char dummy;
    argvv[0] = (char*)"java";
    argvv[1] = (char*)"java";
    mercury_init(1, argvv, &dummy); /* DIES IN HERE! */

    /* call the C function foo_test(), which is the interface */
    printf("foo_test(42) returns %s\n", foo_test(42) ? "TRUE" : "FALSE");

In my code,  I do the Mercury calls in the same function as the 
initialization,
so that is not the problem.

In fact, my calling C from Java (using JNI) works fine, calling Mercury from
C only works fine, but it blows up when I do Java->C->Mercury (and I haven't
yet found out how to get gdb going with Java, so I can't tell exactly where
the problem is).

My suspicion is that mercury_init does things that interact badly with the
Java (maybe having two garbage collectors running is a bad thing?).

Can anyone who knows about the internals of Mercury shed light on what the
problem might be, and is Java->C->Mercury likely to be even possible?

I can send or post a small sample that demonstrates this if anyone wants to
have a look (I'm not posting it now because I'd have to tidy it up to 
make it
smaller).

In desparation I tried to install one of the non-gc grades of Mercury to see
if it was a garbage collector conflict, but that doesn't even install.

Cheers,
Roy Ward.






--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list