summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-24 21:06:26 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-24 21:06:26 -0700
commita18c7822a44770e476a3cbb1b5979d368c596b37 (patch)
tree1ba65dfe4236baefbf3a32ad76a59e05656fc406
parent14ce6cae2aac2931fa7f895fade2c3cac627cddd (diff)
downloadtxr-a18c7822a44770e476a3cbb1b5979d368c596b37.tar.gz
txr-a18c7822a44770e476a3cbb1b5979d368c596b37.tar.bz2
txr-a18c7822a44770e476a3cbb1b5979d368c596b37.zip
ffi: eliminate overloading of mtypes member.
* ffi.c (struct txr_ffi_type): New member, eltype. Represents element type of arrays and target type of pointers, so that the mtypes member isn't overloaded for this purpose, and will only represent the list of types of a struct. (ffi_struct_type_mark): Mark eltype, since this function is used by arrays also. (ffi_ptr_type_mark): Mark eltype. Do not mark mtypes, since the ptr types don't use it any more. (ffi_varray_alloc, ffi_wchar_get, ffi_cptr_get, ffi_cptr_alloc, ffi_ptr_in_in, ffi_ptr_in_d_in, ffi_ptr_in_out, ffi_ptr_out_in, ffi_ptr_out_put, ffi_ptr_out_out, ffi_ptr_get, ffi_ptr_d_get, ffi_ptr_in_put, ffi_ptr_out_s_in, ffi_ptr_in_release, ffi_array_in_common, ffi_array_put_common, ffi_array_out_common, ffi_array_get_common, ffi_array_release_comon, ffi_array_null_term_in, ffi_array_null_term_get, ffi_varray_release, ffi_carray_get, ffi_carray_put): Access eltype instead of mtypes. (make_ffi_type_builtin): Don't initialize mnames and mtypes to nil, since we are using calloc. (make_ffi_type_pointer): Don't initialize mnames or mtypes to nil. Do initialize eltype to the target type. (make_ffi_type_array): Initialize eltype instead of mtypes. (ffi_type_compile): For cptr and carray, initialize eltype instead of mtypes.
-rw-r--r--ffi.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/ffi.c b/ffi.c
index d6326d4f..7c4212f2 100644
--- a/ffi.c
+++ b/ffi.c
@@ -100,6 +100,7 @@ struct txr_ffi_type {
val lt;
val syntax;
val mnames;
+ val eltype;
val mtypes;
cnum size, align;
cnum nelem;
@@ -162,6 +163,7 @@ static void ffi_struct_type_mark(val obj)
struct txr_ffi_type *tft = ffi_type_struct(obj);
gc_mark(tft->lt);
gc_mark(tft->syntax);
+ gc_mark(tft->eltype);
gc_mark(tft->mnames);
gc_mark(tft->mtypes);
}
@@ -171,7 +173,7 @@ static void ffi_ptr_type_mark(val obj)
struct txr_ffi_type *tft = ffi_type_struct(obj);
gc_mark(tft->lt);
gc_mark(tft->syntax);
- gc_mark(tft->mtypes);
+ gc_mark(tft->eltype);
}
static struct cobj_ops ffi_type_builtin_ops =
@@ -262,7 +264,7 @@ static mem_t *ffi_fixed_alloc(struct txr_ffi_type *tft, val obj, val self)
static mem_t *ffi_varray_alloc(struct txr_ffi_type *tft, val obj, val self)
{
cnum len = c_num(length(obj));
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
return chk_calloc(len, etft->size);
}
@@ -598,19 +600,19 @@ static val ffi_wchar_get(struct txr_ffi_type *tft, mem_t *src, val self)
static void ffi_cptr_put(struct txr_ffi_type *tft, val n, mem_t *dst,
val self)
{
- mem_t *p = cptr_handle(n, tft->mtypes, self);
+ mem_t *p = cptr_handle(n, tft->eltype, self);
*coerce(mem_t **, dst) = p;
}
static val ffi_cptr_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
mem_t *p = *coerce(mem_t **, src);
- return cptr_typed(p, tft->mtypes, 0);
+ return cptr_typed(p, tft->eltype, 0);
}
static mem_t *ffi_cptr_alloc(struct txr_ffi_type *tft, val ptr, val self)
{
- return coerce(mem_t *, cptr_addr_of(ptr, tft->mtypes, self));
+ return coerce(mem_t *, cptr_addr_of(ptr, tft->eltype, self));
}
static val ffi_str_in(struct txr_ffi_type *tft, int copy,
@@ -808,7 +810,7 @@ static void ffi_closure_put(struct txr_ffi_type *tft, val ptr, mem_t *dst,
static val ffi_ptr_in_in(struct txr_ffi_type *tft, int copy, mem_t *src,
val obj, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t **loc = coerce(mem_t **, src);
if (tgtft->in != 0)
@@ -821,7 +823,7 @@ static val ffi_ptr_in_in(struct txr_ffi_type *tft, int copy, mem_t *src,
static val ffi_ptr_in_d_in(struct txr_ffi_type *tft, int copy, mem_t *src,
val obj, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t **loc = coerce(mem_t **, src);
if (tgtft->in != 0)
@@ -832,7 +834,7 @@ static val ffi_ptr_in_d_in(struct txr_ffi_type *tft, int copy, mem_t *src,
static void ffi_ptr_in_out(struct txr_ffi_type *tft, int copy, val s,
mem_t *dst, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
if (tgtft->out != 0) {
mem_t *buf = *coerce(mem_t **, dst);
@@ -843,7 +845,7 @@ static void ffi_ptr_in_out(struct txr_ffi_type *tft, int copy, val s,
static val ffi_ptr_out_in(struct txr_ffi_type *tft, int copy, mem_t *src,
val obj, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t **loc = coerce(mem_t **, src);
if (tgtft->in != 0)
@@ -858,7 +860,7 @@ static val ffi_ptr_out_in(struct txr_ffi_type *tft, int copy, mem_t *src,
static void ffi_ptr_out_put(struct txr_ffi_type *tft, val s, mem_t *dst,
val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
if (s == nil) {
*coerce(mem_t **, dst) = 0;
@@ -871,7 +873,7 @@ static void ffi_ptr_out_put(struct txr_ffi_type *tft, val s, mem_t *dst,
static void ffi_ptr_out_out(struct txr_ffi_type *tft, int copy, val s,
mem_t *dst, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t *buf = *coerce(mem_t **, dst);
if (tgtft->out != 0)
@@ -882,7 +884,7 @@ static void ffi_ptr_out_out(struct txr_ffi_type *tft, int copy, val s,
static val ffi_ptr_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t *ptr = *coerce(mem_t **, src);
return ptr ? tgtft->get(tgtft, ptr, self) : nil;
@@ -890,7 +892,7 @@ static val ffi_ptr_get(struct txr_ffi_type *tft, mem_t *src, val self)
static val ffi_ptr_d_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t **loc = coerce(mem_t **, src);
val ret = *loc ? tgtft->get(tgtft, *loc, self) : nil;
@@ -902,7 +904,7 @@ static val ffi_ptr_d_get(struct txr_ffi_type *tft, mem_t *src, val self)
static void ffi_ptr_in_put(struct txr_ffi_type *tft, val s, mem_t *dst,
val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
if (s == nil) {
*coerce(mem_t **, dst) = 0;
@@ -922,7 +924,7 @@ static void ffi_ptr_out_null_put(struct txr_ffi_type *tft, val s, mem_t *dst,
static val ffi_ptr_out_s_in(struct txr_ffi_type *tft, int copy,
mem_t *src, val obj, val self)
{
- val tgttype = tft->mtypes;
+ val tgttype = tft->eltype;
struct txr_ffi_type *tgtft = ffi_type_struct(tgttype);
mem_t **loc = coerce(mem_t **, src);
if (tgtft->in != 0)
@@ -934,7 +936,7 @@ static val ffi_ptr_out_s_in(struct txr_ffi_type *tft, int copy,
static void ffi_ptr_in_release(struct txr_ffi_type *tft, val obj, mem_t *dst)
{
- struct txr_ffi_type *tgtft = ffi_type_struct(tft->mtypes);
+ struct txr_ffi_type *tgtft = ffi_type_struct(tft->eltype);
mem_t **loc = coerce(mem_t **, dst);
if (tgtft->release != 0 && *loc != 0)
@@ -1171,7 +1173,7 @@ static void ffi_bchar_array_put(struct txr_ffi_type *tft, val str, mem_t *dst,
static val ffi_array_in_common(struct txr_ffi_type *tft, int copy,
mem_t *src, val vec, val self, cnum nelem)
{
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
ucnum offs = 0;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size, i;
@@ -1215,7 +1217,7 @@ static val ffi_array_in(struct txr_ffi_type *tft, int copy, mem_t *src,
static void ffi_array_put_common(struct txr_ffi_type *tft, val vec, mem_t *dst,
val self, cnum nelem)
{
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size;
int nt = tft->null_term;
@@ -1250,7 +1252,7 @@ static void ffi_array_put(struct txr_ffi_type *tft, val vec, mem_t *dst,
static void ffi_array_out_common(struct txr_ffi_type *tft, int copy, val vec,
mem_t *dst, val self, cnum nelem)
{
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size;
int nt = tft->null_term;
@@ -1289,7 +1291,7 @@ static void ffi_array_out(struct txr_ffi_type *tft, int copy, val vec,
static val ffi_array_get_common(struct txr_ffi_type *tft, mem_t *src, val self,
cnum nelem)
{
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
if (tft->char_conv) {
return ffi_char_array_get(tft, src, nelem);
@@ -1323,7 +1325,7 @@ static val ffi_array_get(struct txr_ffi_type *tft, mem_t *src, val self)
static void ffi_array_release_common(struct txr_ffi_type *tft, val vec,
mem_t *dst, cnum nelem)
{
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
ucnum offs = 0;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size, i;
@@ -1368,7 +1370,7 @@ static val ffi_varray_null_term_in(struct txr_ffi_type *tft, int copy, mem_t *sr
val vec_in, val self)
{
val vec = vector(zero, nil);
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size;
cnum offs, i;
@@ -1401,7 +1403,7 @@ static val ffi_varray_null_term_get(struct txr_ffi_type *tft, mem_t *src,
val self)
{
val vec = vector(zero, nil);
- val eltype = tft->mtypes;
+ val eltype = tft->eltype;
struct txr_ffi_type *etft = ffi_type_struct(eltype);
cnum elsize = etft->size;
cnum offs, i;
@@ -1435,13 +1437,13 @@ static void ffi_varray_release(struct txr_ffi_type *tft, val vec, mem_t *dst)
static val ffi_carray_get(struct txr_ffi_type *tft, mem_t *src, val self)
{
mem_t *p = *coerce(mem_t **, src);
- return make_carray(tft->mtypes, p, -1, nil);
+ return make_carray(tft->eltype, p, -1, nil);
}
static void ffi_carray_put(struct txr_ffi_type *tft, val carray, mem_t *dst,
val self)
{
- mem_t *p = carray_get(carray, tft->mtypes, self);
+ mem_t *p = carray_get(carray, tft->eltype, self);
*coerce(mem_t **, dst) = p;
}
@@ -1460,7 +1462,6 @@ static val make_ffi_type_builtin(val syntax, val lisp_type,
tft->ft = ft;
tft->syntax = syntax;
tft->lt = lisp_type;
- tft->mnames = tft->mtypes = nil;
tft->size = size;
tft->align = align;
tft->put = put;
@@ -1492,11 +1493,10 @@ static val make_ffi_type_pointer(val syntax, val lisp_type, cnum size,
tft->ft = &ffi_type_pointer;
tft->syntax = syntax;
tft->lt = lisp_type;
- tft->mnames = tft->mtypes = nil;
tft->size = tft->align = size;
tft->put = put;
tft->get = get;
- tft->mtypes = tgtype;
+ tft->eltype = tgtype;
tft->in = in;
tft->out = out;
tft->release = release;
@@ -1587,7 +1587,7 @@ static val make_ffi_type_array(val syntax, val lisp_type,
tft->syntax = syntax;
tft->lt = lisp_type;
tft->mnames = nil;
- tft->mtypes = eltype;
+ tft->eltype = eltype;
tft->put = ffi_array_put;
tft->get = ffi_array_get;
tft->in = ffi_array_in;
@@ -1794,7 +1794,7 @@ val ffi_type_compile(val syntax)
&ffi_type_pointer,
ffi_cptr_put, ffi_cptr_get);
struct txr_ffi_type *tft = ffi_type_struct(type);
- tft->mtypes = tag;
+ tft->eltype = tag;
return type;
} else if (sym == carray_s) {
val element_type = ffi_type_compile(cadr(syntax));
@@ -1803,7 +1803,7 @@ val ffi_type_compile(val syntax)
&ffi_type_pointer,
ffi_carray_put, ffi_carray_get);
struct txr_ffi_type *tft = ffi_type_struct(type);
- tft->mtypes = element_type;
+ tft->eltype = element_type;
return type;
}
uw_throwf(error_s, lit("~a: unrecognized type operator: ~s"),