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

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

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

Name: FFI-Kernel-mt.157
Author: mt
Time: 17 May 2021, 10:03:47.21887 am
UUID: eee9f199-4910-6b4b-b9b5-1c793d7ce342
Ancestors: FFI-Kernel-mt.156

Fixes some bugs with empty array types during code loading.

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

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
  flag: #contentVsContainer;
  assert: [contentType isTypeAlias or: [contentType isArrayType not]]
  description: 'No support for direct multi-dimensional containers yet. Use type aliases.'.
 
  self
+ assert: [contentType isVoid not]
+ description: 'No array types for void type!!'.
+
+ self
  assert: [
  (ArrayTypes at: contentType typeName
  ifPresent: [:sizes | sizes at: numElements ifAbsent: [nil]]
  ifAbsent: [nil] ) isNil]
  description: 'Array type already exists. Use #typeNamed: to access it.'.
 
  type := ExternalArrayType basicNew.
  pointerType := ExternalPointerType basicNew.
 
  "1) Regular type"
  byteSize := numElements
  ifNil: [0] ifNotNil: [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: (numElements ifNil: [0] ifNotNil: [contentType byteAlignment]);
  setReferentClass: contentType referentClass;
  setContentType: contentType;
  setSize: numElements.
 
  "2) Pointer type. Reuse the compiledSpec of the content-type's pointer type."
  pointerType
  setReferencedType: type;
  compiledSpec: (WordArray with: (self pointerSpec bitOr: FFIFlagAtomic "HACK!! To deceive the FFI plugin :)"));
  byteAlignment: self pointerAlignment;
  setReferentClass: nil.
 
  "3) Remember this new array type."
  (ArrayTypes at: contentType typeName ifAbsentPut: [WeakValueDictionary new])
  at: numElements put: type.
 
  ^ type!

Item was changed:
  ----- Method: ExternalArrayType>>isTypeAlias (in category 'testing') -----
  isTypeAlias
 
+ self isUnknownType ifTrue: [^ false].
+
  ^ self isArrayOfArrays not
  and: [referentClass notNil
  and: [referentClass isTypeAlias
  and: [referentClass originalType isArrayType]]]!

Item was changed:
  ----- Method: ExternalArrayType>>isUnknownType (in category 'testing') -----
  isUnknownType
+ "Array of unknown type is also an unknown type."
+
+ ^ self contentType isUnknownType!
-
- ^ false!

Item was changed:
  ----- Method: ExternalStructure class>>doneCompiling (in category 'class management') -----
  doneCompiling
  "Base class changed to something that is an external structure now."
 
+ [self compileFields] ifError: [ "Ignore unfinished field specs" ].
+ self externalType isUnknownType ifTrue: [self externalType becomeKnownType].!
- [self compileFields] ifError: [ "Ignore unfinished field specs" ].!

Item was changed:
  ----- Method: ExternalUnknownType class>>newTypeForUnknownNamed: (in category 'instance creation') -----
+ newTypeForUnknownNamed: label
- newTypeForUnknownNamed: typeName
 
+ | typeName type pointerType |
+ typeName := label asSymbol.
- | type pointerType |
  self
  assert: [(StructTypes includesKey: typeName) not]
  description: 'Type already exists. Use #typeNamed: to access it.'.
 
  type := ExternalUnknownType basicNew
  compiledSpec: (WordArray with: self structureSpec);
+ byteAlignment: 0; "dummy until #newReferentClass: is called"
+ setReferentClass: typeName;
  yourself.
  self assert: [type isEmpty].
 
  pointerType := ExternalPointerType basicNew
  compiledSpec: (WordArray with: self pointerSpec);
  byteAlignment: self pointerAlignment;
  yourself.
  self assert: [pointerType isPointerType].
 
  "Connect non-pointer type with pointer type."
  type setReferencedType: pointerType.
  pointerType setReferencedType: type.
 
  "Remember this new struct type."
+ StructTypes at: typeName put: type.
- StructTypes at: typeName asSymbol put: type.
 
  ^ type!

Item was changed:
  ----- Method: ExternalUnknownType>>typeName (in category 'accessing') -----
  typeName
 
+ self assert: [referentClass isSymbol].
+ ^ referentClass "Usually just the name of the class."!
- self shouldNotImplement.!