From 9280a061f0e85a6510aab304a017e010b997d6e9 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 29 Apr 2017 06:51:55 -0700 Subject: ffi: correct treatment of (ptr buf). The buf FFI type's alloc virtual should return a pointer to the buffer's pointer, not the buffer itself. What's currently going on is something silly, whereby the pointer to the buffer is stored into the buffer itself. * buf.c (buf_addr_of): New function. * buf.c (buf_addr_of): Declared. * ffi.c (ffi_buf_alloc): Use buf_addr_of instead of buf_get. --- buf.c | 6 ++++++ buf.h | 1 + ffi.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/buf.c b/buf.c index 58cd4177..661514be 100644 --- a/buf.c +++ b/buf.c @@ -204,6 +204,12 @@ mem_t *buf_get(val buf, val self) return b->data; } +mem_t **buf_addr_of(val buf, val self) +{ + struct buf *b = buf_handle(buf, self); + return &b->data; +} + void buf_fill(val buf, mem_t *src, val self) { struct buf *b = buf_handle(buf, self); diff --git a/buf.h b/buf.h index 8102fff8..b65f7037 100644 --- a/buf.h +++ b/buf.h @@ -32,6 +32,7 @@ val buf_trim(val buf); val buf_set_length(val obj, val len, val init_val); val length_buf(val buf); mem_t *buf_get(val buf, val self); +mem_t **buf_addr_of(val buf, val self); void buf_fill(val buf, mem_t *src, val self); #if HAVE_I8 diff --git a/ffi.c b/ffi.c index aa55a39e..cad0376d 100644 --- a/ffi.c +++ b/ffi.c @@ -642,7 +642,7 @@ static val ffi_buf_get(struct txr_ffi_type *tft, mem_t *src, val self) static mem_t *ffi_buf_alloc(struct txr_ffi_type *tft, val buf, val self) { (void) tft; - return buf_get(buf, self); + return coerce(mem_t *, buf_addr_of(buf, self)); } static void ffi_ptr_walk(struct txr_ffi_type *tft, mem_t *ctx, -- cgit v1.2.3