caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andy Yang <yyu08@yahoo.com>
To: John Prevost <j.prevost@gmail.com>, ayerkes@speakeasy.net
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions
Date: Sun, 11 Jul 2004 21:46:21 -0700 (PDT)	[thread overview]
Message-ID: <20040712044621.65581.qmail@web53205.mail.yahoo.com> (raw)
In-Reply-To: <d849ad2a04071120394ea28021@mail.gmail.com>


Thanks a lot! You are correct about the pointer
representation in Ocaml. However, just now I tried
your codes, it still crashes. 

Actually, SAT_Manager is a pointer to a C++ class
object. In order to use the C++ library in Ocaml,
firstly a C wrapper is added onto the C++ code( this
part has been tested. Calling from the C wrapper,
these  C++ objects work fine.) Then I tried to call
these wrapper functions from Ocaml. 

One questions: Why do you mention C++ codes here? It
seems that currently Ocaml support onlu C interfaces.

Thanks a lot!

Andy

--- John Prevost <j.prevost@gmail.com> wrote:
> You shouldn't have to package up a non-caml managed
> pointer in any
> sort of caml structure at all.  Take a look at
> section 18.6 of the
> manual, specifically the definitions of
> curses_initscr and
> curses_wrefresh.  Any pointer that's outside the
> caml heap (that is,
> pretty much any pointer that you're getting from a
> non-caml function)
> can simply be treated as opaque, and you can use
> Caml's type system to
> make sure it's valid (as long as the C code always
> handles these
> pointers correctly.)
> 
> I'd write your code like the following, based on
> that:
> 
> Caml code:
> type sat_manager
> external zchaff_InitManager : unit -> sat_manager
> external zchall_ReadCnf : sat_manager -> string ->
> unit
> 
> C++ code:
> value zchaff_InitManager(void)
> {
>   CAMLparam0();
>   CAMLreturn((value) SAT_InitManager());
> }
> 
> void zchaff_ReadCnf(value mng, value filename)
> {
>   CAMLparam2(mng, filename);
>   SAT_Manager solver = (void*)mng;
>   cout<<"solver = "<<hex <<solver <<endl;
>   assert(solver != NULL);  
>   char * fn = String_val(filename);  
>   cout<<"file = "<<fn <<endl;
>   read_cnf(solver, fn);
>   CAMLreturn0;
> }
> 
> One thing I wonder about, though, is the line:
> 
>   SAT_Manager solver = (void*)mng;
> 
> shouldn't you be casting to something other than
> (void*) here?  Not
> that I know anything about how the type SAT_Manager
> is represented.
> 
> John.
> 



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

-------------------
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-07-12  4:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-12  3:39 John Prevost
2004-07-12  4:46 ` Andy Yang [this message]
2004-07-12 10:55 ` Gerd Stolpmann
2004-07-12 12:03   ` Richard Jones
2004-07-12 12:55     ` Jean-Christophe Filliatre
  -- strict thread matches above, loose matches on Subject: below --
2004-07-11  1:20 Andy Yang
2004-07-11 18:14 ` art yerkes
2004-07-11 18:58   ` Andy Yang
2004-07-12 11:04     ` Gerd Stolpmann
2004-07-12 11:35     ` Damien Doligez
2004-07-12 13:16       ` Andy Yang
2004-07-12 13:33         ` Olivier Andrieu
2004-07-12 15:39           ` Andy Yang
2004-07-12  6:55 ` Anne Pacalet

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=20040712044621.65581.qmail@web53205.mail.yahoo.com \
    --to=yyu08@yahoo.com \
    --cc=ayerkes@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=j.prevost@gmail.com \
    /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).