mirror of
https://abf.rosa.ru/djam/python-cython.git
synced 2025-02-23 22:02:47 +00:00
73 lines
3 KiB
Diff
73 lines
3 KiB
Diff
https://github.com/cython/cython/commit/2a0d703048db48b31cc7ed84d8fe6aff46c60469
|
|
|
|
diff -ruN a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
|
|
--- a/Cython/Compiler/ExprNodes.py 2023-05-24 17:32:13.000000000 +0900
|
|
+++ b/Cython/Compiler/ExprNodes.py 2023-07-02 12:31:46.317048164 +0900
|
|
@@ -5797,8 +5797,6 @@
|
|
if self.is_temp and self.type.is_reference:
|
|
self.type = PyrexTypes.CFakeReferenceType(self.type.ref_base_type)
|
|
|
|
- # Called in 'nogil' context?
|
|
- self.nogil = env.nogil
|
|
if (self.nogil and
|
|
func_type.exception_check and
|
|
func_type.exception_check != '+'):
|
|
@@ -5920,6 +5918,7 @@
|
|
code.error_goto_if_null(self.result(), self.pos)))
|
|
code.put_gotref(self.py_result())
|
|
elif func_type.is_cfunction:
|
|
+ nogil = not code.funcstate.gil_owned
|
|
if self.has_optional_args:
|
|
actual_nargs = len(self.args)
|
|
expected_nargs = len(func_type.args) - func_type.optional_arg_count
|
|
@@ -5947,7 +5946,7 @@
|
|
if exc_val is not None:
|
|
exc_checks.append("%s == %s" % (self.result(), func_type.return_type.cast_code(exc_val)))
|
|
if exc_check:
|
|
- if self.nogil:
|
|
+ if nogil:
|
|
exc_checks.append("__Pyx_ErrOccurredWithGIL()")
|
|
else:
|
|
exc_checks.append("PyErr_Occurred()")
|
|
@@ -5965,7 +5964,7 @@
|
|
if func_type.exception_check == '+':
|
|
translate_cpp_exception(code, self.pos, '%s%s;' % (lhs, rhs),
|
|
self.result() if self.type.is_pyobject else None,
|
|
- func_type.exception_value, self.nogil)
|
|
+ func_type.exception_value, nogil)
|
|
else:
|
|
if exc_checks:
|
|
goto_error = code.error_goto_if(" && ".join(exc_checks), self.pos)
|
|
diff -ruN a/Cython/Compiler/UtilNodes.py b/Cython/Compiler/UtilNodes.py
|
|
--- a/Cython/Compiler/UtilNodes.py 2023-05-24 17:32:13.000000000 +0900
|
|
+++ b/Cython/Compiler/UtilNodes.py 2023-07-02 12:32:49.046659801 +0900
|
|
@@ -10,7 +10,7 @@
|
|
from . import ExprNodes
|
|
from .Nodes import Node
|
|
from .ExprNodes import AtomicExprNode
|
|
-from .PyrexTypes import c_ptr_type
|
|
+from .PyrexTypes import c_ptr_type, c_bint_type
|
|
|
|
|
|
class TempHandle(object):
|
|
@@ -357,3 +357,20 @@
|
|
def generate_result_code(self, code):
|
|
self.result_ref.result_code = self.result()
|
|
self.body.generate_execution_code(code)
|
|
+
|
|
+
|
|
+class HasGilNode(AtomicExprNode):
|
|
+ """
|
|
+ Simple node that evaluates to 0 or 1 depending on whether we're
|
|
+ in a nogil context
|
|
+ """
|
|
+ type = c_bint_type
|
|
+
|
|
+ def analyse_types(self, env):
|
|
+ return self
|
|
+
|
|
+ def generate_result_code(self, code):
|
|
+ self.has_gil = code.funcstate.gil_owned
|
|
+
|
|
+ def calculate_result_code(self):
|
|
+ return "1" if self.has_gil else "0"
|