<div dir="ltr">Hi Vijay,<div><br></div><div>Looks good.</div><div><br></div><div>A possible improvement is to drop the malloc() call you do and just read() straight into ___BODY(data_vect) , this saves you a round of copying too, and is also in some limited sense safer as there's no malloc() that could return NULL anymore.</div>

<div><br></div><div>Last note would be that at the time SMP is released, every access out there of the Scheme heap from C calls such as ___BODY() will need to be gone through as then, I suppose, unlike now, GC:s could happen also during FFI calls - my best understanding is that the primary solution will be using ___STILL objects only. Interestingly enough, this is what |make-u8vector| makes already today, for u8vectors bigger than ___MSECTION_BIGGEST , however that logic is not a lot to be relied on so I guess it'll be relevant to implement a |make-still-u8vector| or alike then.</div>

<div><br></div><div>Mikael</div><div class="gmail_extra"><br><div class="gmail_quote">2013/9/25 Vijay Mathew <span dir="ltr"><<a href="mailto:vijay.the.lisper@gmail.com" target="_blank">vijay.the.lisper@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi,<br><br>Thanks for reviewing my code. <br>

<br>I have updated the C function as follows:<br><br>int read_bytes (int fd, size_t count, ___SCMOBJ data_vect)<div class="im"><br> {<br>   void *data = malloc (count);<br></div>
   int result;<br><br>   if (data == NULL)<br>     result = -1;<br>   else<br>     {<br>       result = read (fd, data, count);<br>       if (result > 0)<br>         memcpy (___BODY (data_vect), data, result);<br>       free (data);<br>


     }<br>   return result;<br> }<br><br></div>A call from scheme will look like:<br><br>(read-bytes fd count (make-u8vector count 0))<br><br></div>I suppose now I don't have to worry about leaks or heap-overflow-exceptions.<br>


<br></div>Thanks,<br><br></div>--Vijay<br></div><div class=""><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 8:52 PM, Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><br>
On 2013-09-23, at 11:14 AM, Vijay Mathew <<a href="mailto:vijay.the.lisper@gmail.com" target="_blank">vijay.the.lisper@gmail.com</a>> wrote:<br>
<br>
> The following C function is a wrapper for the `read' system call.<br>
> It returns a pair that contains the number of bytes read and the data.<br>
> Is this the right way to initialize a u8vector from C?<br>
<br>
</div>There are a few things I would do differently, such as heap overflow checking.  But for the particular task of providing a wrapper to the read system call I would use a different interface.  Why don't you allocate the buffer in Scheme before calling read?  That would simplify the C code (avoiding GC issues) and would be more efficient.<br>



<span><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>