Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
0a2ecd7f
Commit
0a2ecd7f
authored
Nov 18, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more metaclass cleanups, merged some redundant code, Py2.3 fix
parent
799c6e78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
54 deletions
+51
-54
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+51
-54
No files found.
Cython/Compiler/ExprNodes.py
View file @
0a2ecd7f
...
@@ -7439,6 +7439,38 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
...
@@ -7439,6 +7439,38 @@ static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
find_py2_metaclass_utility_code
=
UtilityCode
(
proto
=
'''
static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases); /*proto*/
'''
,
impl
=
'''
static PyObject *__Pyx_FindPy2Metaclass(PyObject *bases) {
PyObject *metaclass;
/* Default metaclass */
#if PY_MAJOR_VERSION < 3
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = PyObject_GetAttrString(base, "__class__");
if (!metaclass) {
PyErr_Clear();
metaclass = (PyObject*) Py_TYPE(base);
}
} else {
metaclass = (PyObject *) &PyClass_Type;
}
#else
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = (PyObject*) Py_TYPE(base);
} else {
metaclass = (PyObject *) &PyType_Type;
}
#endif
Py_INCREF(metaclass);
return metaclass;
}
'''
)
create_class_utility_code
=
UtilityCode
(
create_class_utility_code
=
UtilityCode
(
proto
=
"""
proto
=
"""
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
...
@@ -7447,42 +7479,25 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na
...
@@ -7447,42 +7479,25 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na
impl
=
"""
impl
=
"""
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
PyObject *modname) {
PyObject *modname) {
PyObject *result
= NULL
;
PyObject *result;
PyObject *metaclass
= NULL
;
PyObject *metaclass;
if (PyDict_SetItemString(dict, "__module__", modname) < 0)
if (PyDict_SetItemString(dict, "__module__", modname) < 0)
return NULL;
return NULL;
/* Python2 __metaclass__ */
/* Python2 __metaclass__ */
metaclass = PyDict_GetItemString(dict, "__metaclass__");
metaclass = PyDict_GetItemString(dict, "__metaclass__");
if (metaclass) {
if (!metaclass) {
Py_INCREF(metaclass);
/* Default metaclass */
} else {
#if PY_MAJOR_VERSION < 3
metaclass = __Pyx_FindPy2Metaclass(bases);
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = PyObject_GetAttrString(base, "__class__");
if (!metaclass) {
PyErr_Clear();
metaclass = (PyObject *)base->ob_type;
}
} else
metaclass = (PyObject *) &PyClass_Type;
#else
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = (PyObject *)base->ob_type;
} else
metaclass = (PyObject *) &PyType_Type;
#endif
}
}
Py_INCREF(metaclass);
result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
Py_DECREF(metaclass);
Py_DECREF(metaclass);
return result;
return result;
}
}
"""
)
"""
,
requires
=
[
find_py2_metaclass_utility_code
])
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
...
@@ -7495,9 +7510,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
...
@@ -7495,9 +7510,7 @@ static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObj
impl
=
"""
impl
=
"""
PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw)
PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw)
{
{
PyObject *metaclass = NULL;
PyObject *metaclass = PyDict_GetItemString(mkw, "metaclass");
metaclass = PyDict_GetItemString(mkw, "metaclass");
if (metaclass) {
if (metaclass) {
Py_INCREF(metaclass);
Py_INCREF(metaclass);
if (PyDict_DelItemString(mkw, "metaclass") < 0) {
if (PyDict_DelItemString(mkw, "metaclass") < 0) {
...
@@ -7506,28 +7519,7 @@ PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw)
...
@@ -7506,28 +7519,7 @@ PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw)
}
}
return metaclass;
return metaclass;
}
}
/* Default metaclass */
return __Pyx_FindPy2Metaclass(bases);
#if PY_MAJOR_VERSION < 3
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = PyObject_GetAttrString(base, "__class__");
if (metaclass == NULL) {
PyErr_Clear();
metaclass = (PyObject *)base->ob_type;
}
} else {
metaclass = (PyObject *) &PyClass_Type;
}
#else
if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
PyObject *base = PyTuple_GET_ITEM(bases, 0);
metaclass = (PyObject *)base->ob_type;
} else {
metaclass = (PyObject *) &PyType_Type;
}
#endif
Py_INCREF(metaclass);
return metaclass;
}
}
PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *mkw, PyObject *modname, PyObject *doc)
PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *mkw, PyObject *modname, PyObject *doc)
...
@@ -7604,16 +7596,21 @@ PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObje
...
@@ -7604,16 +7596,21 @@ PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObje
PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, PyObject *mkw)
PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, PyObject *mkw)
{
{
PyObject *result;
PyObject *result;
PyObject *margs;
PyObject *margs = PyTuple_New(3);
margs = PyTuple_Pack(3, name, bases, dict, NULL);
if (!margs)
if (!margs)
return NULL;
return NULL;
Py_INCREF(name);
Py_INCREF(bases);
Py_INCREF(dict);
PyTuple_SET_ITEM(margs, 0, name);
PyTuple_SET_ITEM(margs, 1, bases);
PyTuple_SET_ITEM(margs, 2, dict);
result = PyEval_CallObjectWithKeywords(metaclass, margs, mkw);
result = PyEval_CallObjectWithKeywords(metaclass, margs, mkw);
Py_DECREF(margs);
Py_DECREF(margs);
return result;
return result;
}
}
"""
)
"""
,
requires
=
[
find_py2_metaclass_utility_code
])
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment