summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/ffi.c b/ffi.c
index fe55e642..239c8d3c 100644
--- a/ffi.c
+++ b/ffi.c
@@ -2461,8 +2461,10 @@ static val ffi_buf_in(struct txr_ffi_type *tft, int copy, mem_t *src,
(void) tft;
- if (copy && *loc != origptr)
- obj = if2(*loc, make_duplicate_buf(length_buf(obj), *loc));
+ if (copy && *loc != origptr) {
+ type_check(self, obj, BUF);
+ obj = if2(*loc, make_duplicate_buf(obj->b.len, *loc, self));
+ }
return obj;
}
@@ -2484,7 +2486,7 @@ static val ffi_buf_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
mem_t *p = *coerce(mem_t **, src);
(void) self;
- return p ? make_duplicate_buf(num(tft->nelem), p) : nil;
+ return p ? make_duplicate_buf(tft->nelem, p, self) : nil;
}
static val ffi_buf_d_in(struct txr_ffi_type *tft, int copy, mem_t *src,
@@ -2495,7 +2497,7 @@ static val ffi_buf_d_in(struct txr_ffi_type *tft, int copy, mem_t *src,
(void) self;
if (copy) {
- obj = if2(*loc, make_borrowed_buf(num(tft->nelem), *loc));
+ obj = if2(*loc, make_borrowed_buf(tft->nelem, *loc));
*loc = 0;
}
@@ -2519,7 +2521,7 @@ static void ffi_buf_d_put(struct txr_ffi_type *tft, val buf, mem_t *dst,
static val ffi_buf_d_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
mem_t **loc = coerce(mem_t **, src);
- val ret = *loc ? make_borrowed_buf(num(tft->nelem), *loc) : nil;
+ val ret = *loc ? make_borrowed_buf(tft->nelem, *loc) : nil;
(void) self;
*loc = 0;
return ret;
@@ -6249,7 +6251,7 @@ val buf_carray(val carray)
struct txr_ffi_type *etft = scry->eltft;
if (scry->nelem >= 0) {
cnum bytes = scry->nelem * etft->size;
- return make_duplicate_buf(num(bytes), scry->data);
+ return make_duplicate_buf(bytes, scry->data, self);
}
uw_throwf(error_s, lit("~a: size of ~s carray unknown"), self, carray, nao);
}
@@ -6750,7 +6752,7 @@ val put_carray(val carray, val offs, val stream)
struct carray *scry = carray_struct_checked(self, carray);
struct txr_ffi_type *etft = scry->eltft;
ucnum size = convert(ucnum, etft->size) * convert(ucnum, scry->nelem);
- val buf = make_borrowed_buf(unum(size), scry->data);
+ val buf = make_borrowed_buf(size, scry->data);
val pos = default_arg(offs, zero);
val ret = put_buf(buf, pos, stream);
gc_hint(carray);
@@ -6763,7 +6765,7 @@ val fill_carray(val carray, val offs, val stream)
struct carray *scry = carray_struct_checked(self, carray);
struct txr_ffi_type *etft = scry->eltft;
ucnum size = convert(ucnum, etft->size) * convert(ucnum, scry->nelem);
- val buf = make_borrowed_buf(unum(size), scry->data);
+ val buf = make_borrowed_buf(size, scry->data);
val pos = default_arg(offs, zero);
val ret = fill_buf(buf, pos, stream);
gc_hint(carray);
@@ -7299,12 +7301,11 @@ val put_obj(val obj, val type, val stream)
val self = lit("put-obj");
struct txr_ffi_type *tft = ffi_type_struct_checked(self, type);
cnum size = tft->size;
- val len = num(size);
mem_t *data = coerce(mem_t *, zalloca(size));
obj_t buf_obj;
- val buf = init_borrowed_buf(&buf_obj, len, data);
+ val buf = init_borrowed_buf(&buf_obj, size, data);
tft->put(tft, obj, data, self);
- return eql(put_buf(buf, zero, stream), len);
+ return eql(put_buf(buf, zero, stream), num(size));
}
@@ -7313,11 +7314,10 @@ val get_obj(val type, val stream)
val self = lit("get-obj");
struct txr_ffi_type *tft = ffi_type_struct_checked(self, type);
cnum size = tft->size;
- val len = num(size);
mem_t *data = coerce(mem_t *, zalloca(size));
obj_t buf_obj;
- val buf = init_borrowed_buf(&buf_obj, len, data);
- if (neql(fill_buf(buf, zero, stream), len))
+ val buf = init_borrowed_buf(&buf_obj, size, data);
+ if (neql(fill_buf(buf, zero, stream), num(size)))
return nil;
return tft->get(tft, data, self);
}
@@ -7327,11 +7327,10 @@ val fill_obj(val obj, val type, val stream)
val self = lit("fill-obj");
struct txr_ffi_type *tft = ffi_type_struct_checked(self, type);
cnum size = tft->size;
- val len = num(size);
mem_t *data = coerce(mem_t *, zalloca(size));
obj_t buf_obj;
- val buf = init_borrowed_buf(&buf_obj, len, data);
- if (neql(fill_buf(buf, zero, stream), len))
+ val buf = init_borrowed_buf(&buf_obj, size, data);
+ if (neql(fill_buf(buf, zero, stream), num(size)))
return nil;
return tft->in(tft, 1, data, obj, self);
}