Fix pushed and ticket closed.

http://hg.cython.org/cython-devel/rev/8a58f1544bd8


On Thu, Oct 15, 2009 at 12:40 PM, Lisandro Dalcin <[email protected]> wrote:
> On Thu, Oct 15, 2009 at 3:49 AM, Stefan Behnel <[email protected]> wrote:
>>
>> Dag Sverre Seljebotn wrote:
>>> Stefan Behnel wrote:
>>>> it looks like Py3.1 has its own way of defining external C-APIs:
>>>>
>>>> http://docs.python.org/3.1/extending/extending.html#using-capsules
>>>>
>>>> I guess we should switch to that method for C code being compiled under
>>>> Py3.1+, so that Cython modules become compatible with other C extensions
>>>> that start using that mechanism.
>>>
>>> Am I right in thinking that this is basically a standardization of what
>>> we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance
>>> with what we put in capsules and what we put in __pyx_capi?
>>
>> Actually, rereading their examples now, it's not quite the same thing.
>> Cython exports a dict that contains PyCObjects/PyCapsules for each
>> function, whereas their proposed approach is encapsulated by a header file
>> that is presented to work like this:
>>
>> Export:
>>
>> - you create a void* array containing function pointers
>> - you wrap the pointer to it in a PyCapsule
>> - you write a header file around it that defines the names and an import
>>  function in whatever way.
>>
>> Import:
>>
>> The import function in the header file calls
>>
>>        PyCapsule_Import(fq_module_attribute_name, non_blocking_flag)
>>
>> to import the module and retrieve the pointer by attribute name.
>>
>> The header file additionally defines a call macro that just statically
>> knows at what offset in the pointer table you find the right function.
>>
>> Look at the example header file at the link above for details.
>>
>> I actually find Pyrex's/Cython's way of doing that a *lot* nicer and safer.
>>
>> However, the main machinery for C-API users is that you get a header file
>> from whatever source, #include it in your C source, call the import
>> function it defines, and can then call the function as you see fit. That's
>> the same for both cases, so the way Cython exports the C-API is just fine 
>> IMO.
>>
>> OTOH, PyCapsule_Import() won't work on Cython modules, as it doesn't export
>> a plain void* but a dict of void*.
>>
>> Also, Cython can't directly cimport a C-API that's defined in the described
>> way. Instead, you have to use the header file and call the import function
>> manually. But that's not too much overhead, as you have to define the
>> functions anyway. Switching to the described way would really remove
>> features from Cython here, with no added gain.
>>
>> Stefan
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
>
> After such comprehensive review, do you understand now why I said that
> I was not going to make any comment and just fix Cython to make it
> work ;-) ? For the Pyrex/Cython POV, the new PyCapsule has very little
> to add...
>
> HOWEVER, still we could take advantage of the strictness of
> PyCapsule... using full module/[class]/funcname alongside the
> signature would be a good way to prevent (malicious) Python code to
> change the c-api dicts and vtable dicts and break things... I'm not a
> security guy, but just in case ...
>
>
>
>
>
> --
> 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
>



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