[MLton] Shared libraries for MLton

Jens Axel Søgaard jensaxel@soegaard.net
Thu, 28 Jul 2005 18:14:17 +0200


Matthew Fluet wrote:
>>>>>    o NOTE: The first garbage collection provokes a crash, the
>>>>>            error is probably to be found here.

>>>>That is unfortunate.

>>>Indeed. Fixing it requires a bit more knowledge of the inner
>>>workings of MLton than I have at the moment, so I hope someone
>>>can point in the right direction.

>>As best I can make out, the problem is that the Thread_returnToC primitive 
>>does not leave the ML stack in a good state.  Apparently, we don't do as 
>>many assertions and don't make as many assumptions about the 
>>callFromCHandler thread as we do about the currentThread.  And, whatever 
>>bad state the callFromCHandler thread is in, it is fixed when transfering 
>>control to an _export-ed ML function before a GC occurs when the 
>>callFromCHandler thread as been switched to.

> Interestingly enough, if I add
> 
> 	GC_switchToThread (&gcState, gcState.callFromCHandler, 0);	\
> 
> to the end of init_function in c-main.h, then I can get Jens' example to 
> compile and run without any segfault.  As a bonus, this also works for the 
> bytecode codegen, though the native x86 codegen has a mysterious segfault 
> when trying to return to init_function.

Did you do more? If I add the above line, recompile mltin and then run 
the c-test I get:

   ...
   init_function> After main
   Call from C to SML raised exception.
   unhandled exception: Fail: Thread.atomicEnd with no atomicBegin


-- 
Jens Axel Søgaard