--VijayThanks,Is that correct?Thanks again for all the great feedback!I think the call to ____FIX() is not required if Scheme code access the C function through a declaration like this:
(define read-bytes (c-lambda (int unsigned-int scheme-object) int "read_bytes"))
On Wed, Sep 25, 2013 at 8:34 PM, Marc Feeley <feeley@iro.umontreal.ca> wrote:
You can simplify you code further to:
On 2013-09-25, at 4:48 AM, Vijay Mathew <vijay.the.lisper@gmail.com> wrote:
> 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.
return ___FIX(read (fd, ___BODY(data_vect), count));
int read_bytes (int fd, size_t count, ___SCMOBJ data_vect)
{
}
Marc