[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Francois Rouaix <francois.rouaix@g...> |
| Subject: | Dynamic linking on MacOSX & bus error |
This is a very MacOSX specific question I'm afraid - apologies to
platform-independent readers.
I'm perplexed by the following: the same simple code invoking an external
trivial Cocoa method works fine when linked with -custom and crashes when
not. Anyone has a clue of what I am doing wrong? This is ocaml 3.09.3 and a
G4 PB under 10.4.11 (Tiger).
$ cat foo.m
#define CAML_NAME_SPACE
#include <caml/callback.h>
#include <caml/memory.h>
#import <Foundation/NSAutoreleasePool.h>
static NSAutoreleasePool *arp =nil;
value caml_init_default(value unit)
{
CAMLparam0();
if (nil == arp) {
arp = [[NSAutoreleasePool alloc] init];
}
CAMLreturn(Val_int(0));
}
$ cat foo.ml
external init : unit -> unit = "caml_init_default"
let () = init()
let f() =
prerr_endline "Hello World!"
$ cat main.ml
let _ = Foo.f()
$ cat build
rm -f foo.o foo.cm* main.cm*
gcc -c -g -I$(ocamlc -where) foo.m
ocamlmklib -o foo foo.ml foo.o -ccopt -g -ccopt -framework -ccopt Foundation
-lobjc
ocamlc -c main.ml
ocamlc -verbose -custom -o main-custom -g -I . foo.cma main.cmo
ocamlc -verbose -o main-dyn -g -I . foo.cma main.cmo
$ bash build
+ gcc -o 'main-custom' -I'/usr/local/lib/ocaml' -g -framework Foundation
/tmp/camlprim5918c8.c '-L.' '-L/usr/local/lib/ocaml' '-lfoo' '-lobjc'
-lcamlrun -lcurses -lpthread
$ ./main-custom
Hello World!
$ ./main-dyn
Bus error
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000020
0x90a410f8 in objc_msgSend ()
(gdb) bt
#0 0x90a410f8 in objc_msgSend ()
#1 0x00093f1c in caml_init_default (unit=1) at foo.m:13
#2 0x00018554 in caml_interprete ()
#3 0x000123fc in caml_main ()
#4 0x00002684 in main ()
Somehow NSautoreleasePool is nil?
--f