| 121 | typedef PyObject *(*fortranfunc)(PyObject *, PyObject *, PyObject *, void *); |
| 122 | |
| 123 | PyObject * |
| 124 | PyFortranObject_New(FortranDataDef *defs, f2py_void_func init) |
| 125 | { |
| 126 | int i; |
| 127 | PyFortranObject *fp = NULL; |
| 128 | PyObject *v = NULL; |
| 129 | if (init != NULL) { /* Initialize F90 module objects */ |
| 130 | (*(init))(); |
| 131 | } |
| 132 | fp = PyObject_New(PyFortranObject, &PyFortran_Type); |
| 133 | if (fp == NULL) { |
| 134 | return NULL; |
| 135 | } |
| 136 | if ((fp->dict = PyDict_New()) == NULL) { |
| 137 | Py_DECREF(fp); |
| 138 | return NULL; |
| 139 | } |
| 140 | fp->len = 0; |
| 141 | while (defs[fp->len].name != NULL) { |
| 142 | fp->len++; |
| 143 | } |
| 144 | if (fp->len == 0) { |
| 145 | goto fail; |
| 146 | } |
| 147 | fp->defs = defs; |
| 148 | for (i = 0; i < fp->len; i++) { |
| 149 | if (fp->defs[i].rank == -1) { /* Is Fortran routine */ |
| 150 | v = PyFortranObject_NewAsAttr(&(fp->defs[i])); |
| 151 | if (v == NULL) { |
| 152 | goto fail; |
| 153 | } |
| 154 | PyDict_SetItemString(fp->dict, fp->defs[i].name, v); |
| 155 | Py_XDECREF(v); |
| 156 | } |
| 157 | else if ((fp->defs[i].data) != |
| 158 | NULL) { /* Is Fortran variable or array (not allocatable) */ |
| 159 | PyArray_Descr * |
| 160 | descr = get_descr_from_type_and_elsize(fp->defs[i].type, |
| 161 | fp->defs[i].elsize); |
| 162 | if (descr == NULL) { |
| 163 | goto fail; |
| 164 | } |
| 165 | v = PyArray_NewFromDescr(&PyArray_Type, descr, fp->defs[i].rank, |
| 166 | fp->defs[i].dims.d, NULL, fp->defs[i].data, |
| 167 | NPY_ARRAY_FARRAY, NULL); |
| 168 | if (v == NULL) { |
| 169 | Py_DECREF(descr); |
| 170 | goto fail; |
| 171 | } |
| 172 | PyDict_SetItemString(fp->dict, fp->defs[i].name, v); |
| 173 | Py_XDECREF(v); |
| 174 | } |
| 175 | } |
| 176 | return (PyObject *)fp; |
| 177 | fail: |
| 178 | Py_XDECREF(fp); |
| 179 | return NULL; |
| 180 | } |
nothing calls this directly
no test coverage detected