Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: third_party/cython/src/Cython/Utility/Printing.c

Issue 385073004: Adding cython v0.20.2 in third-party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reference cython dev list thread. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/cython/src/Cython/Utility/Overflow.c ('k') | third_party/cython/src/Cython/Utility/Profile.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/cython/src/Cython/Utility/Printing.c
diff --git a/third_party/cython/src/Cython/Utility/Printing.c b/third_party/cython/src/Cython/Utility/Printing.c
new file mode 100644
index 0000000000000000000000000000000000000000..71aa7eafe95d64f82afe719c479e3aac32f0bd6c
--- /dev/null
+++ b/third_party/cython/src/Cython/Utility/Printing.c
@@ -0,0 +1,176 @@
+////////////////////// Print.proto //////////////////////
+//@substitute: naming
+
+static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
+#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
+static PyObject* $print_function = 0;
+static PyObject* $print_function_kwargs = 0;
+#endif
+
+////////////////////// Print.cleanup //////////////////////
+//@substitute: naming
+
+#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
+Py_CLEAR($print_function);
+Py_CLEAR($print_function_kwargs);
+#endif
+
+////////////////////// Print //////////////////////
+//@substitute: naming
+
+#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
+static PyObject *__Pyx_GetStdout(void) {
+ PyObject *f = PySys_GetObject((char *)"stdout");
+ if (!f) {
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
+ }
+ return f;
+}
+
+static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
+ int i;
+
+ if (!f) {
+ if (!(f = __Pyx_GetStdout()))
+ return -1;
+ }
+ Py_INCREF(f);
+ for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
+ PyObject* v;
+ if (PyFile_SoftSpace(f, 1)) {
+ if (PyFile_WriteString(" ", f) < 0)
+ goto error;
+ }
+ v = PyTuple_GET_ITEM(arg_tuple, i);
+ if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
+ goto error;
+ if (PyString_Check(v)) {
+ char *s = PyString_AsString(v);
+ Py_ssize_t len = PyString_Size(v);
+ if (len > 0) {
+ // append soft-space if necessary (not using isspace() due to C/C++ problem on MacOS-X)
+ switch (s[len-1]) {
+ case ' ': break;
+ case '\f': case '\r': case '\n': case '\t': case '\v':
+ PyFile_SoftSpace(f, 0);
+ break;
+ default: break;
+ }
+ }
+ }
+ }
+ if (newline) {
+ if (PyFile_WriteString("\n", f) < 0)
+ goto error;
+ PyFile_SoftSpace(f, 0);
+ }
+ Py_DECREF(f);
+ return 0;
+error:
+ Py_DECREF(f);
+ return -1;
+}
+
+#else /* Python 3 has a print function */
+
+static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
+ PyObject* kwargs = 0;
+ PyObject* result = 0;
+ PyObject* end_string;
+ if (unlikely(!$print_function)) {
+ $print_function = PyObject_GetAttr($builtins_cname, PYIDENT("print"));
+ if (!$print_function)
+ return -1;
+ }
+ if (stream) {
+ kwargs = PyDict_New();
+ if (unlikely(!kwargs))
+ return -1;
+ 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_SetItem(kwargs, PYIDENT("end"), end_string) < 0) {
+ Py_DECREF(end_string);
+ goto bad;
+ }
+ Py_DECREF(end_string);
+ }
+ } else if (!newline) {
+ if (unlikely(!$print_function_kwargs)) {
+ $print_function_kwargs = PyDict_New();
+ if (unlikely(!$print_function_kwargs))
+ return -1;
+ end_string = PyUnicode_FromStringAndSize(" ", 1);
+ if (unlikely(!end_string))
+ return -1;
+ if (PyDict_SetItem($print_function_kwargs, PYIDENT("end"), end_string) < 0) {
+ Py_DECREF(end_string);
+ return -1;
+ }
+ Py_DECREF(end_string);
+ }
+ kwargs = $print_function_kwargs;
+ }
+ result = PyObject_Call($print_function, arg_tuple, kwargs);
+ if (unlikely(kwargs) && (kwargs != $print_function_kwargs))
+ Py_DECREF(kwargs);
+ if (!result)
+ return -1;
+ Py_DECREF(result);
+ return 0;
+bad:
+ if (kwargs != $print_function_kwargs)
+ Py_XDECREF(kwargs);
+ return -1;
+}
+#endif
+
+////////////////////// PrintOne.proto //////////////////////
+//@requires: Print
+
+static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/
+
+////////////////////// PrintOne //////////////////////
+
+#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
+
+static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
+ if (!f) {
+ if (!(f = __Pyx_GetStdout()))
+ return -1;
+ }
+ Py_INCREF(f);
+ if (PyFile_SoftSpace(f, 0)) {
+ if (PyFile_WriteString(" ", f) < 0)
+ goto error;
+ }
+ if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
+ goto error;
+ if (PyFile_WriteString("\n", f) < 0)
+ goto error;
+ Py_DECREF(f);
+ return 0;
+error:
+ Py_DECREF(f);
+ return -1;
+ /* the line below is just to avoid C compiler
+ * warnings about unused functions */
+ return __Pyx_Print(f, NULL, 0);
+}
+
+#else /* Python 3 has a print function */
+
+static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
+ int res;
+ PyObject* arg_tuple = PyTuple_Pack(1, o);
+ if (unlikely(!arg_tuple))
+ return -1;
+ res = __Pyx_Print(stream, arg_tuple, 1);
+ Py_DECREF(arg_tuple);
+ return res;
+}
+
+#endif
« no previous file with comments | « third_party/cython/src/Cython/Utility/Overflow.c ('k') | third_party/cython/src/Cython/Utility/Profile.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698