1 ////////////////////// Print.proto //////////////////////
4 static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
5 #if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
6 static PyObject* $print_function = 0;
7 static PyObject* $print_function_kwargs = 0;
10 ////////////////////// Print.cleanup //////////////////////
13 #if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
14 Py_CLEAR($print_function);
15 Py_CLEAR($print_function_kwargs);
18 ////////////////////// Print //////////////////////
21 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
22 static PyObject *__Pyx_GetStdout(void) {
23 PyObject *f = PySys_GetObject((char *)"stdout");
25 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
30 static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
34 if (!(f = __Pyx_GetStdout()))
38 for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
40 if (PyFile_SoftSpace(f, 1)) {
41 if (PyFile_WriteString(" ", f) < 0)
44 v = PyTuple_GET_ITEM(arg_tuple, i);
45 if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
47 if (PyString_Check(v)) {
48 char *s = PyString_AsString(v);
49 Py_ssize_t len = PyString_Size(v);
51 // append soft-space if necessary (not using isspace() due to C/C++ problem on MacOS-X)
54 case '\f': case '\r': case '\n': case '\t': case '\v':
55 PyFile_SoftSpace(f, 0);
63 if (PyFile_WriteString("\n", f) < 0)
65 PyFile_SoftSpace(f, 0);
74 #else /* Python 3 has a print function */
76 static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
80 if (unlikely(!$print_function)) {
81 $print_function = PyObject_GetAttr($builtins_cname, PYIDENT("print"));
86 kwargs = PyDict_New();
87 if (unlikely(!kwargs))
89 if (unlikely(PyDict_SetItem(kwargs, PYIDENT("file"), stream) < 0))
92 end_string = PyUnicode_FromStringAndSize(" ", 1);
93 if (unlikely(!end_string))
95 if (PyDict_SetItem(kwargs, PYIDENT("end"), end_string) < 0) {
96 Py_DECREF(end_string);
99 Py_DECREF(end_string);
101 } else if (!newline) {
102 if (unlikely(!$print_function_kwargs)) {
103 $print_function_kwargs = PyDict_New();
104 if (unlikely(!$print_function_kwargs))
106 end_string = PyUnicode_FromStringAndSize(" ", 1);
107 if (unlikely(!end_string))
109 if (PyDict_SetItem($print_function_kwargs, PYIDENT("end"), end_string) < 0) {
110 Py_DECREF(end_string);
113 Py_DECREF(end_string);
115 kwargs = $print_function_kwargs;
117 result = PyObject_Call($print_function, arg_tuple, kwargs);
118 if (unlikely(kwargs) && (kwargs != $print_function_kwargs))
125 if (kwargs != $print_function_kwargs)
131 ////////////////////// PrintOne.proto //////////////////////
134 static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
136 ////////////////////// PrintOne //////////////////////
138 #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
140 static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
142 if (!(f = __Pyx_GetStdout()))
146 if (PyFile_SoftSpace(f, 0)) {
147 if (PyFile_WriteString(" ", f) < 0)
150 if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
152 if (PyFile_WriteString("\n", f) < 0)
159 /* the line below is just to avoid C compiler
160 * warnings about unused functions */
161 return __Pyx_Print(f, NULL, 0);
164 #else /* Python 3 has a print function */
166 static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
168 PyObject* arg_tuple = PyTuple_Pack(1, o);
169 if (unlikely(!arg_tuple))
171 res = __Pyx_Print(stream, arg_tuple, 1);
172 Py_DECREF(arg_tuple);