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 RAA06215; Wed, 24 Jul 2002 17:00:58 +0200 (MET DST) 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 RAA06127 for ; Wed, 24 Jul 2002 17:00:42 +0200 (MET DST) Received: from mail.eecs.harvard.edu (bowser.eecs.harvard.edu [140.247.60.24]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6OF0UH14121; Wed, 24 Jul 2002 17:00:30 +0200 (MET DST) Received: by mail.eecs.harvard.edu (Postfix, from userid 32210) id ACF3E54C7DD; Wed, 24 Jul 2002 11:00:29 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.eecs.harvard.edu (Postfix) with ESMTP id AA19454C7B6; Wed, 24 Jul 2002 11:00:29 -0400 (EDT) Date: Wed, 24 Jul 2002 11:00:29 -0400 (EDT) From: Michael Tucker To: Xavier Leroy Cc: "Caml-List@Inria.Fr" Subject: Re: [Caml-list] CamlIDL and function pointers In-Reply-To: <20020723103916.B30947@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, Thanks for the help. I have seen another approach mentioned, but have not been able to get it to work. I thought I could rewrite my struct for the IDL as: typedef strcut funp { int i; } funp_t; But leave the C version intact. Supposedly it would just ignore the other field when passing it through to Caml. If that's the case, I was thinking it might be possible to write the following in the IDL: void myfun ([in, unique] funp_t* f) quote(call, " _res = f->funp_fun ();"); So, I guess I would like to be able to ignore a field when converting from C to Caml (and vice versa), but would like to be able to access the field from all code on the C side (even that generated by camlidl). I naively tried adding the function pointer field to the structure in the generated header file, so that my stub code would compile, but that didn't solve my problem. When I call myfun, I got a segmentation fault if I pass it a valid structure. I also tried editing the custom call to check for NULL and failwith a string, but the only change was that after calling with None it would raise an exception -- any valid structure still segfaults. I assume that is because I'm accessing an invalid field in the string, however a simple C program including the same header file can access it without a problem. Any ideas on what is going wrong or how I can fix it? Thanks, Mike On Tue, 23 Jul 2002, Xavier Leroy wrote: > > How would one annotate the following C struct for camlidl: > > > > typedef struct funp { > > int i; > > void (*funp_fun) (); > > } funp_t; > > > > Is it possible? Looking at the specs I don't see how one can have a > > field that is a pointer to a function. Any ideas, or pointers (no pun > > intended) to examples? > > CamlIDL, like the DCE and Microsoft IDL from which it derives, doesn't > support exchanging function pointers between C and Caml. Your best > bet is to declare funp_t as an abstract type in the IDL file: > > typedef [abstract] struct funp * funp_t; > > and export C functions that do what you need to do on this funp_t > type, e.g. > > void invoke(funp_t arg); > > where "invoke" is defined directly in C somewhere else: > > void invoke(funp_t arg) { arg->funp_fun(arg->i); } > > Of course, you won't be able to, say, construct a funp_t where the > function part is actually a Caml function. If you need that kind of > callback mechanism, you'll have to write some of the stub code by hand, > using Caml's callback functions. Alternatively, if you can re-shape > your struct funp till it looks like a COM interface, you could then use > the CamlIDL "interface" declaration and get Caml->C and C->Caml calls. > > Hope this helps, > > - Xavier Leroy > ------------------- > 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 > ------------------- 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