You see!! All your observations just seems to indicate I do not
actually undestand the whole thing. Please, if you have the time, can
you clarify me a bit this:
I have this class Info (something like a dictionary ) wrapping some
MPI calls for getting and setting (key,value) pairs (they have to be
ascii, 8-bits strings in order MPI understands them)
cdef class Info:
# ...
def Get(self, char key[]):
"""
Retrieve the value associated with a key
"""
cdef char value[MPI_MAX_INFO_VAL]
cdef int flag = 0
CHKERR( MPI_Info_get(self.ob_mpi, key, maxlen, value, &flag) )
if not flag: return (None, False)
else: return (value, True)
def Set(self, char key[], char value[]):
"""
Add the (key,value) pair to info, and overrides the value if a
value for the same key was previously set
"""
CHKERR( MPI_Info_set(self.ob_mpi, key, value) )
So then all your comments actually means that I should not take any
special action in Cython for wrapping this, and then
* - If I run this in Python 2, I just do: info.Set("key", ''value")
* - If I run this in Python 3, I should do: info.Set(b"key", b"value")
In that case, suppose now that a user running on Python 3 does the following:
>>> info.Set("key", "value") .
This is broken, because MPI will not recognize the key or the value,
as they are not C plain char arrays containing null-terminated ascii
8-bits string.
Then, how should I modify my *.pyx code to detect this and generate an
error/warning, or even try to coerce the input to ascii 8-bits if the
input is 'unicode', or pass it unchanged if the input is 'bytes'? And
all this working both in 2.3/2.4/2.5/2.6 and 3.0??
On 5/9/08, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> Lisandro Dalcin wrote:
> > Well, at this point I'm a bit confused... The unicode stuff is the
> > weakest point in my knowledge of Python internals...
>
>
> :) that's just because Unicode is not exactly trivial - especially if you have
> to start thinking about bytes at some point.
>
>
>
> > Anyway, I will not be able to work on this in the next two weeks, so
> > if anyone wants to go on and give a try, just start applying the patch
> > to 'cython-devel-py3' repo (I'm not concerned at all about credits for
> > the original patch ;-) ) in order this does not stagnate.
>
>
> done.
>
>
>
> > At any
> > point, I can contribute testing against my project, just ask me for
> > help.
>
>
> some test cases would be greatly appreciated. :)
>
>
>
> > Finally, IMHO Cython pyx-level and generated C-level code should work
> > with any Python version.
>
>
> But your code shouldn't change semantics when you change the runtime
> environment. Otherwise it would become completely impossible to write
> portable
> code.
>
>
>
> > So, if in a pyx file I wrote "abc", then, by
> > default, it should be a ascii string for Py2 and a unicode one for
> > Py3.
>
>
> Not quite right. If you did that in a .py file, that would be the case. If you
> do that in Cython, a literal must not change its type, because it compiles
> to C.
>
>
>
> > And Cython should grow a new special 'char' type (like it has for
> > bint) to specify ascii string.
>
>
> Why is that? Two things: what's special about an ASCII string compared to a
> byte string in general? And: why aren't "bytes" and "bytearray" enough?
>
>
>
> > Then, at the C-level, and depending on
> > Python major version, the proper conversion py->c or c->py can be
> > managed. If not, wrapping legacy C libs and targeting Py2 and Py3 is
> > going to be a nightmare.
>
>
> It's a nightmare if your code changes behaviour. I think there should be a
> command line switch "-3" for compiling plain Py3 code at some point (as
> opposed to normal Py2 code) or maybe that should be determined by the runtime
> environment of the *compiler*, but the Cython language itself should stay
> compatible to Py2.6 for now.
>
>
> Stefan
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
--
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