caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] CamlDL/Abstract pointers problem
@ 2004-01-29 13:06 ronniec95
  2004-01-29 15:02 ` Richard Jones
  0 siblings, 1 reply; 14+ messages in thread
From: ronniec95 @ 2004-01-29 13:06 UTC (permalink / raw)
  To: caml-list

Hi list,

I'm trying to create an FFI to a messaging interface and keep getting problems
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 reproduces
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 = (Foo*) malloc(sizeof(Foo));
	f->x = 10;
	f->y = (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 () = 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\camlstartupd503a3.asm">NUL
+ cl /nologo /MT /Fe"go" -I"e:\\Local\\ObjectiveCaml\\lib" "c:\TEMP\camlstartupca0b4c.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. BTW.
Generating my own handcoded stubs appears to  work fine (though is extremely
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 anything
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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-01-30 20:55 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-29 13:06 [Caml-list] CamlDL/Abstract pointers problem ronniec95
2004-01-29 15:02 ` Richard Jones
2004-01-29 15:52   ` ronniec95
2004-01-29 16:32     ` art yerkes
2004-01-29 19:04   ` skaller
2004-01-29 19:26     ` Richard Jones
2004-01-29 19:55       ` Alain.Frisch
2004-01-29 20:24         ` Richard Jones
2004-01-29 23:07           ` David Brown
2004-01-30  0:20           ` Jacques Garrigue
2004-01-30  7:04             ` Brian Hurt
2004-01-30 15:36               ` Jacques Garrigue
2004-01-30 16:52                 ` Brian Hurt
2004-01-30 20:56               ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).