Lendfating / leveldb

Automatically exported from code.google.com/p/leveldb
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Insufficient definitions in platform endianness detection #137

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
There is some mess across platforms in how they define endianness, especially 
in number of underscores in definition prefix, i.e. __BYTE_ORDER vs _BYTE_ORDER 
and so on.

The port/port_posix.h tries to handle it, but on some platforms, perticularly, 
on NetBSD 6.x, compiler fails with the following error:

c++ -O2 -I/usr/pkg/include -I. -I./include -fno-builtin-memcmp -D_REENTRANT 
-DOS_NETBSD -DLEVELDB_PLATFORM_POSIX -DSNAPPY -O2 -DNDEBUG        -c 
db/builder.cc -o db/builder.o
In file included from ./port/port.h:14:0,
                 from ./db/filename.h:14,
                 from db/builder.cc:7:
./port/port_posix.h:67:35: error: '__BYTE_ORDER' was not declared in this scope
./port/port_posix.h:67:35: error: '__LITTLE_ENDIAN' was not declared in this 
scope
gmake: *** [db/builder.o] Error 1

Exactly the same case exists for FreeBSD before it was handled in Issue 98 
(https://code.google.com/p/leveldb/issues/detail?id=98).

I'd like to suggest the following patch so the endianness detection could be 
handled a little bit more gracefully:

--- port/port_posix.h.orig      2012-12-27 18:32:31.000000000 +0000
+++ port/port_posix.h
@@ -7,6 +7,13 @@
 #ifndef STORAGE_LEVELDB_PORT_PORT_POSIX_H_
 #define STORAGE_LEVELDB_PORT_PORT_POSIX_H_

+#ifndef __BYTE_ORDER
+#define __BYTE_ORDER   _BYTE_ORDER
+#endif
+#ifndef __LITTLE_ENDIAN
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#endif
+
 #undef PLATFORM_IS_LITTLE_ENDIAN
 #if defined(OS_MACOSX)
   #include <machine/endian.h>

Original issue reported on code.google.com by mike.vol...@gmail.com on 5 Jan 2013 at 9:21

GoogleCodeExporter commented 9 years ago
This helps fix build problems on OpenBSD as well. Would be great if it could be 
included.

Original comment by frankgroeneveld on 6 Mar 2014 at 7:04