how to write defmacro for a defcfun/defun combo in cffi?

Discussion of Common Lisp

how to write defmacro for a defcfun/defun combo in cffi?

Postby joeish80829 » Thu Oct 24, 2013 5:33 pm

here is the defcfun and deffun combo

;; void cvSplit(const CvArr* src, CvArr* dst0, CvArr* dst1, CvArr* dst2, CvArr* dst3)
;; Note: I had to use "CV-MERGE" instead of "MERGE" for the Common Lisp name of CV-MERGE so I named this
;; function CV-SPLIT so they would match.
(cffi:defcfun ("cvSplit" %split) :void
(src cv-arr)
(dest-0 cv-arr)
(dest-1 cv-arr)
(dest-2 cv-arr)
(dest-3 cv-arr))

(defun cv-split (src dest-0 &optional (dest-1 (cffi:null-pointer)) (dest-2 (cffi:null-pointer)) (dest-3 (cffi:null-pointer)))
"Divides a multi-channel array into several single-channel arrays."
(%split src dest-0 dest-1 dest-2 dest-3))

it works as expected errors at all

my attempt at a macro(new to macros) below works in one piece of code when the defun it is in is evaluated at the repl then ran at the repl

;; #define cvCvtPixToPlane cvSplit
(defmacro cvt-pix-to-plane (src dest-0 &optional (dest-1 (cffi:null-pointer))
(dest-2 (cffi:null-pointer)) (dest-3 (cffi:null-pointer)))
"Macro for CV-SPLIT"
`(cv-split ,src ,dest-0 ,dest-1 ,dest-2 ,dest-3))

but in the same code when used the exact same way inside emacs (using slime/sbcl on ubuntu saucy) when it is placed inside a newly opened file (.lisp) or even my well used test.lisp file and ran with slime-compile-and-load-file i get

Objects of type SB-SYS:SYSTEM-AREA-POINTER can't be dumped into fasl files.
#.(SB-SYS:INT-SAP #X00000000)

can you help me figure out the issue and write macros with null-pointers correctly
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 3 guests