[Gdal-dev] (OGR) shapelib on ARM Linux bugfix

Etienne Dube etdube at globetrotter.net
Wed Apr 7 01:12:55 EDT 2004

Hello everyone,

While developping a GPS mapping app for Qtopia / Opie, I stumbled across a 
problem with the OGR Shapefile driver, occuring only on ARM CPUs (the program 
runs fine on my x86 desktop.) The SHPOpen() function seems to read garbage 
values instead of geographic coordinates from the ESRI shapefile. I was 
suspecting a byte ordering problem with double precision floating point 
values, but the ARM family uses little-endian byte ordering, like x86. The 
catch is, ARMs don't have a numerical coprocessor; floating point operations 
are emulated in software. For some reasons, the FPU emulation in ARM Linux 
uses a rather strange byte-ordering scheme for double precision numbers (see 
http://handhelds.org/hypermail/ipaq/163/16349.html and 
http://handhelds.org/hypermail/ipaq/163/16352.html). Each 32-bit word in the 
64-bit double value is stored little-endian, but the most significative 
32-bit word comes last in memory ("big-wordian").

I had to do a major revamping of shpopen.c in order to add support for ARM. I 
added a few functions to detect the three possible double precision byte 
orders (big-endian, little-endian, and ARM's little-endian/big-wordian) and 
swap the double values according to it. It adds a _slight_ performance hit 
compared to the current implementation of shpopen.c, but this will be 
negligible for virtually all applications.

The modified code was briefly tested on both ARM and x86 systems, I'll do a 
few more tests to see if it doesn't break file writing / creation (no major 
changes were done to the logic of the program, except for things related to 
byte ordering, so it should be all right.) As I don't have a PPC/Sparc 
machine, I didn't do any test to see if it still works with big-endian CPU 
(I'm pretty sure it will.)

I included the patch (diff'ed against the most recent shpopen.c from the OGR 
CVS tree) with this message. Frank, any comments or questions on this? Feel 
free to commit the changes back to the OGR tree.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: shpopen.patch
Type: text/x-diff
Size: 29152 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040407/170f77aa/shpopen.bin

More information about the Gdal-dev mailing list