Hi,

Johannes Wienke wrote:
> I've just noticed that using NULL values in char* is a bad idea when
> converting them to a python string.

Every pointer can potentially be NULL. If Cython added NULL checks to
everything that might be NULL, you'd get pretty inefficient code with loads of
expensive conditionals. You should take care to write robust code yourself.


> *Wouldn't it be a good idea to automatically convert them to None?*

What would be gained from having to check for None instead of having to check
for NULL? Checking for NULL, referencing None and then checking for None is
definitely more expensive than a straight check for NULL in your code.

If you *really* want None, then you can use something like this:

    cdef inline stringOrNone(char* value):
         if value is NULL: return None
         return value

and wrap all your char*->byte string conversions explicitly in a call to this
function. Remember, explicit is better than implicit.

Stefan

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to