Commit f98755eb authored by Stefan Behnel's avatar Stefan Behnel

fix print implementation in Py3, make it more suitable for potential inlining

parent 4964e6d8
...@@ -5106,7 +5106,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { ...@@ -5106,7 +5106,7 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
PyObject* kwargs = 0; PyObject* kwargs = 0;
PyObject* result = 0; PyObject* result = 0;
PyObject* end_string; PyObject* end_string;
if (!%(PRINT_FUNCTION)s) { if (unlikely(!%(PRINT_FUNCTION)s)) {
%(PRINT_FUNCTION)s = __Pyx_GetAttrString(%(BUILTINS)s, "print"); %(PRINT_FUNCTION)s = __Pyx_GetAttrString(%(BUILTINS)s, "print");
if (!%(PRINT_FUNCTION)s) if (!%(PRINT_FUNCTION)s)
return -1; return -1;
...@@ -5117,35 +5117,41 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) { ...@@ -5117,35 +5117,41 @@ static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
return -1; return -1;
if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0)) if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
goto bad; goto bad;
if (!newline) {
end_string = PyUnicode_FromStringAndSize(" ", 1);
if (unlikely(!end_string))
goto bad;
if (PyDict_SetItemString(kwargs, "end", end_string) < 0) {
Py_DECREF(end_string);
goto bad;
}
Py_DECREF(end_string);
} }
} } else if (!newline) {
if (!newline) { if (unlikely(!%(PRINT_KWARGS)s)) {
if (!kwargs)
kwargs = %(PRINT_KWARGS)s;
if (!kwargs) {
%(PRINT_KWARGS)s = PyDict_New(); %(PRINT_KWARGS)s = PyDict_New();
if unlikely((!%(PRINT_KWARGS)s)) if (unlikely(!%(PRINT_KWARGS)s))
return -1; return -1;
kwargs = %(PRINT_KWARGS)s; end_string = PyUnicode_FromStringAndSize(" ", 1);
} if (unlikely(!end_string))
end_string = PyUnicode_FromStringAndSize(" ", 1); goto bad;
if (unlikely(!end_string)) if (PyDict_SetItemString(%(PRINT_KWARGS)s, "end", end_string) < 0) {
goto bad; Py_DECREF(end_string);
if (PyDict_SetItemString(%(PRINT_KWARGS)s, "end", end_string) < 0) { goto bad;
}
Py_DECREF(end_string); Py_DECREF(end_string);
goto bad;
} }
Py_DECREF(end_string); kwargs = %(PRINT_KWARGS)s;
} }
result = PyObject_Call(%(PRINT_FUNCTION)s, arg_tuple, kwargs); result = PyObject_Call(%(PRINT_FUNCTION)s, arg_tuple, kwargs);
if (unlikely(kwargs) && (kwargs != %(PRINT_FUNCTION)s)) if (unlikely(kwargs) && (kwargs != %(PRINT_KWARGS)s))
Py_DECREF(kwargs); Py_DECREF(kwargs);
if (!result) if (!result)
return -1; return -1;
Py_DECREF(result); Py_DECREF(result);
return 0; return 0;
bad: bad:
if (kwargs != %(PRINT_FUNCTION)s) if (kwargs != %(PRINT_KWARGS)s)
Py_XDECREF(kwargs); Py_XDECREF(kwargs);
return -1; return -1;
} }
......
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