[postgis-tickets] r17582 - Strip out getMachineEndian() in favour of configure-time check
Paul Ramsey
pramsey at cleverelephant.ca
Tue Jul 2 12:47:07 PDT 2019
Author: pramsey
Date: 2019-07-02 12:47:06 -0700 (Tue, 02 Jul 2019)
New Revision: 17582
Modified:
trunk/liblwgeom/liblwgeom_internal.h
trunk/liblwgeom/lookup3.c
trunk/liblwgeom/lwin_wkb.c
trunk/liblwgeom/lwout_wkb.c
trunk/liblwgeom/lwutil.c
Log:
Strip out getMachineEndian() in favour of configure-time check
Modified: trunk/liblwgeom/liblwgeom_internal.h
===================================================================
--- trunk/liblwgeom/liblwgeom_internal.h 2019-07-02 09:48:14 UTC (rev 17581)
+++ trunk/liblwgeom/liblwgeom_internal.h 2019-07-02 19:47:06 UTC (rev 17582)
@@ -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);
Modified: trunk/liblwgeom/lookup3.c
===================================================================
--- trunk/liblwgeom/lookup3.c 2019-07-02 09:48:14 UTC (rev 17581)
+++ trunk/liblwgeom/lookup3.c 2019-07-02 19:47:06 UTC (rev 17582)
@@ -47,7 +47,10 @@
* 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 @@
#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);
Modified: trunk/liblwgeom/lwin_wkb.c
===================================================================
--- trunk/liblwgeom/lwin_wkb.c 2019-07-02 09:48:14 UTC (rev 17581)
+++ trunk/liblwgeom/lwin_wkb.c 2019-07-02 19:47:06 UTC (rev 17582)
@@ -689,17 +689,14 @@
/* 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);
LWDEBUGF(4,"Got WKB type number: 0x%X", wkb_type);
Modified: trunk/liblwgeom/lwout_wkb.c
===================================================================
--- trunk/liblwgeom/lwout_wkb.c 2019-07-02 09:48:14 UTC (rev 17581)
+++ trunk/liblwgeom/lwout_wkb.c 2019-07-02 19:47:06 UTC (rev 17582)
@@ -182,8 +182,8 @@
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 @@
if ( ! (variant & WKB_NDR || variant & WKB_XDR) ||
(variant & WKB_NDR && variant & WKB_XDR) )
{
- if ( getMachineEndian() == NDR )
+ if (IS_BIG_ENDIAN)
+ variant = variant | WKB_XDR;
+ else
variant = variant | WKB_NDR;
- else
- variant = variant | WKB_XDR;
}
/* Allocate the buffer */
Modified: trunk/liblwgeom/lwutil.c
===================================================================
--- trunk/liblwgeom/lwutil.c 2019-07-02 09:48:14 UTC (rev 17581)
+++ trunk/liblwgeom/lwutil.c 2019-07-02 19:47:06 UTC (rev 17582)
@@ -330,16 +330,6 @@
}
-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)
{
More information about the postgis-tickets
mailing list