Commit 8a133cf5 authored by Stefan Behnel's avatar Stefan Behnel

reduce code duplication for DECREF code generation

parent 8c04e6f9
...@@ -1613,10 +1613,7 @@ class CCodeWriter(object): ...@@ -1613,10 +1613,7 @@ class CCodeWriter(object):
self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type)) self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type))
def put_decref(self, cname, type, nanny=True): def put_decref(self, cname, type, nanny=True):
if nanny: self._put_decref(cname, type, nanny, null_check=False, clear=False)
self.putln("__Pyx_DECREF(%s);" % self.as_pyobject(cname, type))
else:
self.putln("Py_DECREF(%s);" % self.as_pyobject(cname, type))
def put_var_gotref(self, entry): def put_var_gotref(self, entry):
if entry.type.is_pyobject: if entry.type.is_pyobject:
...@@ -1638,36 +1635,38 @@ class CCodeWriter(object): ...@@ -1638,36 +1635,38 @@ class CCodeWriter(object):
if entry.type.is_pyobject: if entry.type.is_pyobject:
self.putln("__Pyx_INCREF(%s);" % self.entry_as_pyobject(entry)) self.putln("__Pyx_INCREF(%s);" % self.entry_as_pyobject(entry))
def put_decref_clear(self, cname, type, nanny=True): def put_decref_clear(self, cname, type, nanny=True, clear_before_decref=False):
from PyrexTypes import py_object_type, typecast self._put_decref(cname, type, nanny, null_check=False,
if nanny: clear=True, clear_before_decref=clear_before_decref)
self.putln("__Pyx_DECREF(%s); %s = 0;" % (
typecast(py_object_type, type, cname), cname))
else:
self.putln("Py_DECREF(%s); %s = 0;" % (
typecast(py_object_type, type, cname), cname))
def put_xdecref(self, cname, type, nanny=True, have_gil=True): def put_xdecref(self, cname, type, nanny=True, have_gil=True):
if type.is_memoryviewslice: self._put_decref(cname, type, nanny, null_check=True,
self.put_xdecref_memoryviewslice(cname, have_gil=have_gil) have_gil=have_gil, clear=False)
return
if nanny: def put_xdecref_clear(self, cname, type, nanny=True, clear_before_decref=False):
self.putln("__Pyx_XDECREF(%s);" % self.as_pyobject(cname, type)) self._put_decref(cname, type, nanny, null_check=True,
else: clear=True, clear_before_decref=clear_before_decref)
self.putln("Py_XDECREF(%s);" % self.as_pyobject(cname, type))
def put_xdecref_clear(self, cname, type, nanny=True): def _put_decref(self, cname, type, nanny=True, null_check=False,
have_gil=True, clear=False, clear_before_decref=False):
if type.is_memoryviewslice: if type.is_memoryviewslice:
self.put_xdecref_memoryviewslice(cname) self.put_xdecref_memoryviewslice(cname, have_gil=have_gil)
return return
if nanny: prefix = nanny and '__Pyx' or 'Py'
self.putln("__Pyx_XDECREF(%s); %s = 0;" % ( X = null_check and 'X' or ''
self.as_pyobject(cname, type), cname))
if clear:
if clear_before_decref:
if not nanny:
X = '' # CPython doesn't have a Py_XCLEAR()
self.putln("%s_%sCLEAR(%s);" % (prefix, X, cname))
else:
self.putln("%s_%sDECREF(%s); %s = 0;" % (
prefix, X, self.as_pyobject(cname, type), cname))
else: else:
self.putln("Py_XDECREF(%s); %s = 0;" % ( self.putln("%s_%sDECREF(%s);" % (
self.as_pyobject(cname, type), cname)) prefix, X, self.as_pyobject(cname, type)))
def put_var_decref(self, entry): def put_var_decref(self, entry):
if entry.type.is_pyobject: if entry.type.is_pyobject:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment