From: Paul Ramsey Date: Tue, 2 Jul 2019 19:47:06 +0000 (+0000) Subject: Strip out getMachineEndian() in favour of configure-time check X-Git-Tag: 3.0.0alpha4~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=084e0f0c94496c31a9abd72bc2140d2e6131407d;p=postgis Strip out getMachineEndian() in favour of configure-time check git-svn-id: http://svn.osgeo.org/postgis/trunk@17582 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h index c6565b06c..1e748faab 100644 --- a/liblwgeom/liblwgeom_internal.h +++ b/liblwgeom/liblwgeom_internal.h @@ -123,9 +123,11 @@ #ifdef WORDS_BIGENDIAN #define SIZE_GET(varsize) ((varsize) & 0x3FFFFFFF) #define SIZE_SET(varsize, len) ((varsize) = ((len) & 0x3FFFFFFF)) +#define IS_BIG_ENDIAN 1 #else #define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF) #define SIZE_SET(varsize, len) ((varsize) = (((uint32_t)(len)) << 2)) +#define IS_BIG_ENDIAN 0 #endif /** @@ -165,7 +167,6 @@ /* Machine endianness */ #define XDR 0 /* big endian */ #define NDR 1 /* little endian */ -extern char getMachineEndian(void); uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2); diff --git a/liblwgeom/lookup3.c b/liblwgeom/lookup3.c index e7b6e7c2a..67f4da21d 100644 --- a/liblwgeom/lookup3.c +++ b/liblwgeom/lookup3.c @@ -47,7 +47,10 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. * My best guess at if you are big-endian or little-endian. This may * need adjustment. */ -#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ +#if (defined(WORDS_BIGENDIAN)) +# define HASH_LITTLE_ENDIAN 0 +# define HASH_BIG_ENDIAN 1 +#elif (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ __BYTE_ORDER == __LITTLE_ENDIAN) || \ (defined(i386) || defined(__i386__) || defined(__i486__) || \ defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) @@ -67,7 +70,6 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #define hashmask(n) (hashsize(n)-1) #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) - #if 0 static uint32_t hashword(const uint32_t *k, size_t length, uint32_t initval); static void hashword2 (const uint32_t *k, size_t length, uint32_t *pc, uint32_t *pb); diff --git a/liblwgeom/lwin_wkb.c b/liblwgeom/lwin_wkb.c index c7e5c905c..ede85b8b9 100644 --- a/liblwgeom/lwin_wkb.c +++ b/liblwgeom/lwin_wkb.c @@ -689,16 +689,13 @@ LWGEOM* lwgeom_from_wkb_state(wkb_parse_state *s) /* Check the endianness of our input */ s->swap_bytes = LW_FALSE; - if( getMachineEndian() == NDR ) /* Machine arch is little */ - { - if ( ! wkb_little_endian ) /* Data is big! */ - s->swap_bytes = LW_TRUE; - } - else /* Machine arch is big */ - { - if ( wkb_little_endian ) /* Data is little! */ - s->swap_bytes = LW_TRUE; - } + + /* Machine arch is big endian, request is for little */ + if (IS_BIG_ENDIAN && wkb_little_endian) + s->swap_bytes = LW_TRUE; + /* Machine arch is little endian, request is for big */ + else if ((!IS_BIG_ENDIAN) && (!wkb_little_endian)) + s->swap_bytes = LW_TRUE; /* Read the type number */ wkb_type = integer_from_wkb_state(s); diff --git a/liblwgeom/lwout_wkb.c b/liblwgeom/lwout_wkb.c index 4d4a55863..803079230 100644 --- a/liblwgeom/lwout_wkb.c +++ b/liblwgeom/lwout_wkb.c @@ -182,8 +182,8 @@ static uint8_t* endian_to_wkb_buf(uint8_t *buf, uint8_t variant) static inline int wkb_swap_bytes(uint8_t variant) { /* If requested variant matches machine arch, we don't have to swap! */ - if ( ((variant & WKB_NDR) && (getMachineEndian() == NDR)) || - ((! (variant & WKB_NDR)) && (getMachineEndian() == XDR)) ) + if (((variant & WKB_NDR) && !IS_BIG_ENDIAN) || + ((!(variant & WKB_NDR)) && IS_BIG_ENDIAN)) { return LW_FALSE; } @@ -826,10 +826,10 @@ uint8_t* lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out) if ( ! (variant & WKB_NDR || variant & WKB_XDR) || (variant & WKB_NDR && variant & WKB_XDR) ) { - if ( getMachineEndian() == NDR ) - variant = variant | WKB_NDR; - else + if (IS_BIG_ENDIAN) variant = variant | WKB_XDR; + else + variant = variant | WKB_NDR; } /* Allocate the buffer */ diff --git a/liblwgeom/lwutil.c b/liblwgeom/lwutil.c index af756f2d3..cbd48d190 100644 --- a/liblwgeom/lwutil.c +++ b/liblwgeom/lwutil.c @@ -330,16 +330,6 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int } -char -getMachineEndian(void) -{ - static int endian_check_int = 1; /* don't modify this!!! */ - - return *((char *) &endian_check_int); /* 0 = big endian | xdr, - * 1 = little endian | ndr - */ -} - void error_if_srid_mismatch(int32_t srid1, int32_t srid2) {