Ticket #573 (new defect)
Mismatched c ptr types warning in closures when using cdef classes
| Reported by: | dmalcolm | Owned by: | somebody |
|---|---|---|---|
| Priority: | major | Milestone: | wishlist |
| Component: | Code Generation | Keywords: | |
| Cc: |
Description
Am attempting to compile complex legacy code with cython (for speed) and am running into warnings in the generated .c code
Given the following:
import sys
cdef class Foo(object):
def __init(self, log):
self.log = log
def bar(self):
def inner(a):
return self.log.write(str(a))
self.log = sys.stdout
inner(42)
cython-0.13 and latest cython-devel handles it, but I get compilation warnings from gcc on compiling the generated .c code:
$ cython innerfunction.pyx $ gcc -I/usr/include/python2.6 -lpython2.6 innerfunction.c innerfunction.c: In function ‘__pyx_pf_13innerfunction_3Foo_bar’: innerfunction.c:547: warning: assignment from incompatible pointer type innerfunction.c:575: warning: passing argument 1 of ‘PyObject_SetAttr’ from incompatible pointer type /usr/include/python2.6/object.h:472: note: expected ‘struct PyObject *’ but argument is of type ‘struct __pyx_obj_13innerfunction_Foo *’
The error in question at line 547 is on this line:
__pyx_cur_scope->__pyx_v_self = __pyx_v_self;
where:
struct __pyx_obj_13innerfunction___pyx_scope_struct_bar {
PyObject_HEAD
PyObject *__pyx_v_inner;
struct __pyx_obj_13innerfunction_Foo *__pyx_v_self;
};
and the locals are:
PyObject *__pyx_v_self struct __pyx_obj_13innerfunction___pyx_scope_struct_bar *__pyx_cur_scope;
so the closure struct has a ptr to the underlying struct class, whereas self is a PyObject?*
Similarly, at line 575, we have:
if (PyObject_SetAttr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s__log, __pyx_t_2) < 0)
where the compiler is unhappy with the passing of the subclass*, rather than a PyObject?*
Obviously these are safely cast-able in both cases, but it would be nicer to avoid compilation warnings.
Change History
Note: See
TracTickets for help on using
tickets.
