Hi,
Actually, the bytes should probably be allocated in the structure, right?
struct ipv4_addr_struct {
C_header tag;
uint8_t octets[4];
};
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;
--
Claude Marinier
On Thu, 27 Jun 2013, Claude Marinier wrote:
On Thu, 27 Jun 2013, Dan Leslie wrote:
There's a section on accessing external objects that covers this sort of
thing:
http://wiki.call-cc.org/man/4/Accessing%20external%20objects#returning-large-objects-or-chunks-of-memory-to-scheme
This addresses a different issue. The PCAP event handler in C calls the
packet handler in Scheme. I am looking for a way to create saddr_o and
daddr_o and give them to scheme like this.
vector = C_alloc( C_SIZEOF_VECTOR(7) );
vector_o = C_vector( &vector, 7,
C_fix(ethtype),
saddr_o, daddr_o,
C_fix(ip_proto),
C_fix(type), C_fix(code),
C_fix(tot_len) );
ret = process_packet( vector_o ); // call Scheme code
It's possible to allocate C structures under the control of the Chicken GC:
http://wiki.call-cc.org/allocating-c-structures-under-control-of-the-chicken-gc
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;
This would be handled by the GC, right?
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 ?
However, you can also leave control up to the user rather than the GC and
they can use free:
http://api.call-cc.org/doc/lolevel/free
I prefer to let the GC handle it.
Personally, I like to allocate blobs and srfi-4 vectors in scheme and pass
them as parameters to C functions to be mutated.
Wrong direction: I call scheme from C.
On 6/27/2013 10:07 AM, Claude Marinier wrote:
Hi,
A function in pcap-interface.c calls Chicken Scheme. It builds a vector
containing a bunch of things, e.g. C_fix(ethtype), and the source and
destination addresses as vectors. The scheme code converts the address
vectors to u8vector (u16vector for IPv6). This is a lot of work: just
under 20% of CPU time is spent in vector->u8vector.
If I could create a blob in C and pass it to scheme, the scheme code could
use blob->u8vector/shared and blob->u16vector/shared which would achieve
the same result with much less work.
What is the recommended way to pass a blob to scheme from C?
Is there a way to create a u8vector or u16vector directly in C?
Thank you.
--
Claude Marinier
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users