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 FAA18878; Mon, 12 Jul 2004 05:39:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA18604 for ; Mon, 12 Jul 2004 05:39:29 +0200 (MET DST) Received: from mproxy.gmail.com (rproxy.gmail.com [64.233.170.205]) by nez-perce.inria.fr (8.12.10/8.12.10) with SMTP id i6C3dSEV021826 for ; Mon, 12 Jul 2004 05:39:28 +0200 Received: by mproxy.gmail.com with SMTP id d19so318428rnf for ; Sun, 11 Jul 2004 20:39:16 -0700 (PDT) Received: by 10.38.9.62 with SMTP id 62mr117890rni; Sun, 11 Jul 2004 20:39:16 -0700 (PDT) Message-ID: Date: Sun, 11 Jul 2004 23:39:16 -0400 From: John Prevost To: ayerkes@speakeasy.net Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions Cc: caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40F207F0.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; prevost:01 prevost:01 caml-list:01 crashes:01 non-caml:01 curses:01 initscr:01 curses:01 non-caml:01 opaque:01 caml's:01 pointers:01 camlparam:01 camlreturn:01 mng:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = "<