From: Paul Ramsey Date: Tue, 20 Aug 2019 16:01:52 +0000 (+0000) Subject: Change run-time endianness checks to compile-time X-Git-Tag: 3.0.0beta1~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01a5c5ece38dad4b7db9b2caf33f96eee4c3bf22;p=postgis Change run-time endianness checks to compile-time Leave 3rd party code unchanged Closes #4439 git-svn-id: http://svn.osgeo.org/postgis/trunk@17740 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/pgsql2shp-core.c b/loader/pgsql2shp-core.c index d486edc94..698281b4d 100644 --- a/loader/pgsql2shp-core.c +++ b/loader/pgsql2shp-core.c @@ -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 @@ getMaxFieldSize(PGconn *conn, char *schema, char *table, char *fname) 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 @@ ShpDumperCreate(SHPDUMPERCONFIG *config) 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 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state) 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); } diff --git a/loader/pgsql2shp-core.h b/loader/pgsql2shp-core.h index 205714b98..b26a28862 100644 --- a/loader/pgsql2shp-core.h +++ b/loader/pgsql2shp-core.h @@ -106,9 +106,6 @@ typedef struct shp_dumper_state /* 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; diff --git a/raster/rt_core/rt_serialize.c b/raster/rt_core/rt_serialize.c index 9f1d35d1c..a3e1ce0a2 100644 --- a/raster/rt_core/rt_serialize.c +++ b/raster/rt_core/rt_serialize.c @@ -728,7 +728,11 @@ rt_raster_deserialize(void* serialized, int header_only) { 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);