style warning from passing keyword as enum arguments of inlined foreign functions in sbcl with SPEED 3

Bug #1750647 reported by 3b
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
New
Undecided
Unassigned

Bug Description

(cffi:defcenum (foo) (:a 1))

(declaim (inline foo))

(cffi:defcfun foo :void (a foo))

(defun bar ()
  (declare (optimize speed))
  (foo :a))

; in: DEFUN BAR
; (FOO :A)
; --> BLOCK LET LET IF
; ==>
; #:VALUE2
;
; caught STYLE-WARNING:
; This is not a (UNSIGNED-BYTE 32):
; :A
; See also:
; The SBCL Manual, Node "Handling of Types"
;

the DEFCFUN expands to something similar to
(defun foo (a)
  (let ((a (if (keywordp a)
               (cffi:foreign-enum-value a 'foo)
               a)))
    (cffi:foreign-funcall ... a ...)))

and SBCL doesn't constant-fold KEYWORDP since the symbol could be uninterned from KEYWORD package, so it can't be sure :a won't be passed to the foreign function.

Possibly it should use SYMBOLP there instead since unrecognized non-keyword symbols are an error either way, and in the edge case of someone uninterning a keyword used in an enum, it should probably still be accepted.

Revision history for this message
3b (00003b) wrote :

actually, looking closer, DEFCENUM and FOREIGN-ENUM-VALUE accept non-keyword keys, so KEYWORDP is wrong there anyway

Revision history for this message
3b (00003b) wrote :
Revision history for this message
Luís Oliveira (luismbo) wrote : Re: [Bug 1750647] Re: style warning from passing keyword as enum arguments of inlined foreign functions in sbcl with SPEED 3

Ah, I wonder when DEFCENUM started taking non-keywords. The idea was that
having a single namespace for enum members would match the C semantics,
IIRC.

On Tue, Feb 20, 2018, 21:10 3b <email address hidden> wrote:

> https://github.com/cffi/cffi/pull/129
>
> --
> You received this bug notification because you are subscribed to CFFI.
> https://bugs.launchpad.net/bugs/1750647
>
> Title:
> style warning from passing keyword as enum arguments of inlined
> foreign functions in sbcl with SPEED 3
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/cffi/+bug/1750647/+subscriptions
>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.