FFI: fix "&{*}"
This commit is contained in:
parent
0c3d83c50b
commit
b089337ee8
@ -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));
|
||||
}
|
||||
|
||||
@ -334,4 +334,15 @@ StructOfPtrs operateOnStructOfPtrs(StructOfPtrs arg, StructOfPtrs ptr[2]) {
|
||||
.ptr2 = ptr[0].ptr1,
|
||||
.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;
|
||||
}
|
||||
}
|
||||
@ -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,3‿4⟩⊸+⚇0 ⟨10, 20‿30⟩
|
||||
|
||||
f ↩ "lib.so" •FFI "&"‿"updatePointerWithinPointer"‿">&{i32,*}"
|
||||
•Show {x‿y: x ⋈ (y.Cast "u8").Sub p}¨ F {⟨𝕩×1000, p.Add 𝕩×100⟩}¨ ↕5
|
||||
|
||||
f ↩ "lib.so" •FFI "&"‿"updatePointerWithinPointer"‿">&{i32,*u8}"
|
||||
•Show {x‿y: x ⋈ y.Sub p}¨ F {⟨𝕩×1000, (p.Add 𝕩×100).Cast ""⟩}¨ ↕5
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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 ⟩ ⟩
|
||||
|
||||
Loading…
Reference in New Issue
Block a user