FFI: fix "&{*}"

This commit is contained in:
dzaima 2024-03-07 14:42:15 +02:00
parent 0c3d83c50b
commit b089337ee8
4 changed files with 20 additions and 1 deletions

View File

@ -729,7 +729,7 @@ void genObj(B o, B c, void* ptr, B* sourceObjs) { // doesn't consume
void* dataStruct = dataAll+sizeof(usz);
*((usz*)dataAll) = ia;
SGetU(c)
for (usz i = 0; i < ia; i++) genObj(t->a[0].o, GetU(c, i), dataStruct + elSz*i, sourceObjs);
for (usz i = 0; i < ia; i++) genObj(t->a[0].o, GetU(c, i), dataStruct + elSz*i, NULL);
*(void**)ptr = dataStruct;
*sourceObjs = vec_addN(*sourceObjs, tag(TOBJ(dataAll), OBJ_TAG));
}

View File

@ -335,3 +335,14 @@ StructOfPtrs operateOnStructOfPtrs(StructOfPtrs arg, StructOfPtrs ptr[2]) {
.ptrs = {arg.ptrs[0], ptr[1].ptrs[1]}
};
}
typedef struct PtrWrapper {
int32_t x;
char* ptr;
} PtrWrapper;
void updatePointerWithinPointer(PtrWrapper* ptr) {
for (int i = 0; i < 5; i++) {
ptr[i].x+= i*10;
ptr[i].ptr+= i;
}
}

View File

@ -131,6 +131,12 @@ Section "# Struct of pointers"
sop "{*,*i32,[2]*}"
f "lib.so"•FFI sop, "operateOnStructOfPtrs", sop, "[2]"sop
•Show {(𝕩.Cast "u8").Sub p}0 F {(p.Add 𝕩).Cast ""}0 1,2,34+0 10, 2030
f "lib.so" •FFI "&""updatePointerWithinPointer"">&{i32,*}"
•Show {xy: x (y.Cast "u8").Sub p}¨ F {𝕩×1000, p.Add 𝕩×100}¨ 5
f "lib.so" •FFI "&""updatePointerWithinPointer"">&{i32,*u8}"
•Show {xy: x y.Sub p}¨ F {𝕩×1000, (p.Add 𝕩×100).Cast ""}¨ 5
}

View File

@ -136,3 +136,5 @@ text
# Struct of pointers
⟨ 12 21 ⟨ 13 34 ⟩ ⟩
⟨ ⟨ 0 0 ⟩ ⟨ 1010 101 ⟩ ⟨ 2020 202 ⟩ ⟨ 3030 303 ⟩ ⟨ 4040 404 ⟩ ⟩
⟨ ⟨ 0 0 ⟩ ⟨ 1010 101 ⟩ ⟨ 2020 202 ⟩ ⟨ 3030 303 ⟩ ⟨ 4040 404 ⟩ ⟩