]> granicus.if.org Git - postgis/commitdiff
Change run-time endianness checks to compile-time
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 20 Aug 2019 16:01:52 +0000 (16:01 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 20 Aug 2019 16:01:52 +0000 (16:01 +0000)
Leave 3rd party code unchanged
Closes #4439

git-svn-id: http://svn.osgeo.org/postgis/trunk@17740 b70326c6-7e19-0410-871a-916f4a2858ee

loader/pgsql2shp-core.c
loader/pgsql2shp-core.h
raster/rt_core/rt_serialize.c

index d486edc94ad9abf4b74009af5fc7af0fbfcc21ba..698281b4de4ea164ba61e9f279817001281c345e 100644 (file)
@@ -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);
        }
index 205714b98b93133f993aab76d2f8b5c94aca3728..b26a288628ab85a8ffd37ba5aa7667d626a56664 100644 (file)
@@ -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;
 
index 9f1d35d1c581ca3080e731485fd7c910491e1df5..a3e1ce0a2cd3bc47b2c8910bab9982e34a539415 100644 (file)
@@ -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);