diff --git a/defcfun.lisp b/defcfun.lisp index 5002c6d..36bb4ad 100644 --- a/defcfun.lisp +++ b/defcfun.lisp @@ -5,7 +5,7 @@ (defun cffi-object-type-p (type) (when-let ((type (cffi-pointer-type-p type))) - (and (typep (setf type (cffi::ensure-parsed-base-type (cffi::pointer-type type))) 'cffi::foreign-struct-type) type))) + (and (typep (setf type (cffi::ensure-parsed-base-type (cffi-pointer-type type))) 'cffi::foreign-struct-type) type))) (defparameter *return-argument-names* '(#:%%claw-result-)) @@ -80,7 +80,7 @@ :collect `(push (cons nil (compose (lambda (,body) `(let ((,(assoc-value ,temp-vars ',name) ,,name)) . ,,body)) #'list)) ,dynamic-extent-forms)) (nreversef ,dynamic-extent-forms) (lambda (,(caar args) ,body) - `(cffi:with-foreign-object (,,(caar args) ',',(cffi::pointer-type (cffi::ensure-parsed-base-type (cadar args)))) + `(cffi:with-foreign-object (,,(caar args) ',',(cffi-pointer-type (cffi::ensure-parsed-base-type (cadar args)))) ,(reduce #'funcall ,(if *optimize-out-temporary-object-p* `(loop :for (,name . ,form) :in ,dynamic-extent-forms :if ,name @@ -122,8 +122,8 @@ (return-pointer-from-result-p `(pointer-cpointer ,result ',(or (ignore-some-conditions (cobject-class-definition-not-found-error) (cobject-class-definition-class (find-cobject-class-definition - (cffi::pointer-type return-pointer-from-result-p)))) - (cffi::name (cffi::pointer-type return-pointer-from-result-p))))) + (cffi-pointer-type return-pointer-from-result-p)))) + (cffi::name (cffi-pointer-type return-pointer-from-result-p))))) (t result)))))) `(progn (defun ,symbol ,(mapcar #'car args) diff --git a/definition.lisp b/definition.lisp index 58f9324..718b26b 100644 --- a/definition.lisp +++ b/definition.lisp @@ -99,9 +99,9 @@ (cffi::foreign-string-type 'string) (cffi::foreign-array-type `(carray ,(cobject-class-definition-class - (find-cobject-class-definition (cffi::ensure-parsed-base-type (cffi::element-type type)))) + (find-cobject-class-definition (cffi::ensure-parsed-base-type (cffi-element-type type)))) ,(cffi::dimensions type))) (cffi::foreign-pointer-type `(cpointer ,(cobject-class-definition-class - (find-cobject-class-definition (cffi::ensure-parsed-base-type (cffi::pointer-type type)))))) + (find-cobject-class-definition (cffi::ensure-parsed-base-type (cffi-pointer-type type)))))) (t (error 'cobject-class-definition-not-found-error :type type)))))))) diff --git a/macros.lisp b/macros.lisp index d14d548..3375b1e 100644 --- a/macros.lisp +++ b/macros.lisp @@ -91,7 +91,7 @@ :element-type ',(cobject-class-definition-class (find-cobject-class-definition (cffi::ensure-parsed-base-type - (cffi::element-type slot-type)))))) + (cffi-element-type slot-type)))))) (cffi::foreign-pointer-type `(%make-cpointer :pointer ,slot-value @@ -99,7 +99,7 @@ :element-type ',(cobject-class-definition-class (find-cobject-class-definition (cffi::ensure-parsed-base-type - (cffi::pointer-type slot-type)))))) + (cffi-pointer-type slot-type)))))) (t slot-value)))) (etypecase slot (cffi::aggregate-struct-slot @@ -236,7 +236,7 @@ (when (typep (cffi::actual-type type) 'cffi::foreign-struct-type) (push `(define-type-cobject-class (,name ,type)) definitions))) (cffi::foreign-pointer-type - (push-definition (cffi::pointer-type type))) + (push-definition (cffi-pointer-type type))) (cffi::foreign-struct-type (mapc (compose #'push-definition #'cffi::parse-type #'cffi::slot-type) (hash-table-values (cffi::slots type))) diff --git a/test/package.lisp b/test/package.lisp index 62299b6..3ccaf48 100644 --- a/test/package.lisp +++ b/test/package.lisp @@ -364,3 +364,21 @@ (of-type carray (aggregate-struct-c *aggregate-struct*)) (is equal '(unsigned-byte 8) (carray-element-type (aggregate-struct-b *aggregate-struct*))) (is carray-equal (make-carray 2 :element-type '(unsigned-byte 8) :initial-contents '(2 3)) (aggregate-struct-c *aggregate-struct*)))) + +(defcstruct void-pointer-struct + (a :pointer) + (b (:pointer :pointer)) + (c (:pointer :void)) + (d (:pointer (:pointer :void)))) + +(define-cobject-class (:struct void-pointer-struct)) + +(define-test void-pointer :parent suite + (let* ((carray (make-carray 1 :element-type '(unsigned-byte 32) :initial-contents '(123456))) + (cpointer (make-carray 1 :element-type '(cpointer (unsigned-byte 32)) :initial-contents (list carray)))) + (is = 123456 (cref (cref cpointer))) + (let ((struct (make-void-pointer-struct :a carray :b cpointer :c carray :d cpointer))) + (is = 123456 (cref (pointer-cpointer (cobject-pointer (void-pointer-struct-a struct)) '(unsigned-byte 32)))) + (is = 123456 (cref (cref (pointer-cpointer (cobject-pointer (void-pointer-struct-b struct)) '(cpointer (unsigned-byte 32)))))) + (is = 123456 (cref (pointer-cpointer (cobject-pointer (void-pointer-struct-c struct)) '(unsigned-byte 32)))) + (is = 123456 (cref (cref (pointer-cpointer (cobject-pointer (void-pointer-struct-d struct)) '(cpointer (unsigned-byte 32))))))))) diff --git a/type.lisp b/type.lisp index d4cb8cd..a531eb6 100644 --- a/type.lisp +++ b/type.lisp @@ -38,3 +38,8 @@ (or (type= type1 type2) (and (symbolp type1) (symbolp type2) (eql (find-class type1 nil) (find-class type2 nil)))))) + +(setf (fdefinition 'cffi-element-type) (fdefinition 'cffi::element-type)) + +(defun cffi-pointer-type (type) + (or (cffi::pointer-type type) :void))