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

Function stream_python_file

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

Source from the content-addressed store, hash-verified

124
125
126NPY_NO_EXPORT stream *
127stream_python_file(PyObject *obj, const char *encoding)
128{
129 python_chunks_from_file *fb;
130
131 fb = (python_chunks_from_file *)PyMem_Calloc(1, sizeof(python_chunks_from_file));
132 if (fb == NULL) {
133 PyErr_NoMemory();
134 return NULL;
135 }
136
137 fb->stream.stream_nextbuf = (void *)&fb_nextbuf;
138 fb->stream.stream_close = &fb_del;
139
140 fb->encoding = encoding;
141 Py_INCREF(obj);
142 fb->file = obj;
143
144 fb->read = PyObject_GetAttrString(obj, "read");
145 if (fb->read == NULL) {
146 goto fail;
147 }
148 fb->chunksize = PyLong_FromLong(READ_CHUNKSIZE);
149 if (fb->chunksize == NULL) {
150 goto fail;
151 }
152
153 return (stream *)fb;
154
155fail:
156 fb_del((stream *)fb);
157 return NULL;
158}
159
160
161/*

Callers 1

_load_from_filelikeFunction · 0.85

Calls 1

fb_delFunction · 0.85

Tested by

no test coverage detected