[cffi-devel] problem overriding enum types

Arthur Smyles atsmyles at earthlink.net
Fri Sep 8 13:59:13 UTC 2006


Stephen Compall wrote:
> Arthur Smyles wrote:
>> I was following the tutorial about defining new types ( http://common-lisp.net/project/cffi/manual/html_node/Tutorial_002dTypes.html#Tutorial_002dTypes). When I tried to redefine the type translator for an enum type (translate-from-foreign), the type was not being changed. I took a look at the source code and discovered that translate-type-from-foreign is specialized on enum types. However, unlike the unspecialized method, this method doesn't call translate-from-foreign. Either the manual is out of date, or there is a bug here.
>
> Translation is done only for foreign-typedefs, which are created with
> define-foreign-type.
>
> I don't think more general type-translation extension can be done well
> without aligning the framework more with CLOS.
>

I've updated the translate-type-{to/from}-foreign methods to call the translate-{from/to}-foreign methods if they are specialized. Otherwise it does what it did before. This fixes the problem that I was having at least.

Arthur

(defmethod translate-type-from-foreign (value (type foreign-enum))
  (if (find-method #'translate-from-foreign nil `(t (eql ,(name type))) nil)
    (translate-from-foreign value (name type))
    (%foreign-enum-keyword type value)))

(defmethod translate-type-to-foreign (value (type foreign-enum))
  (if (find-method #'translate-to-foreign nil `(t (eql ,(name type))) nil)
    (translate-to-foreign value (name type))
    (if (keywordp value)
      (%foreign-enum-value type value)
      value)))



More information about the cffi-devel mailing list