<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)<br> {<br>   void *data = malloc (count);<br>
   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="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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 2013-09-23, at 11:14 AM, Vijay Mathew <<a href="mailto:vijay.the.lisper@gmail.com">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 class="HOEnZb"><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div><br></div>