My extension code generator for C++

Stefan Behnel stefan_ml at behnel.de
Sun Jul 4 02:38:34 EDT 2010


Rouslan Korneychuk, 03.07.2010 19:22:
> The code also never uses PyArg_ParseTuple or its variants. It converts
> every argument using the appropriate PyX_FromY functions. I noticed
> PyBindGen does the following when a conversion is needed for one argument:
>
> py_retval = Py_BuildValue((char *) "(O)", value);
> if (!PyArg_ParseTuple(py_retval, (char *) "i", &self->obj->y)) {
> Py_DECREF(py_retval);
> return -1;
> }
> Py_DECREF(py_retval);
>
> On the other hand, here's the implementation for __sequence__getitem__:
>
> PyObject * obj_DVector___sequence__getitem__(obj_DVector
> *self,Py_ssize_t index) {
> try {
> std::vector<double,std::allocator<double> > &base =
> cast_base_DVector(reinterpret_cast<PyObject*>(self));
> return PyFloat_FromDouble(base.at(py_ssize_t_to_ulong(index)));
>
> } EXCEPT_HANDLERS(0)
> }

Check the code that Cython uses for these things. It generates specialised 
type conversion code that has received a lot of careful benchmarking and 
testing on different platforms.

Stefan




More information about the Python-list mailing list