ffi 0.9: foreign-result chains — handle threaded through struct + List
96/96 regression tests pass (+ffi-09-foreign-result-chain).
Opaque C-handle pattern that mirrors how real sx code threads
MTLBuffer*, AAssetManager*, file pointers, etc. through composite
sx values. C side has a trivial heap-int handle (`ffi_chain_make`
returning `void*`, `ffi_chain_bump` / `_peek` / `_dispose`). The sx
side exercises:
1. Chained calls — make -> bump -> bump -> peek; one handle
threaded through four FFI sites in sequence.
2. Struct field — `Counter { handle: *void; label: string; }`
hosts the handle; methods/accesses go through
`.handle` to feed back into C.
3. List(*void) — push N handles, iterate, peek each, iterate
again to bump each, iterate again to read
back. Catches any aliasing / lifetime breakage
when handles round-trip through the slice
backing of List.
This commit is contained in:
1
tests/expected/ffi-09-foreign-result-chain.exit
Normal file
1
tests/expected/ffi-09-foreign-result-chain.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
13
tests/expected/ffi-09-foreign-result-chain.txt
Normal file
13
tests/expected/ffi-09-foreign-result-chain.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
peek after make = 100
|
||||
bump(+5) = 105
|
||||
bump(+3) = 108
|
||||
peek after bumps = 108
|
||||
ctr label = ctr-a
|
||||
ctr peek = 50
|
||||
ctr after bump = 57
|
||||
list[0] peek = 0
|
||||
list[1] peek = 10
|
||||
list[2] peek = 20
|
||||
list[0] after bump= 1
|
||||
list[1] after bump= 11
|
||||
list[2] after bump= 21
|
||||
Reference in New Issue
Block a user