caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: ronniec95@lineone.net
To: caml-list@inria.fr
Subject: [Caml-list] CamlDL/Abstract pointers problem
Date: Thu, 29 Jan 2004 13:06:39 +0000	[thread overview]
Message-ID: <40169E8D00006067@mk-cpfrontend-1.mail.uk.tiscali.com> (raw)

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


             reply	other threads:[~2004-01-29 13:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-29 13:06 ronniec95 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40169E8D00006067@mk-cpfrontend-1.mail.uk.tiscali.com \
    --to=ronniec95@lineone.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).