Merge remote branch 'origin/topic/gregor/fix-val-64bit'

* origin/topic/gregor/fix-val-64bit:
  Fixing endianess error in XDR when data is not 4-byte aligned.
  Fix for Val constructor with new int64 typedefs.
  New fix for OS X 10.5 compile error wrt llabs()
  Revert "Fix for OS X 10.5 compile error wrt llabs()"
This commit is contained in:
Robin Sommer 2011-02-25 09:53:59 -08:00
commit 9b94218c63
9 changed files with 28 additions and 69 deletions

11
CHANGES
View file

@ -1,3 +1,14 @@
1.6-dev.47 Fri Feb 25 10:40:22 PST 2011
- Fixing endianess error in XDR when data is not 4-byte aligned.
(Gregor Maier)
- Fix for Val constructor with new int64 typedefs. (Gregor Maier)
- Updated fix for OS X 10.5 compile error wrt llabs(). (Gregor Maier)
- Fix more compiler warning wrt printf format strings. (Gregor Maier)
1.6-dev.45 Tue Feb 8 21:28:01 PST 2011 1.6-dev.45 Tue Feb 8 21:28:01 PST 2011
- Fixing a number of compiler warnings. (Seth Hall and Robin Sommer) - Fixing a number of compiler warnings. (Seth Hall and Robin Sommer)

View file

@ -1 +1 @@
1.6-dev.45 1.6-dev.47

View file

@ -1,6 +1,3 @@
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
# alternate malloc is faster for FreeBSD, but needs more testing # alternate malloc is faster for FreeBSD, but needs more testing
# need to add way to set this from the command line # need to add way to set this from the command line
@ -10,28 +7,6 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(USE_NMALLOC true) set(USE_NMALLOC true)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# The following may have a greater scope than just Darwin
# (i.e. any platform w/ GCC < 4.1.0), but I've only seen
# it on OS X 10.5, which has GCC 4.0.1, so the workaround
# will be stuck here for now.
#
# See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13943
check_cxx_source_compiles("
#include <math.h>
#include <cstdlib>
using namespace std;
int main() {
llabs(1);
return 0;
}
" darwin_llabs_works)
if (NOT darwin_llabs_works)
# abs() should be used in this case, the long long version should
# exist in the __gnu_cxx namespace
set(DARWIN_NO_LLABS true)
endif ()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(HAVE_LINUX true) set(HAVE_LINUX true)
@ -50,7 +25,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "irix")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "ultrix") elseif (${CMAKE_SYSTEM_NAME} MATCHES "ultrix")
list(APPEND CMAKE_C_FLAGS -std1 -g3) list(APPEND CMAKE_C_FLAGS -std1 -g3)
list(APPEND CMAKE_CXX_FLAGS -std1 -g3) list(APPEND CMAKE_CXX_FLAGS -std1 -g3)
include(CheckCSourceCompiles)
check_c_source_compiles(" check_c_source_compiles("
#include <sys/types.h> #include <sys/types.h>
int main() { int main() {

View file

@ -146,6 +146,3 @@
/* Define u_int8_t */ /* Define u_int8_t */
#define u_int8_t @U_INT8_T@ #define u_int8_t @U_INT8_T@
/* Whether llabs will be ambiguous in stdlib.h and cstdlib headers */
#cmakedefine DARWIN_NO_LLABS

View file

@ -369,25 +369,25 @@ bool XMLSerializationFormat::Write(char v, const char* tag)
bool XMLSerializationFormat::Write(uint16 v, const char* tag) bool XMLSerializationFormat::Write(uint16 v, const char* tag)
{ {
const char* tmp = fmt("%u", v); const char* tmp = fmt("%"PRIu16, v);
return WriteElem(tag, "uint16", tmp, strlen(tmp)); return WriteElem(tag, "uint16", tmp, strlen(tmp));
} }
bool XMLSerializationFormat::Write(uint32 v, const char* tag) bool XMLSerializationFormat::Write(uint32 v, const char* tag)
{ {
const char* tmp = fmt("%u", v); const char* tmp = fmt("%"PRIu32, v);
return WriteElem(tag, "uint32", tmp, strlen(tmp)); return WriteElem(tag, "uint32", tmp, strlen(tmp));
} }
bool XMLSerializationFormat::Write(uint64 v, const char* tag) bool XMLSerializationFormat::Write(uint64 v, const char* tag)
{ {
const char* tmp = fmt("%llu", v); const char* tmp = fmt("%"PRIu64, v);
return WriteElem(tag, "uint64", tmp, strlen(tmp)); return WriteElem(tag, "uint64", tmp, strlen(tmp));
} }
bool XMLSerializationFormat::Write(int64 v, const char* tag) bool XMLSerializationFormat::Write(int64 v, const char* tag)
{ {
const char* tmp = fmt("%lld", v); const char* tmp = fmt("%"PRId64, v);
return WriteElem(tag, "int64", tmp, strlen(tmp)); return WriteElem(tag, "int64", tmp, strlen(tmp));
} }

View file

@ -515,11 +515,12 @@ Val* Val::SizeVal() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case TYPE_INTERNAL_INT: case TYPE_INTERNAL_INT:
#ifdef DARWIN_NO_LLABS // Return abs value. However abs() only works on ints and llabs
return new Val(abs(val.int_val), TYPE_COUNT); // doesn't work on Mac OS X 10.5. So we do it by hand
#else if ( val.int_val < 0 )
return new Val(llabs(val.int_val), TYPE_COUNT); return new Val(-val.int_val, TYPE_COUNT);
#endif else
return new Val(val.int_val, TYPE_COUNT);
case TYPE_INTERNAL_UNSIGNED: case TYPE_INTERNAL_UNSIGNED:
return new Val(val.uint_val, TYPE_COUNT); return new Val(val.uint_val, TYPE_COUNT);

View file

@ -87,7 +87,7 @@ public:
#endif #endif
} }
Val(int i, TypeTag t) Val(int32 i, TypeTag t)
{ {
val.int_val = bro_int_t(i); val.int_val = bro_int_t(i);
type = base_type(t); type = base_type(t);
@ -97,27 +97,7 @@ public:
#endif #endif
} }
Val(long i, TypeTag t) Val(uint32 u, TypeTag t)
{
val.int_val = bro_int_t(i);
type = base_type(t);
attribs = 0;
#ifdef DEBUG
bound_id = 0;
#endif
}
Val(unsigned int u, TypeTag t)
{
val.uint_val = bro_uint_t(u);
type = base_type(t);
attribs = 0;
#ifdef DEBUG
bound_id = 0;
#endif
}
Val(unsigned long u, TypeTag t)
{ {
val.uint_val = bro_uint_t(u); val.uint_val = bro_uint_t(u);
type = base_type(t); type = base_type(t);

View file

@ -17,13 +17,13 @@ uint32 extract_XDR_uint32(const u_char*& buf, int& len)
return 0; return 0;
} }
uint32 bits32 = XDR_aligned(buf) ? *(uint32*) buf : // Takes care of alignment and endianess differences.
((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); uint32 bits32 = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
buf += 4; buf += 4;
len -= 4; len -= 4;
return ntohl(bits32); return bits32;
} }
double extract_XDR_uint64_as_double(const u_char*& buf, int& len) double extract_XDR_uint64_as_double(const u_char*& buf, int& len)

View file

@ -10,11 +10,6 @@
#include "util.h" #include "util.h"
inline int XDR_aligned(const u_char* buf)
{
return (((unsigned long) buf) & 0x3) == 0;
}
extern uint32 extract_XDR_uint32(const u_char*& buf, int& len); extern uint32 extract_XDR_uint32(const u_char*& buf, int& len);
extern double extract_XDR_uint64_as_double(const u_char*& buf, int& len); extern double extract_XDR_uint64_as_double(const u_char*& buf, int& len);
extern double extract_XDR_time(const u_char*& buf, int& len); extern double extract_XDR_time(const u_char*& buf, int& len);