Permalink
Browse files

first commit

  • Loading branch information...
1 parent e15b716 commit e527fd7e421ff53e3465f513d847afd3354ee0ef @Balooga committed Mar 16, 2010
Showing with 51 additions and 13 deletions.
  1. +29 −0 LICENSE
  2. +5 −0 NEWS
  3. +2 −0 TODO
  4. +1 −0 package.lisp
  5. +4 −8 simple-finalizer.asd
  6. +10 −5 simple-finalizer.lisp
View
29 LICENSE
@@ -0,0 +1,29 @@
+Copyright (c) 2010, Luke J. Crook
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+* Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+* Neither the name of the Luke J. Crook nor the names of contributors
+to this software may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
5 NEWS
@@ -0,0 +1,5 @@
+-*- mode: org -*-
+
+* Version 0.1 released <2010-03-15 Mon>
+
+Initial Release.
View
2 TODO
@@ -0,0 +1,2 @@
+-*- mode: org -*-
+
View
@@ -12,4 +12,5 @@
#:fp
#:gc-p
#:free
+ #:free-p
#:this-fp))
View
@@ -1,10 +1,10 @@
;;; -*- lisp -*-
-(defpackage #:simple-finalizer
+(defpackage #:simple-finalizer-system
(:use #:cl #:asdf))
-(in-package #:simple-finalizer)
+(in-package #:simple-finalizer-system)
-(defsystem :simple-finalizer
+(defsystem simple-finalizer
:description "A simple Common Lisp finalizer for foreign objects when using CFFI and TRIVIAL-GARBAGE."
:version "0.1"
:author "Luke Crook <luke@balooga.com>"
@@ -15,9 +15,5 @@
(pushnew :simple-finalizer *features*))
:components
((:file "package")
- (:file "simple-finalizer")
- (:html-file "index")
- (:doc-file "README")
- (:doc-file "COPYING")
- (:doc-file "CONTRIBUTORS"))
+ (:file "simple-finalizer"))
:serial t)
View
@@ -5,11 +5,13 @@
((foreign-pointer-to-object
:reader fp
:initform (error ":FP must not be NIL.")
- :initarg :fp)
+ :initarg :fp
+ :documentation "Returns the foreign object reference.")
(garbage-collect
:reader gc-p
:initform t
- :initarg :gc)
+ :initarg :gc
+ :documentation "Returns `T` if the foreign object will be finalized.")
(free-function
:initform #'cffi:foreign-free
:initarg :free))
@@ -30,9 +32,6 @@
(error "`:FREE` is NIL. No function to free the foreign object defined."))
(tg:finalize self (lambda () (funcall foreign-free foreign-pointer))))))
-(defgeneric fp (foreign-object)
- (:documentation "Returns the foreign object reference."))
-
(defgeneric free (foreign-object)
(:documentation "An explicit cleanup method. When freed, `GC-P` will be NIL."))
(defmethod free ((self foreign-object))
@@ -65,6 +64,12 @@
(defmethod this-fp ((self foreign-object))
(slot-value self 'foreign-pointer-to-object))
+(defgeneric free-p (foreign-object)
+ (:documentation "Returns `T if the foreign object was previously deleted using `FREE`."))
+(defmethod free-p ((self foreign-object))
+ (and (not (gc-p self)) (not (fp self))))
+
+
(defun simple-free (func-fp type)
(declare (ignore type))
#'(lambda (obj-fp)

0 comments on commit e527fd7

Please sign in to comment.