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

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

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

Name: FFI-Kernel-mt.156
Author: mt
Time: 17 May 2021, 8:47:59.239407 am
UUID: 8a83dbdc-1aed-e943-a350-efcdfe3b945f
Ancestors: FFI-Kernel-mt.155

Allow empty array types so that code loading can work. Since structure types are initialized only partially when referenced in an FFI call, this must be possible for array types too, which can reference to those not-yet-fully-initialized struct types as content type.

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

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 byteSize > 0] "No arrays of empty structs or void type."
- description: 'No array types for empty structs or 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!