[Python-Dev] C-level duck typing (original) (raw)
Robert Bradshaw robertwb at gmail.com
Wed May 16 22:24:42 CEST 2012
- Previous message: [Python-Dev] C-level duck typing
- Next message: [Python-Dev] C-level duck typing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, May 16, 2012 at 11:33 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
Does this use case make sense to everyone?
The reason why we are discussing this on python-dev is that we are looking for a general way to expose these C level signatures within the Python ecosystem. And Dag's idea was to expose them as part of the type object, basically as an addition to the current Python level tpcall() slot. The use case makes sense, yet there is also a long-standing solution already to expose APIs and function pointers: the capsule objects. If you want to avoid dictionary lookups on the server side, implement tpgetattro, comparing addresses of interned strings.
Yes, that's an idea worth looking at. The point implementing tp_getattro to avoid dictionary lookups overhead is a good one, worth trying at least. One drawback is that this approach does require the GIL (as does _PyType_Lookup).
Regarding the C function being faster than the dictionary lookup (or at least close enough that the lookup takes time), yes, this happens all the time. For example one might be solving differential equations and the "user input" is essentially a set of (usually simple) double f(double) and its derivatives.
- Robert
- Previous message: [Python-Dev] C-level duck typing
- Next message: [Python-Dev] C-level duck typing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]