[Pyrex] Please support C++
Lenard Lindstrom
len-l at telus.net
Tue Oct 18 20:06:01 CEST 2005
On 18 Oct 2005 at 8:53, David M. Cooke wrote:
> On Oct 17, 2005, at 18:04, David M. Cooke wrote:
> > Oooh, this sounds like what I was trying figure out, to track down
> > some more compiler warnings. Basically, (PyObject *) was being used to
> > cast an extension type, even when there was an explicit cast to
> > that type.
> > I'm currently getting around it with a postprocessor on the generated
> > .c file.
>
> Greg asked me to post an example:
>
[Pyrex code snip]
>
> def donothing(o):
> cdef ArrayType array1, array2
>
> array1 = PyArray_ContiguousFromObject(o, PyArray_DOUBLE, 1, 1)
> array2 = <ArrayType>PyArray_ContiguousFromObject(o,
> PyArray_DOUBLE, 1, 1)
>
Thanks. This gave me problems too. But it was quickly fixed with the assignment
casting system I added to Pyrex.
> The two calls to PyArray_ContiguousFromObject generate code that set
> array1 and array2 like this:
>
[C code snip]
>
> /* "/home/cookedm/stuff/python/Numeric/pyrex-api/testcast.pyx":32 */
> __pyx_1 = ((PyObject *)PyArray_ContiguousFromObject
> (__pyx_v_o,PyArray_DOUBLE,1
> ,1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32;
> goto __pyx_
> L1;}
> Py_INCREF(((PyObject *)__pyx_1));
> Py_DECREF(((PyObject *)__pyx_v_array2));
> __pyx_v_array2 = ((PyObject *)__pyx_1);
> Py_DECREF(__pyx_1); __pyx_1 = 0;
>
/* "C:\user\projects\python23\pyrex_test\array\assign.pyx":33 */
__pyx_1 = ((PyObject *)PyArray_ContiguousFromObject(__pyx_v_o,PyArray_DOUBLE,1,1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; goto __pyx_L1;}
Py_INCREF(((PyObject *)__pyx_1));
Py_DECREF(((PyObject *)__pyx_v_array2));
__pyx_v_array2 = (PyArrayObject *)((PyObject *)__pyx_1);
Py_DECREF(__pyx_1); __pyx_1 = 0;
Is this better? The example compiled as VC++ 6.0 without a peep. It is not pretty,
but it works. This is what you get when you have casts that aren't quiet casts. I have
retained automatic conversion of extension types to (PyObject *). But if it is
removed the assignment casting system will accommodate the change.
P.S.
I have the patch to remove some the warnings due to unreferenced variables but
have to tried it since I do not know how it will interact with my changes. I will like to
try it when I am finished with this.
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list