[MATRIX-SIG] Seg fault in netcdfmodule

Jeffery D. Collins jcollins@pacificnet.net
Wed, 28 Jan 1998 21:49:14 -0800


I'm having problems with segmentation faults when using
netCDFmodule.c and/or ncmodule.c with Python-1.5 under
solaris 2.6.  The problem arises when trying to read values
from the variables as in:

>>> import netcdf
>>> fh = netcdf.NetCDFFile('test.nc')
>>> v = fh.variables['cosx']
>>> v[0]
=> segmentation fault

or
>>> import nc
>>> fh = nc.open('test.nc')
>>> v = fh.var('cosx')
>>> v[0]
=> segmentation fault

It doesn't seem to matter if v is indexed as above or as a slice - the
same error
is produced.  Additionally, other objects seem to work fine (eg,
fh.variables
prints the variable dictionary).

I suspect the gcc (2.7.2) compiler.  A recent OS upgrade (2.5.1 to 2.6)
required a recompile
of gcc, then a recompile of Python-1.5, NumPy (the EZ Hinsen version),
and the
netcdf modules listed above (all as shared modules).  I also recompiled
Python-1.4
and performed the above tests with mixed results - one of the two still
produced a
seg fault.   Note that I had no problems under Python-1.4 compiled with
the gcc under
Solaris 2.5.1.


I also noticed a problem with ncmodule (NetCDFmodule seems to be ok)
under
Linux as compiled for Python-1.5 that doesn't exist for Python-1.4:

Python-1.4 (libc5,  linux-2.0.29):
>>> import nc
>>> fh = nc.open('test.nc')
>>> v = fh.var('cos2x')
>>> v[0]
1.0
>>> v[1]
0.773474097252
>>> v[:]
[1.0, 0.773474097252, 0.299152284861, 0.00681934831664, 0.161359220743,
0.622742772102, 0.972908616066, 0.894570231438, 0.458710312843,
0.0602631233633, 0.0602631233633, 0.458710312843, 0.894570231438,
0.972908616066, 0.622742772102, 0.161359220743, 0.00681934831664,
0.299152284861, 0.773474097252, 1.0]
>>> v[0]
1.0
>>>

Python-1.5 (same OS):
>>> import nc
>>> fh  = nc.open('test.nc')
>>> v = fh.var('cos2x')
>>> v[0]
1.0
>>> v[1]
0.773474097252
>>> v[:]
Traceback (innermost last):
  File "<stdin>", line 1, in ?
nc.error: Problem getting data for variable <cos2x> (8)
>>> v[0]
Fatal Python error: PyString_InternInPlace: strings only please!
Abort
 %

-----------------------

Any suggestions?  Perhaps I need to flip a compiler flag (or upgrade to
a more recent
version).   In building gcc, there is the question of which malloc to
use - the system's
version or gcc's version - I always choose the default (gcc's, I think)
- maybe that's
a problem.

I'll try the Sun compiler (cc) next to see what happens.

Thanks,

Jeff



_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________