Skip to content

Issue with f2py in Numpy 1.13 when character arrays appear in a callback function #10027

@swryan

Description

@swryan

There is an issue with f2py in Numpy 1.13 when character arrays appear in a callback function. The following example works with Numpy 1.12 but not in 1.13:

#! /usr/bin/env python

from __future__ import print_function
import numpy
from subprocess import call

#
# build extension from FORTRAN source
#
source = """
       subroutine func_with_callback(callBack, cu, lencu)

       implicit none

       integer :: lencu
       character*8 cu(lencu)
       external callBack

       print *,'Lencu:', lencu

       print *,'Calling callback...'
       call callBack(cu, lencu)
       print *,'Back in fortran...'

       end subroutine func_with_callback
"""

with open("callback.f", "w") as src_file:
    src_file.write(source)

rc = call("f2py callback.f -m callback -h callback.pyf".split())
if rc: quit()

rc = call("f2py -c callback.pyf callback.f".split())
if rc: quit()


#
# define callback function
#
def callBack(cu, lencu):
    print ('In callback:', cu)

#
# call library function with callback
#
from callback import func_with_callback
print(func_with_callback.__doc__)

print("\nNumpy Version:", numpy.__version__, "\n")

cu = numpy.zeros((1, 8), 'c')

func_with_callback(callBack, cu)

================

Numpy Version: 1.12.1

Lencu: 1
Calling callback...
In callback: [['' '' '' '' '' '' '' '']]
Back in fortran...

================

Numpy Version: 1.13.3

Lencu: 1
Calling callback...
Call-back cb_callback_in_func_with_callback__user__routines failed.
Traceback (most recent call last):
File "test_callback.py", line 57, in
func_with_callback(callBack, cu)
ValueError: data type must provide an itemsize

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions