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

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

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

Name: FFI-Kernel-mt.105
Author: mt
Time: 12 June 2020, 7:44:46.025226 pm
UUID: f8493ed8-b9dc-494c-b072-eba13f606180
Ancestors: FFI-Kernel-mt.104

Code clean up. Make #atomicTypeName and #atomicTypeNamed: behave the same, i.e., no pointer (*) support.

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

Item was changed:
  ----- Method: ExternalType class>>atomicTypeNamed: (in category 'instance lookup') -----
  atomicTypeNamed: typeName
+ "If not found, look up 'type constants' protocol as lightweight alias to atomic type."
- "Supports pointer-type lookup such as for 'long*' and also 'long *'."
-
- | isPointerType actualTypeName type |
- (isPointerType := typeName last == $*)
- ifTrue: [actualTypeName := typeName allButLast withoutTrailingBlanks]
- ifFalse: [actualTypeName := typeName].
 
+ ^ AtomicTypes
+ at: typeName
+ ifAbsent: [
+ (self class includesSelector: typeName)
+ ifTrue: [self perform: typeName]]!
- (Symbol lookup: actualTypeName)
- ifNotNil: [:sym | actualTypeName := sym].
-
- ^ (type := (AtomicTypes at: actualTypeName ifAbsent: [nil])
- ifNil: [ "Supports 'type constants' protocol of ExternalTypes."
- (self class includesSelector: actualTypeName)
- ifTrue: [self perform: actualTypeName]])
- ifNotNil: [isPointerType ifTrue: [type asPointerType] ifFalse: [type]]!

Item was changed:
  ----- Method: ExternalType class>>c_ulong (in category 'type constants - extra') -----
  c_ulong
  "Try to approximate a fitting type for 'usigned long' in a C interface. See comment in #c_long."
 
+ ^ self typeNamed: 'u', self c_long atomicTypeName!
- ^ self atomicTypeNamed: 'u', self c_long atomicTypeName!

Item was changed:
+ ----- Method: ExternalType class>>string (in category 'type constants - extra') -----
- ----- Method: ExternalType class>>string (in category 'type constants') -----
  string
  ^ self char asPointerType!

Item was changed:
  ----- Method: ExternalType class>>structTypeNamed: (in category 'instance lookup') -----
  structTypeNamed: typeName
  "Answers the external type for the struct named typeName. If there is no type yet, create a new one but only if typeName can be matched to an existing class in the system already. If you still need a type even if there is no such class present, use #newTypeNamed: to create a type with an unknown referent class."
-
- "Supports pointer-type lookup such as for 'MyStruct*' and also 'MyStruct *'."
 
+ ^ (StructTypes at: typeName ifAbsent: [nil])
+ ifNil: [ "Create struct types for existing struct classes on-the-fly."
+ (self environment classNamed: typeName)
- | isPointerType actualTypeName type |
- (isPointerType := typeName last == $*)
- ifTrue: [actualTypeName := typeName allButLast withoutTrailingBlanks]
- ifFalse: [actualTypeName := typeName].
-
- (Symbol lookup: actualTypeName)
- ifNotNil: [:sym | actualTypeName := sym].
-
- type := (StructTypes at: actualTypeName ifAbsent: [nil])
- ifNil: [
- (self environment classNamed: actualTypeName)
  ifNotNil: [:cls | (cls includesBehavior: ExternalStructure) ifTrue: [
+ StructTypes removeKey: typeName ifAbsent: [].
+ self newTypeNamed: typeName]]]!
- StructTypes removeKey: actualTypeName ifAbsent: [].
- self newTypeNamed: actualTypeName]]].
-
- ^ type ifNotNil: [isPointerType ifTrue: [type asPointerType] ifFalse: [type]]!

Item was changed:
  ----- Method: ExternalType class>>typeNamed: (in category 'instance lookup') -----
  typeNamed: typeName
+ "Supports pointer-type lookup for both atomic and structure types.
+ Examples: 'long', 'long*', 'long *' or 'MyStruct', 'MyStruct*', 'MyStruct *'"
+
+ | isPointerType actualTypeName type |
+ (isPointerType := typeName last == $*)
+ ifTrue: [actualTypeName := typeName allButLast withoutTrailingBlanks]
+ ifFalse: [actualTypeName := typeName].
 
+ (Symbol lookup: actualTypeName)
+ ifNotNil: [:sym | actualTypeName := sym].
- (self atomicTypeNamed: typeName)
- ifNotNil: [:type | ^ type].
- (self structTypeNamed: typeName)
- ifNotNil: [:type | ^ type].
 
+ type := (self atomicTypeNamed: actualTypeName)
+ ifNil: [self structTypeNamed: actualTypeName].
+
+ ^ type ifNotNil: [isPointerType ifTrue: [type asPointerType] ifFalse: [type]]!
- ^ nil!