Commit d1e5d1f6 authored by Stefan Behnel's avatar Stefan Behnel

replace lots of dynamically created string constants in utility code by static Python constants

parent d1e3aee9
......@@ -15,7 +15,7 @@ static PyObject* __Pyx_Globals(void) {
Py_ssize_t i;
//PyObject *d;
PyObject *names = NULL;
PyObject *globals = PyObject_GetAttrString($module_cname, "__dict__");
PyObject *globals = PyObject_GetAttr($module_cname, PYIDENT("__dict__"));
if (!globals) {
PyErr_SetString(PyExc_TypeError,
"current module must have __dict__ attribute");
......@@ -111,8 +111,8 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
locals = globals;
}
if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
if (PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()) < 0)
if (PyDict_GetItem(globals, PYIDENT("__builtins__")) == NULL) {
if (PyDict_SetItem(globals, PYIDENT("__builtins__"), PyEval_GetBuiltins()) < 0)
goto bad;
}
......
......@@ -701,7 +701,7 @@ static PyObject *
_obj_to_str(PyObject *obj)
{
if (PyType_Check(obj))
return PyObject_GetAttrString(obj, "__name__");
return PyObject_GetAttr(obj, PYIDENT("__name__"));
else
return PyObject_Str(obj);
}
......
......@@ -123,7 +123,7 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
Py_DECREF(ev);
#else
{
PyObject* args = PyObject_GetAttrString(ev, "args");
PyObject* args = PyObject_GetAttr(ev, PYIDENT("args"));
Py_DECREF(ev);
if (likely(args)) {
value = PyObject_GetItem(args, 0);
......@@ -310,7 +310,7 @@ static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
} else {
PyObject *meth;
gen->is_running = 1;
meth = PyObject_GetAttrString(yf, "close");
meth = PyObject_GetAttr(yf, PYIDENT("close"));
if (unlikely(!meth)) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_WriteUnraisable(yf);
......@@ -402,7 +402,7 @@ static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
if (__Pyx_Generator_CheckExact(yf)) {
ret = __Pyx_Generator_Throw(yf, args);
} else {
PyObject *meth = PyObject_GetAttrString(yf, "throw");
PyObject *meth = PyObject_GetAttr(yf, PYIDENT("throw"));
if (unlikely(!meth)) {
Py_DECREF(yf);
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
......
......@@ -400,7 +400,7 @@ static PyObject *__Pyx_FindPy2Metaclass(PyObject *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, (char *)"__class__");
metaclass = PyObject_GetAttr(base, PYIDENT("__class__"));
if (!metaclass) {
PyErr_Clear();
metaclass = (PyObject*) Py_TYPE(base);
......@@ -428,10 +428,10 @@ static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw); /*proto*
//@requires: FindPy2Metaclass
static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw) {
PyObject *metaclass = PyDict_GetItemString(mkw, "metaclass");
PyObject *metaclass = PyDict_GetItem(mkw, PYIDENT("metaclass"));
if (metaclass) {
Py_INCREF(metaclass);
if (PyDict_DelItemString(mkw, "metaclass") < 0) {
if (PyDict_DelItem(mkw, PYIDENT("metaclass")) < 0) {
Py_DECREF(metaclass);
return NULL;
}
......@@ -453,13 +453,13 @@ static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *na
PyObject *result;
PyObject *metaclass;
if (PyDict_SetItemString(dict, "__module__", modname) < 0)
if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0)
return NULL;
if (PyDict_SetItemString(dict, "__qualname__", qualname) < 0)
if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0)
return NULL;
/* Python2 __metaclass__ */
metaclass = PyDict_GetItemString(dict, "__metaclass__");
metaclass = PyDict_GetItem(dict, PYIDENT("__metaclass__"));
if (metaclass) {
Py_INCREF(metaclass);
} else {
......@@ -484,7 +484,7 @@ static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases,
PyObject *ns;
PyObject *str;
prep = PyObject_GetAttrString(metaclass, (char *)"__prepare__");
prep = PyObject_GetAttr(metaclass, PYIDENT("__prepare__"));
if (!prep) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return NULL;
......
......@@ -39,6 +39,10 @@ static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
/////////////// pop.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L); /*proto*/
/////////////// pop ///////////////
static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000
if (likely(PyList_CheckExact(L))
......@@ -53,12 +57,16 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Pop(PyObject* L) {
}
#endif
#endif
return PyObject_CallMethod(L, (char*)"pop", NULL);
return PyObject_CallMethodObjArgs(L, PYIDENT("pop"), NULL);
}
/////////////// pop_index.proto ///////////////
static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix); /*proto*/
/////////////// pop_index ///////////////
static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
PyObject *r, *m, *t, *py_ix;
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02040000
......@@ -79,7 +87,7 @@ static PyObject* __Pyx_PyObject_PopIndex(PyObject* L, Py_ssize_t ix) {
}
#endif
py_ix = t = NULL;
m = __Pyx_GetAttrString(L, "pop");
m = PyObject_GetAttr(L, PYIDENT("pop"));
if (!m) goto bad;
py_ix = PyInt_FromSsize_t(ix);
if (!py_ix) goto bad;
......@@ -258,6 +266,10 @@ static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t i
/////////////// dict_getitem_default.proto ///////////////
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value); /*proto*/
/////////////// dict_getitem_default ///////////////
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
PyObject* value;
#if PY_MAJOR_VERSION >= 3
......@@ -278,7 +290,7 @@ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObjec
Py_INCREF(value);
} else {
PyObject *m;
m = __Pyx_GetAttrString(d, "get");
m = PyObject_GetAttr(d, PYIDENT("get"));
if (!m) return NULL;
value = PyObject_CallFunctionObjArgs(m, key,
(default_value == Py_None) ? NULL : default_value, NULL);
......@@ -291,6 +303,10 @@ static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObjec
/////////////// dict_setdefault.proto ///////////////
static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value); /*proto*/
/////////////// dict_setdefault ///////////////
static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value) {
PyObject* value;
#if PY_MAJOR_VERSION >= 3
......@@ -315,7 +331,7 @@ static PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *d
Py_INCREF(value);
} else {
PyObject *m;
m = __Pyx_GetAttrString(d, "setdefault");
m = PyObject_GetAttr(d, PYIDENT("setdefault"));
if (!m) return NULL;
value = PyObject_CallFunctionObjArgs(m, key, default_value, NULL);
Py_DECREF(m);
......
......@@ -72,7 +72,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
PyObject* result = 0;
PyObject* end_string;
if (unlikely(!$print_function)) {
$print_function = __Pyx_GetAttrString($builtins_cname, "print");
$print_function = PyObject_GetAttr($builtins_cname, PYIDENT("print"));
if (!$print_function)
return -1;
}
......@@ -80,13 +80,13 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
kwargs = PyDict_New();
if (unlikely(!kwargs))
return -1;
if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
if (unlikely(PyDict_SetItem(kwargs, PYIDENT("file"), stream) < 0))
goto bad;
if (!newline) {
end_string = PyUnicode_FromStringAndSize(" ", 1);
if (unlikely(!end_string))
goto bad;
if (PyDict_SetItemString(kwargs, "end", end_string) < 0) {
if (PyDict_SetItem(kwargs, PYIDENT("end"), end_string) < 0) {
Py_DECREF(end_string);
goto bad;
}
......@@ -100,7 +100,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
end_string = PyUnicode_FromStringAndSize(" ", 1);
if (unlikely(!end_string))
return -1;
if (PyDict_SetItemString($print_function_kwargs, "end", end_string) < 0) {
if (PyDict_SetItem($print_function_kwargs, PYIDENT("end"), end_string) < 0) {
Py_DECREF(end_string);
return -1;
}
......
......@@ -130,7 +130,7 @@ static {{struct_type_decl}} {{funcname}}(PyObject * o) {
{{for member in var_entries:}}
{{py:attr = "result." + member.cname}}
value = PyMapping_GetItemString(o, (char *) "{{member.name}}");
value = PyObject_GetItem(o, PYIDENT("{{member.name}}"));
if (!value) {
PyErr_SetString(PyExc_ValueError, "No value specified for struct "
"attribute '{{member.name}}'");
......
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