FFI: FFI-Tools-mt.13.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-Tools-mt.13.mcz

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

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

Name: FFI-Tools-mt.13
Author: mt
Time: 8 June 2020, 11:20:14.827961 am
UUID: bf0f2436-af2c-dc46-a314-b94d9aaee7ab
Ancestors: FFI-Tools-mt.12

Complements FFI-Kernel-mt.100. Requires Squeak 6.0alpha to be at Morphic-mt.1666.

=============== Diff against FFI-Tools-mt.12 ===============

Item was removed:
- ----- Method: ExternalData>>explorerContents (in category '*FFI-Tools') -----
- explorerContents
-
- ^ super explorerContents, ((self isNull not and: [self mightBeCString]) ifFalse: [#()] ifTrue: [
- {ObjectExplorerWrapper
- with: self fromCStringLimited
- name: 'as C string'
- model: self}])!

Item was added:
+ ----- Method: ExternalData>>explorerContentsMetaFields (in category '*FFI-Tools') -----
+ explorerContentsMetaFields
+ "Ignore because our type is already in the basic explorer fields because it is an instance variable."
+ ^ #()!

Item was added:
+ ----- Method: ExternalData>>explorerContentsStructFields (in category '*FFI-Tools') -----
+ explorerContentsStructFields
+
+ ^ (self isNull not and: [self mightBeCString]) ifFalse: [#()] ifTrue: [
+ {ObjectExplorerWrapper
+ with: self fromCStringLimited
+ name: 'as C string'
+ model: self}]!

Item was removed:
- ----- Method: ExternalData>>explorerContentsTypeFields (in category '*FFI-Tools') -----
- explorerContentsTypeFields
- "Ignore because our type is already in the basic explorer fields because it is an instance variable."
- ^ #()!

Item was added:
+ ObjectExplorerWrapper subclass: #ExternalObjectHandleWrapper
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'FFI-Tools'!
+
+ !ExternalObjectHandleWrapper commentStamp: 'mt 6/8/2020 10:27' prior: 0!
+ I am a wrapper around handles of external objects. I am used in the object explorer tool. My role is to fine-tune the string representation of handles that are neither ByteArray nor ExternalAddress.!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper>>getHandle (in category 'accessing') -----
+ getHandle
+
+ ^ self object!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper>>objectString (in category 'accessing') -----
+ objectString
+
+ self getHandle class == ExternalAddress ifTrue: [^ super objectString].
+ self getHandle class == ByteArray ifTrue: [^ super objectString].
+
+ "Type aliases to atomic types store primitive Smalltalk objects in their handle. Indicate that role of actually being a handle for the FFI plugin with a small prefix."
+ ^ '-> ', super objectString!

Item was changed:
  ----- Method: ExternalStructure class>>allFieldSelectors (in category '*FFI-Tools') -----
  allFieldSelectors
  "Answer a list of all simple getters for fields in this structure. Rely on the #fields definition but only return selectors that are actually implemented. Consequently for any change in #fields, #defineFields should be called before calling this method."
 
- self flag: #dicuss. "mt: To which extent should tools support type aliasing when subclassing ExternalStructure instead of subclassing ExternalTypeAlias."
  ^ self isTypeAlias
  ifTrue: [(ExternalType typeNamed: self originalTypeName) referentClass
+ ifNil: ["i.e, type alias to atomic type (e.g., typedef long MyStruct) or pointer-type of atomic (e.g., typedef char* MyLabel)"
+ self fields first ifNil: [#()] ifNotNil: [:selector | {selector}]]
+ ifNotNil: [:structClass | "i.e., type alias to structure type (e.g., typedef MyStruct MyStructAlias) or pointer-type of structure (e.g., typedef MyStruct* MyStructPointer)"
+ structClass allFieldSelectors]]
- ifNil: [#()] ifNotNil: [:structClass | structClass allFieldSelectors]]
  ifFalse: [
  self fields
  collect: [:spec | spec first]
+ thenSelect: [:selector | selector notNil]]!
- thenSelect: [:selector |
- selector notNil and: [self includesSelector: selector]]]!

Item was changed:
  ----- Method: ExternalStructure>>explorerContents (in category '*FFI-Tools') -----
  explorerContents
+ "Prefix all instance variables and append extra meta information (e.g., the external type) as well as all structure fields as defined in #fields."
+
-
  | basicExplorerFields |
  basicExplorerFields := super explorerContents.
  basicExplorerFields do: [:explorerField |
+ explorerField itemName = 'handle' ifTrue: [
+ explorerField changeClassTo: ExternalObjectHandleWrapper].
  explorerField itemName: '_', explorerField itemName].
  ^ basicExplorerFields,
+ self explorerContentsMetaFields,
- self explorerContentsTypeFields,
  self explorerContentsStructFields!

Item was added:
+ ----- Method: ExternalStructure>>explorerContentsMetaFields (in category '*FFI-Tools') -----
+ explorerContentsMetaFields
+ "Answer extra fields for the object explorer to show meta information about this structure."
+
+ ^ {ObjectExplorerWrapper
+ with: (self class externalType ifNotNil: [:type |
+ handle class == ExternalAddress ifTrue: [type asPointerType] ifFalse: [type]])
+ name: '_type'
+ model: self}!

Item was changed:
  ----- Method: ExternalStructure>>explorerContentsStructFields (in category '*FFI-Tools') -----
  explorerContentsStructFields
 
+ ^ self class allFieldSelectors collect: [:simpleGetter |
- ^ self class allFieldSelectors replace: [:simpleGetter |
  ObjectExplorerWrapper
+ with: (self isNull ifFalse: [self perform: simpleGetter])
- with: (self isNull ifFalse: [self value perform: simpleGetter])
  name: simpleGetter
  model: self]!

Item was removed:
- ----- Method: ExternalStructure>>explorerContentsTypeFields (in category '*FFI-Tools') -----
- explorerContentsTypeFields
-
- ^ {ObjectExplorerWrapper
- with: (handle isExternalAddress ifTrue: [self class externalType asPointerType] ifFalse: [self class externalType])
- name: '_type'
- model: self}!

Item was changed:
  ----- Method: ExternalTypeAlias class>>allFieldSelectors (in category '*FFI-Tools') -----
  allFieldSelectors
  "Overridden because we know that we are an alias."
 
  ^ (ExternalType typeNamed: self originalTypeName) referentClass
+ ifNil: [#() "Not needed. See #explorerContentsMetaFields."]
- ifNil: [#()]
  ifNotNil: [:structClass | structClass allFieldSelectors]!

Item was added:
+ ----- Method: ExternalTypeAlias>>explorerContentsMetaFields (in category '*FFI-Tools') -----
+ explorerContentsMetaFields
+ "Add a field to -- just in case -- explore the external object after casting to it."
+
+ ^ super explorerContentsMetaFields, {ObjectExplorerWrapper
+ with: self value
+ name: '_value'
+ model: self}!

Item was removed:
- ----- Method: ExternalTypeAlias>>explorerContentsTypeFields (in category '*FFI-Tools') -----
- explorerContentsTypeFields
- "Add a field to -- just in case -- explore the external object after casting to it."
-
- ^ super explorerContentsTypeFields, {ObjectExplorerWrapper
- with: self value
- name: '_value'
- model: self}!