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:)
Joeish W joeish80829@yahoo.com writes:
[SKIPPED CODE]
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:)
Did you read the tutorial and the CFFI manual?
To be short, you should only use the mem-aref in lowlevel code and in that case you are better of using the (mem-aref (c-pointer ...)) construct.
However if you want to expose the members of the C++ class instance you should lookup the defcstruct documentation in the CFFI manual.
Wim Oudshoorn