Commit 87723ec1 authored by Liam Healy's avatar Liam Healy

Finalizer in alloc-gsl-struct replaces free-gsl-struct

Using trivial-garbage to define a portable finalizer in
#'alloc-gsl-struct.  Removed #'free-gsl-struct; #'expand-data no
longer calls #'free-gsl-struct.  As in the old free-gsl-struct, the
finalizer removes the gsl-vector-c or gsl-matrix-c, and the
gsl-block-c if applicable.  Test results are the same (1 failure for
unrelated reason).
parent ebf82b24
;; "Data" is bulk arrayed data, like vectors, matrices, permutations,
;; combinations, or histograms.
;; Liam Healy 2008-04-06 21:23:41EDT
;; Time-stamp: <2008-11-15 19:46:51EST data.lisp>
;; Time-stamp: <2008-11-23 08:55:31EST data.lisp>
;; $Id$
(in-package :gsl)
......@@ -211,8 +211,7 @@
(setf (c-pointer ,symbol) ,cptr)
,@(when sync-exit `((copy-c-to-cl ,symbol))))
(free-gsl-struct ,symbol)))))))
,@(when sync-exit `((copy-c-to-cl ,symbol))))))))))
;;;; Syncronize C and CL
......@@ -315,25 +314,18 @@
(cffi:foreign-slot-value blockptr 'gsl-block-c 'data)
(c-pointer object)
(cffi:foreign-slot-value blockptr 'gsl-block-c 'size)
(total-size object)
(mpointer object)
(alloc-from-block object))))
(total-size object))
(let ((array-struct (alloc-from-block object)))
(lambda ()
(unless (eq blockptr array-struct)
(cffi:foreign-free blockptr))
(cffi:foreign-free array-struct)))
(setf (mpointer object) array-struct))))
(defmethod mpointer :before ((object gsl-data))
"Make a GSL struct if there isn't one already."
(unless (slot-value object 'mpointer)
(alloc-gsl-struct object)
(defun free-gsl-struct (object)
"Free the C structure(s) and memory for data."
;; This should happen immediately at the end of the
;; with-pointer-to-array and substitutes for the GSL "_free"
;; functions.
(when (block-pointer object)
(unless (eq (block-pointer object) (mpointer object))
(cffi:foreign-free (block-pointer object))) ; free the block struct
(setf (block-pointer object) nil))
(when (mpointer object)
(cffi:foreign-free (mpointer object)) ; free the larger struct
(setf (mpointer object) nil)))
;; Definition of GSLL system
;; Liam Healy
;; Time-stamp: <2008-11-16 12:14:14EST gsll.asd>
;; Time-stamp: <2008-11-22 17:13:51EST gsll.asd>
;; $Id$
(asdf:defsystem "gsll"
......@@ -9,7 +9,7 @@
:version "0"
:author "Liam M. Healy"
:licence "LLGPL v3, FDL"
:depends-on (cffi cl-utilities)
:depends-on (cffi trivial-garbage cl-utilities)
((:module init
......@@ -33,7 +33,7 @@
:depends-on (init)
((:file "foreign-friendly")
(:file "data")
(:file "data" :depends-on (foreign-friendly))
(:file "vector" :depends-on (data))
(:file "matrix" :depends-on (data vector))
(:file "maref" :depends-on (data vector matrix))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment