FFI: FFI-Kernel-mt.104.mcz

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

FFI: FFI-Kernel-mt.104.mcz

commits-2
Marcel Taeumel uploaded a new version of FFI-Kernel to project FFI:
http://source.squeak.org/FFI/FFI-Kernel-mt.104.mcz

==================== Summary ====================

Name: FFI-Kernel-mt.104
Author: mt
Time: 11 June 2020, 10:55:09.189855 am
UUID: 4867f4c0-e2a0-3f45-8392-9445111c80c5
Ancestors: FFI-Kernel-mt.103

Adds lightweight aliases for 'long' and 'unsigned long' in C. Do not confuse it with Squeak FFI 'long', which is 'int' or rather 'int32_t'.

(We might want to add a warning for programmers that want to compile methods or struct fields using 'long' instead of 'c_long' or 'int32_t'. To help them think about the issue.)

=============== Diff against FFI-Kernel-mt.103 ===============

Item was added:
+ ----- Method: ExternalType class>>c_long (in category 'type constants - extra') -----
+ c_long
+ "Try to approximate a fitting type for 'long' in a C interface. First, note that this is not the same as 'long' in Squeak FFI, which is always 4 byte and hence corresponds to 'int' or rather 'int32_t' in C. Second, note that we do not want to expose the platforms underlying data model in Squeak because the OpenSmalltalk VM has no support for all kinds of architectures out there but only a popular subset such as x86-based ones. Still, this method is written to explicate the issue of different data models for 32-bit and 64-bit platforms."
+
+ | platform dataModel |
+ platform := FFIPlatformDescription current.
+ dataModel := platform wordSize = 4
+ ifTrue: ['ILP32']
+ ifFalse: [platform isWindows
+ ifTrue: ['LLP64']
+ ifFalse: ['LP64']].
+ ^ dataModel caseOf: {
+ ['ILP32'] -> [self int32_t].
+ ['LP64'] -> [self int64_t].
+ ['LLP64'] -> [self int32_t] }!

Item was added:
+ ----- Method: ExternalType class>>c_ulong (in category 'type constants - extra') -----
+ c_ulong
+ "Try to approximate a fitting type for 'usigned long' in a C interface. See comment in #c_long."
+
+ ^ self atomicTypeNamed: 'u', self c_long atomicTypeName!