swig expert
Didrik Pinte
dpinte at itae.be
Fri Oct 6 18:06:22 CEST 2006
Le vendredi 06 octobre 2006 à 17:11 +0200, Bernhard Reiter a écrit :
> On Wednesday 04 October 2006 16:18, Didrik Pinte wrote:
> > I've tried to update dbflib.i in order to support encoding conversion
> > using PyString_AsDecodedObject. This seems to work pretty fine now and
> > allow Thuban to work from scratch with any user locale and nearly any
> > file encoding.
> >
> > Because I'm running a Debian/sid system, I had only swig 1.3.29 and no
> > previous version. So, highly motivated, i've updated the dbflib.i and
> > shapelib.i files. It builds fine but I have a little problem when
> > testing the lib.
>
> Can you describe your problems in more detail?
> Best is to also add a patch, so if somebody wants to look into it,
> it can be done right away.
Ok. The patch is here
http://wald.intevation.org/tracker/index.php?func=detail&aid=191&group_id=6&atid=107
Here are the two problems :
[1] this new version does not seem to be happy with unicode objects in
place of str objects. When calling shapefile.ShapeFile(filename) from
Thuban, the library complains about the type of the argument :
--------------------------------------------------------------------------
An unhandled exception occurred:
in method 'new_ShapeFile', argument 1 of type 'char *'
(please report to http://thuban.intevation.org/bugtracker.html)
Traceback (most recent call last):
File
"/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 297, in invoke_command
command.Execute(self.Context())
File
"/home/did/projets/python/thuban/current/thuban/test/../Thuban/UI/command.py", line 121, in Execute
apply(self.function, (context,) + self.args + args, kw)
File
"/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 1072, in call_method
apply(getattr(context.mainwindow, methodname), args)
File
"/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 573, in AddLayer
store = self.application.Session().OpenShapefile(filename)
File
"/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/session.py", line 296, in OpenShapefile
store = ShapefileStore(self, filename)
File
"/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/data.py", line 204, in __init__
self._open_shapefile()
File
"/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/data.py", line 207, in _open_shapefile
self.shapefile = shapelib.ShapeFile(self.FileName())
File
"/home/did/projets/python/thuban/current/thuban/Thuban/../Lib/shapelib.py", line 73, in __init__
this = _shapelib.new_ShapeFile(*args)
TypeError: in method 'new_ShapeFile', argument 1 of type 'char *'
--------------------------------------------------------------------------
I've investigated the problem and found a workaround. In the
Lib/shapelib.py, changing the args tuple at line 73 so that it contains
only str objects and no more unicode ones solve the problem ... That's a
bit strange. I've reported the problem on the swig-user mailing list but
have received no answer at the moment.
[2] The second problem is really strange :
When calling the original libraries/pyshapelib/pytest.py, everything
works fine BUT if you do the following, you get an error :
Original code :
--------------------------------------------------------------------
make_shapefile("testfile")
read_shapefile("testfile")
--------------------------------------------------------------------
Modified code causing the bug :
--------------------------------------------------------------------
make_shapefile("testfile")
import os
os.path.exists("testfile.shp")
read_shapefile("testfile")
--------------------------------------------------------------------
Output :
([10.0, 10.0, 0.0, 0.0], [20.0, 20.0, 0.0, 0.0])
[[(10.0, 10.0), (10.0, 20.0), (20.0, 20.0), (10.0, 10.0)]]
([0.0, 0.0, 0.0, 0.0], [40.0, 40.0, 0.0, 0.0])
[[(0.0, 0.0), (0.0, 40.0), (40.0, 40.0), (40.0, 0.0), (0.0, 0.0)],
[(10.0, 10.0), (20.0, 10.0), (20.0, 20.0), (10.0, 20.0), (10.0, 10.0)]]
Traceback (most recent call last):
File "pytest.py", line 88, in ?
os.path.exists("testfile.shp")
File "/usr/lib/python2.4/posixpath.py", line 171, in exists
st = os.stat(path)
TypeError: shapefile already closed
It is like if the handle was closed but still kept some kind of
reference on the previously opened shapefile.
> > Is there any swig "expert" here that can help me to find a good solution
> > to debug it ?
>
> The result of swig usually is just C and Python so there is no magic in
> debugging it.
> Lately we thought that doing a python-wrapper for shapelib without swig
> is better, because there is so much fine tuning when you use swig for each
> language that you do not win much in using swig.
Any suggestion for a swig-replacement ? Boost.Python ?
Didrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message
=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20061006/bbd9e33d/attachment.bin
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)