[postgis-tickets] r17740 - Change run-time endianness checks to compile-time
Paul Ramsey
pramsey at cleverelephant.ca
Tue Aug 20 09:01:52 PDT 2019
Author: pramsey
Date: 2019-08-20 09:01:52 -0700 (Tue, 20 Aug 2019)
New Revision: 17740
Modified:
trunk/loader/pgsql2shp-core.c
trunk/loader/pgsql2shp-core.h
trunk/raster/rt_core/rt_serialize.c
Log:
Change run-time endianness checks to compile-time
Leave 3rd party code unchanged
Closes #4439
Modified: trunk/loader/pgsql2shp-core.c
===================================================================
--- trunk/loader/pgsql2shp-core.c 2019-08-20 15:17:36 UTC (rev 17739)
+++ trunk/loader/pgsql2shp-core.c 2019-08-20 16:01:52 UTC (rev 17740)
@@ -45,7 +45,6 @@
/* Prototypes */
static int reverse_points(int num_points, double *x, double *y, double *z, double *m);
static int is_clockwise(int num_points,double *x,double *y,double *z);
-static int is_bigendian(void);
static SHPObject *create_point(SHPDUMPERSTATE *state, LWPOINT *lwpoint);
static SHPObject *create_multipoint(SHPDUMPERSTATE *state, LWMPOINT *lwmultipoint);
static SHPObject *create_polygon(SHPDUMPERSTATE *state, LWPOLY *lwpolygon);
@@ -577,21 +576,6 @@
return size;
}
-static int
-is_bigendian(void)
-{
- int test = 1;
-
- if ( (((char *)(&test))[0]) == 1)
- {
- return 0; /*NDR (little_endian) */
- }
- else
- {
- return 1; /*XDR (big_endian) */
- }
-}
-
char *
shapetypename(int num)
{
@@ -1186,7 +1170,6 @@
state->dbffieldnames = NULL;
state->dbffieldtypes = NULL;
state->pgfieldnames = NULL;
- state->big_endian = is_bigendian();
state->message[0] = '\0';
colmap_init(&state->column_map);
@@ -1890,30 +1873,27 @@
if (state->fieldcount > 0)
strcat(state->main_scan_query, ",");
- if (state->big_endian)
+#ifdef WORDS_BIGENDIAN
+ if (state->pgis_major_version > 0)
{
- if (state->pgis_major_version > 0)
- {
- sprintf(buf, "ST_asEWKB(ST_SetSRID(%s::geometry, 0), 'XDR') AS _geoX", quote_identifier(state->geo_col_name) );
- }
- else
- {
- sprintf(buf, "asbinary(%s::geometry, 'XDR') AS _geoX",
- quote_identifier(state->geo_col_name) );
- }
+ sprintf(buf, "ST_asEWKB(ST_SetSRID(%s::geometry, 0), 'XDR') AS _geoX", quote_identifier(state->geo_col_name) );
}
- else /* little_endian */
+ else
{
- if (state->pgis_major_version > 0)
- {
- sprintf(buf, "ST_AsEWKB(ST_SetSRID(%s::geometry, 0), 'NDR') AS _geoX", quote_identifier(state->geo_col_name) ) ;
- }
- else
- {
- sprintf(buf, "asbinary(%s::geometry, 'NDR') AS _geoX",
- quote_identifier(state->geo_col_name) );
- }
+ sprintf(buf, "asbinary(%s::geometry, 'XDR') AS _geoX",
+ quote_identifier(state->geo_col_name) );
}
+#else
+ if (state->pgis_major_version > 0)
+ {
+ sprintf(buf, "ST_AsEWKB(ST_SetSRID(%s::geometry, 0), 'NDR') AS _geoX", quote_identifier(state->geo_col_name) ) ;
+ }
+ else
+ {
+ sprintf(buf, "asbinary(%s::geometry, 'NDR') AS _geoX",
+ quote_identifier(state->geo_col_name) );
+ }
+#endif
strcat(state->main_scan_query, buf);
}
Modified: trunk/loader/pgsql2shp-core.h
===================================================================
--- trunk/loader/pgsql2shp-core.h 2019-08-20 15:17:36 UTC (rev 17739)
+++ trunk/loader/pgsql2shp-core.h 2019-08-20 16:01:52 UTC (rev 17740)
@@ -106,9 +106,6 @@
/* Version of PostGIS being used */
int pgis_major_version;
- /* 0=dumper running on little endian, 1=dumper running on big endian */
- int big_endian;
-
/* OID for geometries */
int geom_oid;
Modified: trunk/raster/rt_core/rt_serialize.c
===================================================================
--- trunk/raster/rt_core/rt_serialize.c 2019-08-20 15:17:36 UTC (rev 17739)
+++ trunk/raster/rt_core/rt_serialize.c 2019-08-20 16:01:52 UTC (rev 17740)
@@ -728,7 +728,11 @@
const uint8_t *beg = NULL;
uint16_t i = 0;
uint16_t j = 0;
- uint8_t littleEndian = isMachineLittleEndian();
+#ifdef WORDS_BIGENDIAN
+ uint8_t littleEndian = LW_FALSE;
+#else
+ uint8_t littleEndian = LW_TRUE;
+#endif
assert(NULL != serialized);
More information about the postgis-tickets
mailing list