[Numpy-discussion] f2py function callback: error while using repeated arguments in function call

Yves Frederix yves.frederix@gmail....
Sun Nov 8 07:25:11 CST 2009


Hi,

I am doing a simple function callback from fortran to python for which
the actual function call in fortran has repeated arguments.

! callback_error.f90:
subroutine testfun(x)
   double precision, intent(in) :: x
   double precision :: y
!f2py intent(callback) foo
!f2py double precision :: arg1
!f2py double precision :: arg2
!f2py double precision :: y
!f2py external y = foo(arg1, arg2)
   external foo
   y = foo(x, x)     !  <-- this causes problems
   print *, 'y:', y
end subroutine testfun


Running f2py gives the following error:

<snip>
compile options: '-I/tmp/tmpTVsLUT/src.linux-i686-2.6
-I/usr/lib/python2.6/dist-packages/numpy/core/include
-I/usr/include/python2.6 -c'
gcc: /tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:256: error:
redefinition of parameter ‘x_cb_capi’
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:256: note: previous
definition of ‘x_cb_capi’ was here
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c: In function ‘foo_’:
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:265: error:
redefinition of ‘x’
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:264: note: previous
definition of ‘x’ was here
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:256: error:
redefinition of parameter ‘x_cb_capi’
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:256: note: previous
definition of ‘x_cb_capi’ was here
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c: In function ‘foo_’:
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:265: error:
redefinition of ‘x’
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c:264: note: previous
definition of ‘x’ was here
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv
-O2 -Wall -Wstrict-prototypes -fPIC
-I/tmp/tmpTVsLUT/src.linux-i686-2.6
-I/usr/lib/python2.6/dist-packages/numpy/core/include
-I/usr/include/python2.6 -c
/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.c -o
/tmp/tmpTVsLUT/tmp/tmpTVsLUT/src.linux-i686-2.6/callbackmodule.o"
failed with exit status 1

If I change the fortran code slightly, making a copy of the input
argument and using this copy instead of the second 'x' in the function
call, the compilation succeeds.

! callback_ok.f90
subroutine testfun(x)
   double precision, intent(in) :: x
   double precision :: y
   double precision :: xtmp
!f2py intent(callback) foo
!f2py double precision :: arg1
!f2py double precision :: arg2
!f2py double precision :: y
!f2py external y = foo(arg1, arg2)
   external foo
   xtmp = x
   y = foo(x, xtmp)    ! <-- this works
   print *, 'y:', y
end subroutine testfun


Is this expected behavior? I am using f2py that comes with the
python-numpy package (version 1:1.3.0-3) from Ubuntu Karmic.

Regards,
YVES


More information about the NumPy-Discussion mailing list