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

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

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

Name: FFI-Tools-mt.33
Author: mt
Time: 20 May 2021, 4:09:18.82558 pm
UUID: 33654c93-d0a2-5143-a683-044770efb5d5
Ancestors: FFI-Tools-mt.32

Fixes issue with printing large byte-array handles in object explorer. Makes the text representation of byte-array handles configurable.

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

Item was changed:
  ObjectExplorerWrapper subclass: #ExternalObjectHandleWrapper
  instanceVariableNames: ''
+ classVariableNames: 'MaxVisibleBytes MaxVisibleDots'
- 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 class>>maxVisibleBytes (in category 'preferences') -----
+ maxVisibleBytes
+ <preference: 'Max. visible bytes in byte arrays'
+ categoryList: #('FFI Tools')
+ description: 'Set the maximum number of visible bytes to show when exploring a byte-array handle before trimming the bytes, e.g. #[ 0 0 0 0 ...555 bytes... 0 0 0 0 ]'
+ type: #Number>
+ ^MaxVisibleBytes ifNil: [32]!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper class>>maxVisibleBytes: (in category 'preferences') -----
+ maxVisibleBytes: anInteger
+
+ MaxVisibleBytes := anInteger ifNotNil: [:i | i rounded].!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper class>>maxVisibleDots (in category 'preferences') -----
+ maxVisibleDots
+ <preference: 'Max. visible dots in byte arrays'
+ categoryList: #('FFI Tools')
+ description: 'Set the maximum number of visible dots to show when exploring a byte-array handle before summarizing the skipped bytes in composite structs, e.g. #[ . . . . . . . . 0 0 0 0 ...356 bytes... ]'
+ type: #Number>
+ ^MaxVisibleDots ifNil:[12]!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper class>>maxVisibleDots: (in category 'preferences') -----
+ maxVisibleDots: anInteger
+
+ MaxVisibleDots := anInteger ifNotNil: [:i | i rounded].!

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

Item was changed:
  ----- Method: ExternalObjectHandleWrapper>>objectString (in category 'accessing') -----
  objectString
 
+ ^ String streamContents: [:stream |
+ (thisContext objectClass: self object) == ByteArrayReadWriter
+ ifTrue: [self printReadWriterOn: stream]
+ ifFalse: [stream nextPutAll: super objectString]]!
- | label handle skipLimit |
- label := super objectString.
- handle := self getHandle.
- skipLimit := 16.
-
- ^ handle isExternalAddress ifTrue: [label] ifFalse: [
- (thisContext objectClass: handle) == ByteArrayReadWriter
- ifFalse: [label]
- ifTrue: [ | begin end tokens |
- label :=(thisContext object: handle instVarAt: 3) "byteArray" printString.
- label := label copyFrom: 3 to: (label size - 1).
- begin := (thisContext object: handle instVarAt: 1) "byteOffset" + 1.
- end := begin - 1 + (thisContext object: handle instVarAt: 2) "byteSize".
- String streamContents: [:stream |
- stream nextPutAll: '#[ '.
- tokens := label findTokens: ' ' "#[0 0 0 0 0]".
- begin > skipLimit ifTrue: [
- stream nextPutAll: '. . ', (begin - 1) asString, ' bytes . . '.
- tokens := tokens allButFirst: begin - 1.
- end := end - begin + 1. begin := 1].
- (1 to: end) do: [:index | | token |
- token := tokens at: index.
- index >= begin
- ifTrue: [stream nextPutAll: token]
- ifFalse: ["Skip byte info" stream nextPut: $.].
- stream space].
- (tokens size - end + 1) > skipLimit ifTrue: [
- stream nextPutAll: '. . ', (tokens size - end) asString, ' bytes . . '.
- tokens := tokens allButLast: tokens size - end.
- end := tokens size].
- (tokens size - end) timesRepeat: [
- "Skip byte info" stream nextPut: $..
- stream space].
- stream nextPutAll: ']'.
- ]]].!

Item was added:
+ ----- Method: ExternalObjectHandleWrapper>>printReadWriterOn: (in category 'printing') -----
+ printReadWriterOn: stream
+
+ | handle array head tail numBytes maxVisibleDots maxVisibleBytes |
+ handle := self object.
+ maxVisibleDots := 12. "e.g. #[ . . . . . . . . 0 0 0 0 ...356 bytes... ]"
+ maxVisibleBytes := 32. "e.g. #[ 0 0 0 0 ...555 bytes... 0 0 0 0 ]"
+
+ array := (thisContext object: handle instVarAt: 3) "byteArray".
+ head := (thisContext object: handle instVarAt: 1) "byteOffset".
+ numBytes := (thisContext object: handle instVarAt: 2) "byteSize".
+ tail := array size - head - numBytes.
+
+ stream nextPutAll: '#[ '.
+
+ head > 0 ifTrue: [
+ head > maxVisibleDots
+ ifTrue: [stream nextPutAll: '...', head asString, ' bytes... ']
+ ifFalse: [head timesRepeat: [stream nextPut: $.; space]]].
+
+ numBytes > maxVisibleBytes
+ ifTrue: [ "Trim inner bytes"
+ head + 1 to: head + (maxVisibleBytes / 2) do: [:index |
+ stream nextPutAll: (array at: index) asString; space].
+ stream nextPutAll: '...', (numBytes - maxVisibleBytes) asString, ' bytes... '.
+ array size - tail - (maxVisibleBytes / 2) + 1 to: array size - tail do: [:index |
+ stream nextPutAll: (array at: index) asString; space]]
+ ifFalse: [ "No trimming"
+ head + 1 to: array size - tail do: [:index |
+ stream nextPutAll: (array at: index) asString; space]].
+
+ tail > 0 ifTrue: [
+ tail > maxVisibleDots
+ ifTrue: [stream nextPutAll: '...', tail asString, ' bytes... ']
+ ifFalse: [tail timesRepeat: [stream nextPut: $.; space]]].
+
+ stream nextPutAll: ']'.
+ !