Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#64] SML/NJ crashes when CML is used together with foreign code

Date:
2011-03-01 00:12
Priority:
3
State:
Open
Submitted by:
Bug Submitter (webuser)
Assigned to:
Matthias Blume (blume)
Machine Architecture:
x86
Operating System:
MacOS X
Component:
SML/NJ Library
Resolution:
None
Severity:
Minor
OS Version:
OS X 10.6.6
SML/NJ Version:
110.72
Keywords:
CML, FFI
URL:
Transcript (of reproduction):
Ivan-MacBook:test ivan$ gcc -m32 -O2 -std=c99 -Wall -Wextra -pedantic -c ctest.c Ivan-MacBook:test ivan$ libtool -dynamic -o ctest.so ctest.o -lc Ivan-MacBook:test ivan$ ml-nlffigen -dir FFI -cmfile test.cm -include ../library.sml ctest.c Ivan-MacBook:test ivan$ sml Standard ML of New Jersey v110.72 [built: Wed Jan 26 00:56:21 2011] - CM.make est.cm; [autoloading] [library $smlnj/cm/cm.cm is stable] [library $smlnj/internal/cm-sig-lib.cm is stable] [library $/pgraph.cm is stable] [library $smlnj/internal/srcpath-lib.cm is stable] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] [scanning test.cm] [library $c/c.cm is stable] [library $cml/cml.cm is stable] [scanning (test.cm):FFI/test.cm] [library $c/internals/c-int.cm is stable] [parsing (test.cm):FFI/(test.cm):f-init.sml] [creating directory FFI/.cm/SKEL] [parsing (test.cm):FFI/(test.cm):callop-0.sml] [parsing (test.cm):FFI/(test.cm):fptr-rtti-0.sml] [parsing (test.cm):FFI/(test.cm):../library.sml] [creating directory .cm/SKEL] [library $c/memory/memory.cm is stable] [parsing (test.cm):test.sml] [library $cml/cml-internal.cm is stable] [library $cml/core-cml.cm is stable] [compiling (test.cm):FFI/(test.cm):../library.sml] [creating directory .cm/GUID] [creating directory .cm/x86-unix] [code: 559, data: 39, env: 210 bytes] [compiling (test.cm):FFI/(test.cm):callop-0.sml] [creating directory FFI/.cm/x86-unix] [code: 284, env: 261 bytes] [compiling (test.cm):FFI/(test.cm):fptr-rtti-0.sml] [code: 528, env: 277 bytes] [compiling (test.cm):FFI/(test.cm):f-init.sml] [code: 949, data: 33, env: 189 bytes] [compiling (test.cm):test.sml] [code: 540, env: 262 bytes] $Execute: required privileges are: c-int primitive [New bindings added.] val it = true : bool - Main.doit (); /opt/local/share/smlnj/bin/sml: Fatal error -- Uncaught exception Fail with inconsistent state DEFAULT for signal 20 raised at Basis/Implementation/NJ/internal-signals.sml:346.16-346.24
Source (for reproduction):
---- ctest.c ---- void init(void) { } ---- test.sml ---- structure Main = struct fun loop () = loop () : unit fun main () = (F_init.f (); loop ()) fun doit () = RunCML.doit (main, NONE) end ---- library.sml ---- (* Helper module to load the object code *) structure Library = struct local val lh = DynLinkage.open_lib { name = ./ctest.so, global = true, lazy = true } in fun libh s = let val sh = DynLinkage.lib_symbol (lh, s) in fn () = DynLinkage.addr sh end end end ---- test.cm ---- group is $/basis.cm $c/c.cm $cml/cml.cm FFI/test.cm test.sml
Summary:
SML/NJ crashes when CML is used together with foreign code

Detailed description
When using CML together with FFI, SML/NJ crashes with:

Fatal error -- Uncaught exception Fail with inconsistent state DEFAULT for signal 20 raised at Basis/Implementation/NJ/internal-signals.sml:346.16-346.24
Additional comments:
Problem only occurs when using CML and FFI code in the same
session. CML alone works fine as does FFI.

I found a workaround and that is to mask sigALRM before running
CML code - so far that appears to fix the problem though Im not
yet sure if it breaks anything else.

structure RunCML = struct

open RunCML

local
open Signals

val doit = doit
in
fun doit args =
( maskSignals (MASK [sigALRM])
; doit args
; unmaskSignals (MASK [sigALRM])
)
end
end

Fix:
Workaround mentioned in comments, though its not an actual fix.

Submitted via web form by Ivan Tomac ivan.tomac@gmail.com

Comments:

No Comments Have Been Posted

Attached Files:

Changes

Field Old Value Date By
assigned_tonone2011-03-22 13:34jhr