Commit e5b1dccb authored by Stefan Behnel's avatar Stefan Behnel

factor out builtin access code

parent afba831b
......@@ -1107,11 +1107,10 @@ class GlobalState(object):
def put_cached_builtin_init(self, pos, name, cname):
w = self.parts['cached_builtins']
interned_cname = self.get_interned_identifier(name).cname
from ExprNodes import get_name_interned_utility_code
self.use_utility_code(get_name_interned_utility_code)
w.putln('%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
self.use_utility_code(
UtilityCode.load_cached("GetBuiltinName", "ObjectHandling.c"))
w.putln('%s = __Pyx_GetBuiltinName(%s); if (!%s) %s' % (
cname,
Naming.builtins_cname,
interned_cname,
cname,
w.error_goto(pos)))
......
......@@ -1767,11 +1767,11 @@ class NameNode(AtomicExprNode):
elif entry.is_builtin:
assert entry.type.is_pyobject, "Python global or builtin not a Python object"
interned_cname = code.intern_identifier(self.entry.name)
code.globalstate.use_utility_code(get_name_interned_utility_code)
code.globalstate.use_utility_code(
UtilityCode.load_cached("GetBuiltinName", "ObjectHandling.c"))
code.putln(
'%s = __Pyx_GetName(%s, %s); %s' % (
'%s = __Pyx_GetBuiltinName(%s); %s' % (
self.result(),
Naming.builtins_cname,
interned_cname,
code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result())
......@@ -10425,10 +10425,6 @@ class DocstringRefNode(ExprNode):
#
#------------------------------------------------------------------------------------
get_name_interned_utility_code = UtilityCode.load_cached("GetGlobalName", "ObjectHandling.c")
#------------------------------------------------------------------------------------
pyerr_occurred_withgil_utility_code= UtilityCode(
proto = """
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
......
......@@ -578,23 +578,17 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
}
/////////////// GetGlobalName.proto ///////////////
/////////////// GetBuiltinName.proto ///////////////
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/
/////////////// GetGlobalName ///////////////
/////////////// GetBuiltinName ///////////////
//@requires: PyObjectGetAttrStr
//@substitute: naming
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
PyObject *result;
result = __Pyx_PyObject_GetAttrStr(dict, name);
if (!result) {
if (dict != $builtins_cname) {
PyErr_Clear();
result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
}
if (!result) {
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
PyObject* result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
if (unlikely(!result)) {
PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
"name '%U' is not defined", name);
......@@ -602,7 +596,6 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
"name '%s' is not defined", PyString_AS_STRING(name));
#endif
}
}
return result;
}
......@@ -611,7 +604,7 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/
/////////////// GetModuleGlobalName ///////////////
//@requires: PyObjectGetAttrStr
//@requires: GetBuiltinName
//@substitute: naming
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
......@@ -626,15 +619,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
if (!result) {
PyErr_Clear();
#endif
result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
if (unlikely(!result)) {
PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
"name '%U' is not defined", name);
#else
"name '%s' is not defined", PyString_AS_STRING(name));
#endif
}
result = __Pyx_GetBuiltinName(name);
}
return result;
}
......
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