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

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

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

Name: FFI-Kernel-mt.179
Author: mt
Time: 28 May 2021, 12:52:03.4977 pm
UUID: c02c8260-e6ed-4845-a202-ddf2cd193be0
Ancestors: FFI-Kernel-mt.178

Adds #isStringType check to speed up ExternalData.

Fixes access and code generation for array types and pointer-to-array types.

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

Item was changed:
  ----- Method: ExternalArrayType>>handle:at: (in category 'external data') -----
  handle: handle at: byteOffset
 
+ | resultHandle |
+ resultHandle := handle structAt: byteOffset length: self byteSize.
+ ^ self isTypeAlias
+ ifTrue: [referentClass fromHandle: resultHandle]
+ ifFalse: [ExternalData fromHandle: resultHandle type: self]!
- ^ ExternalData
- fromHandle: (handle structAt: byteOffset length: self byteSize)
- type: self!

Item was added:
+ ----- Method: ExternalArrayType>>isStringType (in category 'testing - special') -----
+ isStringType
+
+ ^ false!

Item was changed:
  ----- Method: ExternalArrayType>>readFieldAt: (in category 'external structure') -----
  readFieldAt: byteOffset
 
+ ^ self isTypeAlias
+ ifTrue: [
+ '^ {1} fromHandle: (handle structAt: {1} length: {2})'
+ format: {
+ referentClass name.
+ byteOffset.
+ self byteSize}]
+ ifFalse: [
+ '^ ExternalData fromHandle: (handle structAt: {1} length: {2}) type: {3}'
+ format: {
+ byteOffset.
+ self byteSize.
+ self storeStringForField}]!
- ^ '^ ExternalData fromHandle: (handle structAt: {1} length: {2}) type: {3}'
- format: {
- byteOffset.
- self byteSize.
- self storeStringForField}!

Item was added:
+ ----- Method: ExternalAtomicType>>isStringType (in category 'testing - special') -----
+ isStringType
+
+ ^ false!

Item was changed:
  ----- Method: ExternalData>>setContentType: (in category 'initialize-release') -----
  setContentType: externalType
 
+ | newContentType |
+ (newContentType := externalType) isStringType ifTrue: [
+ newContentType := newContentType asNonPointerType].
- externalType = ExternalType string ifTrue: [
- ^ self setContentType: externalType asNonPointerType].
 
+ self setType: (newContentType isVoid
+ ifTrue: [newContentType "Size gets lost for void."]
+ ifFalse: [newContentType asArrayType: self size]).!
- self setType: (externalType isVoid
- ifTrue: [externalType "Size gets lost for void."]
- ifFalse: [externalType asArrayType: self size]).!

Item was changed:
  ----- Method: ExternalData>>setType: (in category 'private') -----
  setType: externalType
  "Private. Set the type used to derive content and container types. If you want to change the content type later, use #setContentType:."
 
+ | newType isVoid |
+ (newType := externalType) isStringType ifTrue: [
+ newType := newType asNonPointerType].
- externalType = ExternalType string ifTrue: [
- ^ self setType: externalType asNonPointerType].
 
+ (isVoid := newType isVoid) ifTrue: [
+ newType := newType asPointerType].
- externalType isVoid ifTrue: [
- ^ self setType: externalType asPointerType].
 
+ (newType isArrayType or: [isVoid or: [newType asNonPointerType isVoid]])
+ ifTrue: [type := newType "array type or void*"]
+ ifFalse: [type := (newType asArrayType: nil)].
- (externalType isArrayType or: [externalType asNonPointerType isVoid])
- ifTrue: [type := externalType "array type or void*"]
- ifFalse: [type := (externalType asArrayType: nil)].
 
  contentType := nil.!

Item was changed:
  ----- Method: ExternalPointerType>>handle:at: (in category 'external data') -----
  handle: handle at: byteOffset
 
+ | referentClassToUse |
+ referentClassToUse := self isPointerTypeForArray
+ ifFalse: [referentClass]
+ ifTrue: [self asNonPointerType isTypeAlias
+ ifTrue: [self asNonPointerType referentClass] ifFalse: [nil]].
+ ^ referentClassToUse
- ^ referentClass
  ifNotNil: [
+ referentClassToUse fromHandle: (handle pointerAt: byteOffset length: self byteSize)]
- referentClass fromHandle: (handle pointerAt: byteOffset length: self byteSize)]
  ifNil: [
  ExternalData
  fromHandle: (handle pointerAt: byteOffset length: self byteSize)
  type: self asNonPointerType "content type"]!

Item was changed:
  ----- Method: ExternalPointerType>>isPointerTypeForArray (in category 'testing') -----
  isPointerTypeForArray
+ "referentClass is currently nil for pointer-to-array types. All operations on referentClass should check this to then use the referentClass from the non-pointer type. Might be changed once array information are encoded in the headerWord."
+
-
  ^ self asNonPointerType isArrayType!

Item was added:
+ ----- Method: ExternalPointerType>>isStringType (in category 'testing - special') -----
+ isStringType
+ "If pointer to atomic, the atomic type is encoded directly in the headerWord. Might change in the future; use #asNonPointerType in that case."
+
+ ^ self atomicType = FFITypeUnsignedChar!

Item was changed:
  ----- Method: ExternalPointerType>>readFieldAt: (in category 'external structure') -----
  readFieldAt: byteOffset
+
+ | referentClassToUse |
+ referentClassToUse := self isPointerTypeForArray
+ ifFalse: [referentClass]
+ ifTrue: [self asNonPointerType isTypeAlias
+ ifTrue: [self asNonPointerType referentClass] ifFalse: [nil]].
- "
- ExternalStructure defineAllFields.
- "
  ^ '^ {1} fromHandle: (handle pointerAt: {2} length: {3}){4}'
  format: {
+ (referentClassToUse ifNil: [ExternalData]) name.
- (referentClass ifNil: [ExternalData]) name.
  byteOffset.
  self byteSize.
+ referentClassToUse ifNotNil: [''] ifNil: [
- referentClass ifNotNil: [''] ifNil: [
  ' type: ', self asNonPointerType "content type" storeStringForField]}!

Item was added:
+ ----- Method: ExternalStructureType>>isStringType (in category 'testing - special') -----
+ isStringType
+
+ ^ false!

Item was added:
+ ----- Method: ExternalType>>isStringType (in category 'testing - special') -----
+ isStringType
+
+ | type |
+ type := self atomicType.
+ ^ type = FFITypeUnsignedChar and: [self isPointerType]!