FFI | How to call a function that expects a "long" argument in C?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

FFI | How to call a function that expects a "long" argument in C?

marcel.taeumel
Hi, there.

I want to understand how data models for 64-bit influence the image side of Squeak FFI.

I discovered that there are test functions in the SqueakFFIPrims plugin (sqFFITestFuncs.c) that expect actual "long" types. So, I assume that that is the "long" from C, not Squeak FFI, and thus different on 64-bit Windows vs. 64-bit Unix.

ffiTest4LongSum
ffiTestLongs8
ffiTest8longSum
ffiTestMixedDoublesAndLongs (!!!)

Only the last one is actually called from FFI Tests, which could be worse. Because there is not yet a mechanism in place that considers the data model an 64-bit platforms.

So, I think that an atomic type alias for such a C "long" argument could be defined like this:

(wordSize = 4 or: [platformName = 'Win32'])
   ifTrue: ['long' "meaning 'int' in the plugin]
   ifFalse: ['longlong']

Yet, I have no clue on how to name such a type alias. long_t ? native_long_t ? Squeak FFI's 'long' is already taken, and it is always 4 byte.

Would it make sense to also query the data model through a primitive and add that to FFIPlatformDescription? LLP64, LP64, ILP64, SILP64, ... 

Best,
Marcel


Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to call a function that expects a "long" argument in C?

Nicolas Cellier


Le mar. 9 juin 2020 à 19:19, Marcel Taeumel <[hidden email]> a écrit :
Hi, there.

I want to understand how data models for 64-bit influence the image side of Squeak FFI.

I discovered that there are test functions in the SqueakFFIPrims plugin (sqFFITestFuncs.c) that expect actual "long" types. So, I assume that that is the "long" from C, not Squeak FFI, and thus different on 64-bit Windows vs. 64-bit Unix.

ffiTest4LongSum
ffiTestLongs8
ffiTest8longSum
ffiTestMixedDoublesAndLongs (!!!)

Only the last one is actually called from FFI Tests, which could be worse. Because there is not yet a mechanism in place that considers the data model an 64-bit platforms.

So, I think that an atomic type alias for such a C "long" argument could be defined like this:

(wordSize = 4 or: [platformName = 'Win32'])
   ifTrue: ['long' "meaning 'int' in the plugin]
   ifFalse: ['longlong']

BTW, I documented as I discovered in a serie of SO questions like
Yet, I have no clue on how to name such a type alias. long_t ? native_long_t ? Squeak FFI's 'long' is already taken, and it is always 4 byte.

Me neither... c_long?

Would it make sense to also query the data model through a primitive and add that to FFIPlatformDescription? LLP64, LP64, ILP64, SILP64, ... 

YAGNI

Best,
Marcel



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to call a function that expects a "long" argument in C?

Nicolas Cellier


Le mar. 9 juin 2020 à 22:39, Nicolas Cellier <[hidden email]> a écrit :


Le mar. 9 juin 2020 à 19:19, Marcel Taeumel <[hidden email]> a écrit :
Hi, there.

I want to understand how data models for 64-bit influence the image side of Squeak FFI.

I discovered that there are test functions in the SqueakFFIPrims plugin (sqFFITestFuncs.c) that expect actual "long" types. So, I assume that that is the "long" from C, not Squeak FFI, and thus different on 64-bit Windows vs. 64-bit Unix.

ffiTest4LongSum
ffiTestLongs8
ffiTest8longSum
ffiTestMixedDoublesAndLongs (!!!)

Only the last one is actually called from FFI Tests, which could be worse. Because there is not yet a mechanism in place that considers the data model an 64-bit platforms.

So, I think that an atomic type alias for such a C "long" argument could be defined like this:

(wordSize = 4 or: [platformName = 'Win32'])
   ifTrue: ['long' "meaning 'int' in the plugin]
   ifFalse: ['longlong']

BTW, I documented as I discovered in a serie of SO questions like

I'm on a poor man hp sucking touchpad... Give me back my Mac!

Feel free to add new answers for updated FFI when ready.

Yet, I have no clue on how to name such a type alias. long_t ? native_long_t ? Squeak FFI's 'long' is already taken, and it is always 4 byte.

Me neither... c_long?

Would it make sense to also query the data model through a primitive and add that to FFIPlatformDescription? LLP64, LP64, ILP64, SILP64, ... 

YAGNI

Best,
Marcel



Reply | Threaded
Open this post in threaded view
|

Re: FFI | How to call a function that expects a "long" argument in C?

marcel.taeumel
Hi Nicolas,

good idea! I just did that.


Best,
Marcel

Am 09.06.2020 22:42:03 schrieb Nicolas Cellier <[hidden email]>:



Le mar. 9 juin 2020 à 22:39, Nicolas Cellier <[hidden email]> a écrit :


Le mar. 9 juin 2020 à 19:19, Marcel Taeumel <[hidden email]> a écrit :
Hi, there.

I want to understand how data models for 64-bit influence the image side of Squeak FFI.

I discovered that there are test functions in the SqueakFFIPrims plugin (sqFFITestFuncs.c) that expect actual "long" types. So, I assume that that is the "long" from C, not Squeak FFI, and thus different on 64-bit Windows vs. 64-bit Unix.

ffiTest4LongSum
ffiTestLongs8
ffiTest8longSum
ffiTestMixedDoublesAndLongs (!!!)

Only the last one is actually called from FFI Tests, which could be worse. Because there is not yet a mechanism in place that considers the data model an 64-bit platforms.

So, I think that an atomic type alias for such a C "long" argument could be defined like this:

(wordSize = 4 or: [platformName = 'Win32'])
   ifTrue: ['long' "meaning 'int' in the plugin]
   ifFalse: ['longlong']

BTW, I documented as I discovered in a serie of SO questions like

I'm on a poor man hp sucking touchpad... Give me back my Mac!

Feel free to add new answers for updated FFI when ready.

Yet, I have no clue on how to name such a type alias. long_t ? native_long_t ? Squeak FFI's 'long' is already taken, and it is always 4 byte.

Me neither... c_long?

Would it make sense to also query the data model through a primitive and add that to FFIPlatformDescription? LLP64, LP64, ILP64, SILP64, ... 

YAGNI

Best,
Marcel