3 ;;; Weak pointers and data structures
5 ;;; (c) 2008 Straylight/Edgeware
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 (:import-from #:sb-ext #:make-weak-pointer #:weak-pointer-value)
29 (:import-from #:ext #:make-weak-pointer #:weak-pointer-value)
30 (:export #:make-weak-pointer #:weak-pointer-value))
31 (cl:in-package #:weak)
33 #+(or allegro common-lispworks)
35 (defun make-weak-pointer (object)
36 (make-array 1 :initial-contents (list object) :weak t))
37 (defun weak-pointer-value (weak)
43 "static GC_PTR fetch_obj(GC_PTR p) { return *(cl_object *)p; }")
44 (defun make-weak-pointer (object)
45 (ffi:c-inline (object) (:object) :pointer-void "
47 cl_object *weak = GC_malloc_atomic(sizeof(cl_object));
49 GC_general_register_disappearing_link(weak, GC_base(#0));
53 (defun weak-pointer-value (weak)
54 (ffi:c-inline (weak) (:pointer-void) (values :object :object) "
56 cl_object obj = GC_call_with_alloc_lock(fetch_obj, #0);
57 if (obj) { @(return 0) = obj; @(return 1) = @t; }
58 else { @(return 0) = @nil; @(return 1) = @nil; }
62 #-(or sbcl cmu clisp allegro common-lispworks ecl)
64 (defun make-weak-pointer (object) object)
65 (defun weak-pointer-value (weak) (values weak t)))
67 ;;;----- That's all, folks --------------------------------------------------