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 IAA23212; Wed, 30 Apr 2003 08:13:35 +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 IAA21862 for ; Wed, 30 Apr 2003 08:13:34 +0200 (MET DST) Received: from opus.davidb.org (66-75-152-1.san.rr.com [66.75.152.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h3U6DXT29845 for ; Wed, 30 Apr 2003 08:13:33 +0200 (MET DST) Received: from davidb by opus.davidb.org with local (Exim 3.31 #1 (Debian)) id 19AkqS-0005Pf-00 for ; Tue, 29 Apr 2003 23:13:32 -0700 Date: Tue, 29 Apr 2003 23:13:32 -0700 From: David Brown To: Caml List Subject: Re: [Caml-list] Binding problem. Message-ID: <20030430061332.GA20759@opus.davidb.org> References: <20030430052829.GA19254@opus.davidb.org> <200304300941.19681.snob@metalinkltd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200304300941.19681.snob@metalinkltd.com> User-Agent: Mutt/1.4i X-Spam: no; 0.00; caml-list:01 0400,:01 nickolay:01 camlparam:01 pointers:01 bug:01 val:01 char:01 malloc:01 ocaml:01 caml:01 compile:02 binding:03 string:03 dave:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Apr 30, 2003 at 09:41:19AM +0400, Nickolay Kolchin-Semyonov wrote: > Always use CAMLparam with true arguments number! There's no real point, since some of the arguments are C heap pointers, so they're never going to move. It also isn't needed if the arguments are only used before the first allocation. > You have a bug in > caml_sqlite_compile (value db, value query) > > strcpy (String_val (tmp), tail); > > Don't do that. Instead work with char pointers and convert to Ocaml types only > at function end. I.e. (I just fixed code that don't like, without > understanding your algorithms) Actually, that part works just fine, at least the string manipulation. The example you give needs to change the Field (pair, 1) = copy_string (tmp); into a Store_field (pair, 1, copy_string (tmp)); since the copy_string can call the GC, and could move the pair into the shared heap. I learned this because I just figured out what was wrong with the binding :-) The code I have there is kind of gross, but will always work, since sqlite always will return a tail value that points later on. I kind of wanted to avoid a malloc and free to copy a value that in normal cases will never be used. Thanks for looking at it, Dave ------------------- 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