Jeremy Smith <[EMAIL PROTECTED]> writes:
> Luís Oliveira wrote:
>>
>> Many (?) months ago, way before 0.9.0 (the first actual release of
>> CFFI), the behaviour of MEM-REF (and others) changed so that the type
>> translators are called (in this case, the :STRING type translator). So,
>> MEM-REF will call FOREIGN-STRING-TO-LISP for you.
>
> Thanks guys, that's great news. I've implemented the fix so it does it
> with the 'old' CFFI (the one I use!) which doesn't automatically do
> this, and the new one (which does), by using 'typep' to check for
> string-ness.
>
> I'm not sure if this is really the proper use of 'case' but Lisp allows
> 'if' to specify any of 2 values, so I think it'll work.
>
> I'll upload it soon if it works with the newer CFFI. I haven't got CVS
> running at common-lisp.net yet, but I'll look into it when I have time.
>
> (defun pygetarg (variable type)
> "Helper function for handling python arguments, used by
> gen-pycallback. Should never be used directly from code - use defpyfun
> with its arg format"
> (case type
> (long (cffi:mem-ref variable :long))
> ;If it's decoded by the new version of CFFI
> (if (typep (cffi:mem-ref variable :string) 'string)
> (string (cffi:mem-ref variable :string))))
> (string (cffi:foreign-string-to-lisp (cffi:mem-ref variable
> :string))))
If this works for you it is not obvious (to me) why. If the
indentation indicates two IF branches, there is a parenthesis
mismatch. Try to MACROEXPAND the CASE form to see the resulting
code. I would recommend something like
(defun pygetarg (variable type)
"Helper function for handling python arguments, used by
gen-pycallback. Should never be used directly from code - use defpyfun
with its arg format"
(case type
(long (cffi:mem-ref variable :long))
(string (if (typep (cffi:mem-ref variable :string) 'string)
(cffi:mem-ref variable :string)
(cffi:foreign-string-to-lisp (cffi:mem-ref variable
:string))))))
Also using ECASE instead of CASE might be appropriate.
As Luis already pointed out switching to a more current version of
CFFI is probably a good idea. And mentioning this dependency on a
specific version on the python-on-lisp home page might also motivate
others to update their ancient CFFI version :-)
Regards,
Marco
_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners