Message: 1Date: Thu, 20 Aug 2015 17:51:43 +0200From: Esteban Lorenzano <estebanlm@gmail.com>Subject: [Vm-dev] nested structures with FFI?To: Squeak Virtual Machine Development Discussion <vm-dev@lists.squeakfoundation.org>Message-ID: <4F31ED4B-6246-43D6-B85B-7215D8570D28@gmail.com>Content-Type: text/plain; charset=utf-8Hi,I’m doing some tests with nested structures (to handle the conversion of NativeBoost-FFI to regular FFI) and I’m having some problems when accessing fields in the nested structure. For example, this tests: FFITestNestingStructure class>>#fieldsDesc ^ #( byte one; FFITestStructure nested; )FFITestStructure class>>#fieldsDesc ^ #( byte byte; short short; long long; float float; double double; int64 int64; )(definition is NB-compatible, so do not take the differences with regular FFI into account)testNestedStructure | s1 | s1 := FFITestNestingStructure new. s1 nested byte: 42. self assert: s1 nested byte = 42testExternallyAllocatedNestedStructure | s1 | s1 := FFITestNestingStructure externalNew. self assert: s1 getHandle class = ExternalAddress. s1 nested byte: 42. self assert: s1 nested byte = 42fails always because s1 nested byte = 0. (which is obviously bad). I remember Eliot saying that structures with FFI was not being optimal, and I wonder (before start digging more in deep) if this could have something to do?
I use nested structs in NB for the libgit2 bindings and they work as advertised. There can be problems if some structure is packed (i.e. uses non-4-byte alignment for some field) but that shouldn’t apply in your test case.
Not sure if this helps you in any way but I thought I’d let you know :)