Hi, Thanks for reviewing my code. I have updated the C function as follows: int read_bytes (int fd, size_t count, ___SCMOBJ data_vect) { void *data = malloc (count); int result; if (data == NULL) result = -1; else { result = read (fd, data, count); if (result > 0) memcpy (___BODY (data_vect), data, result); free (data); } return result; } A call from scheme will look like: (read-bytes fd count (make-u8vector count 0)) I suppose now I don't have to worry about leaks or heap-overflow-exceptions. Thanks, --Vijay On Tue, Sep 24, 2013 at 8:52 PM, Marc Feeley <feeley@iro.umontreal.ca>wrote:
On 2013-09-23, at 11:14 AM, Vijay Mathew <vijay.the.lisper@gmail.com> wrote:
The following C function is a wrapper for the `read' system call. It returns a pair that contains the number of bytes read and the data. Is this the right way to initialize a u8vector from C?
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.
Marc