[Thuban-commits] r2806 - branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jan 11 18:39:52 CET 2008


Author: bramz
Date: 2008-01-11 18:39:52 +0100 (Fri, 11 Jan 2008)
New Revision: 2806

Modified:
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
Log:
dbflibmodule.c: dbfopen.c returns integers with width > 10 as FTDouble
to avoid overflow in C int. Also, all integers are read as doubles anyway
(dbfopen.c casts integers to int on the very last moment).  Use 
PyLong_FromDouble to convert all things with 0 decimals to long integers.

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2008-01-09 00:43:45 UTC (rev 2805)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2008-01-11 17:39:52 UTC (rev 2806)
@@ -1,3 +1,10 @@
+2008-01-11  Bram de Greve <bram.degreve at bramz.net>
+
+	* dbflibmodule.c: dbfopen.c returns integers with width > 10 as FTDouble
+	to avoid overflow in C int. Also, all integers are read as doubles anyway
+	(dbfopen.c casts integers to int on the very last moment).  Use 
+	PyLong_FromDouble to convert all things with 0 decimals to long integers.
+
 2008-01-08  Bram de Greve <bram.degreve at bramz.net>
 
 	* shapelibmodule.c, dbflibmodule.c, pyshapelib_common.h:

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2008-01-09 00:43:45 UTC (rev 2805)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c	2008-01-11 17:39:52 UTC (rev 2806)
@@ -220,6 +220,10 @@
 	
 	field_name[0] = '\0';
 	field_type = DBFGetFieldInfo(self->handle, field, field_name, &width, &decimals);
+	if (field_type == FTDouble && decimals == 0)
+	{
+		field_type = FTInteger;
+	}
 	name_object = dbffile_decode_string(self, field_name);
 	
 	return Py_BuildValue("iOii", field_type, name_object, width, decimals);
@@ -266,9 +270,9 @@
 */
 static PyObject* do_read_attribute(DBFFileObject* self, int record, int field, char * name)
 {
-	int type, width;
+	int type, decimals;
 	const char* string;
-	type = DBFGetFieldInfo(self->handle, field, name, &width, NULL);
+	type = DBFGetFieldInfo(self->handle, field, name, NULL, &decimals);
 	
 	/* For strings NULL and the empty string are indistinguishable
 	* in DBF files. We prefer empty strings instead for backwards
@@ -288,9 +292,13 @@
 			if (string) return dbffile_decode_string(self, string);
 
 		case FTInteger:
-			return PyInt_FromLong((long)DBFReadIntegerAttribute(self->handle, record, field));
+			return PyLong_FromDouble(DBFReadDoubleAttribute(self->handle, record, field));
 
 		case FTDouble:
+			if (decimals == 0)
+			{
+				return PyLong_FromDouble(DBFReadDoubleAttribute(self->handle, record, field));
+			}
 			return PyFloat_FromDouble(DBFReadDoubleAttribute(self->handle, record, field));
 			
 		case FTLogical:



More information about the Thuban-commits mailing list