..say I have this:
SWGtk> (defcenum UpdateType :continuous :discontinous :delayed)
..then do:
SWGtk> (foreign-enum-value 'UpdateType :not-valid)
..I get a meaningful message from CFFI:
:not-valid is not defined as a keyword for enum type #<cffi::foreign-enum UpdateType>.
..very nice; as expected. But if I do:
SWGtk> (foreign-funcall "someCFunction" UpdateType :not-valid)
..I get:
The value nil is not of type (signed-byte 32).
It is almost impossible to debug this because I cannot see any NIL anywhere. :not-valid is a constant here of course - but if it is in a variable:
SWGtk> (foreign-funcall "someCFunction" UpdateType some-variable)
..`some-variable' _still_ doesn't contain NIL so I've been lost for quite some time here.
On 12/20/06, Lars Rune Nøstdal larsnostdal@gmail.com wrote:
SWGtk> (foreign-funcall "someCFunction" UpdateType :not-valid)
..I get:
The value nil is not of type (signed-byte 32).
The following patch should fix that. Before commiting this patch, though, I wanted to write a regression test. That kind of requires a proper error condition instead of simple-error and having a proper error condition would probably remove the need for the errorp argument that introduced this bug in the first place.
IIRC, this was added by request of the cffi-unix folks who wanted to deal gracefully with incomplete enums or something like that. cffi-unix folks, wouldn't a condition work better than this errorp argument? Well, I suppose we could have both ways of doing this... Any comments?
diff -rN -u old-cffi/src/enum.lisp new-cffi/src/enum.lisp --- old-cffi/src/enum.lisp 2006-12-20 15:07:48.000000000 +0000 +++ new-cffi/src/enum.lisp 2006-12-20 15:07:48.000000000 +0000 @@ -110,11 +110,11 @@
(defmethod translate-type-to-foreign (value (type foreign-enum)) (if (keywordp value) - (%foreign-enum-value type value) + (%foreign-enum-value type value :errorp t) value))
(defmethod translate-type-from-foreign (value (type foreign-enum)) - (%foreign-enum-keyword type value)) + (%foreign-enum-keyword type value :errorp t))
;;;# Foreign Bitfields as Lisp keywords ;;;