[MLton] Shared libraries for MLton
Matthew Fluet
fluet@cs.cornell.edu
Thu, 28 Jul 2005 16:17:27 -0400 (EDT)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
--1417689696-2050599397-1122581633=:14282
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.LNX.4.58.0507281617211.14282@lion.cs.cornell.edu>
> >>>>> o NOTE: The first garbage collection provokes a crash, the
> >>>>> error is probably to be found here.
>
> >>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
Yes, you need to modify basis-library/mlton/mlton.sml to inc the atomic
state before returning to C, since the thread switch will dec the atomic
state.
I've attached my current diff, based on your previous patch and following
my recent commit to regularize the names of _build_const constants.
--1417689696-2050599397-1122581633=:14282
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="shared-library.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.58.0507281613530.14282@lion.cs.cornell.edu>
Content-Description:
Content-Disposition: ATTACHMENT; FILENAME="shared-library.patch"
SW5kZXg6IGluY2x1ZGUvYy1tYWluLmgNCj09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT0NClJDUyBmaWxlOiAvY3Zzcm9vdC9tbHRvbi9tbHRvbi9pbmNsdWRlL2Mt
bWFpbi5oLHYNCnJldHJpZXZpbmcgcmV2aXNpb24gMS4xMw0KZGlmZiAtcjEu
MTMgYy1tYWluLmgNCjU5YzU5LDc4DQo8IH0NCi0tLQ0KPiB9ICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICBcDQo+IHZvaWQgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgIFwNCj4gIF9fYXR0cmlidXRlX18oKGNvbnN0cnVjdG9yKSkJCQkJCQlc
DQo+IGluaXRfZnVuY3Rpb24gKGludCBkdW1teSkgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwNCj4geyAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgXA0KPiAgICAgICAgIGludCBhcmdjPTE7ICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICBcDQo+ICAgICAgICAgdm9pZCAqYXJndlsyXTsgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwNCj4gCXN0
cnVjdCBjb250IGNvbnQ7CQkJCQkJXA0KPiAgICAgICAgIGFyZ3ZbMF0gPSAi
YmFyIjsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICBcDQo+ICAgICAgICAgYXJndlsxXSA9IE5VTEw7ICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwNCj4g
CUluaXRpYWxpemUgKGFsLCBtZywgbWZzLCBtbWMsIHBrLCBwcyk7CQkJC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PT09PQ0KUkNTIGZpbGU6IC9jdnNyb290L21sdG9uL21sdG9uL21sdG9u
L21haW4vbWFpbi5mdW4sdg0KcmV0cmlldmluZyByZXZpc2lvbiAxLjk2DQpk
aWZmIC1yMS45NiBtYWluLmZ1bg0KMzk3YTM5OCwzOTkNCj4gICAgICAgIChF
eHBlcnQsICJzaGFyZWQtbGlicmFyeSIsICIge2ZhbHNlfHRydWV9IiwNCj4g
ICAgICAgICAiZ2VuZXJhdGUgc2hhcmVkLWxpYnJhcnkiLCBib29sUmVmIENv
bnRyb2wuc2hhcmVkTGlicmFyeSksDQo=
--1417689696-2050599397-1122581633=:14282--