[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

cffi -- bare references to struct types are deprecated. Please use ...

Jim Newton

6/30/2015 8:13:00 AM

I'm getting a lot of warnings at runtime like the following.

STYLE-WARNING:
bare references to struct types are deprecated. Please use (:POINTER
(:STRUCT
GTK::TREE-ITER-CSTRUCT)) or (:STRUCT
GTK::TREE-ITER-CSTRUCT)

I've tracked this down to what looks like suspicious code in CFFI, in the file types.lisp.

The three functions in question (actually a function and 2 macros) are shown below.
It looks to me like the return value of parse-deprecated-struct-type is completely ignored,
nevertheless a style warning is issued and an instance is created with make-instance.
Of course there might be side-effects of make-instance, so I hesitate to remove
the call.

Anyway, in the two macros defcstruct and defcunion, the call to parse-deprecated-struct-type is followed by the allocation and return of a list such as (:struct <name>) or (:union <name>).

I don't see the purpose of issuing a style warning 1000s of times at runtime for code which is running but has no effects. Moreover it seems defcstruct and defcunion anyway create the type of data the warning is suggesting be created.

When I comment out the call to simple-style-warning, I get a big performance increase speed in my gtk application.

Can anyone give a good reason why we need parse-deprecated-struct-type at all?


(defun parse-deprecated-struct-type (name struct-or-union)
(check-type struct-or-union (member :struct :union))
(let* ((struct-type-name `(,struct-or-union ,name))
(struct-type (parse-type struct-type-name)))
(simple-style-warning "bare references to struct types are deprecated. ~
Please use ~S or ~S."
`(:pointer ,struct-type-name)
struct-type-name)
(make-instance (class-of struct-type)
:alignment (alignment struct-type)
:size (size struct-type)
:slots (slots struct-type)
:name (name struct-type)
:bare t)))

(defmacro defcstruct (&whole body name-and-options &body fields)
"Define the layout of a foreign structure."
(discard-docstring fields)
(destructuring-bind (name . options)
(ensure-list name-and-options)
(let ((conc-name (getf options :conc-name)))
(remf options :conc-name)
(unless (getf options :class) (setf (getf options :class) (symbolicate name '-tclass)))
`(eval-when (:compile-toplevel :load-toplevel :execute)
;; m-f-s-t could do with this with mop:ensure-class.
,(when-let (class (getf options :class))
`(defclass ,class (foreign-struct-type
translatable-foreign-type)
()))
(notice-foreign-struct-definition ',name ',options ',fields)
,@(when conc-name
(generate-struct-accessors name conc-name
(mapcar #'car fields)))
,@(when *defcstruct-hook*
;; If non-nil, *defcstruct-hook* should be a function
;; of the arguments that returns NIL or a list of
;; forms to include in the expansion.
(apply *defcstruct-hook* name-and-options fields))
(define-parse-method ,name ()
(parse-deprecated-struct-type ',name :struct ',body))
'(:struct ,name)))))


(defmacro defcunion (&whole body name-and-options &body fields)
"Define the layout of a foreign union."
(discard-docstring fields)
(destructuring-bind (name &key size)
(ensure-list name-and-options)
(declare (ignore size))
`(eval-when (:compile-toplevel :load-toplevel :execute)
(notice-foreign-union-definition ',name-and-options ',fields)
(define-parse-method ,name ()
(parse-deprecated-struct-type ',name :union ',body))
'(:union ,name))))