FFI: FFI-CallbacksTests-mt.3.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-CallbacksTests-mt.3.mcz

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

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

Name: FFI-CallbacksTests-mt.3
Author: mt
Time: 28 May 2021, 11:16:30.0737 am
UUID: c7b02b69-cc7d-5148-af00-423356b5bd8c
Ancestors: FFI-CallbacksTests-mt.2

Complements FFI-Callbacks-mt.22

=============== Diff against FFI-CallbacksTests-mt.2 ===============

Item was changed:
  ----- Method: FFICallbackTests>>expectedFailures (in category 'failures') -----
  expectedFailures
 
  ^ #(
+ test02SortArrayOfDoublesRaw "Coercing checks are too aggressive or just wrong."
- test02SortArrayOfDoublesRaw "Checked on 32-bit. Coercing checks are too aggressive or just wrong."
  test04SortArrayOfIntegersRaw "See above."
  )!

Item was changed:
  ----- Method: FFICallbackTests>>test08ManagedCallback (in category 'tests') -----
  test08ManagedCallback
 
  | array unsorted sorted compare callback |
  unsorted := #(71 66 33 77 16 63 91 54 48 52).
  sorted := #(16 33 48 52 54 63 66 71 77 91).
 
  array := ExternalType int32_t allocate: 10.
  1 to: array size do: [:index |
  array at: index put: (unsorted at: index)].
 
  compare := [:a :b | (a - b) sign].
+ callback := compare gcSignature: #(int32_t 'int32_t*' 'int32_t*').
- callback := FFICallback newGC.
- callback
- setBlock: compare
- signature: #(int32_t 'int32_t*' 'int32_t*').
 
  lib
  qsort: array
  with: array size
  with: array contentType byteSize
  with: callback.
  self assert: (sorted hasEqualElements: array).
 
+ "Callback no longer needed but still there."
  Smalltalk garbageCollect.
  self deny: callback isNull.
+
+ "Callback depends on the existence of the compare block."
+ self
+ assert: callback
+ identical: (FFICallback lookupCallbackForEvaluable: compare).
  compare := nil.
  Smalltalk garbageCollect.
  self assert: callback isNull.!

Item was added:
+ ----- Method: FFICallbackTests>>test09UnmanagedCallback (in category 'tests') -----
+ test09UnmanagedCallback
+
+ | array unsorted sorted compare callback |
+ unsorted := #(71 66 33 77 16 63 91 54 48 52).
+ sorted := #(16 33 48 52 54 63 66 71 77 91).
+
+ array := ExternalType int32_t allocate: 10.
+ 1 to: array size do: [:index |
+ array at: index put: (unsorted at: index)].
+
+ compare := [:a :b | (a - b) sign].
+ callback := compare signature: #(int32_t 'int32_t*' 'int32_t*').
+
+ lib
+ qsort: array
+ with: array size
+ with: array contentType byteSize
+ with: callback.
+ self assert: (sorted hasEqualElements: array).
+
+ "Callback no longer needed but still there."
+ Smalltalk garbageCollect.
+ self deny: callback isNull.
+
+ "Callback independent from the compare block."
+ self assert: (FFICallback lookupCallbackForEvaluable: compare) isNil.
+ compare := nil.
+ Smalltalk garbageCollect.
+ self deny: callback isNull.
+
+ "Callback needs to be free'd manually."
+ callback free.
+ self assert: callback isNull.!