summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-05-20 08:57:19 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-05-20 09:09:20 +0200
commit89d2488f7bfd6010b2a5482daede5a26759e1e6d (patch)
tree03d7e71e17882b5f2fdb09e6a777cdf9d67511e7
parentcbe43273439f030acac13bf204b4c1bae66b37bf (diff)
downloadcython-89d2488f7bfd6010b2a5482daede5a26759e1e6d.tar.gz
The names of Cython's internal types (functions, generator, coroutine, etc.) are now prefixed with the shared module name, instead of making them look like homeless builtins.
See https://bugs.python.org/issue20204 See https://github.com/python/cpython/commit/490055a1673b524da2ebe2312f072aba2a826036
-rw-r--r--Cython/Compiler/ModuleNode.py2
-rw-r--r--Cython/Utility/CommonStructures.c4
-rw-r--r--Cython/Utility/Coroutine.c8
-rw-r--r--Cython/Utility/CythonFunction.c8
-rw-r--r--Cython/Utility/ModuleSetupCode.c2
-rw-r--r--tests/run/common_utility_types.srctree2
-rw-r--r--tests/run/fused_def.pyx2
-rw-r--r--tests/run/test_coroutines_pep492.pyx6
8 files changed, 18 insertions, 16 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 4023a1dde..bb4e3ea57 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -711,6 +711,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
from .. import __version__
code.putln('#define CYTHON_ABI "%s"' % __version__.replace('.', '_'))
+ code.putln('#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI')
+ code.putln('#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."')
code.putln('#define CYTHON_HEX_VERSION %s' % build_hex_version(__version__))
code.putln("#define CYTHON_FUTURE_DIVISION %d" % (
Future.division in env.context.future_directives))
diff --git a/Cython/Utility/CommonStructures.c b/Cython/Utility/CommonStructures.c
index e2bf227fd..4b572defb 100644
--- a/Cython/Utility/CommonStructures.c
+++ b/Cython/Utility/CommonStructures.c
@@ -8,7 +8,7 @@ static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyType_Spec *spec, PyObject *
/////////////// FetchCommonType ///////////////
static PyObject *__Pyx_FetchSharedCythonABIModule(void) {
- PyObject *abi_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+ PyObject *abi_module = PyImport_AddModule((char*) __PYX_ABI_MODULE_NAME);
if (!abi_module) return NULL;
Py_INCREF(abi_module);
return abi_module;
@@ -126,7 +126,7 @@ static void* __Pyx_FetchCommonPointer(void* pointer, const char* name) {
PyObject* capsule = NULL;
void* value = NULL;
- abi_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
+ abi_module = PyImport_AddModule((char*) __PYX_ABI_MODULE_NAME);
if (!abi_module) return NULL;
Py_INCREF(abi_module);
diff --git a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c
index 8151fec34..a69a40299 100644
--- a/Cython/Utility/Coroutine.c
+++ b/Cython/Utility/Coroutine.c
@@ -1468,7 +1468,7 @@ static PyMethodDef __pyx_CoroutineAwait_methods[] = {
static PyTypeObject __pyx_CoroutineAwaitType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "coroutine_wrapper", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", /*tp_name*/
sizeof(__pyx_CoroutineAwaitObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __Pyx_CoroutineAwait_dealloc,/*tp_dealloc*/
@@ -1616,7 +1616,7 @@ static __Pyx_PyAsyncMethodsStruct __pyx_Coroutine_as_async = {
static PyTypeObject __pyx_CoroutineType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "coroutine", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "coroutine", /*tp_name*/
sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
@@ -1732,7 +1732,7 @@ static int __pyx_IterableCoroutine_init(void);/*proto*/
static PyTypeObject __pyx_IterableCoroutineType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "iterable_coroutine", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "iterable_coroutine", /*tp_name*/
sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
@@ -1851,7 +1851,7 @@ static PyGetSetDef __pyx_Generator_getsets[] = {
static PyTypeObject __pyx_GeneratorType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "generator", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "generator", /*tp_name*/
sizeof(__pyx_CoroutineObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __Pyx_Coroutine_dealloc,/*tp_dealloc*/
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index bd096bf93..c9098d953 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -811,7 +811,7 @@ static PyType_Slot __pyx_CyFunctionType_slots[] = {
};
static PyType_Spec __pyx_CyFunctionType_spec = {
- "cython_function_or_method",
+ __PYX_TYPE_MODULE_PREFIX "cython_function_or_method",
sizeof(__pyx_CyFunctionObject),
0,
// TODO: Support _Py_TPFLAGS_HAVE_VECTORCALL and _Py_TPFLAGS_HAVE_VECTORCALL
@@ -821,7 +821,7 @@ static PyType_Spec __pyx_CyFunctionType_spec = {
#else
static PyTypeObject __pyx_CyFunctionType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "cython_function_or_method", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", /*tp_name*/
sizeof(__pyx_CyFunctionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/
@@ -1335,7 +1335,7 @@ static PyType_Slot __pyx_FusedFunctionType_slots[] = {
};
static PyType_Spec __pyx_FusedFunctionType_spec = {
- "fused_cython_function",
+ __PYX_TYPE_MODULE_PREFIX "fused_cython_function",
sizeof(__pyx_FusedFunctionObject),
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
@@ -1352,7 +1352,7 @@ static PyMappingMethods __pyx_FusedFunction_mapping_methods = {
static PyTypeObject __pyx_FusedFunctionType_type = {
PyVarObject_HEAD_INIT(0, 0)
- "fused_cython_function", /*tp_name*/
+ __PYX_TYPE_MODULE_PREFIX "fused_cython_function", /*tp_name*/
sizeof(__pyx_FusedFunctionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor) __pyx_FusedFunction_dealloc, /*tp_dealloc*/
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index be629c066..4f7824862 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -1648,7 +1648,7 @@ static void __Pyx_FastGilFuncInit(void);
#if CYTHON_FAST_GIL
-#define __Pyx_FastGIL_ABI_module "_cython_" CYTHON_ABI
+#define __Pyx_FastGIL_ABI_module __PYX_ABI_MODULE_NAME
#define __Pyx_FastGIL_PyCapsuleName "FastGilFuncs"
#define __Pyx_FastGIL_PyCapsule \
__Pyx_FastGIL_ABI_module "." __Pyx_FastGIL_PyCapsuleName
diff --git a/tests/run/common_utility_types.srctree b/tests/run/common_utility_types.srctree
index 1f3d2aea3..35daad505 100644
--- a/tests/run/common_utility_types.srctree
+++ b/tests/run/common_utility_types.srctree
@@ -31,7 +31,7 @@ print("importing...")
import a, b
print(type(a.funcA))
-assert type(a.funcA).__name__ == 'cython_function_or_method'
+assert type(a.funcA).__name__.endswith('cython_function_or_method')
assert type(a.funcA) is type(b.funcB)
assert a.funcA.func_globals is a.__dict__
diff --git a/tests/run/fused_def.pyx b/tests/run/fused_def.pyx
index efd578298..0f5ec1bbd 100644
--- a/tests/run/fused_def.pyx
+++ b/tests/run/fused_def.pyx
@@ -143,7 +143,7 @@ def run_cyfunction_check():
fused_cython_function
1
"""
- print(type(opt_func).__name__)
+ print(type(opt_func).__name__.rsplit('.', 1)[-1])
print(__Pyx_CyFunction_Check(opt_func)) # should be True
def test_opt_func():
diff --git a/tests/run/test_coroutines_pep492.pyx b/tests/run/test_coroutines_pep492.pyx
index b274160e8..a12307174 100644
--- a/tests/run/test_coroutines_pep492.pyx
+++ b/tests/run/test_coroutines_pep492.pyx
@@ -109,7 +109,7 @@ class AsyncYield(object):
def run_async(coro):
#assert coro.__class__ is types.GeneratorType
- assert coro.__class__.__name__ in ('coroutine', '_GeneratorWrapper'), coro.__class__.__name__
+ assert coro.__class__.__name__.rsplit('.', 1)[-1] in ('coroutine', '_GeneratorWrapper'), coro.__class__.__name__
buffer = []
result = None
@@ -123,7 +123,7 @@ def run_async(coro):
def run_async__await__(coro):
- assert coro.__class__.__name__ in ('coroutine', '_GeneratorWrapper'), coro.__class__.__name__
+ assert coro.__class__.__name__.rsplit('.', 1)[-1] in ('coroutine', '_GeneratorWrapper'), coro.__class__.__name__
aw = coro.__await__()
buffer = []
result = None
@@ -895,7 +895,7 @@ class CoroutineTest(unittest.TestCase):
raise StopIteration
with silence_coro_gc():
- self.assertRegex(repr(foo()), '^<coroutine object.* at 0x.*>$')
+ self.assertRegex(repr(foo()), '^<[^\s]*coroutine object.* at 0x.*>$')
def test_func_4(self):
async def foo():