In constantenum, :optional constants that are not actualy defined get spurious values
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
New
|
Undecided
|
Unassigned |
Bug Description
When there is an entry in **CONSTANTENUM** with :optional, and it is not
defined in C, grovelling ends up output just the name without a value.
When this is parsed inside **parse-
src/enum.lisp, it is assign the next integer after the previous entry,
because it defaults to **default-value** which is assigned to **(1+
value)** while processing the previous entry. This gives it a spurious
value. It is specially bad when this spurious value is the same as the
proper value of a previous entry, because it overwrites the reverse
mapping from the value to the name in line 101:
`(setf (gethash value value-keywords) keyword)`
I found this when trying to run the tests of the system "osicat-tests"
on freebsd. in
https:/
it defines **(constantenum errno-values ..)** with **ENONET** as
optional. On freebsd it is not defined, so gets the next value after
the value of the previous entry which happens to be 66, which then
overrides the real reverse mapping from 66 to *ENOTEMPTY**. That
appears as failure in the test **osicat-
I think **constantenum** in grovel/grovel.lisp should always give a
value to the constant when it is undefined in C. Currently it gives -1
when it is not :optional (and a warning), which is probbaly good
enough as a first try. It can also check the value of **optional** and
if it is an integer use it, thus giving the user a way to specify a
default value.