[SciPy-User] Fwd: f2py segfault

Juan fiolj@yahoo....
Mon Jan 18 06:19:48 CST 2010

Hi, thanks for the advice. I did not notice that the integer division could be a
source for trouble. Now I changed all the routines. However, I still have the
same segmentation fault.

debug-capi:Python C/API function
debug-capi:int ndim=shape(state,0):input,optional,scalar
debug-capi:Checking `shape(state,0)==ndim'
debug-capi:int ntrajectories=shape(state,1):input,optional,scalar
debug-capi:Checking `shape(state,1)==ntrajectories'
debug-capi:Fortran subroutine `sub0(state,&ndim,&ntrajectories)'
debug-capi:Building return value.
debug-capi:Python C/API function mymod.sub0: successful.
debug-capi:Freeing memory.
debug-capi:Python C/API function
Segmentation fault

The working sub1 has two other arguments d_i and d_f which are real scalars, the
full signatures are:

  subroutine sub0(state, Ndim, Ntrajectories)
    integer(I32), intent(IN) :: Ndim
    integer(I32), intent(IN) :: Ntrajectories
    real(R64), intent(INOUT), dimension(Ndim,Ntrajectories) :: state
  end subroutine sub0

  subroutine sub1(state,d_i,d_f, Ndim,Ntrajectories)
    integer(4), intent(IN) :: Ndim
    integer(4), intent(IN) :: Ntrajectories
    real(8), intent(INOUT), dimension(Ndim, Ntrajectories) :: state
    real(8), intent(IN) :: d_i
    real(8), intent(IN) :: d_f
    print *, shape(state), Ndim, Ntrajectories
  end subroutine sub1

and I am calling from my script as:

import mymod
di=0., df=10.
r= np.zeros((Ndim,Ntrajectories),dtype=np.float64, order='Fortran')

mymod.sub1(r, di, df)

As it can be seen from the debug output, f2py is checking the arguments for sub0
but it segfault before checking the args in sub1 (with no very informative

It may well be a problem related to theworkings of the routines but they work
when I use them in tests on pure fortran code. Additionally I get a very similar
error message if I call sub0 (mymod.sub0(r)) instead of sub1 (mymod.sub1(r, di,
df)) the second time in the python script.

Any ideas? Thanks again. Juan

-------- Original Message --------
Subject: f2py segfault
Date: Sun, 17 Jan 2010 15:28:23 -0300
From: Juan <fiolj@yahoo.com>
To: scipy-user@scipy.org

Hi, I don't know if this is the right place (if it is not, please point me in
the right direction).
I am using f2py with some own programs and I am going insane with a segmentation
fault. It is probably a problem in my code but I'd like to know if someone has
any hint
to give me since I've been trying different things for two days already.

I've got a few routines in fortran with in/out arrays. When I call one of the
routines it works well. The second routine I call crashes the program. I've been
changing routines and it seems that it does not matter with routines I use.

Basically, the fortran routines have the signature:

More information about the SciPy-User mailing list