f2py and callbacks with variables

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 deen@mpia.de +49-6221-528-375 Max Planck Institut für Astronomie (MPIA) Königstuhl 17 D-69117 Heidelberg, Germany

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 <deen@mpia.de> wrote:

Hi Pearu- Thanks so much! This works! Can you point me to a reference for the format of the .pyf files? My ~day of searching found a few pages on the scipy website, but nothing which went into this amount of detail. I also asked Stackoverflow, and unless you object, I'd like to add your explanation and mark it as SOLVED for future poor souls wrestling with this problem. I'll also update the github repository with before and after versions of the .pyf file. Cheers, Casey On 08/12/2015 09:34 PM, Pearu Peterson wrote:
-- Dr. Casey Deen Post-doctoral Researcher deen@mpia.de +49-6221-528-375 Max Planck Institut für Astronomie (MPIA) Königstuhl 17 D-69117 Heidelberg, Germany

Hi Casey, On Wed, Aug 12, 2015 at 11:46 PM, Casey Deen <deen@mpia.de> wrote:
Try this: https://sysbio.ioc.ee/projects/f2py2e/usersguide/index.html#signature-file
Go ahead with stackoverflow. Best regards, Pearu Cheers,
participants (2)
-
Casey Deen
-
Pearu Peterson