caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Tucker <mtucker@eecs.harvard.edu>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: "Caml-List@Inria.Fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] CamlIDL and function pointers
Date: Wed, 24 Jul 2002 11:00:29 -0400 (EDT)	[thread overview]
Message-ID: <Pine.BSF.4.44.0207241044120.29256-100000@bowser.eecs.harvard.edu> (raw)
In-Reply-To: <20020723103916.B30947@pauillac.inria.fr>

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


  parent reply	other threads:[~2002-07-24 15:00 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-15 21:22 [Caml-list] Caml productivity Pal-Kristian Engstad
2002-07-20 15:16 ` William Chesters
2002-07-22 18:22   ` Pal-Kristian Engstad
2002-07-22 18:41     ` achrist
2002-07-22 19:23       ` Pal-Kristian Engstad
2002-07-22 21:13         ` [Caml-list] CamlIDL and function pointers Michael Tucker
2002-07-23  8:39           ` Xavier Leroy
2002-07-23 13:11             ` Dmitry Bely
2002-07-24 15:00             ` Michael Tucker [this message]
2002-07-25  9:36               ` Xavier Leroy
2002-07-22 21:26     ` Games (Re: [Caml-list] Caml productivity.) Oleg
2002-07-23  2:56       ` Issac Trotts
2002-07-23 11:03         ` eijiro_sumii
2002-07-23 16:17           ` Charles Martin
2002-07-29  3:36           ` Andrei de A. Formiga
2002-07-29  6:32             ` Florian Hars
2002-07-29 10:23             ` eijiro_sumii
     [not found]               ` <001901c237a7$9e685920$890bfea9@mimbi>
2002-07-30  4:52                 ` eijiro_sumii
2002-07-30 18:13                   ` Jonathan Coupe
2002-07-30  6:16                     ` eijiro_sumii
2002-08-01 15:39                     ` John Max Skaller
2002-08-01 15:59                       ` Markus Mottl
2002-08-01 16:28                       ` Jonathan Coupe
     [not found]                         ` <86vg6ta9o6.fsf@laurelin.dementia.org>
2002-08-02 12:50                           ` Jonathan Coupe
2002-08-02 14:51                         ` John Max Skaller
2002-07-25  3:19       ` Chris Hecker
2002-07-28 13:45         ` Jonathan Coupe
2002-07-29  0:57           ` Michael Vanier
2002-07-22 22:00     ` [Caml-list] Caml productivity Alexander V.Voinov
2002-07-20 15:25 ` Oleg
2002-07-22  6:41 ` Tom
2002-07-22 10:46 ` Nicolas Cannasse
2002-07-22 17:46   ` Pal-Kristian Engstad
2002-07-24  3:20     ` Travis Bemann
2002-07-24  9:45       ` Pal-Kristian Engstad
2002-07-26 21:42         ` Chris Hecker
2002-07-27  4:41           ` Issac Trotts
2002-07-27  5:49             ` Chris Hecker
2002-07-27 14:49               ` John Max Skaller
2002-07-27  9:06           ` Oleg
2002-07-27 18:18             ` Chris Hecker
2002-07-29  8:13         ` Nicolas Cannasse
2002-07-30  4:46           ` Travis Bemann
2002-07-24  8:02     ` Nicolas Cannasse
2002-07-24  8:25       ` Jérôme Marant
2002-07-24 10:00       ` Pal-Kristian Engstad
2002-07-27  9:06         ` Oleg

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=Pine.BSF.4.44.0207241044120.29256-100000@bowser.eecs.harvard.edu \
    --to=mtucker@eecs.harvard.edu \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@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).