Lisandro Dalcin wrote:
> On Fri, Sep 11, 2009 at 7:17 PM, Robert Bradshaw wrote:
>> On Sep 11, 2009, at 2:23 PM, Lisandro Dalcin wrote:
>>
>>> Well, I guess it is too late to complain... But I think that explicit
>>> is better than implicit here, then I do not like this... I do not even
>>> like the automatic casting to bare char* !! It is almost impossible to
>>> be 100% sure that you code is bytes/unicode clean!

Sounds like FUD to me. This has nothing to do with Unicode. Cython will
continue to give you compile time errors if you do this:

        cdef char* s = some_unicode_string

or this:

        cdef char* s = some_unicode_string.encode('UTF-8')


>>> Could we have at least a compile directive (or perhaps better/easier a
>>> global option?)  to DISABLE these automatic castings to char*/uchar* ?
>> It's certainly too late to disable it now, but I would be up for an
>> option that gives errors/warnings. (Maybe -W or lint flags of some
>> kind.)
>
> In understand ... Anyway, the implicit cast would not bother me at all
> I I would be able to disable it...

Would you also want to disable automatic casts between Python int and C int?

I do see the difference that string handling involves a bit of reference
keeping care. But that would still be the case when you use explicit casts.
In many, many cases, all you need to do is to pass a byte string into a C
function, where the lifetime of the Python string is automatically assured
by the function call lifetime. That's such a common use case that I can't
imagine requiring more code than

        some_c_function(some_python_byte_string)


>> Just out of curiosity, what would the explicit method be?
> 
> No idea... perhaps a manual cast? char *p =<char*> pystring ...

I find it *very* convenient that Cython allows you to get the pointer to
Python's byte string buffer with a simple assignment. I honestly doubt that
an explicit cast would serve anyone.


>> Python/C API?
> 
> That's more or less what I'm currently doing in mpi4py...

I keep thinking about safe ways to make it easier for users to convert
between Python unicode strings and C byte strings. Making it harder to
convert between Python byte strings and C byte strings certainly wouldn't
help here.

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

Reply via email to