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

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

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

Name: FFI-Kernel-mt.133
Author: mt
Time: 5 May 2021, 6:22:06.654784 pm
UUID: 5b4d9432-d53c-424d-9d60-7e9dd5c7ce64
Ancestors: FFI-Kernel-mt.132

Since empty array types such as char[] are not actually supported, e.g., in struct defs, disallow them for now to not deceive users trying to work with them and then wonder about strange results.

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

Item was changed:
  ----- Method: ExternalArrayType class>>newTypeForContentType:size: (in category 'instance creation') -----
  newTypeForContentType: contentType size: numElements
  "!!!!!! Be aware that only the pointer type can be used in calls. As of SqueakFFIPrims VMMaker.oscog-eem.2950, there is no actual support for array types in the FFI plugin !!!!!!"
 
  | type pointerType headerWord byteSize |
  self
  assert: [contentType isPointerType not]
  description: 'No support for pointers as content type yet!!'.
 
  self
+ assert: [numElements > 0]
+ description: 'Empty array types are not supported!!'.
+
+ self
  assert: [contentType byteSize > 0]
  description: 'Invalid byte size!!'.
 
  self
  assert: [(ArrayTypes includesKey: contentType typeName -> numElements) not]
  description: 'Array type already exists. Use #typeNamed: to access it.'.
 
  type := self "ExternalArrayType" basicNew.
  pointerType := ExternalType basicNew.
 
  "1) Regular type"
  byteSize := numElements * contentType byteSize.
  self assert: [byteSize <= FFIStructSizeMask].
  headerWord := contentType headerWord.
  headerWord := headerWord bitClear: FFIStructSizeMask.
  headerWord := headerWord bitOr: byteSize.
  type
  setReferencedType: pointerType;
  compiledSpec: (WordArray with: headerWord);
  byteAlignment: contentType byteAlignment;
  setReferentClass: contentType referentClass;
  setSize: numElements.
 
  "2) Pointer type. Reuse the compiledSpec of the content-type's pointer type."
  pointerType
  setReferencedType: type;
  compiledSpec: contentType asPointerType compiledSpec copy;
  byteAlignment: contentType asPointerType byteAlignment;
  setReferentClass: contentType asPointerType referentClass.
 
  "3) Remember this new array type."
  ArrayTypes
  at: contentType typeName -> numElements
  put: type.
 
  ^ type!

Item was changed:
  ----- Method: ExternalType class>>newTypeNamed: (in category 'instance creation') -----
  newTypeNamed: aTypeName
  "Create a new struct type or array type. Not needed for atomic types; see #initializeDefaultTypes."
 
  | structClass arraySpec |
  self
  assert: [aTypeName last ~~ $*]
  description: 'Pointer type will be created automatically'.
 
  aTypeName last == $] ifTrue: [ "array type, e.g., char[50]"
  arraySpec := self parseArrayTypeName: aTypeName.
  arraySpec second ifNil: [arraySpec at: 2 put: (self newTypeNamed: arraySpec first)].
- arraySpec third ifNil: [arraySpec at: 3 put: 0].
  ^ self
  newTypeForContentType: arraySpec second
  size: arraySpec third].
 
  structClass := (self environment classNamed: aTypeName)
  ifNotNil: [:class | (class includesBehavior: ExternalStructure) ifTrue: [class]].
 
  ^ structClass
  ifNil: [self newTypeForUnknownNamed: aTypeName]
  ifNotNil: [self newTypeForStructureClass: structClass]!

Item was changed:
  (PackageInfo named: 'FFI-Kernel') postscript: 'Smalltalk removeFromStartUpList: ExternalAddress.
  Smalltalk removeFromStartUpList: ExternalObject.
 
  "Adds housekeeping for array types."
+ ExternalType resetAllStructureTypes..
- ExternalType resetAllStructureTypes.
 
  "Re-generate all field accessors because type checks are now controlled by a new preference."
  ExternalStructure defineAllFields.
  '!