[GRASS-dev] RE: [GRASS-user] Question with Python-SWIG example [SEC=UNCLASSIFIED]

Glynn Clements glynn at gclements.plus.com
Tue May 18 19:04:19 EDT 2010


Martin Landa wrote:

> 2010/5/18 Glynn Clements <glynn at gclements.plus.com>:
> > What platform, Python version, ctypesgen version?
> 
> Debian GNU/Linux unstable, x86-32
> Python 2.5.5
> ctypesgen from SVN

FWIW, I'm using Python 2.6.4. I've also checked with the latest SVN
version of ctypesgen, but haven't found any differences.

> > The G_find_raster2() definition should look like:
> >
> > # /usr/local/src/grass/7.0/dist.i686-pc-linux-gnu/include/grass/gisdefs.h: 220
> > if hasattr(_libs['grass_gis'], 'G_find_raster2'):
> >    G_find_raster2 = _libs['grass_gis'].G_find_raster2
> >    G_find_raster2.restype = ReturnString
> >    G_find_raster2.argtypes = [String, String]
> 
> I found
> 
> dist.i686-pc-linux-gnu/etc/python/grass/lib/grass.py:    if
> hasattr(_lib, 'G_find_raster2'):
> dist.i686-pc-linux-gnu/etc/python/grass/lib/grass.py:
> G_find_raster2 = _lib.G_find_raster2
> dist.i686-pc-linux-gnu/etc/python/grass/lib/grass.py:
> G_find_raster2.restype = String
> dist.i686-pc-linux-gnu/etc/python/grass/lib/grass.py:
> G_find_raster2.argtypes = [String, String]
> dist.i686-pc-linux-gnu/etc/python/grass/lib/grass.py:
> G_find_raster2.errcheck = ReturnString

Okay; I know why this (the code differences) is happening:

Hmm. From ctypesgencore/printer/printer.py:

    def print_fixed_function(self, function):
        self.srcinfo(function.src)
        if function.source_library:
            print >>self.file, "if hasattr(_libs[%r], %r):" % \
                (function.source_library,function.c_name())
            print >>self.file, "    %s = _libs[%r].%s" % \
                (function.py_name(),function.source_library,function.c_name())
            print >>self.file, "    %s.restype = %s" % \
                (function.py_name(),function.restype.py_string())
            print >>self.file, "    %s.argtypes = [%s]" % (function.py_name(),
                ', '.join([a.py_string() for a in function.argtypes]))
        else:
            print >>self.file, "for _lib in _libs.values():"
            print >>self.file, "    if hasattr(_lib, %r):" % function.c_name()
            print >>self.file, "        %s = _lib.%s" % (function.py_name(),function.c_name())
            print >>self.file, "        %s.restype = %s" % (function.py_name(),function.restype.py_string())
            print >>self.file, "        %s.argtypes = [%s]" % (function.py_name(),
                ', '.join([a.py_string() for a in function.argtypes]))
            print >>self.file, "        break"

I'm getting the first case, while you're getting the second.

The source_library field is only set if it manages to load the
library. I don't use GRASS "sessions"; I just set all of the
environment variables from my ~/.bash_profile, so GRASS commands work
everywhere.

This means that LD_LIBRARY_PATH includes $GISBASE/lib while I'm
building GRASS. If I unset LD_LIBRARY_PATH before building, I get the
second case.

This particular issue should be fixed by r42311. I don't know if this
is related to the problem, but it's something to eliminate.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list