FFI: FFI-Tools-mt.29.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.29.mcz

Marcel Taeumel uploaded a new version of FFI-Tools to project FFI:

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

Name: FFI-Tools-mt.29
Author: mt
Time: 7 May 2021, 11:55:55.901725 am
UUID: 80be7cad-4657-4446-b564-15c92683b1b9
Ancestors: FFI-Tools-mt.28

Complements FFI-Kernel-mt.139 and FFI-Kernel-mt.140.

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

Item was changed:
  ----- Method: ExternalData>>explorerContentsStructFields (in category '*FFI-Tools') -----
  "In case some data interpretation omitted to convert char*, which is a (null-terminated) C string, to Smalltalk string."
  size notNil ifTrue: [
  ^ self withIndexCollect: [:each :index |
  with: each
  name: index printString
  model: self]].
+ ^ (ExternalStructureInspector readCStrings and: [self mightBeCString]) ifFalse: [#()] ifTrue: [
- ^ (self isNull not and: [self containerType = ExternalType string]) ifFalse: [#()] ifTrue: [
+ with: ([self fromCString] ifError: [:msg | '<', msg, '>'])
- with: self fromCString
  name: 'as C string'
  model: self}]!

Item was changed:
  ----- Method: ExternalData>>hasContentsInExplorer (in category '*FFI-Tools') -----
  ^ super hasContentsInExplorer
+ or: [size notNil or: [ExternalStructureInspector readCStrings and: [self mightBeCString]]]!
- or: [self isNull not and: [self containerType = ExternalType string]]!

Item was changed:
  ----- Method: ExternalStructure>>explorerOkToClose (in category '*FFI-Tools') -----
  "We are being explored and that explorer wants to close. If we point to external memory, ask the user whether we should free it to avoid leaks."
+ | byteSize |
  (handle isExternalAddress and: [handle isNull not]) ifTrue: [
  (Project uiManager
  confirm: ('There are <b>{1}</b> bytes addressed.<br>Do you want to <b>free</b> the allocated memory?'
  translated format: {
+ (byteSize := self externalType byteSize) > 0
+ ifTrue: [byteSize] ifFalse: ['an unknown number of']. }) asTextFromHtml
- [self byteSize] ifError: ['an unknown number of']. }) asTextFromHtml
  orCancel: [^ false]
  title: 'External Address Detected' translated)
  ifTrue: [self free]].
  ^ true!

Item was changed:
  Inspector subclass: #ExternalStructureInspector
  instanceVariableNames: ''
+ classVariableNames: 'ReadCStrings'
- classVariableNames: ''
  poolDictionaries: ''
  category: 'FFI-Tools'!

Item was added:
+ ----- Method: ExternalStructureInspector class>>readCStrings (in category 'preferences') -----
+ readCStrings
+ <preference: 'Read C strings'
+ categoryList: #('FFI Tools')
+ description: 'When true, reads for the type char* will automatically continue to read the memory up to the NUL character and answer a Smalltalk string. CAN BE DANGEROUS!! ... but convenient in explorers and inspector tools.'
+ type: #Boolean>
+ ^ReadCStrings ifNil:[false]!

Item was added:
+ ----- Method: ExternalStructureInspector class>>readCStrings: (in category 'preferences') -----
+ readCStrings: aBoolean
+ ReadCStrings := aBoolean.!