MCPcopy Create free account
hub / github.com/numpy/numpy / process_stringlike

Function process_stringlike

numpy/core/src/multiarray/textreading/stream_pyobject.c:45–64  ·  view source on GitHub ↗

* Helper function to support byte objects as well as unicode strings. * * NOTE: Steals a reference to `str` (although usually returns it unmodified). */

Source from the content-addressed store, hash-verified

43 * NOTE: Steals a reference to `str` (although usually returns it unmodified).
44 */
45static inline PyObject *
46process_stringlike(PyObject *str, const char *encoding)
47{
48 if (PyBytes_Check(str)) {
49 PyObject *ustr;
50 ustr = PyUnicode_FromEncodedObject(str, encoding, NULL);
51 if (ustr == NULL) {
52 return NULL;
53 }
54 Py_DECREF(str);
55 return ustr;
56 }
57 else if (!PyUnicode_Check(str)) {
58 PyErr_SetString(PyExc_TypeError,
59 "non-string returned while reading data");
60 Py_DECREF(str);
61 return NULL;
62 }
63 return str;
64}
65
66
67static inline void

Callers 2

fb_nextbufFunction · 0.85
it_nextbufFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected