caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Binding problem.
@ 2003-04-30  5:28 David Brown
       [not found] ` <200304300941.19681.snob@metalinkltd.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Brown @ 2003-04-30  5:28 UTC (permalink / raw)
  To: Caml List

I'm trying to create a binding to sqlite.  It seems to work most of the
time, except occasionally it makes the ocaml GC segv.

If anyone has time to glance at this binding, I would really appreciate
it, perhaps just another pair of eyes might find the problem.
Otherwise, if I can't find anything wrong with the binding, I might have
to go try and figure out if sqlite is steping on the ocaml heap somehow.

Since the file is lengthy, I've put it on my web server:

<http://www.davidb.org/sqlite/sqlite-stub.c>
<http://www.davidb.org/sqlite/sqlite.ml>

I can mail the files to anyone who requests them.

Once I make these bindings work, I can release them :-)

Thanks,
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Binding problem.
       [not found] ` <200304300941.19681.snob@metalinkltd.com>
@ 2003-04-30  6:13   ` David Brown
  0 siblings, 0 replies; 4+ messages in thread
From: David Brown @ 2003-04-30  6:13 UTC (permalink / raw)
  To: Caml List

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Binding problem, fixed.
       [not found] ` <20030430060602.GA20670@opus.davidb.org>
@ 2003-04-30 21:20   ` David Brown
  0 siblings, 0 replies; 4+ messages in thread
From: David Brown @ 2003-04-30 21:20 UTC (permalink / raw)
  To: Caml List

On Tue, Apr 29, 2003 at 11:06:02PM -0700, David Brown wrote:

> I'm trying to create a binding to sqlite.  It seems to work most of the
> time, except occasionally it makes the ocaml GC segv.

I found a pair of problems.  The first was using: I used Field (var, n)
= ... where I needed to use Store_field.

To, make sure I understand this.  I am allowed to use Field (var, n) =
as long as I can guarantee that 'var' is not shared.  In other words, it
was allocated with alloc_small (or equivalent), and no other allocations
have taken place.  If I'm doing other allocations (say to come up with
the values to store), then I need to make sure that modify gets called.

The second was to use

        Store_field (var, n, copy_string (...));

The string needs to be put in a variable and assigned in a separate
step.  Otherwise 'var' might get moved by the garbage collector, and C
doesn't guarantee anything about evaluation order.

I put the working versions of the binding files on the web server if
anyone wants to look at them.  They still need some cleaning up.

<http://www.davidb.org/sqlite/sqlite-stub.c>
<http://www.davidb.org/sqlite/sqlite.ml>

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Binding problem.
  2003-04-30  5:28 [Caml-list] Binding problem David Brown
       [not found] ` <200304300941.19681.snob@metalinkltd.com>
       [not found] ` <20030430060602.GA20670@opus.davidb.org>
@ 2003-05-01  4:49 ` David Brown
  2 siblings, 0 replies; 4+ messages in thread
From: David Brown @ 2003-05-01  4:49 UTC (permalink / raw)
  To: Caml List

On Tue, Apr 29, 2003 at 10:28:29PM -0700, David Brown wrote:

> I'm trying to create a binding to sqlite.  It seems to work most of the
> time, except occasionally it makes the ocaml GC segv.

Well, I've been chasing quite a red herring.  I got so frustrated with
the SQLite binding "causing" the SEGVs that I stubbed all of the calls
out.  My program still randomly SEGVs.

Turns out the problem is in Unix.LargeFile.lstat.  For more information,
see bug 1665.  The binding there suffers from the same problem that I
have no so easily learned to spot: field assignments with something that
can activate the garbage collector.

Dave Brown

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-05-01  4:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-30  5:28 [Caml-list] Binding problem David Brown
     [not found] ` <200304300941.19681.snob@metalinkltd.com>
2003-04-30  6:13   ` David Brown
     [not found] ` <20030430060602.GA20670@opus.davidb.org>
2003-04-30 21:20   ` [Caml-list] Binding problem, fixed David Brown
2003-05-01  4:49 ` [Caml-list] Binding problem David Brown

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).