| Anonymous | Login | Signup for a new account | 2013-05-18 13:11 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0004166 | OCaml | OCaml general | public | 2006-11-21 19:52 | 2012-09-14 23:49 | ||||||
| Reporter | mottl | ||||||||||
| Assigned To | |||||||||||
| Priority | normal | Severity | minor | Reproducibility | always | ||||||
| Status | acknowledged | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 3.09.3 | ||||||||||
| Target Version | 4.01.0+dev | Fixed in Version | |||||||||
| Summary | 0004166: Incorrect module initialisation order with "external" declarations | ||||||||||
| Description | We have a module (lets call it "Foo") that interfaces C-bindings and exports functions defined as "external" in its .mli-file. This module is packed with others into one module, which again is part of a .cmxa-file. If we link this library with another module (say, "Bar") that uses only functions defined "external" in "Foo", we observed that toplevel expressions in "Foo" did not get evaluated. Here is a schematic example: foo.ml: ----- external foo : unit -> unit = "foo" external init : unit -> unit = "init" let () = print_endline "init"; init () ----- foo.mli: ----- external foo : unit -> unit ----- bar.ml: ----- let () = print_endline "bar"; Foo.foo () ----- Since "Bar" depends on "Foo", you would expect that the toplevel expression in "foo.ml" gets evaluated first, which should print "init" and e.g. initialise the C-bindings. But we see "bar" first, and our application crashes, because the C-bindings are not evaluated. Interestingly, changing "foo.mli" as follows solves the problem: foo.mli: --- val foo : unit -> unit --- This indicates that exclusively calling functions exported as "external" will prevent the linker from figuring out which modules should be initialized first. This seems to be a bug, it shouldn't matter whether we use "val" or "external". | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | |||||||||||
Relationships |
||||||
|
||||||
Notes |
|
|
(0003861) doligez (manager) 2006-11-24 15:43 |
I'm downgrading this to "minor" since there is an easy workaround: always use "val" instead of "external" in your .mli files. |
|
(0005690) ygrek (reporter) 2010-10-26 16:47 |
and it also bites those lazy folks (like me) who do not write mli interfaces.. |
|
(0005753) edwin (reporter) 2010-12-23 16:10 |
Perhaps ocaml should give a warning if you use 'external' in .mli files. Due to this bug exceptions are not registered in C code, which causes caml_raise_arg_with to be invoked with a NULL exception, which in turn causes a segfault. |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2006-11-21 19:52 | mottl | New Issue | |
| 2006-11-24 15:43 | doligez | Note Added: 0003861 | |
| 2006-11-24 15:43 | doligez | Severity | major => minor |
| 2006-11-24 15:43 | doligez | Status | new => acknowledged |
| 2007-08-29 02:13 | garrigue | Relationship added | related to 0004374 |
| 2010-10-26 16:47 | ygrek | Note Added: 0005690 | |
| 2010-12-23 16:10 | edwin | Note Added: 0005753 | |
| 2012-07-11 16:14 | doligez | Target Version | => 4.01.0+dev |
| 2012-07-31 13:37 | doligez | Target Version | 4.01.0+dev => 4.00.1+dev |
| 2012-09-14 23:49 | doligez | Target Version | 4.00.1+dev => 4.01.0+dev |
| Copyright © 2000 - 2011 MantisBT Group |