On 4 August 2014 12:37, Thomas Bany <mun.sysdev@gmail.com> wrote:
Hi everyone !
I experience troubles with NBExternalStructure in NativeBoost when the structure modeled contains fields with different types. For example, manipulating the following structure poses no problem and I can manipulate the fields correctly:
typedef struct abc_s { double a; double b; double c; } abc;
However, setting field 'a' to be an int yields the following symptoms: ¤ From Pharo to C (function with 'abc' as argument type), the fields are badly read. ¤ From C to Pharo (function with 'abc' as return type), the VM crash without an error nor a dump.
Am I doing something wrong or is it maybe specific to the compiler I use (the one that comes with Visual Studio Express 2013) ?
This caused by wrong alignment of structure in memory. Different compilers can align structures differently, and there's no way to know it at run time. Try to change the # *byteAlignment of the structure.Also, if nothing helps, you can use dummy fields* for padding fields, like in your example: int a; int dummy; double b; double c;
I'm pretty sure I could go arround this using NBExternalObject and building the structure on C side, but it would be nice to avoid it.
On a side note, my understanding is that creating a structure on Pharo side will have it stored in Pharo memory. Is it problematic when it comes to pass it by value ? Or should I manage the copying on the C heap to be safe ?
Thomas.
-- Best regards, Igor Stasenko.