[f2py] Structure support?
James Amundson
amundson@fnal.gov
25 Mar 2002 15:34:33 -0600
--=-SVSq6oJw2/JkMzEIjO3S
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Mon, 2002-03-25 at 14:56, Pearu Peterson wrote:
>
>
> On 25 Mar 2002, James Amundson wrote:
> > Wrapping the structures by hand I understand. I have two problems, only
> > one of which I know how to fix:
> >
> > 1) The declaration of the triplet type above causes f2py to barf. (I can
> > supply details if necessary.) Is there some way to tell f2py to ignore
> > the type definition.
>
> Yes, by not trying to wrap functions that have `type' type of arguments.
> f2py should ignore anything in the function body that it does not need for
> building a wrapper. Otherwise, it is f2py bug and then you can send me a
> illustrative example and I'll fix it.
My problem is not with functions that take 'type' arguments, but with
modules that simply define types. Here is a simple example.
First, the files:
good.f90:
------------------------------------------------------------------------
module good
integer :: myinteger
contains
function foo(a)
integer :: a,foo
foo = a*a
end function foo
end module good
------------------------------------------------------------------------
bad.f90:
------------------------------------------------------------------------
module bad
type triplet
integer :: x,y,z
end type triplet
integer :: myinteger
contains
function foo(a)
integer :: a,foo
foo = a*a
end function foo
end module bad
------------------------------------------------------------------------
"bad" is bad because it contains a type definition, even though it
doesn't actually use it for anything.
I can run good.f90 through f2py and get what I expect:
------------------------------------------------------------------------
|abacus>f2py -c good.f90 -m good -lgood -DF2PY_REPORT_ATEXIT_DISABLE >& good.log
|abacus>python -c "import good; print good.__doc__"
This module 'good' is auto-generated with f2py (version:2.13.175-1233).
Functions:
Fortran 90/95 modules:
good --- myinteger,foo().
------------------------------------------------------------------------
When I run bad.f90 through f2py and try to use it, I get a segmentation
fault. I have attached both good.log and bad.log to the end of this
message.
------------------------------------------------------------------------
|abacus>f2py -c bad.f90 -m bad -lbad -DF2PY_REPORT_ATEXIT_DISABLE >&
bad.log
|abacus>python -c "import bad; print bad.__doc__"
Segmentation fault
------------------------------------------------------------------------
In order to see what is going on, we can look at the signature files.
Again, everything looks the way I would expect for good.f90.
------------------------------------------------------------------------
|abacus>f2py -h good.pyf good.f90
Reading fortran codes...
Reading file 'good.f90'
Post-processing...
Block: good
Block: foo
Saving signatures to file "./good.pyf"
Stopping. Edit the signature file and then run f2py on the signature
file: f2py ./good.pyf
Or run GNU make to build shared module: gmake -f Makefile-<modulename>
Or run: python setup_<modulename>.py build
|abacus>cat good.pyf
!%f90 -*- f90 -*-
module good ! in good.f90
integer :: myinteger
function foo(a) ! in good.f90:good
integer :: a
integer :: foo
end function foo
end module good
! This file was auto-generated with f2py (version:2.13.175-1233).
! See http://cens.ioc.ee/projects/f2py2e/
------------------------------------------------------------------------
The signature file is clearly truncated for bad.f90:
------------------------------------------------------------------------
|abacus>f2py -h bad.pyf bad.f90
Reading fortran codes...
Reading file 'bad.f90'
Line #5 in bad.f90:" integer :: myinteger"
analyzeline: no group yet. Creating program group with name "bad".
crackline: groupcounter=1 groupname={3: 'function', 2: 'program', 1:
'module', 0: ''}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming
"end" statement.
Post-processing...
Block: bad
Block: triplet
Block: bad
Block: foo
Saving signatures to file "./bad.pyf"
Stopping. Edit the signature file and then run f2py on the signature
file: f2py ./bad.pyf
Or run GNU make to build shared module: gmake -f Makefile-<modulename>
Or run: python setup_<modulename>.py build
|abacus>cat bad.pyf
!%f90 -*- f90 -*-
module bad ! in bad.f90
type triplet ! in bad.f90:bad
end type triplet
end module bad
! This file was auto-generated with f2py (version:2.13.175-1233).
! See http://cens.ioc.ee/projects/f2py2e/
------------------------------------------------------------------------
Everything after the type declaration is truncated. I have seen this
behaviour on other files.
Thanks again for all your help. I really didn't expect such quick
responses when I started with these questions!
--Jim
--=-SVSq6oJw2/JkMzEIjO3S
Content-Disposition: attachment; filename=good.log
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=good.log; charset=ISO-8859-1
module GOOD
module function FOO
8 Lines Compiled
external subroutine F2PYWRAP_GOOD_FOO
external subroutine F2PYINITGOOD
16 Lines Compiled
/tmp/@18321.0/goodmodule.c:121: warning: function declaration isn't a proto=
type
/tmp/@18321.0/goodmodule.c:194: warning: function declaration isn't a proto=
type
/tmp/@18321.0/goodmodule.c:195: warning: function declaration isn't a proto=
type
['good']
running build
running run_f2py
f2py-ing a new /tmp/@18321.0/good.pyf
f2py-opts: -m good -h /tmp/@18321.0/good.pyf --overwrite-signature
Reading fortran codes...
Reading file 'good.f90'
Post-processing...
Block: good
Block: good
Block: foo
Saving signatures to file "/tmp/@18321.0/good.pyf"
f2py-ing /tmp/@18321.0/good.pyf to /tmp/@18321.0/goodmodule.c
f2py-opts: --build-dir /tmp/@18321.0 --build-dir /tmp/@18321.0
Reading fortran codes...
Reading file '/tmp/@18321.0/good.pyf'
Post-processing...
Block: good
Block: good
Block: foo
Building modules...
Building module "good"...
Constructing F90 module support for "good"...
Variables: myinteger
Creating wrapper for Fortran function "foo"("foo")...
Constructing wrapper function "good.foo"...
foo =3D foo(a)
Wrote C/API module "good" to file "/tmp/@18321.0/goodmodule.c"
Fortran wrappers are saved to "/tmp/@18321.0/good-f2pywrappers.f"
running build_flib
scipy_distutils.command.build_flib.absoft_fortran_compiler
scipy_distutils.command.build_flib.mips_fortran_compiler
scipy_distutils.command.build_flib.sun_fortran_compiler
scipy_distutils.command.build_flib.intel_ia32_fortran_compiler
using Intel 5.0.1 Fortran compiler
building 'good' library
ifc -KPIC -O3 -xM -DF2PY_REPORT_ATEXIT_DISABLE -I/home/amundson/opt/lib=
/python2.1/site-packages/f2py2e/src -c good.f90 -o /tmp/@18321.0/good.o
ifc -KPIC -FI -w90 -w95 -O3 -xM -DF2PY_REPORT_ATEXIT_DISABLE -I/home/a=
mundson/opt/lib/python2.1/site-packages/f2py2e/src -c /tmp/@18321.0/good-f2=
pywrappers.f -o /tmp/@18321.0/good-f2pywrappers.o
ar -cur /tmp/@18321.0/libgood.a /tmp/@18321.0/good.o /tmp/@18321.0/good-f2=
pywrappers.o
running build_ext
good good needs fortran libraries 1 0
replacing linker_so ['gcc', '-shared'] with ['ifc', '-shared']
building 'good' extension
gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DF2PY_REPORT_ATEXIT_DISABLE -I/=
home/amundson/opt/lib/python2.1/site-packages/f2py2e/src -I/usr/include/pyt=
hon2.1 -c /home/amundson/opt/lib/python2.1/site-packages/f2py2e/src/fortran=
object.c -o /tmp/@18321.0/fortranobject.o
gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DF2PY_REPORT_ATEXIT_DISABLE -I/=
home/amundson/opt/lib/python2.1/site-packages/f2py2e/src -I/usr/include/pyt=
hon2.1 -c /tmp/@18321.0/goodmodule.c -o /tmp/@18321.0/goodmodule.o
ifc -shared /tmp/@18321.0/fortranobject.o /tmp/@18321.0/goodmodule.o -L/tmp=
/@18321.0 -lgood -o ./good.so
restoring linker_so ['gcc', '-shared']
--=-SVSq6oJw2/JkMzEIjO3S
Content-Disposition: attachment; filename=bad.log
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=bad.log; charset=ISO-8859-1
module BAD
module function FOO
11 Lines Compiled
external subroutine F2PYINITBAD
10 Lines Compiled
/tmp/@18351.0/badmodule.c:63: warning: function declaration isn't a prototy=
pe
/tmp/@18351.0/badmodule.c: In function `f2py_setup_bad':
/tmp/@18351.0/badmodule.c:64: warning: unused variable `i_f2py'
/tmp/@18351.0/badmodule.c: At top level:
/tmp/@18351.0/badmodule.c:66: warning: function declaration isn't a prototy=
pe
/tmp/@18351.0/badmodule.c:67: warning: function declaration isn't a prototy=
pe
['bad']
running build
running run_f2py
f2py-ing a new /tmp/@18351.0/bad.pyf
f2py-opts: -m bad -h /tmp/@18351.0/bad.pyf --overwrite-signature
Reading fortran codes...
Reading file 'bad.f90'
Line #5 in bad.f90:" integer :: myinteger"
analyzeline: no group yet. Creating program group with name "bad".
crackline: groupcounter=3D3 groupname=3D{5: 'function', 4: 'program', 3: 'm=
odule', 2: 'interface', 1: 'module', 0: ''}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming "en=
d" statement.
crackline: groupcounter=3D2 groupname=3D{5: 'function', 4: 'program', 3: 'm=
odule', 2: 'interface', 1: 'module', 0: ''}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming "en=
d" statement.
crackline: groupcounter=3D1 groupname=3D{5: 'function', 4: 'program', 3: 'm=
odule', 2: 'interface', 1: 'module', 0: ''}
crackline: Mismatch of blocks encountered. Trying to fix it by assuming "en=
d" statement.
Post-processing...
Block: bad
Block: bad
Block: triplet
Block: bad
Block: foo
Saving signatures to file "/tmp/@18351.0/bad.pyf"
f2py-ing /tmp/@18351.0/bad.pyf to /tmp/@18351.0/badmodule.c
f2py-opts: --build-dir /tmp/@18351.0 --build-dir /tmp/@18351.0
Reading fortran codes...
Reading file '/tmp/@18351.0/bad.pyf'
Post-processing...
Block: bad
Block: bad
Block: triplet
Building modules...
Building module "bad"...
Constructing F90 module support for "bad"...
Skipping type triplet
Wrote C/API module "bad" to file "/tmp/@18351.0/badmodule.c"
Fortran wrappers are saved to "/tmp/@18351.0/bad-f2pywrappers.f"
running build_flib
scipy_distutils.command.build_flib.absoft_fortran_compiler
scipy_distutils.command.build_flib.mips_fortran_compiler
scipy_distutils.command.build_flib.sun_fortran_compiler
scipy_distutils.command.build_flib.intel_ia32_fortran_compiler
using Intel 5.0.1 Fortran compiler
building 'bad' library
ifc -KPIC -O3 -xM -DF2PY_REPORT_ATEXIT_DISABLE -I/home/amundson/opt/lib=
/python2.1/site-packages/f2py2e/src -c bad.f90 -o /tmp/@18351.0/bad.o
ifc -KPIC -FI -w90 -w95 -O3 -xM -DF2PY_REPORT_ATEXIT_DISABLE -I/home/a=
mundson/opt/lib/python2.1/site-packages/f2py2e/src -c /tmp/@18351.0/bad-f2p=
ywrappers.f -o /tmp/@18351.0/bad-f2pywrappers.o
ar -cur /tmp/@18351.0/libbad.a /tmp/@18351.0/bad.o /tmp/@18351.0/bad-f2pyw=
rappers.o
running build_ext
bad bad needs fortran libraries 1 0
replacing linker_so ['gcc', '-shared'] with ['ifc', '-shared']
building 'bad' extension
gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DF2PY_REPORT_ATEXIT_DISABLE -I/=
home/amundson/opt/lib/python2.1/site-packages/f2py2e/src -I/usr/include/pyt=
hon2.1 -c /home/amundson/opt/lib/python2.1/site-packages/f2py2e/src/fortran=
object.c -o /tmp/@18351.0/fortranobject.o
gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DF2PY_REPORT_ATEXIT_DISABLE -I/=
home/amundson/opt/lib/python2.1/site-packages/f2py2e/src -I/usr/include/pyt=
hon2.1 -c /tmp/@18351.0/badmodule.c -o /tmp/@18351.0/badmodule.o
ifc -shared /tmp/@18351.0/fortranobject.o /tmp/@18351.0/badmodule.o -L/tmp/=
@18351.0 -lbad -o ./bad.so
restoring linker_so ['gcc', '-shared']
--=-SVSq6oJw2/JkMzEIjO3S--