[Cffi-devel] Still can't mem-aref the output of a metaobject with provided code

Joeish W joeish80829 at yahoo.com
Sat May 3 09:45:42 UTC 2014


I do appreciate all your attention to my types GC issue so far but when Wim gave me this untested code:

(defmethod translate-to-foreign ((lisp-value cv-matrix) (c-type cv-mat))
     (values  (c-pointer lisp-value) lisp-value))


I thought it worked but I still had my mem-aref macro defined to access the c-pointer value so I didn't get a good test?

for example I'm referring to the lisp wrapper for this C function now, but it is identical to the cv-matrix one:

Scalar* cv_create_Scalar(double val0, double val1, double val2, double val3)
{
    return new Scalar(val0, val1, val2, val3);
}


I now have my lisp wrapper and types/finalizers for the above c function defined like this:

(defcfun ("cv_create_Scalar" %scalar) scalar 
  (val0 :double)
  (val1 :double)
  (val2 :double)
  (val3 :double))

(define-foreign-type scalar ()
  ((garbage-collect  :reader garbage-collect :initform nil :initarg 
                     :garbage-collect))
  (:actual-type :pointer)
  (:simple-parser scalar))


(defclass cv-scalar ()
  ((c-pointer :reader c-pointer :initarg :c-pointer)))


(defmethod translate-to-foreign ((lisp-value cv-scalar) (c-type scalar))
   (values  (c-pointer lisp-value) lisp-value))  <--the new version Wim gave me untested


(defmethod translate-from-foreign (c-pointer (c-type scalar))
  (let ((scalar (make-instance 'cv-scalar :c-pointer c-pointer)))
    (when (garbage-collect c-type)
      (tg:finalize scalar (lambda () (del-scalar c-pointer))))
    scalar))


When I run (defparameter a (%scalar 1d0 2d0 3d0 4d0))  and (mem-aref a :double)  I still get:

The value #<CV-SCALAR {10046BC833}>
is not of type
  SB-SYS:SYSTEM-AREA-POINTER.



but when I run  (mem-aref (c-pointer a) :double)  it works.



What do I have to change in my types so I can mem-aref  "A" normally, like this 

(mem-aref a :double)...Any help is much appreciated:)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20140503/6861acca/attachment.html>


More information about the cffi-devel mailing list