Returns number of bytes consumed from buf, or -1 on error. */
| 213 | |
| 214 | /* Returns number of bytes consumed from buf, or -1 on error. */ |
| 215 | static Py_ssize_t |
| 216 | format_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 | |
| 258 | static PyObject * |
| 259 | fortran_doc(FortranDataDef def) |