Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Toplevel crashes when trying to call external functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andy Yang <yyu08@y...>
Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions

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