diff --git a/cde/lib/DtMmdb/object/oid_t.C b/cde/lib/DtMmdb/object/oid_t.C index 0cc7c567e..f57f18430 100644 --- a/cde/lib/DtMmdb/object/oid_t.C +++ b/cde/lib/DtMmdb/object/oid_t.C @@ -91,7 +91,7 @@ oid_t::oid_t(const char* source, Boolean ascii_format, Boolean swap_order) memcpy((char*)&v_i_code, source, sizeof(v_i_code)); if ( swap_order == true ) - ORDER_SWAP_LONG(v_i_code); + ORDER_SWAP_I_CODE_T(v_i_code); } else { istringstream in((char*)source); @@ -248,7 +248,7 @@ void oid_t::to_char_string(char* sink, Boolean swap_order) const if ( swap_order == true ) { i_code_t x = v_i_code; - ORDER_SWAP_LONG(x); + ORDER_SWAP_I_CODE_T(x); memcpy(sink, (char*)&x, sizeof(x)); } else memcpy(sink, (char*)&v_i_code, sizeof(v_i_code)); diff --git a/cde/lib/DtMmdb/object/oid_t.h b/cde/lib/DtMmdb/object/oid_t.h index a2a0e3649..3b4c0ea0e 100644 --- a/cde/lib/DtMmdb/object/oid_t.h +++ b/cde/lib/DtMmdb/object/oid_t.h @@ -65,6 +65,7 @@ typedef unsigned short c_code_t; typedef mmdb_pos_t i_code_t; #define OID_T_SZ (sizeof(i_code_t)) +#define ORDER_SWAP_I_CODE_T(x) ORDER_SWAP(i_code_t, x) /************************************* // class code root diff --git a/cde/lib/DtMmdb/storage/spointer.h b/cde/lib/DtMmdb/storage/spointer.h index f45641bba..aa13b45e0 100644 --- a/cde/lib/DtMmdb/storage/spointer.h +++ b/cde/lib/DtMmdb/storage/spointer.h @@ -118,7 +118,7 @@ public: }; void swap_order() { - ORDER_SWAP_LONG(fwd_ptr); + ORDER_SWAP_MMDB_POS_T(fwd_ptr); ORDER_SWAP_UINT(header.int_view); swapped = true; }; diff --git a/cde/lib/DtMmdb/utility/macro.h b/cde/lib/DtMmdb/utility/macro.h index 295619f83..f88c3ebfe 100644 --- a/cde/lib/DtMmdb/utility/macro.h +++ b/cde/lib/DtMmdb/utility/macro.h @@ -77,48 +77,18 @@ /* little endian to/from big endian swap macros. */ -#define ORDER_SWAP_LONG(x) \ -{ \ - long tmp_long = x; \ - ((unsigned char*)&x)[0] = ((unsigned char*)&tmp_long)[3]; \ - ((unsigned char*)&x)[1] = ((unsigned char*)&tmp_long)[2]; \ - ((unsigned char*)&x)[2] = ((unsigned char*)&tmp_long)[1]; \ - ((unsigned char*)&x)[3] = ((unsigned char*)&tmp_long)[0]; \ +#define ORDER_SWAP(type, value) \ +{ \ + type tmp = value; \ + int n = sizeof(type) - 1; \ + for (int i = 0; i <= n; ++i) \ + ((uint8_t *)&value)[i] = ((uint8_t *)&tmp)[n - i]; \ } -#define ORDER_SWAP_FLOAT(x) \ -{ \ - float tmp_float = x; \ - ((unsigned char*)&x)[0] = ((unsigned char*)&tmp_float)[3]; \ - ((unsigned char*)&x)[1] = ((unsigned char*)&tmp_float)[2]; \ - ((unsigned char*)&x)[2] = ((unsigned char*)&tmp_float)[1]; \ - ((unsigned char*)&x)[3] = ((unsigned char*)&tmp_float)[0]; \ -} - -#define ORDER_SWAP_INT(x) \ -{ \ - int tmp_uint = x; \ - ((unsigned char*)&x)[0] = ((unsigned char*)&tmp_uint)[3]; \ - ((unsigned char*)&x)[1] = ((unsigned char*)&tmp_uint)[2]; \ - ((unsigned char*)&x)[2] = ((unsigned char*)&tmp_uint)[1]; \ - ((unsigned char*)&x)[3] = ((unsigned char*)&tmp_uint)[0]; \ -} - -#define ORDER_SWAP_UINT(x) \ -{ \ - unsigned int tmp_uint = x; \ - ((unsigned char*)&x)[0] = ((unsigned char*)&tmp_uint)[3]; \ - ((unsigned char*)&x)[1] = ((unsigned char*)&tmp_uint)[2]; \ - ((unsigned char*)&x)[2] = ((unsigned char*)&tmp_uint)[1]; \ - ((unsigned char*)&x)[3] = ((unsigned char*)&tmp_uint)[0]; \ -} - -#define ORDER_SWAP_USHORT(x) \ -{ \ - unsigned short tmp_ushort = x; \ - ((unsigned char*)&x)[0] = ((unsigned char*)&tmp_ushort)[1]; \ - ((unsigned char*)&x)[1] = ((unsigned char*)&tmp_ushort)[0]; \ -} - +#define ORDER_SWAP_FLOAT(x) ORDER_SWAP(float, x) +#define ORDER_SWAP_LONG(x) ORDER_SWAP(long, x) +#define ORDER_SWAP_INT(x) ORDER_SWAP(int, x) +#define ORDER_SWAP_UINT(x) ORDER_SWAP(unsigned int, x) +#define ORDER_SWAP_USHORT(x) ORDER_SWAP(unsigned short, x) +#define ORDER_SWAP_MMDB_POS_T(x) ORDER_SWAP(mmdb_pos_t, x) #endif - diff --git a/cde/lib/DtMmdb/utility/types.h b/cde/lib/DtMmdb/utility/types.h index b7ab58603..33a38beba 100644 --- a/cde/lib/DtMmdb/utility/types.h +++ b/cde/lib/DtMmdb/utility/types.h @@ -47,8 +47,10 @@ #define _types_h 1 #ifdef C_API +#include #include "utility/c_iostream.h" #else +#include #include using namespace std; #endif @@ -60,15 +62,7 @@ typedef char Boolean; typedef void* voidPtr; typedef char* charPtr; -typedef short s_int16; -typedef unsigned short u_int16; - -typedef int s_int32; -typedef unsigned int u_int32; - -typedef long s_long32; - -typedef float s_float32; +typedef intptr_t mmdb_pos_t; enum io_status { done, fail }; @@ -76,14 +70,4 @@ class root; typedef Boolean (*cmp_func_ptr_t)(const void*, const void*); typedef void (*app_func_ptr_t)(const void*); typedef void (*print_func_ptr_t)(ostream&, const void*); - -//enum Boolean { true, false }; - -#if !defined(__linux__) && !defined(CSRG_BASED) -typedef long mmdb_pos_t; -#else -typedef int mmdb_pos_t; -#endif - - #endif