On 6/4/08, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Then why None and not ''? And why None and not a ValueError?

Well, I would not object ValueError. That would be far better than a segfault.

>  > None is automatically converted to Python strings, so you can use it in
>  > every string or print statement without troubles.
>
> Not on my side of the cable:
>     TypeError: cannot concatenate 'str' and 'NoneType' objects

I believe Johannes was actually talking about str(None) -> "None"

>  And the following will still crash, even under your proposal:
>
>     cdef char* s = NULL
>     py_s = s
>     print PyString_GET_SIZE(py_s)

So now I definitely believe that the 'py_s = s' line should generate a
ValueError.

>  And would you also want this to work:
>
>     cdef char* s = None

I do not believe  Johannes asked for this. That should never be valid,
moreover, that should by a Cython compile-time syntax error (I believe
it is, right?)

>  > don't want to waste my time with ugly C memory management stuff.
> This is not about memory management at all. This is about making sure your
>  code handles corner cases correctly. Where does the NULL pointer come from
>  anyway? Is it maybe an error return of a function that you didn't catch? You
>  wouldn't want Cython to find your off-by-one errors also, would you?

So the correct way of handling it is, again, raise ValueError. A
segfault should never be an option.

>
>  I think it's an advantage that you get a straight crash when your code
>  contains the obvious bug that you forgot to test a NULL pointer for a NULL

I really do not see the advantage of a crash. Python has exceptions!!


In short, would it make sense to generate ValueError for  the char* ->
str conversion? Honestly, the performance issues are going to be
really small.


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to