hi!
i'm trying to revive verrazano after the new changes and i ran into the following issues (that were working previously):
==== issue 1
typedef struct Ppoly_t { Ppoint_t *ps; int pn; } Ppoly_t;
previously this ended up as:
(cffi:defcstruct ppoly-t (ps :pointer) (pn :int)) (cffi:define-foreign-type ppoly-t () 'ppoly-t)
which puts head into an endless loop (due to using the old syntax). some heuristic for detecting the old syntax and a warning would be useful if feasible.
==== issue 2
previously it worked
(cffi:define-foreign-type _-off-64-t () '_-quad-t) (cffi:define-foreign-type _-quad-t () ':long-long)
now verrazano generates this:
(cffi:define-foreign-type _-off-64-t () () (:actual-type _-quad-t) (:simple-parser _-off-64-t)) (cffi:define-foreign-type _-quad-t () () (:actual-type :long-long) (:simple-parser _-quad-t))
i'm not sure at all that this is the right way, but this is what i managed to come up with.
for example the :simple-parser argument seems redundant for me, but without that the define-foreign-type macro expands into a mere defclass and the foreign type will not be known to cffi.
but cffi also fails with this, due to the load order (which, if needed to be fixed on the verrazano side, would be a big headache):
Unknown CFFI type: _-QUAD-T.
any toughts?
previously it worked
(cffi:define-foreign-type _-off-64-t () '_-quad-t) (cffi:define-foreign-type _-quad-t () ':long-long)
but cffi also fails with this, due to the load order (which, if needed to be fixed on the verrazano side, would be a big headache):
hm, i was fooled by the original verrazano impl. as i understand it now, cffi:defctype should be used here instead, but using that also leads to the same load order problem.
i've tried to quickly fix this, but it needs more then a simple combination of eval-when's.
my try was something like this:
(PROGN (EVAL-WHEN (:COMPILE-TOPLEVEL) (ENSURE-FOREIGN-TYPE _-OFF-64-T 'FOREIGN-TYPEDEF)) (EVAL-WHEN (:LOAD-TOPLEVEL :EXECUTE) (LET* ((BTYPE (PARSE-TYPE '_-QUAD-T)) (DTYPE (IF (TYPEP BTYPE 'ENHANCED-FOREIGN-TYPE) 'ENHANCED-TYPEDEF 'FOREIGN-TYPEDEF)) (PARSER (ENSURE-FOREIGN-TYPE _-OFF-64-T DTYPE))) (SETF (NAME PARSER) '_-OFF-64-T) (SETF (ACTUAL-TYPE PARSER) BTYPE))))
but the problem is that even at load time we need to (?) call parse type and it may cause problems (?) if it happens in the wrong order. so it needs someone who has better understanding of the type stuff.
if this solution can work, here's where i've stopped:
;; this is instead of notice-foreign-type (defmacro ensure-foreign-type (name parser-type &rest initargs) (with-unique-names (parser) `(let (,parser (find-type-parser ',name)) (if ,parser (unless (typep ,parser ,parser-type) (change-class ,parser ,parser-type ,@initargs)) (setf (find-type-parser ',name) (make-instance ,parser-type ,@initargs))) ,parser)))
(defmacro defctype (name base-type &optional documentation) "Utility macro for simple C-like typedefs." (declare (ignore documentation)) (warn-if-kw-or-belongs-to-cl name) `(progn (eval-when (:compile-toplevel) (ensure-foreign-type ,name 'foreign-typedef)) (eval-when (:load-toplevel :execute) (let* ((btype (parse-type ',base-type)) (dtype (if (typep btype 'enhanced-foreign-type) 'enhanced-typedef 'foreign-typedef)) (parser (ensure-foreign-type ,name dtype))) (setf (name parser) ',name) (setf (actual-type parser) btype)))))
i'm back to darcs unpull for now.
hth,
"Attila Lendvai" attila.lendvai@gmail.com writes:
(cffi:define-foreign-type ppoly-t () 'ppoly-t)
Heh, it took me a while to figure out how that even compiled. It creates a PPOLY-T class with to slots: QUOTE and PPOLY-T. I'm not sure how to reliable detect the old syntax. The old DEFINE-FOREIGN-TYPE is more like the new DEFINE-PARSE-METHOD.
previously it worked
(cffi:define-foreign-type _-off-64-t () '_-quad-t) (cffi:define-foreign-type _-quad-t () ':long-long)
(defmacro defctype* (name base-type) "Like DEFCTYPE but defers instantiation until parse-time." `(define-parse-method ,name () (make-instance 'foreign-typedef :name ',name :actual-type (parse-type ',base-type))))
This should work. It could have a few more features of DEFCTYPE's but that's the basic idea. Would Verrazano need this macro added to CFFI or can it define itself somewhere? Also, suggestions for a better name are welcome.
HTH