Hi Casey,

What you observe, is not a f2py bug. When f2py sees a code like

subroutine foo
  call bar
end subroutine foo

then it will not make an attempt to analyze bar because of implicit
assumption that all statements that has no references to foo arguments are
irrelevant for wrapper function generation.
For your example, f2py needs some help. Try the following signature in .pyf
file:

        subroutine barney ! in :flintstone:nocallback.f
            use test__user__routines, fred=>fred, bambam=>bambam
            intent(callback, hide) fred
            external fred
            intent(callback,hide) bambam
            external bambam
        end subroutine barney

Btw, instead of

  f2py -c -m flintstone flintstone.pyf callback.f nocallback.f

use

  f2py -c flintstone.pyf callback.f nocallback.f

because module name comes from the .pyf file.

HTH,
Pearu

On Wed, Aug 12, 2015 at 7:12 PM, Casey Deen <d...@mpia.de> wrote:

> Hi all-
>
>    I've run into what I think might be a bug in f2py and callbacks to
> python.  Or, maybe I'm not using things correctly.  I have created a
> very minimal example which illustrates my problem at:
>
> https://github.com/soylentdeen/fluffy-kumquat
>
> The issue seems to affect call backs with variables, but only when they
> are called indirectly (i.e. from other fortran routines).  For example,
> if I have a python function
>
> def show_number(n):
>     print("%d" % n)
>
> and I setup a callback in a fortran routine:
>
>       subroutine cb
> cf2py intent(callback, hide) blah
>       external blah
>       call blah(5)
>       end
>
> and connect it to the python routine
> fortranObject.blah = show_number
>
> I can successfully call the cb routine from python:
>
> >fortranObject.cb
> 5
>
> However, if I call the cb routine from within another fortran routine,
> it seems to lose its marbles
>
>       subroutine no_cb
>       call cb
>       end
>
> capi_return is NULL
> Call-back cb_blah_in_cb__user__routines failed.
>
> For more information, please have a look at the github repository.  I've
> reproduced the behavior on both linux and mac.  I'm not sure if this is
> an error in the way I'm using the code, or if it is an actual bug.  Any
> and all help would be very much appreciated.
>
> Cheers,
> Casey
>
>
> --
> Dr. Casey Deen
> Post-doctoral Researcher
> d...@mpia.de                       +49-6221-528-375
> Max Planck Institut für Astronomie (MPIA)
> Königstuhl 17  D-69117 Heidelberg, Germany
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to