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

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

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

Name: FFI-Kernel-mt.108
Author: mt
Time: 14 June 2020, 9:00:19.260471 am
UUID: 824cb928-7cff-544f-8b9e-b34bb376806a
Ancestors: FFI-Kernel-mt.107

Adds a way to store size into external data to be used in an enumeration protocol.

Note that this may just be for debugging when the FFI plugin automatically creates fitting Smalltalk objects from this data. For example, int* can become IntegerArray etc. On second thought, it might be challenging for the FFI plugin to figure out the size of such an array on its own.

(Next: I will try to add a simple #setSizeFromZeroTermination)

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

Item was changed:
  ExternalStructure subclass: #ExternalData
+ instanceVariableNames: 'type size'
- instanceVariableNames: 'type'
  classVariableNames: ''
  poolDictionaries: ''
  category: 'FFI-Kernel'!
 
+ !ExternalData commentStamp: 'mt 6/13/2020 17:26' prior: 0!
- !ExternalData commentStamp: '<historical>' prior: 0!
  Instances of ExternalData explicitly describe objects with associated type. They can be used for describing atomic C types like arrays of atomic types (e.g., 'int[]') or pointer to atomic types (e.g., 'int *').
 
  Instance variables:
+ type <ExternalType> The external type of the receiver. Always a pointer type.
- type <Integer | Behavior> The basic type of the receiver.
 
  The encoding of type is equivalent to that of the basic type in class ExternalType. The interpretation of whether the receiver describes an array of data or a pointer to data depends on the contents of the instance variable 'handle'. If handle contains an ExternalAddress the receiver is treated as pointer to type. If the handle contains a ByteArray the receiver is interpreted as describing an array of type. Note that both interpretations are treated equivalent in external calls, e.g., if one describes an argument to an external call as taking 'int*' then, depending on the type of handle either the actual contents (if ExternalAddress) or a pointer to the contents (if ByteArray) is passed.
 
  !

Item was added:
+ ----- Method: ExternalData>>collect: (in category 'enumerating') -----
+ collect: aBlock
+ "See Collection >> #collect:."
+
+ | newCollection |
+ self sizeCheck.
+ newCollection := Array new: self size.
+ 1 to: self size do:
+ [:index |
+ newCollection at: index put: (aBlock value: (self at: index))].
+ ^ newCollection!

Item was added:
+ ----- Method: ExternalData>>collectWithIndex: (in category 'enumerating') -----
+ collectWithIndex: elementAndIndexBlock
+ "See SequenceableCollection >> #collectWithIndex:."
+
+ ^ self collectWithIndex: elementAndIndexBlock!

Item was added:
+ ----- Method: ExternalData>>do: (in category 'enumerating') -----
+ do: aBlock
+ "See Collection >> #collect:."
+
+ self sizeCheck.
+ 1 to: self size do:
+ [:index | aBlock value: (self at: index)].!

Item was added:
+ ----- Method: ExternalData>>doWithIndex: (in category 'enumerating') -----
+ doWithIndex: elementAndIndexBlock
+ "See SequenceableCollection >> #doWithIndex:."
+
+ self withIndexDo: elementAndIndexBlock.!

Item was added:
+ ----- Method: ExternalData>>reject: (in category 'enumerating') -----
+ reject: aBlock
+ "See Collection >> #reject:."
+
+ ^ self select: [:each | (aBlock value: each) not]!

Item was added:
+ ----- Method: ExternalData>>select: (in category 'enumerating') -----
+ select: aBlock
+ "See Collection >> #select:."
+
+ ^ Array streamContents: [:stream |
+ self do: [:each | (aBlock value: each)
+ ifTrue: [stream nextPut: each]]]!

Item was added:
+ ----- Method: ExternalData>>size (in category 'accessing') -----
+ size
+ "Answer how many elements the receiver contains."
+
+ ^ size
+ !

Item was added:
+ ----- Method: ExternalData>>size: (in category 'accessing') -----
+ size: anInteger
+ "Set the size for the receiver, which will be used when enumerating its elements."
+
+ size := anInteger.
+ !

Item was added:
+ ----- Method: ExternalData>>sizeCheck (in category 'private') -----
+ sizeCheck
+
+ size ifNil: [self error: 'Size is unknown for this data pointer'].!

Item was added:
+ ----- Method: ExternalData>>withIndexCollect: (in category 'enumerating') -----
+ withIndexCollect: elementAndIndexBlock
+ "See SequenceableCollection >> #withIndexCollect:."
+
+ | newCollection |
+ self sizeCheck.
+ newCollection := Array new: self size.
+ 1 to: self size do:
+ [:index |
+ newCollection at: index put:
+ (elementAndIndexBlock
+ value: (self at: index)
+ value: index)].
+ ^ newCollection!

Item was added:
+ ----- Method: ExternalData>>withIndexDo: (in category 'enumerating') -----
+ withIndexDo: elementAndIndexBlock
+ "See SequenceableCollection >> #withIndexDo:."
+
+ self sizeCheck.
+ 1 to: self size do:
+ [:index |
+ elementAndIndexBlock
+ value: (self at: index)
+ value: index].!