Thank you very much for all the help recently,   actually the Rect is a OpenCv C class here:
http://docs.opencv.org/trunk/modules/core/doc/basic_structures.html?highlight=rect#Rect_...does your advice on making a defcstruct for it stand..Remember, the same code works evaluating the same way at the REPL creating a vector<Rectt> like this:


Functions:

;; template < class T, class Alloc = allocator<T> > class vector
;; vector_##t * carray_to_std_vector##tn( t * a, size_t len )
(defcfun ("carray_to_std_vectorr" %c-arr-to-vector-rect) (:pointer vector-rect)
  (a :pointer)
  (len :unsigned-int))

;; template < class T, class Alloc = allocator<T> > class vector
;; t * std_vector##tn##_to_carray( vector_##t * v )
(defcfun ("std_vectorr_to_carray" %vector-rect-to-c-array) (:pointer rect)
  (s (:pointer vector-rect)))


(%c-arr-to-vector-rect
         (foreign-alloc :pointer :initial-contents
                (list (rect 1 2 3 4)
                      (rect 5 6 7 8))) 2)


VECTOR-RECT-SIZE just gets the size of the vector


(dotimes (ic (%vector-rect-size faces))
(setf n (%vector-rect-to-c-array faces))
(format t "~a~%" (rect-x (mem-aref n :pointer ic))))
;
; caught WARNING:
;   undefined variable: N
;
; compilation unit finished
;   Undefined variable:
;     N
;   caught 1 WARNING condition
1 <-- both x values
5



On Saturday, April 26, 2014 4:41 AM, Willem Rein Oudshoorn <woudshoo@xs4all.nl> wrote:
Joeish W <joeish80829@yahoo.com> writes:

> Lisp code is here https://gist.github.com/W-Net-AI/11205892
>  ...
> LCV> (dotimes (ic (vector-rect-size faces))
>            (setf n (%vector-rect-to-c-array faces))
>            (rect-x (mem-aref n :pointer ic)))
>
> this is where it fails, rect-x, my Lisp wrapper for C wrapper for the
> c++ Rect class member x in this statement isn't getting a Rect* so it
> outputs error: Unhandled ;memory fault at #xC9000000D5.  The
> %vector-rect-to-c-array function is a wrapper for the c function in
> the posted c/c++ code. It works as expected on everything else but the
> vector<Rect> output of detectMultiScale.

This fails because `n` is a pointer the data of vector<Rect>. 
So it points to an array of Rect structures, NOT an array of Rect*
(pointers to Rect).

What would work (but I am advising against this), is:

(rect-x (inc-pointer n (* ic SIZE_OF_RECT)))

Where SIZE_OF_RECT is the size of the Rect struct.

What you should do is look into `defcstruct` to properly wrap the Rect
struct and start from there.

Wim Oudshoorn.


_______________________________________________
Cffi-devel mailing list
Cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel