PS: for the first example, the alignment is not respected, the vec3
structure is starting at 9 but uffi is fetching it at 5
On 06/07/2016 17:55, Merwan Ouddane wrote:
Another test:
I replaced double by integer, for visibility...
typedef struct vec3 {
int data[3];
} vec3;
add a second vec3 to position:
typedef struct position {
int i;
vec3 vec;
vec3 vec2;
} position;
Now in pharo:
Position >> fieldsDesc
"self rebuildFieldAccessors"
^ #(
int i;
Vec3 vec;
Vec3 vec2;
)
The size returned for each stucture is 16 instead of 12 that because
of the "8 byte alignment"
Meaning that the "position" structure is corrupted.
With this function:
extern "C" void DLL_EXPORT fillStruct(position *position)
{
position -> i = 19;
(position -> vec).data[0] = 1;
(position -> vec).data[1] = 2;
(position -> vec).data[2] = 3;
(position -> vec2).data[0] = 1;
(position -> vec2).data[1] = 2;
(position -> vec2).data[2] = 3;
}
We will get:
position i == 19
position vec at: 1 == 1
position vec2 at: 1 == 2
On Tue, Jul 5, 2016 at 3:12 PM, Ronie Salgado <ronies...@gmail.com
<mailto:ronies...@gmail.com>> wrote:
I compiled the DLL using Visual Studio 2015 Community Edition.
Later I will check with mingw.
2016-07-05 14:58 GMT+02:00 Merwan Ouddane <merwanoudd...@gmail.com
<mailto:merwanoudd...@gmail.com>>:
Using codeblocks, mine are:
mingw32-g++.exe -m32 -DBUILD_DLL -c main.cpp -o obj\Release\main.o
mingw32-g++.exe -shared
-Wl,--output-def=bin\Release\libTest.def
-Wl,--out-implib=bin\Release\libTest.a -Wl,--dll
obj\Release\main.o -o bin\Release\Test.dll -s -m32
On Tue, Jul 5, 2016 at 2:52 PM, Merwan Ouddane
<merwanoudd...@gmail.com <mailto:merwanoudd...@gmail.com>> wrote:
I am not moving from another plateform :/
I tried it in pharo 6 and I it didn't work either.
It could be my dll. What is your compilation line for the
dll ?
Thanks you,
Merwan
On Tue, Jul 5, 2016 at 2:14 PM, Ronie Salgado
<ronies...@gmail.com <mailto:ronies...@gmail.com>> wrote:
Hi Merwan,
I tested this on Pharo 6 and it is working in Windows.
However, in 32 bits Window doubles have an 8 byte
alignment, unlike Linux where they have a 4 byte
alignment.
Can you try doing the following before performing the
ffi call in Windows, if you are moving an image from
Linux or OS X:
Vec3 rebuildFieldAccessors.
Position rebuildFieldAccessors.
Best regards,
Ronie
2016-07-05 11:11 GMT+02:00 Merwan Ouddane
<merwanoudd...@gmail.com
<mailto:merwanoudd...@gmail.com>>:
Hi,
I have an issue whith nested structures.
I made some "dummy" structures in c:
typedef struct vec3 {
double data[3];
} vec3;
typedef struct position {
int i;
vec3 vec;
} position;
And a "dummy" function to fill it:
void fillStruct(position *position)
{
position -> i = 19;
(position -> vec).data[0] = 1;
(position -> vec).data[1] = 2;
(position -> vec).data[2] = 3;
}
But I can't make the nested structure work.
The "i" is correctly set to 19 but I have values
that doesn't make any sense in the vec3 structure.
In Pharo
I declared the Double3 type for the array inside Vec3:
Double3 := FFITypeArray ofType: 'double' size: 3
Vec3>>fieldsDesc
^ #(
Double3 v;
)
And the position:
Position>>fieldsDesc
^ #(
int i;
Vec3 vec;
)
The ffi call:
^ self ffiCall: #(void fillStruct(Position
*position)) module: 'Test.dll'
Sorry for the long / messy mail :p
Any clues ?
Cheers,
Merwan