FFI: FFI-Kernel-mt.81.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.81.mcz

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

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

Name: FFI-Kernel-mt.81
Author: mt
Time: 1 June 2020, 9:06:23.085523 am
UUID: 32229562-fe90-5b42-8d0d-926e8bc4da7a
Ancestors: FFI-Kernel-mt.80

More flags to document #ffiLongVsInt -- which is an intersting clash of vocabularies. :-)

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

Item was changed:
  ----- Method: ByteArray>>pointerAt: (in category '*FFI-Kernel') -----
  pointerAt: byteOffset
  "Answer a pointer object stored at the given byte address"
 
+ self flag: #ffiLongVsInt. "mt: Here short means 'long', which is actually 'int', and long means 'longlong'. Sigh."
  ^ ExternalAddress wordSize caseOf: {
  [4] -> [self shortPointerAt: byteOffset].
  [8] -> [self longPointerAt: byteOffset] }!

Item was changed:
  ----- Method: ByteArray>>pointerAt:put: (in category '*FFI-Kernel') -----
  pointerAt: byteOffset put: value
  "Store a pointer object at the given byte address"
 
+ self flag: #ffiLongVsInt. "mt: Here short means 'long', which is actually 'int', and long means 'longlong'. Sigh."
  ^ ExternalAddress wordSize caseOf: {
  [4] -> [self shortPointerAt: byteOffset put: value].
  [8] -> [self longPointerAt: byteOffset put: value] }!

Item was changed:
  ----- Method: ExternalType class>>initializeFFIConstants (in category 'class initialization') -----
  initializeFFIConstants
  "ExternalType initialize"
  FFIConstants initialize. "ensure proper initialization"
  AtomicTypeNames := IdentityDictionary new.
  AtomicSelectors := IdentityDictionary new.
  AtomicTypeNames
  at: FFITypeVoid put: 'void';
  at: FFITypeBool put: 'bool';
  at: FFITypeUnsignedByte put: 'byte';
  at: FFITypeSignedByte put: 'sbyte';
  at: FFITypeUnsignedShort put: 'ushort';
  at: FFITypeSignedShort put: 'short';
+ flag: #ffiLongVsInt;
  at: FFITypeUnsignedInt put: 'ulong';
  at: FFITypeSignedInt put: 'long';
  at: FFITypeUnsignedLongLong put: 'ulonglong';
  at: FFITypeSignedLongLong put: 'longlong';
  at: FFITypeUnsignedChar put: 'char';
  at: FFITypeSignedChar put: 'schar';
  at: FFITypeSingleFloat put: 'float';
  at: FFITypeDoubleFloat put: 'double';
  yourself.
 
  AtomicSelectors
  at: FFITypeVoid put: #voidAt:;
  at: FFITypeBool put: #booleanAt:;
  at: FFITypeUnsignedByte put: #unsignedByteAt:;
  at: FFITypeSignedByte put: #signedByteAt:;
  at: FFITypeUnsignedShort put: #unsignedShortAt:;
  at: FFITypeSignedShort put: #signedShortAt:;
+ flag: #ffiLongVsInt;
  at: FFITypeUnsignedInt put: #unsignedLongAt:;
  at: FFITypeSignedInt put: #signedLongAt:;
  at: FFITypeUnsignedLongLong put: #unsignedLongLongAt:;
  at: FFITypeSignedLongLong put: #signedLongLongAt:;
  at: FFITypeUnsignedChar put: #unsignedCharAt:;
  at: FFITypeSignedChar put: #signedCharAt:;
  at: FFITypeSingleFloat put: #floatAt:;
  at: FFITypeDoubleFloat put: #doubleAt:;
  yourself!

Item was changed:
  ----- Method: ExternalType>>readFieldAt: (in category 'private') -----
  readFieldAt: byteOffset
  "Answer a string defining the accessor to an entity of the receiver type starting at the given byte offset.
  Private. Used for field definition only."
  self isPointerType ifTrue:
  [| accessor |
+ self flag: #ffiLongVsInt. "mt: Here short means 'long', which is actually 'int', and long means 'longlong'. Sigh."
  accessor := self pointerSize caseOf: {
  [4] -> [#shortPointerAt:].
  [8] -> [#longPointerAt:] }.
  ^String streamContents:
  [:s|
  referentClass
  ifNil:
  [s nextPutAll: '^ExternalData fromHandle: (handle ', accessor, ' ';
  print: byteOffset;
  nextPutAll: ') type: ExternalType ';
  nextPutAll: (AtomicTypeNames at: self atomicType);
  nextPutAll: ' asPointerType']
  ifNotNil:
  [s nextPutAll: '^';
  print: referentClass;
  nextPutAll: ' fromHandle: (handle ', accessor, ' ';
  print: byteOffset;
  nextPut: $)]]].
 
  self isAtomic ifFalse: "structure type"
  [^String streamContents:[:s|
  s nextPutAll:'^';
  print: referentClass;
  nextPutAll:' fromHandle: (handle structAt: ';
  print: byteOffset;
  nextPutAll:' length: ';
  print: self byteSize;
  nextPutAll:')']].
 
  "Atomic non-pointer types"
  ^String streamContents:
  [:s|
  s nextPutAll:'^handle ';
  nextPutAll: (AtomicSelectors at: self atomicType);
  space; print: byteOffset].!

Item was changed:
  ----- Method: ExternalType>>writeFieldAt:with: (in category 'private') -----
  writeFieldAt: byteOffset with: valueName
  "Answer a string defining the accessor to an entity of the receiver type starting at the given byte offset.
  Private. Used for field definition only."
  self isPointerType ifTrue:
  [| accessor |
+ self flag: #ffiLongVsInt. "mt: Here short means 'long', which is actually 'int', and long means 'longlong'. Sigh."
  accessor := self pointerSize caseOf: {
  [4] -> [#shortPointerAt:].
  [8] -> [#longPointerAt:] }.
  ^String streamContents:
  [:s|
  s nextPutAll:'handle ', accessor, ' ';
  print: byteOffset;
  nextPutAll:' put: ';
  nextPutAll: valueName;
  nextPutAll:' getHandle.']].
 
  self isAtomic ifFalse:[
  ^String streamContents:[:s|
  s nextPutAll:'handle structAt: ';
  print: byteOffset;
  nextPutAll:' put: ';
  nextPutAll: valueName;
  nextPutAll:' getHandle';
  nextPutAll:' length: ';
  print: self byteSize;
  nextPutAll:'.']].
 
  ^String streamContents:[:s|
  s nextPutAll:'handle ';
  nextPutAll: (AtomicSelectors at: self atomicType);
  space; print: byteOffset;
  nextPutAll:' put: ';
  nextPutAll: valueName].!