| 359 | } |
| 360 | |
| 361 | static PyObject * |
| 362 | fortran_getattr(PyFortranObject *fp, char *name) |
| 363 | { |
| 364 | int i, j, k, flag; |
| 365 | if (fp->dict != NULL) { |
| 366 | PyObject *v = _PyDict_GetItemStringWithError(fp->dict, name); |
| 367 | if (v == NULL && PyErr_Occurred()) { |
| 368 | return NULL; |
| 369 | } |
| 370 | else if (v != NULL) { |
| 371 | Py_INCREF(v); |
| 372 | return v; |
| 373 | } |
| 374 | } |
| 375 | for (i = 0, j = 1; i < fp->len && (j = strcmp(name, fp->defs[i].name)); |
| 376 | i++) |
| 377 | ; |
| 378 | if (j == 0) |
| 379 | if (fp->defs[i].rank != -1) { /* F90 allocatable array */ |
| 380 | if (fp->defs[i].func == NULL) |
| 381 | return NULL; |
| 382 | for (k = 0; k < fp->defs[i].rank; ++k) fp->defs[i].dims.d[k] = -1; |
| 383 | save_def = &fp->defs[i]; |
| 384 | (*(fp->defs[i].func))(&fp->defs[i].rank, fp->defs[i].dims.d, |
| 385 | set_data, &flag); |
| 386 | if (flag == 2) |
| 387 | k = fp->defs[i].rank + 1; |
| 388 | else |
| 389 | k = fp->defs[i].rank; |
| 390 | if (fp->defs[i].data != NULL) { /* array is allocated */ |
| 391 | PyObject *v = PyArray_New( |
| 392 | &PyArray_Type, k, fp->defs[i].dims.d, fp->defs[i].type, |
| 393 | NULL, fp->defs[i].data, 0, NPY_ARRAY_FARRAY, NULL); |
| 394 | if (v == NULL) |
| 395 | return NULL; |
| 396 | /* Py_INCREF(v); */ |
| 397 | return v; |
| 398 | } |
| 399 | else { /* array is not allocated */ |
| 400 | Py_RETURN_NONE; |
| 401 | } |
| 402 | } |
| 403 | if (strcmp(name, "__dict__") == 0) { |
| 404 | Py_INCREF(fp->dict); |
| 405 | return fp->dict; |
| 406 | } |
| 407 | if (strcmp(name, "__doc__") == 0) { |
| 408 | PyObject *s = PyUnicode_FromString(""), *s2, *s3; |
| 409 | for (i = 0; i < fp->len; i++) { |
| 410 | s2 = fortran_doc(fp->defs[i]); |
| 411 | s3 = PyUnicode_Concat(s, s2); |
| 412 | Py_DECREF(s2); |
| 413 | Py_DECREF(s); |
| 414 | s = s3; |
| 415 | } |
| 416 | if (PyDict_SetItemString(fp->dict, name, s)) |
| 417 | return NULL; |
| 418 | return s; |
nothing calls this directly
no test coverage detected