On Thu, Dec 25, 2008 at 4:49 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Dec 25, Ben Simon wrote:<br>
> I wonder if I'm hosing things up because I'm calling mysql_init without an<br>
> argument. The API says that if the argument is null, it returns back a fresh<br>
> mysql handle. That's what I was intending. But, by not explicitly handing<br>
> in NULL, i may be corrupting matters.<br>
<br>
</div>That sounds very likely: if you omit the type from the interface, then<br>
the foreign function will just use whatever junk happens to be on the<br>
stack. And it sounds like mysql will just assume that it's a pointer<br>
to a struct to fill -- so it stores that information in that random<br>
place. (And it shouldn't be surprising that this leads to a crash at<br>
some later point.)</blockquote><div><br>Yeah, that sounds totally logical.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">> How do I rewrite:<br>
<div class="Ih2E3d">
> (define c-mysql-init (get-ffi-obj "mysql_init" libmysql (_fun -><br>
> _handle)))<br>
> so that the function takes in an explicit NULL?<br>
<br>
</div>Probably something like:<br>
<br>
(define c-mysql-init<br>
(get-ffi-obj "mysql_init" libmysql (_fun _pointer -> _handle)))<br>
<br>
and pass it #f (which translates to NULL). But you can also make it<br>
always pass in NULL with:<br>
<br>
(define c-mysql-init<br>
(get-ffi-obj "mysql_init" libmysql (_fun [_pointer = #f] -> _handle)))<br>
<br>
which makes the generated Scheme function expect no arguments, and<br>
always call the foreign one with #f.</blockquote><div><br>Cool - Thanks! I'll give that a try and see how it works.<br><br>-Ben<br> </div></div><br clear="all"><br>-- <br>Have an idea for software? I can make it happen - <a href="http://www.ideas2executables.com">http://www.ideas2executables.com</a><br>
My Blog: <a href="http://benjisimon.blogspot.com">http://benjisimon.blogspot.com</a><br>