Commit e5b1dccb authored by Stefan Behnel's avatar Stefan Behnel

factor out builtin access code

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