chiark / gitweb /
Bug fix for CLISP
[clg] / gffi / proxy.lisp
index 3670bdbd7d2db081f41d915c84b9cfe845962d0e..4600bf06c3d12a5a280e947346b711c4a40af1c2 100644 (file)
@@ -20,7 +20,7 @@
 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-;; $Id: proxy.lisp,v 1.5 2006/09/29 13:14:19 espen Exp $
+;; $Id: proxy.lisp,v 1.9 2007/06/20 11:13:45 espen Exp $
 
 (in-package "GFFI")
 
@@ -87,7 +87,7 @@ (defun list-invalidated-instances ()
 (defvar *foreign-instance-locations* 
   (make-hash-table #+clisp :weak #+sbcl :weakness :key))
 
-;; TODO: add a ref-counted-proxy subclass
+
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (defclass proxy (virtual-slots-object)
     (#?-(or (sbcl>= 0 9 17) (featurep :clisp))(%location :special t :type pointer))
@@ -167,6 +167,7 @@ (defmethod instance-finalizer ((instance proxy))
 ;; :FINALZIE given to MAKE-PROXY-INSTANCE or non NIL if the proxy was
 ;; created with MAKE-INSTANCE
 (defmethod invalidate-instance ((instance proxy) &optional finalize-p)
+  #+clisp(declare (ignore finalize-p))
   (remove-cached-instance (foreign-location instance))
   #+(or sbcl cmu)
   (progn
@@ -301,6 +302,8 @@   (defmethod compute-slot-writer-function ((slotd effective-virtual-alien-slot-d
          #'(lambda (value object)
              (unless writer
                (setq writer (mkbinding setter nil 'pointer type)))
+             ;; First argument in foreign setters is the object and second
+             ;; is value
              (funcall writer (foreign-location object) value)))
       (call-next-method)))
   
@@ -499,6 +502,20 @@ (defmethod make-proxy-instance ((class proxy-class) location
     (cache-instance instance)
     instance))
 
+;;;; Superclass for ref-counted objects
+
+(defclass ref-counted-object (proxy)
+  ()
+  (:metaclass proxy-class))
+
+(define-type-method from-alien-form ((type ref-counted-object) form 
+                                    &key (ref :copy))
+  (call-next-method type form :ref ref))
+
+(define-type-method from-alien-function ((type ref-counted-object) 
+                                        &key (ref :copy))
+  (call-next-method type :ref ref))
+
 
 ;;;; Superclasses for wrapping of C structures