| 124 | |
| 125 | |
| 126 | NPY_NO_EXPORT stream * |
| 127 | stream_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 | |
| 155 | fail: |
| 156 | fb_del((stream *)fb); |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /* |
no test coverage detected