On Fri, Feb 27, 2009 at 12:23 AM, Robert Bradshaw
<[email protected]> wrote:
> On Feb 26, 2009, at 5:05 PM, Lisandro Dalcin wrote:
>
>> On Thu, Feb 26, 2009 at 9:21 PM, Robert Bradshaw
>> <[email protected]> wrote:
>>> It mostly looks good to me. To summarize, you basically made a macro
>>> that's the function for converting to/from the various types, and
>>> applied that everywhere, right?
>>
>> Yes, though this is preliminary...
>>
>> Perhaps I should make Cython emit the code directly?
>
> I think that's what was there originally. I'm OK with it either way.
>

IMHO, the only benefit of macro-based would be to save disk space...
These functions are generated for every ext module.

>> Moreover, I need to review the Py_ssize_t/size_t converters..
>
> For Py_ssize_t we should be using PyNumber_Index--probably should use
> the same for size_t.
>

OK.. that was what I meant...

>> However, I would like to point a gotcha... The some converters use
>> PyNumber_{Int|Long} ... This is good as they would exercise general
>> Python types implementing the special methods "__int__()" or
>> "__long__()" ... However, they will also accept strings, and even
>> (char) buffer objects !!!! What to do here ?? This makes me feel a bit
>> uncomfortable, seems too much ...
>
> I'm confused, I don't think PyNumber_(Int|Long) accept strings, etc.
> They only accept objects that have implemented the __int__ method.
> Note that I wrote an inline function to extract it directly if it's a
> Python int (as this is an extremely common case).
>

Unfortunately, you are wrong. Plese check PyNumber_(Int|Long)
implementation at core CPython sources...

Anyway, I'll try first to make this work right, signaling overflows
where appropiate...

IMHO, we cannot use things like PyInt_AsUnsignedLongMask()... Do you agree here?


Next we can discuss how to optimize this....

BTW, can I asume that if I write

if ( sizeof(c_type) < sizeof(long) ) {

} else if ( sizeof(c_type) == sizeof(long) ) {

} else {

}

then C compiler will be smart enough to eliminate the branching? (I
know, I have to learn how to read disasemblies....)

I'm thinking on extending all this to extern ctypedef'ed integral,
this way Cython will stop using the base-type's longness of the
typedef.



-- 
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