Skip to content

Commit 9a36ead

Browse files
committed
BUG: Fix f2py string variables in callbacks.
When NPY_CHAR was deprecated and replaced by NPY_STRING in f2py, calls to PyArray_New that previously relied on the type to get the itemsize needed the size explicitly specified, but that modification was missed in some of the code. Because the strings that replacee the 'c' type are always 'S1', we use an itemsize of 1 for the string types and pass it explicitly. Closes numpy#10027.
1 parent 3fa0096 commit 9a36ead

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

numpy/f2py/cb_rules.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@
367367
'pyobjfrom': [{debugcapi: '\tfprintf(stderr,"debug-capi:cb:#varname#\\n");'},
368368
{isintent_c: """\
369369
\tif (#name#_nofargs>capi_i) {
370-
\t\tPyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,0,NPY_ARRAY_CARRAY,NULL); /*XXX: Hmm, what will destroy this array??? */
370+
\t\tint itemsize_ = #atype# == NPY_STRING ? 1 : 0;
371+
\t\t/*XXX: Hmm, what will destroy this array??? */
372+
\t\tPyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,itemsize_,NPY_ARRAY_CARRAY,NULL);
371373
""",
372374
l_not(isintent_c): """\
373375
\tif (#name#_nofargs>capi_i) {
374-
\t\tPyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,0,NPY_ARRAY_FARRAY,NULL); /*XXX: Hmm, what will destroy this array??? */
376+
\t\tint itemsize_ = #atype# == NPY_STRING ? 1 : 0;
377+
\t\t/*XXX: Hmm, what will destroy this array??? */
378+
\t\tPyArrayObject *tmp_arr = (PyArrayObject *)PyArray_New(&PyArray_Type,#rank#,#varname_i#_Dims,#atype#,NULL,(char*)#varname_i#,itemsize_,NPY_ARRAY_FARRAY,NULL);
375379
""",
376380
},
377381
"""

0 commit comments

Comments
 (0)