Commit 46010e39 authored by Stefan Behnel's avatar Stefan Behnel

avoid useless GIL handling on zero-division checks when not in a nogil section

parent d9f3f244
......@@ -9841,6 +9841,7 @@ class DivNode(NumBinopNode):
self.generate_div_warning_code(code)
def generate_div_warning_code(self, code):
in_nogil = self.in_nogil_context
if not self.type.is_pyobject:
if self.zerodivision_check:
if not self.infix:
......@@ -9848,8 +9849,10 @@ class DivNode(NumBinopNode):
else:
zero_test = "%s == 0" % self.operand2.result()
code.putln("if (unlikely(%s)) {" % zero_test)
if in_nogil:
code.put_ensure_gil()
code.putln('PyErr_SetString(PyExc_ZeroDivisionError, "%s");' % self.zero_division_message())
if in_nogil:
code.put_release_ensured_gil()
code.putln(code.error_goto(self.pos))
code.putln("}")
......@@ -9867,8 +9870,10 @@ class DivNode(NumBinopNode):
self.type.empty_declaration_code(),
minus1_check,
self.operand1.result()))
if in_nogil:
code.put_ensure_gil()
code.putln('PyErr_SetString(PyExc_OverflowError, "value too large to perform division");')
if in_nogil:
code.put_release_ensured_gil()
code.putln(code.error_goto(self.pos))
code.putln("}")
......@@ -9877,6 +9882,7 @@ class DivNode(NumBinopNode):
code.putln("if (unlikely((%s < 0) ^ (%s < 0))) {" % (
self.operand1.result(),
self.operand2.result()))
if in_nogil:
code.put_ensure_gil()
code.putln(code.set_error_info(self.pos, used=True))
code.putln("if (__Pyx_cdivision_warning(%(FILENAME)s, "
......@@ -9884,9 +9890,11 @@ class DivNode(NumBinopNode):
'FILENAME': Naming.filename_cname,
'LINENO': Naming.lineno_cname,
})
if in_nogil:
code.put_release_ensured_gil()
code.put_goto(code.error_label)
code.putln("}")
if in_nogil:
code.put_release_ensured_gil()
code.putln("}")
......
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