[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] call Chicken Scheme from C and pass a bytevector
From: |
Felix |
Subject: |
Re: [Chicken-users] call Chicken Scheme from C and pass a bytevector |
Date: |
Fri, 28 Jun 2013 13:48:44 +0200 (CEST) |
> Hum ... this has potential.
>
> struct ipv4_addr_struct {
> C_header tag;
> uint8_t *octets;
> };
> typedef struct ipv4_addr_struct ipv4_addr;
>
> static const C_header BTREE_TAG =
> ((sizeof(ipv4_addr) - sizeof(C_header)) /
> sizeof(C_word)) | C_BYTEVECTOR_TYPE;
Actually, a SRFI-4 numeric vector holds a tag (C_STRUCTURE_TYPE | 2),
a pointer to a Scheme symbol and a pointer to another Scheme "block",
which again holds a tag (C_BYTEVECTOR_TYPE | bytecount) with the
binary data directly following.
>
> This would be handled by the GC, right?
No, pointers pointing outside of the Scheme heap are simply
ignored by the GC.
>
> Would Scheme be able to convert or use this as a u8vector or would it
> be a blob which I could convert with blob->u8vector/shared ?
If you build a structure like I said above, it will be a SRFI-4 XXXvector,
but it might be easier to build only the "blob" (or bytevector). And
use "blob->..." to convert it. "blob->XXXvector" will also copy it into
the garbage collected heap.
cheers,
felix