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

Function format_def

numpy/f2py/src/fortranobject.c:215–256  ·  view source on GitHub ↗

Returns number of bytes consumed from buf, or -1 on error. */

Source from the content-addressed store, hash-verified

213
214/* Returns number of bytes consumed from buf, or -1 on error. */
215static Py_ssize_t
216format_def(char *buf, Py_ssize_t size, FortranDataDef def)
217{
218 char *p = buf;
219 int i;
220 npy_intp n;
221
222 n = PyOS_snprintf(p, size, "array(%" NPY_INTP_FMT, def.dims.d[0]);
223 if (n < 0 || n >= size) {
224 return -1;
225 }
226 p += n;
227 size -= n;
228
229 for (i = 1; i < def.rank; i++) {
230 n = PyOS_snprintf(p, size, ",%" NPY_INTP_FMT, def.dims.d[i]);
231 if (n < 0 || n >= size) {
232 return -1;
233 }
234 p += n;
235 size -= n;
236 }
237
238 if (size <= 0) {
239 return -1;
240 }
241
242 *p++ = ')';
243 size--;
244
245 if (def.data == NULL) {
246 static const char notalloc[] = ", not allocated";
247 if ((size_t)size < sizeof(notalloc)) {
248 return -1;
249 }
250 memcpy(p, notalloc, sizeof(notalloc));
251 p += sizeof(notalloc);
252 size -= sizeof(notalloc);
253 }
254
255 return p - buf;
256}
257
258static PyObject *
259fortran_doc(FortranDataDef def)

Callers 1

fortran_docFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected