aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/cython/Cython
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-07-22 00:59:02 +0300
committershadchin <shadchin@yandex-team.com>2023-07-22 00:59:02 +0300
commit7ecf6c16ab762d4ed40a90ea329eebeb1b8cbca0 (patch)
tree13f625aacca47c9885d8fa31ba97151706ef63bd /contrib/tools/cython/Cython
parent91a8278c558cb2002069ca54215c83568ba6826e (diff)
downloadydb-7ecf6c16ab762d4ed40a90ea329eebeb1b8cbca0.tar.gz
Update Cython to 0.29.36
Diffstat (limited to 'contrib/tools/cython/Cython')
-rw-r--r--contrib/tools/cython/Cython/Compiler/Builtin.py5
-rw-r--r--contrib/tools/cython/Cython/Compiler/ModuleNode.py4
-rw-r--r--contrib/tools/cython/Cython/Compiler/Nodes.py4
-rw-r--r--contrib/tools/cython/Cython/Shadow.py2
-rw-r--r--contrib/tools/cython/Cython/Tempita/_tempita.py125
-rw-r--r--contrib/tools/cython/Cython/Utility/AsyncGen.c11
-rw-r--r--contrib/tools/cython/Cython/Utility/Exceptions.c26
-rw-r--r--contrib/tools/cython/Cython/Utility/ModuleSetupCode.c12
-rw-r--r--contrib/tools/cython/Cython/Utility/ObjectHandling.c4
9 files changed, 62 insertions, 131 deletions
diff --git a/contrib/tools/cython/Cython/Compiler/Builtin.py b/contrib/tools/cython/Cython/Compiler/Builtin.py
index e0d203ae02..c3e202e001 100644
--- a/contrib/tools/cython/Cython/Compiler/Builtin.py
+++ b/contrib/tools/cython/Cython/Compiler/Builtin.py
@@ -417,9 +417,10 @@ def init_builtins():
init_builtin_types()
init_builtin_funcs()
- builtin_scope.declare_var(
+ entry = builtin_scope.declare_var(
'__debug__', PyrexTypes.c_const_type(PyrexTypes.c_bint_type),
- pos=None, cname='(!Py_OptimizeFlag)', is_cdef=True)
+ pos=None, cname='__pyx_assertions_enabled()', is_cdef=True)
+ entry.utility_code = UtilityCode.load_cached("AssertionsEnabled", "Exceptions.c")
global list_type, tuple_type, dict_type, set_type, frozenset_type
global bytes_type, str_type, unicode_type, basestring_type, slice_type
diff --git a/contrib/tools/cython/Cython/Compiler/ModuleNode.py b/contrib/tools/cython/Cython/Compiler/ModuleNode.py
index 1e392a4e3a..fd998d419f 100644
--- a/contrib/tools/cython/Cython/Compiler/ModuleNode.py
+++ b/contrib/tools/cython/Cython/Compiler/ModuleNode.py
@@ -1469,10 +1469,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# in Py3.4+, call tp_finalize() as early as possible
code.putln("#if CYTHON_USE_TP_FINALIZE")
if needs_gc:
- finalised_check = '!_PyGC_FINALIZED(o)'
+ finalised_check = '!__Pyx_PyObject_GC_IsFinalized(o)'
else:
finalised_check = (
- '(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')
+ '(!PyType_IS_GC(Py_TYPE(o)) || !__Pyx_PyObject_GC_IsFinalized(o))')
code.putln(
"if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)"
" && Py_TYPE(o)->tp_finalize) && %s) {" % finalised_check)
diff --git a/contrib/tools/cython/Cython/Compiler/Nodes.py b/contrib/tools/cython/Cython/Compiler/Nodes.py
index f57ddf3dd3..db5d657829 100644
--- a/contrib/tools/cython/Cython/Compiler/Nodes.py
+++ b/contrib/tools/cython/Cython/Compiler/Nodes.py
@@ -6215,8 +6215,10 @@ class AssertStatNode(StatNode):
gil_message = "Raising exception"
def generate_execution_code(self, code):
+ code.globalstate.use_utility_code(
+ UtilityCode.load_cached("AssertionsEnabled", "Exceptions.c"))
code.putln("#ifndef CYTHON_WITHOUT_ASSERTIONS")
- code.putln("if (unlikely(!Py_OptimizeFlag)) {")
+ code.putln("if (unlikely(__pyx_assertions_enabled())) {")
code.mark_pos(self.pos)
self.cond.generate_evaluation_code(code)
code.putln(
diff --git a/contrib/tools/cython/Cython/Shadow.py b/contrib/tools/cython/Cython/Shadow.py
index 6c2b44ea37..a3991f0494 100644
--- a/contrib/tools/cython/Cython/Shadow.py
+++ b/contrib/tools/cython/Cython/Shadow.py
@@ -1,7 +1,7 @@
# cython.* namespace for pure mode.
from __future__ import absolute_import
-__version__ = "0.29.35"
+__version__ = "0.29.36"
try:
from __builtin__ import basestring
diff --git a/contrib/tools/cython/Cython/Tempita/_tempita.py b/contrib/tools/cython/Cython/Tempita/_tempita.py
index 587f6e4841..2af7d258ef 100644
--- a/contrib/tools/cython/Cython/Tempita/_tempita.py
+++ b/contrib/tools/cython/Cython/Tempita/_tempita.py
@@ -33,17 +33,6 @@ from __future__ import absolute_import
import re
import sys
-try:
- import cgi
-except ImportError:
- pass
-try:
- from urllib import quote as url_quote
-except ImportError: # Py3
- try:
- from urllib.parse import quote as url_quote
- except ImportError:
- pass
import os
import tokenize
from io import StringIO
@@ -51,8 +40,7 @@ from io import StringIO
from ._looper import looper
from .compat3 import bytes, unicode_, basestring_, next, is_unicode, coerce_text
-__all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate',
- 'sub_html', 'html', 'bunch']
+__all__ = ['TemplateError', 'Template', 'sub', 'bunch']
in_re = re.compile(r'\s+in\s+')
var_re = re.compile(r'^[a-z_][a-z0-9_]*$', re.I)
@@ -150,9 +138,8 @@ class Template(object):
def from_filename(cls, filename, namespace=None, encoding=None,
default_inherit=None, get_template=get_file_template):
- f = open(filename, 'rb')
- c = f.read()
- f.close()
+ with open(filename, 'rb') as f:
+ c = f.read()
if encoding:
c = c.decode(encoding)
return cls(content=c, name=filename, namespace=namespace,
@@ -417,91 +404,6 @@ class bunch(dict):
self.__class__.__name__,
' '.join(['%s=%r' % (k, v) for k, v in sorted(self.items())]))
-############################################################
-## HTML Templating
-############################################################
-
-
-class html(object):
-
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return self.value
-
- def __html__(self):
- return self.value
-
- def __repr__(self):
- return '<%s %r>' % (
- self.__class__.__name__, self.value)
-
-
-def html_quote(value, force=True):
- if not force and hasattr(value, '__html__'):
- return value.__html__()
- if value is None:
- return ''
- if not isinstance(value, basestring_):
- value = coerce_text(value)
- if sys.version >= "3" and isinstance(value, bytes):
- value = cgi.escape(value.decode('latin1'), 1)
- value = value.encode('latin1')
- else:
- value = cgi.escape(value, 1)
- if sys.version < "3":
- if is_unicode(value):
- value = value.encode('ascii', 'xmlcharrefreplace')
- return value
-
-
-def url(v):
- v = coerce_text(v)
- if is_unicode(v):
- v = v.encode('utf8')
- return url_quote(v)
-
-
-def attr(**kw):
- parts = []
- for name, value in sorted(kw.items()):
- if value is None:
- continue
- if name.endswith('_'):
- name = name[:-1]
- parts.append('%s="%s"' % (html_quote(name), html_quote(value)))
- return html(' '.join(parts))
-
-
-class HTMLTemplate(Template):
-
- default_namespace = Template.default_namespace.copy()
- default_namespace.update(dict(
- html=html,
- attr=attr,
- url=url,
- html_quote=html_quote,
- ))
-
- def _repr(self, value, pos):
- if hasattr(value, '__html__'):
- value = value.__html__()
- quote = False
- else:
- quote = True
- plain = Template._repr(self, value, pos)
- if quote:
- return html_quote(plain)
- else:
- return plain
-
-
-def sub_html(content, **kw):
- name = kw.get('__name')
- tmpl = HTMLTemplate(content, name=name)
- return tmpl.substitute(kw)
-
class TemplateDef(object):
def __init__(self, template, func_name, func_signature,
@@ -1137,11 +1039,6 @@ def fill_command(args=None):
metavar="FILENAME",
help="File to write output to (default stdout)")
parser.add_option(
- '--html',
- dest='use_html',
- action='store_true',
- help="Use HTML style filling (including automatic HTML quoting)")
- parser.add_option(
'--env',
dest='use_env',
action='store_true',
@@ -1168,19 +1065,13 @@ def fill_command(args=None):
template_content = sys.stdin.read()
template_name = '<stdin>'
else:
- f = open(template_name, 'rb')
- template_content = f.read()
- f.close()
- if options.use_html:
- TemplateClass = HTMLTemplate
- else:
- TemplateClass = Template
- template = TemplateClass(template_content, name=template_name)
+ with open(template_name, 'rb') as f:
+ template_content = f.read()
+ template = Template(template_content, name=template_name)
result = template.substitute(vars)
if options.output:
- f = open(options.output, 'wb')
- f.write(result)
- f.close()
+ with open(options.output, 'wb') as f:
+ f.write(result)
else:
sys.stdout.write(result)
diff --git a/contrib/tools/cython/Cython/Utility/AsyncGen.c b/contrib/tools/cython/Cython/Utility/AsyncGen.c
index dd4bf37280..e55b786578 100644
--- a/contrib/tools/cython/Cython/Utility/AsyncGen.c
+++ b/contrib/tools/cython/Cython/Utility/AsyncGen.c
@@ -202,7 +202,9 @@ __Pyx_async_gen_repr(__pyx_CoroutineObject *o)
static int
__Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o)
{
+#if !CYTHON_COMPILING_IN_PYPY
PyThreadState *tstate;
+#endif
PyObject *finalizer;
PyObject *firstiter;
@@ -212,15 +214,22 @@ __Pyx_async_gen_init_hooks(__pyx_PyAsyncGenObject *o)
o->ag_hooks_inited = 1;
+#if CYTHON_COMPILING_IN_PYPY
+ finalizer = _PyEval_GetAsyncGenFinalizer();
+#else
tstate = __Pyx_PyThreadState_Current;
-
finalizer = tstate->async_gen_finalizer;
+#endif
if (finalizer) {
Py_INCREF(finalizer);
o->ag_finalizer = finalizer;
}
+#if CYTHON_COMPILING_IN_PYPY
+ firstiter = _PyEval_GetAsyncGenFirstiter();
+#else
firstiter = tstate->async_gen_firstiter;
+#endif
if (firstiter) {
PyObject *res;
#if CYTHON_UNPACK_METHODS
diff --git a/contrib/tools/cython/Cython/Utility/Exceptions.c b/contrib/tools/cython/Cython/Utility/Exceptions.c
index 87d3a5cddb..8117b92d4b 100644
--- a/contrib/tools/cython/Cython/Utility/Exceptions.c
+++ b/contrib/tools/cython/Cython/Utility/Exceptions.c
@@ -6,6 +6,32 @@
// __Pyx_GetException()
+/////////////// AssertionsEnabled.init ///////////////
+__Pyx_init_assertions_enabled();
+
+/////////////// AssertionsEnabled.proto ///////////////
+
+#define __Pyx_init_assertions_enabled()
+
+#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
+ #define __pyx_assertions_enabled() (1)
+#elif PY_VERSION_HEX < 0x03080000 || CYTHON_COMPILING_IN_PYPY || defined(Py_LIMITED_API)
+ #define __pyx_assertions_enabled() (!Py_OptimizeFlag)
+#elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030900A6
+ // Py3.8+ has PyConfig from PEP 587, but only Py3.9 added read access to it.
+ // Py_OptimizeFlag is deprecated in Py3.12+
+ static int __pyx_assertions_enabled_flag;
+ #define __pyx_assertions_enabled() (__pyx_assertions_enabled_flag)
+
+ #undef __Pyx_init_assertions_enabled
+ static void __Pyx_init_assertions_enabled(void) {
+ __pyx_assertions_enabled_flag = ! _PyInterpreterState_GetConfig(__Pyx_PyThreadState_Current->interp)->optimization_level;
+ }
+#else
+ #define __pyx_assertions_enabled() (!Py_OptimizeFlag)
+#endif
+
+
/////////////// PyThreadStateGet.proto ///////////////
//@substitute: naming
diff --git a/contrib/tools/cython/Cython/Utility/ModuleSetupCode.c b/contrib/tools/cython/Cython/Utility/ModuleSetupCode.c
index 31a8fec231..8503679412 100644
--- a/contrib/tools/cython/Cython/Utility/ModuleSetupCode.c
+++ b/contrib/tools/cython/Cython/Utility/ModuleSetupCode.c
@@ -93,7 +93,7 @@
#define CYTHON_PEP489_MULTI_PHASE_INIT 1
#endif
#undef CYTHON_USE_TP_FINALIZE
- #define CYTHON_USE_TP_FINALIZE 0
+ #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00)
#undef CYTHON_USE_DICT_VERSIONS
#define CYTHON_USE_DICT_VERSIONS 0
#undef CYTHON_USE_EXC_INFO_STACK
@@ -455,10 +455,6 @@ class __Pyx_FakeReference {
/////////////// PythonCompatibility ///////////////
-#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
- #define Py_OptimizeFlag 0
-#endif
-
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
@@ -547,6 +543,12 @@ class __Pyx_FakeReference {
#define __Pyx_DefaultClassType PyType_Type
#endif
+#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY
+ #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
+#else
+ #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o)
+#endif
+
#ifndef Py_TPFLAGS_CHECKTYPES
#define Py_TPFLAGS_CHECKTYPES 0
#endif
diff --git a/contrib/tools/cython/Cython/Utility/ObjectHandling.c b/contrib/tools/cython/Cython/Utility/ObjectHandling.c
index 02574e46ec..5c4d9e1608 100644
--- a/contrib/tools/cython/Cython/Utility/ObjectHandling.c
+++ b/contrib/tools/cython/Cython/Utility/ObjectHandling.c
@@ -194,11 +194,11 @@ static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject*
// We always do a quick slot check because calling PyIter_Check() is so wasteful.
iternextfunc iternext = Py_TYPE(iterator)->tp_iternext;
if (likely(iternext)) {
-#if CYTHON_USE_TYPE_SLOTS
+#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
next = iternext(iterator);
if (likely(next))
return next;
- #if PY_VERSION_HEX >= 0x02070000
+ #if PY_VERSION_HEX >= 0x02070000 && CYTHON_COMPILING_IN_CPYTHON
if (unlikely(iternext == &_PyObject_NextNotImplemented))
return NULL;
#endif