In constantenum, :optional constants that are not actualy defined get spurious values

Bug #1871339 reported by Yehouda
6
This bug affects 1 person
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-foreign-enums-like** in
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://github.com/osicat/osicat/blob/master/posix/basic-unixint.lisp
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-tests::rmdir.error.4**.

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.

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.