summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-20 00:41:52 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-20 00:41:52 -0700
commit2536072b64006004c2999005a1961025725f8bfa (patch)
tree1d96491f3f5578520afa9fd602026d8a71874a7f /ffi.c
parent0069c0b05d810c001c1ab9947b1f8f333caede14 (diff)
downloadtxr-2536072b64006004c2999005a1961025725f8bfa.tar.gz
txr-2536072b64006004c2999005a1961025725f8bfa.tar.bz2
txr-2536072b64006004c2999005a1961025725f8bfa.zip
ffi: bugfix: clone of type points to old self.
* ffi.c (ffi_type_copy, ffi_type_copy_new_ops): The cloned txr_ffi_type structure must have a self member which points to the new cobj, not the original one. Otherwise things are inconsistent. For instance if the clone is being made for the purposes of adjusting alignment, any operation which chases the self pointer will be accessing incorrect attributes. One example of this is (alignof foo.bar) where if bar is the clone of a type, this will incorrectly report the alignment of the original from which bar was cloned, and the original alignment, not the adjusted alignment is reported.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ffi.c b/ffi.c
index 4fbb6d28..437713d7 100644
--- a/ffi.c
+++ b/ffi.c
@@ -3217,14 +3217,18 @@ static val ffi_type_copy(val orig)
{
struct txr_ffi_type *otft = ffi_type_struct(orig);
struct txr_ffi_type *ctft = otft->clone(otft);
- return cobj(coerce(mem_t *, ctft), orig->co.cls, orig->co.ops);
+ val obj = cobj(coerce(mem_t *, ctft), orig->co.cls, orig->co.ops);
+ ctft->self = obj;
+ return obj;
}
static val ffi_type_copy_new_ops(val orig, struct cobj_ops *ops)
{
struct txr_ffi_type *otft = ffi_type_struct(orig);
struct txr_ffi_type *ctft = otft->clone(otft);
- return cobj(coerce(mem_t *, ctft), orig->co.cls, ops);
+ val obj = cobj(coerce(mem_t *, ctft), orig->co.cls, ops);
+ ctft->self = obj;
+ return obj;
}
static struct txr_ffi_type *ffi_simple_clone(struct txr_ffi_type *orig)