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

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

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

Name: FFI-Kernel-mt.163
Author: mt
Time: 21 May 2021, 11:13:45.365138 am
UUID: c175e00a-7423-de4a-8e42-e1fdf6ffb4c9
Ancestors: FFI-Kernel-mt.162

Adds out-of-bounds checks for byte-array handles in composite structures.

Adds #first: #last: #from: to ExternalData extract handles for backwards-filled buffers.

Relax #sizeCheck: in ExternalData to allow for moving back-and-forth in memory.

Complements FFI-Tests-mt.45.

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

Item was added:
+ ----- Method: ByteArrayReadWriter>>checkAt: (in category 'private') -----
+ checkAt: nextByteOffset
+
+ | endOffset |
+ (endOffset := nextByteOffset + byteOffset) > (byteOffset + byteSize)
+ ifTrue: [self errorSubscriptBounds: endOffset].!

Item was added:
+ ----- Method: ByteArrayReadWriter>>checkAt:length: (in category 'private') -----
+ checkAt: nextByteOffset length: numBytes
+
+ | endOffset |
+ (endOffset := nextByteOffset + numBytes - 1) > (byteOffset + byteSize)
+ ifTrue: [self errorSubscriptBounds: endOffset].!

Item was changed:
  ----- Method: ByteArrayReadWriter>>doubleAt: (in category 'read/write atomics') -----
  doubleAt: oByteOffset
 
+ self checkAt: oByteOffset.
  ^ byteArray doubleAt: oByteOffset + byteOffset!

Item was changed:
  ----- Method: ByteArrayReadWriter>>doubleAt:put: (in category 'read/write atomics') -----
  doubleAt: oByteOffset put: value
 
+ self checkAt: oByteOffset.
  ^ byteArray doubleAt: oByteOffset + byteOffset put: value!

Item was changed:
  ----- Method: ByteArrayReadWriter>>floatAt: (in category 'read/write atomics') -----
  floatAt: oByteOffset
 
+ self checkAt: oByteOffset.
  ^ byteArray floatAt: oByteOffset + byteOffset!

Item was changed:
  ----- Method: ByteArrayReadWriter>>floatAt:put: (in category 'read/write atomics') -----
  floatAt: oByteOffset put: value
 
+ self checkAt: oByteOffset.
  ^ byteArray floatAt: oByteOffset + byteOffset put: value!

Item was changed:
  ----- Method: ByteArrayReadWriter>>integerAt:put:size:signed: (in category 'read/write atomics') -----
  integerAt: oByteOffset put: value size: nBytes signed: aBoolean
 
+ self checkAt: oByteOffset.
  ^ byteArray integerAt: oByteOffset + byteOffset put: value size: nBytes signed: aBoolean!

Item was changed:
  ----- Method: ByteArrayReadWriter>>integerAt:size:signed: (in category 'read/write atomics') -----
  integerAt: oByteOffset size: nBytes signed: aBoolean
 
+ self checkAt: oByteOffset.
  ^ byteArray integerAt: oByteOffset + byteOffset size: nBytes signed: aBoolean.!

Item was changed:
  ----- Method: ByteArrayReadWriter>>pointerAt:length: (in category 'read/write pointers') -----
  pointerAt: oByteOffset length: numBytes
 
+ self checkAt: oByteOffset length: numBytes.
  ^ byteArray pointerAt: oByteOffset + byteOffset length: numBytes!

Item was changed:
  ----- Method: ByteArrayReadWriter>>pointerAt:put:length: (in category 'read/write pointers') -----
  pointerAt: oByteOffset put: value length: numBytes
 
+ self checkAt: oByteOffset length: numBytes.
  ^ byteArray pointerAt: oByteOffset + byteOffset put: value length: numBytes!

Item was changed:
  ----- Method: ByteArrayReadWriter>>structAt:length: (in category 'read/write structs') -----
  structAt: newByteOffset length: newLength
 
+ self checkAt: newByteOffset length: newLength.
  ^ ByteArrayReadWriter new
  setArray: byteArray
  offset: byteOffset + newByteOffset - 1
  size: newLength!

Item was changed:
  ----- Method: ByteArrayReadWriter>>structAt:put:length: (in category 'read/write structs') -----
  structAt: newByteOffset put: value length: newLength
 
+ self checkAt: newByteOffset length: newLength.
- (newByteOffset + newLength > byteSize)
- ifTrue: [self errorSubscriptBounds: newByteOffset + newLength].
-
  ^ byteArray
  structAt: byteOffset + newByteOffset - 1
  put: value
  length: newLength!

Item was added:
+ ----- Method: ExternalData>>first: (in category 'accessing') -----
+ first: n
+ "Answer the first n elements of the receiver."
+
+ ^ self from: 1 to: n!

Item was added:
+ ----- Method: ExternalData>>from: (in category 'accessing') -----
+ from: firstIndex
+ "Move the start of this array. Size not needed."
+
+ | byteOffset numElements byteSize contentType |
+ contentType := self contentType.
+ byteOffset := ((firstIndex-1) * contentType byteSize)+1.
+ numElements := (self size ifNotNil: [:sz | sz - firstIndex + 1 max: 0]).
+ byteSize := numElements
+ ifNil: [contentType byteSize]
+ ifNotNil: [numElements * contentType byteSize].
+
+ ^ ExternalData
+ fromHandle: (handle structAt: byteOffset length: (byteSize ifNil: [1]))
+ type: contentType
+ size: numElements!

Item was added:
+ ----- Method: ExternalData>>last: (in category 'accessing') -----
+ last: n
+ "Answer the last n elements of the receiver."
+
+ | sz |
+ self sizeCheck.
+ ^ self from: (sz := self size) - n + 1 to: sz!

Item was changed:
  ----- Method: ExternalData>>sizeCheck: (in category 'private') -----
  sizeCheck: index
+ "Negative indices should work to move back-and-forth in the memory."
+
-
  | sz |
+ ((sz := self size) notNil and: [index > sz])
- ((1 > index) or: [(sz := self size) notNil and: [index > sz]])
  ifTrue: [^ self errorSubscriptBounds: index].!