Hi,

I've just noticed that using NULL values in char* is a bad idea when
converting them to a python string. This results in a segfault:

cdef void doSomething(char *string):
    print string

def doIt():
    cdef char* string = NULL
    doSomething(NULL)

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

For example I have a lot of debug messages that simply indicate which
function is currently called and with which arguments. At the moment
this is always 4 extra lines to check for the NULL value, which could
even be semantically correct for the rest of that function:

cdef void doSomething(char *string):
    if string == NULL:
        printString = None
    else:
        printString = string
    print printString
    # now I want to use NULL...

def doIt():
    cdef char* string = NULL
    doSomething(NULL)

Even if I use a custom function for this (which isn't easy to manage in
formatted strings), this will be or is a common cause for bugs. I don't
want to know the times that I have forgotten to check this...

- Johannes

Attachment: signature.asc
Description: OpenPGP digital signature

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

Reply via email to