Skip to content

Commit 787c316

Browse files
committed
Let Features free Array.
Don't add finalizer to Array in `infoFromFeatures`. Features allocation will free allocated Arrays under the hood.
1 parent 2a33a98 commit 787c316

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/ArrayFire/FFI.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ afCall1' op =
313313
throwAFError =<< op ptrInput
314314
peek ptrInput
315315

316+
-- | Note: We don't add a finalizer to 'Array' since the 'Features' finalizer frees 'Array'
317+
-- under the hood.
316318
featuresToArray
317319
:: Features
318320
-> (Ptr AFArray -> AFFeatures -> IO AFErr)
@@ -324,8 +326,7 @@ featuresToArray (Features fptr1) op =
324326
alloca $ \ptrInput -> do
325327
throwAFError =<< op ptrInput ptr1
326328
Array <$> do
327-
newForeignPtr af_release_array_finalizer
328-
=<< peek ptrInput
329+
newForeignPtr_ =<< peek ptrInput
329330

330331
infoFromFeatures
331332
:: Storable a
@@ -439,4 +440,4 @@ infoFromArray4 (Array fptr1) op =
439440
(,,,) <$> peek ptrInput1
440441
<*> peek ptrInput2
441442
<*> peek ptrInput3
442-
<*> peek ptrInput4
443+
<*> peek ptrInput4

test/ArrayFire/FeaturesSpec.hs

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ spec =
1010
it "Should get features number an array" $ do
1111
let feats = createFeatures 10
1212
getFeaturesNum feats `shouldBe` 10
13-
-- it "Should retain features" $ do
14-
-- let feats = createFeatures 100
15-
-- retainFeatures feats
16-
-- print (getFeaturesSize feats)
17-
-- print (getFeaturesOrientation feats)
18-
-- print (getFeaturesXPos feats)
19-
-- print (getFeaturesXPos feats)
20-
-- scalar @Int 10 `shouldBe` scalar @Int 10
13+
-- print (getFeaturesSize feats)
14+
-- print (getFeaturesOrientation feats)
15+
-- print (getFeaturesXPos feats)
16+
-- print (getFeaturesYPos feats)
2117

0 commit comments

Comments
 (0)