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

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

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

Name: FFI-Kernel-mt.123
Author: mt
Time: 1 May 2021, 10:22:08.119394 am
UUID: 8a1725e7-90a1-2348-9e01-3ce391c4036f
Ancestors: FFI-Kernel-mt.122

Given that we usually talk to external types or external structures (and unions ...) where #allocate: is the current pattern to prepare a list of such things, use #allocateExternal: to allocate external memory, not internal object memory.

While this conflicts with ExternalAddress class #allocate:, clients might not notice because they should usually not deal with the difference between handles being either ByteArray or ExternalAddress (or atomics). I suppose.

Let #free for handles being ExternAdress also null that address. Maybe we could establish a common prototype for a null-address?

(Removes duplicate #isExternalAddress.)

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

Item was removed:
- ----- Method: ByteArray>>isExternalAddress (in category '*FFI-Kernel-testing') -----
- isExternalAddress
- "Return true if the receiver describes the address of an object in the outside world"
- ^false!

Item was added:
+ ----- Method: ExternalStructure class>>allocateExternal: (in category 'instance creation') -----
+ allocateExternal: anInteger
+ "Create an ExternalData with enough room for storing an array of size anInteger of such structure. Don't forget to free the allocated memory!!!!!!"
+ ^self externalType allocateExternal: anInteger!

Item was changed:
  ----- Method: ExternalStructure>>free (in category 'initialize-release') -----
  free
  "Free the handle pointed to by the receiver"
+
+ handle isExternalAddress
+ ifTrue: [handle free; beNull]
+ ifFalse: [handle := nil].!
- (handle ~~ nil and:[handle isExternalAddress]) ifTrue:[handle free].
- handle := nil.!

Item was added:
+ ----- Method: ExternalType>>allocateExternal: (in category 'external data') -----
+ allocateExternal: anInteger
+ "Allocate space for containing an array of size anInteger of this dataType"
+
+ | handle |
+ handle := ExternalAddress allocate: self byteSize * anInteger.
+ ^(ExternalData fromHandle: handle type: self) size: anInteger!