for i in range(3)]
code.putln('PyErr_Fetch(&%s, &%s, &%s);' % (type, value, tb))
code.putln('if (%s) {' % code.unlikely("%s == -1" % (getbuffer % lhs_cname)))
- code.putln('Py_XDECREF(%s); Py_XDECREF(%s); Py_XDECREF(%s);' % (type, value, tb))
+ code.putln('Py_XDECREF(%s); Py_XDECREF(%s); Py_XDECREF(%s);' % (type, value, tb)) # Do not refnanny these!
code.globalstate.use_utility_code(raise_buffer_fallback_code)
code.putln('__Pyx_RaiseBufferFallbackError();')
code.putln('} else {')
# In this case, auxiliary vars should be set up right in initialization to a zero-buffer,
# so it suffices to set the buf field to NULL.
code.putln('if (%s) {' % code.unlikely("%s == -1" % (getbuffer % rhs_cname)))
- code.putln('%s = %s; Py_INCREF(Py_None); %s.buf = NULL;' %
+ code.putln('%s = %s; __Pyx_INCREF(Py_None); %s.buf = NULL;' %
(lhs_cname,
PyrexTypes.typecast(buffer_type, PyrexTypes.py_object_type, "Py_None"),
bufstruct))
ptr = code.funcstate.allocate_temp(self.buffer_type.buffer_ptr_type, manage_ref=False)
rhs_code = rhs.result()
code.putln("%s = %s;" % (ptr, ptrexpr))
+ code.put_gotref("*%s" % ptr)
code.putln("__Pyx_DECREF(*%s); __Pyx_INCREF(%s);" % (
ptr, rhs_code
))
code.putln("*%s %s= %s;" % (ptr, op, rhs_code))
+ code.put_giveref("*%s" % ptr)
code.funcstate.release_temp(ptr)
else:
# Simple case
if self.type.is_pyobject:
rhs.make_owned_reference(code)
code.put_giveref(rhs.py_result())
+ code.put_gotref(select_code)
code.put_decref(select_code, self.ctype())
code.putln(
"%s = %s;" % (
"%s = PySet_New(0); %s" % (
self.result(),
code.error_goto_if_null(self.result(), self.pos)))
+ code.put_gotref(self.py_result())
for arg in self.args:
arg.generate_evaluation_code(code)
code.putln(
# the following line should be removed when this bug is fixed.
code.putln("if (%s == NULL) return 0;" % info)
code.putln("%s->obj = Py_None; __Pyx_INCREF(Py_None);" % info)
+ code.put_giveref("%s->obj" % info) # Do not refnanny object within structs
def getbuffer_error_cleanup(self, code):
info = self.local_scope.arg_entries[1].cname
+ code.put_gotref("%s->obj" % info)
code.putln("__Pyx_DECREF(%s->obj); %s->obj = NULL;" %
(info, info))
def getbuffer_normal_cleanup(self, code):
info = self.local_scope.arg_entries[1].cname
- code.putln("if (%s->obj == Py_None) { __Pyx_DECREF(Py_None); %s->obj = NULL; }" %
- (info, info))
+ code.putln("if (%s->obj == Py_None) {" % info)
+ code.put_gotref("Py_None")
+ code.putln("__Pyx_DECREF(Py_None); %s->obj = NULL;" % info)
+ code.putln("}")
class CFuncDefNode(FuncDefNode):
# C function definition.
code.putln("if (unlikely(!%s)) return %s;" % (
self.starstar_arg.entry.cname, self.error_value()))
self.starstar_arg.entry.xdecref_cleanup = 0
+ code.put_gotref(self.starstar_arg.entry.cname)
+
if self.star_arg:
code.put_incref(Naming.args_cname, py_object_type)
arg.free_temps(code)
code.putln(
code.error_goto_if_null(self.temp_result, self.pos))
+ code.put_gotref(self.temp_result)
code.put_decref_clear(self.temp_result, py_object_type)
def annotate(self, code):
cdef exc.PyObject* type, *value, *tb
if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb)
- (<object>ctx).regref(obj, lineno)
- exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ try:
+ (<object>ctx).regref(obj, lineno)
+ exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ except:
+ Py_XDECREF(<object>type)
+ Py_XDECREF(<object>value)
+ Py_XDECREF(<object>tb)
+ raise
cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, object obj, int lineno):
cdef exc.PyObject* type, *value, *tb
if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb)
- (<object>ctx).delref(obj, lineno)
- exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ try:
+ (<object>ctx).delref(obj, lineno)
+ exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ except:
+ Py_XDECREF(<object>type)
+ Py_XDECREF(<object>value)
+ Py_XDECREF(<object>tb)
+ raise
cdef public void __Pyx_Refnanny_INCREF(void* ctx, object obj, int lineno):
Py_INCREF(obj)
obj = <object>ctx
try:
obj.end()
+ exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ except Exception, e:
+ Py_XDECREF(<object>type)
+ Py_XDECREF(<object>value)
+ Py_XDECREF(<object>tb)
+ raise
finally:
- Py_DECREF(obj)
- exc.PyErr_Restore(<object>type, <object>value, <object>tb)
+ Py_XDECREF(obj)
return 0