From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA32463; Thu, 29 Jan 2004 14:06:47 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA32270 for ; Thu, 29 Jan 2004 14:06:46 +0100 (MET) From: ronniec95@lineone.net Received: from mk-smarthost-3.mail.uk.tiscali.com (mk-smarthost-3.mail.uk.tiscali.com [212.74.114.39]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i0TD6jP09941 for ; Thu, 29 Jan 2004 14:06:46 +0100 (MET) Received: from mk-cpfront-1.mail.uk.tiscali.com ([212.74.114.3]:59928 helo=mk-cpfrontend.uk.tiscali.com) by mk-smarthost-3.mail.uk.tiscali.com with esmtp (Exim 4.24) id 1AmBsa-000BJz-Tq for caml-list@inria.fr; Thu, 29 Jan 2004 13:06:44 +0000 Received: from [141.228.156.225] by mk-cpfrontend.uk.tiscali.com with HTTP; Thu, 29 Jan 2004 13:06:39 +0000 Date: Thu, 29 Jan 2004 13:06:39 +0000 Message-ID: <40169E8D00006067@mk-cpfrontend-1.mail.uk.tiscali.com> Subject: [Caml-list] CamlDL/Abstract pointers problem To: caml-list@inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Loop: caml-list@inria.fr X-Spam: no; 0.00; ronniec:01 lineone:01 pointers:01 ffi:01 passing:01 opaque:01 pointers:01 crashes:01 declspec:01 dllexport:01 struct:01 foo:01 char:01 foo:01 initialise:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi list, I'm trying to create an FFI to a messaging interface and keep getting pro= blems with passing around opaque pointers from C back to Ocaml (crashes). This is on WIN32 btw. Here's the simples example I could thing of that reprodu= ces the problem. Any help is appreciated! --- test.idl --- typedef [abstract,ptr] void* mywindow; quote(C,"__declspec(dllexport)") mywindow init_window(); --- end test.idl --- --- testimpl.c -- typedef struct _Foo { int x; char* y; } Foo; mywindow init_window(void) { /* Initialise a structure */ Foo* f =3D (Foo*) malloc(sizeof(Foo)); f->x =3D 10; f->y =3D (char*)malloc(sizeof(char) * 256); strcpy(f->y,"hello world"); printf("%d %s\n",f->x,f->y); fflush(stdout); return (mywindow)f; // Crashes after leaving this block } --- end testimpl.c --- --- main.ml --- let win () =3D Test.init_window () --- end main.ml --- I'm compiling (test_stub.c (generated) and testimpl.c) with MSVC 6. with flags : /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "CAML_DLL" /D "_USRDLL" and building a cmxa (ocamlopt) file that I link with ocamlopt -verbose -o go -I . -cclib "/link -LIBPATH:C:/Progra~1/Micros~2/= vc98/lib" test.cmxa main.cmx which displays: + ml /nologo /coff /Cp /c /Fo"c:\TEMP\camlstartupca0b4c.obj" "c:\TEMP\cam= lstartupd503a3.asm">NUL + cl /nologo /MT /Fe"go" -I"e:\\Local\\ObjectiveCaml\\lib" "c:\TEMP\camls= tartupca0b4c.obj" "e:\\Local\\ObjectiveCaml\\lib\std_exit.obj" "main.obj" "test.lib" "e :\\Local\\ObjectiveCaml\\lib\stdlib.lib" "libtest.lib" "/link" "-LIBPATH:= C:/Progra~1/Micros~2/vc98/lib" "e:\\Local\\ObjectiveCaml\\lib\libasmrun.lib" advapi32.lib I'm thinking that either I've forgotten to initialise something or linked= with wrong options but I can't figure out what that would be. Any sample program/makefile that works under win32 or hints would be appreciated. BT= W. Generating my own handcoded stubs appears to work fine (though is extrem= ely dull). All I want to do is just give Ocaml a pointer to something I've created in C and pass it back to other C functions later; don't want it to do any= thing with it (including moving it around the ocaml heap).\ Thanks for any help. Ronnie ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners