Commit ccb089d3 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1611 toku_htod32 and toku_dtoh32 replace htonl and ntohl (for internal use).

d stands for disk-byte-order (as opposed to n for network-byte-order)
Disk-byte-order set as Intel byte order for now

git-svn-id: file:///svn/toku/tokudb@10694 c7de825b-a66e-492c-adef-691d508d4ae1
parent d9f7432a
......@@ -44,10 +44,10 @@ ssize_t bread_backwards(BREAD br, void *vbuf, size_t nbytes) {
u_int32_t compressed_length_n, uncompressed_length_n;
assert(br->fileoff>=i4); // there better be the three lengths plus the compressed data.
{ ssize_t r = pread(br->fd, &compressed_length_n, i4, br->fileoff- i4); assert(r==i4); }
u_int32_t compressed_length = ntohl(compressed_length_n);
u_int32_t compressed_length = toku_dtoh32(compressed_length_n);
assert(br->fileoff >= compressed_length + 3*i4);
{ ssize_t r = pread(br->fd, &uncompressed_length_n, i4, br->fileoff-2*i4); assert(r==i4); }
u_int32_t uncompressed_length = ntohl(uncompressed_length_n);
u_int32_t uncompressed_length = toku_dtoh32(uncompressed_length_n);
char *XMALLOC_N(compressed_length, zbuf);
{
ssize_t r = pread(br->fd, zbuf, compressed_length, br->fileoff- compressed_length -2*i4);
......
......@@ -278,7 +278,7 @@ enum brt_layout_version_e {
BRT_LAYOUT_VERSION_7 = 7, // Diff from 6 to 7: Add exact-bit to leafentry_estimate #818, add magic to header #22, add per-subdatase flags #333
BRT_LAYOUT_VERSION_8 = 8, // Diff from 7 to 8: Use murmur instead of crc32. We are going to make a simplification and stop supporting version 7 and before. Current As of Beta 1.0.6
BRT_LAYOUT_VERSION_9 = 9, // Diff from 8 to 9: Variable-sized blocks and compression.
BRT_LAYOUT_VERSION_10 = 10, // Diff from 9 to 10: Variable number of compressed sub-blocks per block
BRT_LAYOUT_VERSION_10 = 10, // Diff from 9 to 10: Variable number of compressed sub-blocks per block, disk byte order == intel byte order
BRT_ANTEULTIMATE_VERSION, // the version after the most recent version
BRT_LAYOUT_VERSION = BRT_ANTEULTIMATE_VERSION-1 // A hack so I don't have to change this line.
};
......
......@@ -457,10 +457,10 @@ int toku_serialize_brtnode_to (int fd, BLOCKNUM blocknum, BRTNODE node, struct b
// write out the compression header
uint32_t *compressed_header_ptr = (uint32_t *)(compressed_buf + uncompressed_magic_len);
if (node->layout_version >= BRT_LAYOUT_VERSION_10)
*compressed_header_ptr++ = toku_htonl(n_sub_blocks);
*compressed_header_ptr++ = toku_htod32(n_sub_blocks);
for (i=0; i<n_sub_blocks; i++) {
compressed_header_ptr[0] = toku_htonl(sub_block_sizes[i].compressed_size);
compressed_header_ptr[1] = toku_htonl(sub_block_sizes[i].uncompressed_size);
compressed_header_ptr[0] = toku_htod32(sub_block_sizes[i].compressed_size);
compressed_header_ptr[1] = toku_htod32(sub_block_sizes[i].uncompressed_size);
compressed_header_ptr += 2;
}
......@@ -591,7 +591,7 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash
// get the layout_version
unsigned char *uncompressed_header = compressed_block;
int layout_version = toku_ntohl(*(uint32_t*)(uncompressed_header+uncompressed_version_offset));
int layout_version = toku_dtoh32(*(uint32_t*)(uncompressed_header+uncompressed_version_offset));
// get the number of compressed sub blocks
int n_sub_blocks;
......@@ -600,7 +600,7 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash
n_sub_blocks = 1;
compression_header_offset = uncompressed_magic_len;
} else {
n_sub_blocks = toku_ntohl(*(u_int32_t*)(&uncompressed_header[uncompressed_magic_len]));
n_sub_blocks = toku_dtoh32(*(u_int32_t*)(&uncompressed_header[uncompressed_magic_len]));
compression_header_offset = uncompressed_magic_len + 4;
}
assert(0 < n_sub_blocks);
......@@ -610,9 +610,9 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash
struct sub_block_sizes sub_block_sizes[n_sub_blocks];
for (i=0; i<n_sub_blocks; i++) {
u_int32_t compressed_size = toku_ntohl(*(u_int32_t*)(&uncompressed_header[compression_header_offset+8*i]));
u_int32_t compressed_size = toku_dtoh32(*(u_int32_t*)(&uncompressed_header[compression_header_offset+8*i]));
if (compressed_size<=0 || compressed_size>(1<<30)) { r = toku_db_badformat(); goto died0; }
u_int32_t uncompressed_size = toku_ntohl(*(u_int32_t*)(&uncompressed_header[compression_header_offset+8*i+4]));
u_int32_t uncompressed_size = toku_dtoh32(*(u_int32_t*)(&uncompressed_header[compression_header_offset+8*i+4]));
if (0) printf("Block %" PRId64 " Compressed size = %u, uncompressed size=%u\n", blocknum.b, compressed_size, uncompressed_size);
if (uncompressed_size<=0 || uncompressed_size>(1<<30)) { r = toku_db_badformat(); goto died0; }
......@@ -1079,7 +1079,7 @@ deserialize_brtheader (u_int32_t size, int fd, DISKOFF off, struct brt_header **
u_int32_t x1764 = x1764_memory(tbuf, block_translation_size_on_disk - 4);
u_int64_t offset = block_translation_size_on_disk - 4;
//printf("%s:%d read from %ld (x1764 offset=%ld) size=%ld\n", __FILE__, __LINE__, block_translation_address_on_disk, offset, block_translation_size_on_disk);
u_int32_t stored_x1764 = toku_ntohl(*(int*)(tbuf + offset));
u_int32_t stored_x1764 = toku_dtoh32(*(int*)(tbuf + offset));
assert(x1764 == stored_x1764);
}
// Create table and read in data.
......@@ -1142,7 +1142,7 @@ int toku_deserialize_brtheader_from (int fd, BLOCKNUM blocknum, struct brt_heade
if (r!=12) return EINVAL;
assert(memcmp(magic,"tokudata",8)==0);
// It's version 7 or later, and the magi clooks OK
return deserialize_brtheader(toku_ntohl(*(int*)(&magic[8])), fd, offset, brth);
return deserialize_brtheader(toku_dtoh32(*(int*)(&magic[8])), fd, offset, brth);
}
unsigned int toku_brt_pivot_key_len (BRT brt, struct kv_pair *pk) {
......@@ -1217,7 +1217,7 @@ read_int (int fd, toku_off_t *at, u_int32_t *result) {
ssize_t r = pread(fd, &v, 4, *at);
if (r<0) return errno;
assert(r==4);
*result = toku_ntohl(v);
*result = toku_dtoh32(v);
(*at) += 4;
return 0;
}
......
......@@ -4365,7 +4365,7 @@ toku_dump_brtnode (FILE *file, BRT brt, BLOCKNUM blocknum, int depth, bytevec lo
FIFO_ITERATE(BNC_BUFFER(node,i), key, keylen, data, datalen, type, xid,
{
data=data; datalen=datalen; keylen=keylen;
fprintf(file, "%*s xid=%"PRIu64" %u (type=%d)\n", depth+2, "", xid, (unsigned)toku_ntohl(*(int*)key), type);
fprintf(file, "%*s xid=%"PRIu64" %u (type=%d)\n", depth+2, "", xid, (unsigned)toku_dtoh32(*(int*)key), type);
//assert(strlen((char*)key)+1==keylen);
//assert(strlen((char*)data)+1==datalen);
});
......@@ -4373,7 +4373,7 @@ toku_dump_brtnode (FILE *file, BRT brt, BLOCKNUM blocknum, int depth, bytevec lo
for (i=0; i<node->u.n.n_children; i++) {
fprintf(file, "%*schild %d\n", depth, "", i);
if (i>0) {
fprintf(file, "%*spivot %d len=%u %u\n", depth+1, "", i-1, node->u.n.childkeys[i-1]->keylen, (unsigned)toku_ntohl(*(int*)&node->u.n.childkeys[i-1]->key));
fprintf(file, "%*spivot %d len=%u %u\n", depth+1, "", i-1, node->u.n.childkeys[i-1]->keylen, (unsigned)toku_dtoh32(*(int*)&node->u.n.childkeys[i-1]->key));
}
toku_dump_brtnode(file, brt, BNC_BLOCKNUM(node, i), depth+4,
(i==0) ? lorange : node->u.n.childkeys[i-1]->key,
......
......@@ -33,7 +33,7 @@ measure_header (int fd, toku_off_t off, // read header from this offset
r=pread(fd, fbuf, 12, off);
assert(r==12);
assert(memcmp(fbuf,"tokudata",8)==0);
int bsize = ntohl(*(u_int32_t*)(fbuf+8));
int bsize = toku_dtoh32(*(u_int32_t*)(fbuf+8));
//printf("Bsize=%d\n", bsize);
(*usize)+=bsize;
assert(bsize<=NSIZE);
......@@ -59,8 +59,8 @@ measure_node (int fd, toku_off_t off, // read header from this offset
assert(r==24);
//printf("fbuf[0..7]=%c%c%c%c%c%c%c%c\n", fbuf[0], fbuf[1], fbuf[2], fbuf[3], fbuf[4], fbuf[5], fbuf[6], fbuf[7]);
assert(memcmp(fbuf,"tokuleaf",8)==0 || memcmp(fbuf, "tokunode", 8)==0);
assert(8==ntohl(*(u_int32_t*)(fbuf+8))); // check file version
int bsize = ntohl(*(u_int32_t*)(fbuf+20));
assert(8==toku_dtoh32(*(u_int32_t*)(fbuf+8))); // check file version
int bsize = toku_dtoh32(*(u_int32_t*)(fbuf+20));
//printf("Bsize=%d\n", bsize);
(*usize)+=bsize;
......
......@@ -6,10 +6,10 @@
// Calculate the fingerprint for a kvpair
static void toku_calc_more_murmur_kvpair (struct x1764 *mm, const void *key, int keylen, const void *val, int vallen) {
int i;
i = toku_htonl(keylen);
i = toku_htod32(keylen);
x1764_add(mm, (void*)&i, 4);
x1764_add(mm, key, keylen);
i = toku_htonl(vallen);
i = toku_htod32(vallen);
x1764_add(mm, (void*)&i, 4);
x1764_add(mm, val, vallen);
}
......@@ -27,8 +27,8 @@ u_int32_t toku_calccrc32_kvpair_struct (const struct kv_pair *kvp) {
u_int32_t toku_calc_fingerprint_cmd (u_int32_t type, TXNID xid, const void *key, u_int32_t keylen, const void *val, u_int32_t vallen) {
unsigned char type_c = (unsigned char)type;
unsigned int a = toku_htonl(xid>>32);
unsigned int b = toku_htonl(xid&0xffffffff);
unsigned int a = toku_htod32(xid>>32);
unsigned int b = toku_htod32(xid&0xffffffff);
struct x1764 mm;
x1764_init(&mm);
x1764_add(&mm, &type_c, 1);
......
......@@ -157,7 +157,7 @@ void murmur_add (struct murmur *mm, const void * key, unsigned int len) {
// We've used up the partial bytes at the beginning of k.
assert(mm->n_bytes_in_k==0);
while (len >= 4) {
u_int32_t k = ntohl(*(u_int32_t *)data);
u_int32_t k = toku_dtoh32(*(u_int32_t *)data);
//printf(" oldh=%08x k=%08x", h, k);
k *= m;
......
......@@ -157,7 +157,7 @@ inline void murmur_add (struct murmur *mm, const void * key, unsigned int len) {
// We've used up the partial bytes at the beginning of k.
assert(mm->n_bytes_in_k==0);
while (len >= 4) {
u_int32_t k = ntohl(*(u_int32_t *)data);
u_int32_t k = toku_dtoh32(*(u_int32_t *)data);
//printf(" oldh=%08x k=%08x", h, k);
k *= m;
......
......@@ -57,7 +57,7 @@ static inline enum le_state get_le_state(LEAFENTRY le) {
static inline void putint (unsigned char *p, u_int32_t i) {
#if 1
*(u_int32_t*)p = toku_htonl(i);
*(u_int32_t*)p = toku_htod32(i);
#else
p[0]=(i>>24)&0xff;
p[1]=(i>>16)&0xff;
......@@ -71,7 +71,7 @@ static inline void putint64 (unsigned char *p, u_int64_t i) {
}
static inline u_int32_t getint (unsigned char *p) {
#if 1
return toku_ntohl(*(u_int32_t*)p);
return toku_dtoh32(*(u_int32_t*)p);
#else
return (p[0]<<24)+(p[1]<<16)+(p[2]<<8)+(p[3]);
#endif
......
......@@ -155,7 +155,7 @@ static int open_logfile (TOKULOGGER logger) {
if (logger->fd==-1) return errno;
}
logger->next_log_file_number++;
int version_l = toku_htonl(log_format_version);
int version_l = toku_htod32(log_format_version);
r = write_it(logger->fd, "tokulogg", 8); if (r!=8) return errno;
r = write_it(logger->fd, &version_l, 4); if (r!=4) return errno;
logger->fsynced_lsn = logger->written_lsn;
......@@ -834,8 +834,8 @@ int toku_read_and_print_logmagic (FILE *f, u_int32_t *versionp) {
if (r!=4) {
return DB_BADFORMAT;
}
//printf("tokulog v.%d\n", toku_ntohl(version));
*versionp=toku_ntohl(version);
//printf("tokulog v.%d\n", toku_dtoh32(version));
*versionp=toku_dtoh32(version);
}
return 0;
}
......@@ -1058,7 +1058,7 @@ int toku_maybe_spill_rollbacks (TOKUTXN txn) {
assert(r==Z_OK);
}
{
u_int32_t v = htonl(compressed_len);
u_int32_t v = toku_htod32(compressed_len);
ssize_t r = write_it(txn->rollentry_fd, &v, sizeof(v)); assert(r==sizeof(v));
}
{
......@@ -1067,11 +1067,11 @@ int toku_maybe_spill_rollbacks (TOKUTXN txn) {
assert(r==(ssize_t)compressed_len);
}
{
u_int32_t v = htonl(w.ndone);
u_int32_t v = toku_htod32(w.ndone);
ssize_t r = write_it(txn->rollentry_fd, &v, sizeof(v)); assert(r==sizeof(v));
}
{
u_int32_t v = htonl(compressed_len);
u_int32_t v = toku_htod32(compressed_len);
ssize_t r = write_it(txn->rollentry_fd, &v, sizeof(v)); assert(r==sizeof(v));
}
toku_free(compressed_buf);
......@@ -1087,7 +1087,7 @@ int toku_maybe_spill_rollbacks (TOKUTXN txn) {
int toku_read_rollback_backwards(BREAD br, struct roll_entry **item, MEMARENA ma) {
u_int32_t nbytes_n; ssize_t sr;
if ((sr=bread_backwards(br, &nbytes_n, 4))!=4) { assert(sr<0); return errno; }
u_int32_t n_bytes=toku_ntohl(nbytes_n);
u_int32_t n_bytes=toku_dtoh32(nbytes_n);
unsigned char *buf = malloc_in_memarena(ma, n_bytes);
if (buf==0) return errno;
if ((sr=bread_backwards(br, buf, n_bytes-4))!=(ssize_t)n_bytes-4) { assert(sr<0); return errno; }
......
......@@ -23,7 +23,7 @@ static inline unsigned int rbuf_char (struct rbuf *r) {
static unsigned int rbuf_int (struct rbuf *r) {
#if 1
assert(r->ndone+4 <= r->size);
u_int32_t result = toku_ntohl(*(u_int32_t*)(r->buf+r->ndone)); // This only works on machines where unaligned loads are OK.
u_int32_t result = toku_dtoh32(*(u_int32_t*)(r->buf+r->ndone)); // This only works on machines where unaligned loads are OK.
r->ndone+=4;
return result;
#else
......
......@@ -36,7 +36,7 @@ test (int seed) {
assert(fd>=0);
for (i=0; i<RECORDS; i++) {
sizes[i] = 1+ random()%RECORDLEN;
sizesn[i] = toku_htonl(sizes[i]);
sizesn[i] = toku_htod32(sizes[i]);
int j;
for (j=0; j<sizes[i]; j++) {
buf[i][j] = wrotedata[nwrote++] = (char)random();
......@@ -44,7 +44,7 @@ test (int seed) {
uLongf compressed_size = compressBound(sizes[i]);
Bytef compressed_buf[compressed_size];
{ int r = compress2(compressed_buf, &compressed_size, (Bytef*)(buf[i]), sizes[i], 1); assert(r==Z_OK); }
u_int32_t compressed_size_n = htonl(compressed_size);
u_int32_t compressed_size_n = toku_htod32(compressed_size);
{ int r = write(fd, &compressed_size_n, 4); assert(r==4); }
{ int r = write(fd, compressed_buf, compressed_size); assert(r==(int)compressed_size); }
{ int r = write(fd, &sizesn[i], 4); assert(r==4); } // the uncompressed size
......
......@@ -5,6 +5,16 @@
#include "brttypes.h"
#include "includes.h"
static char
int32_get_char(u_int32_t i, int which) {
char *c = (char*)&i;
return c[which];
}
#define UINT32TOCHAR(i) int32_get_char(i, 0), int32_get_char(i, 1), int32_get_char(i, 2), int32_get_char(i, 3)
#define UINT64TOCHAR(i) UINT32TOCHAR(i>>32), UINT32TOCHAR(i&0xffffffff)
static void test_leafentry_1 (void) {
LEAFENTRY l;
int r;
......@@ -12,9 +22,9 @@ static void test_leafentry_1 (void) {
r = le_committed(4, "abc", 3, "xy", &msize, &dsize, &l, 0, 0, 0);
assert(r==0);
char expect[] = {LE_COMMITTED,
0, 0, 0, 4,
UINT32TOCHAR(4),
'a', 'b', 'c', 0,
0, 0, 0, 3,
UINT32TOCHAR(3),
'x', 'y', 0};
assert(sizeof(expect)==msize);
assert(msize==dsize);
......@@ -29,10 +39,10 @@ static void test_leafentry_2 (void) {
r = le_both(0x0123456789abcdef0LL, 3, "ab", 4, "xyz", 5, "lmno", &msize, &dsize, &l, 0, 0, 0);
assert(r==0);
char expect[] = {LE_BOTH,
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0, 0, 0, 3, 'a', 'b', 0,
0, 0, 0, 4, 'x', 'y', 'z', 0,
0, 0, 0, 5, 'l', 'm', 'n', 'o', 0};
UINT64TOCHAR(0x0123456789abcdef0LL),
UINT32TOCHAR(3), 'a', 'b', 0,
UINT32TOCHAR(4), 'x', 'y', 'z', 0,
UINT32TOCHAR(5), 'l', 'm', 'n', 'o', 0};
assert(sizeof(expect)==msize);
assert(msize==dsize);
assert(memcmp(l, expect, msize)==0);
......@@ -46,9 +56,9 @@ static void test_leafentry_3 (void) {
r = le_provdel(0x0123456789abcdef0LL, 3, "ab", 5, "lmno", &msize, &dsize, &l, 0, 0, 0);
assert(r==0);
char expect[] = {LE_PROVDEL,
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0, 0, 0, 3, 'a', 'b', 0,
0, 0, 0, 5, 'l', 'm', 'n', 'o', 0};
UINT64TOCHAR(0x0123456789abcdef0LL),
UINT32TOCHAR(3), 'a', 'b', 0,
UINT32TOCHAR(5), 'l', 'm', 'n', 'o', 0};
assert(sizeof(expect)==msize);
assert(msize==dsize);
assert(memcmp(l, expect, msize)==0);
......@@ -62,9 +72,9 @@ static void test_leafentry_4 (void) {
r = le_provpair(0x0123456789abcdef0LL, 3, "ab", 5, "lmno", &msize, &dsize, &l, 0, 0, 0);
assert(r==0);
char expect[] = {LE_PROVPAIR,
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0, 0, 0, 3, 'a', 'b', 0,
0, 0, 0, 5, 'l', 'm', 'n', 'o', 0};
UINT64TOCHAR(0x0123456789abcdef0LL),
UINT32TOCHAR(3), 'a', 'b', 0,
UINT32TOCHAR(5), 'l', 'm', 'n', 'o', 0};
assert(sizeof(expect)==msize);
assert(msize==dsize);
assert(memcmp(l, expect, msize)==0);
......@@ -82,12 +92,12 @@ char zeros[1026];
#define n300zeros n150zeros,n150zeros
#define n301zeros 0,n300zeros
#define n1025zeros n300zeros,n300zeros,n300zeros,n125zeros
char expect_3long[] = {LE_PROVDEL,
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0, 0, 1, 45, n301zeros,
0, 0, 4, 1, n1025zeros};
static void test_leafentry_3long (void) {
char expect_3long[] = {LE_PROVDEL,
UINT64TOCHAR(0x0123456789abcdef0LL),
UINT32TOCHAR(301), n301zeros,
UINT32TOCHAR(1025), n1025zeros};
LEAFENTRY l;
int r;
u_int32_t msize, dsize;
......
......@@ -51,7 +51,7 @@ assert(sizeof(buf) == N_BIGINTS * BIGINT_SIZE);
assert(r==Z_OK);
}
{
u_int32_t v = htonl(compressed_len);
u_int32_t v = toku_htod32(compressed_len);
ssize_t r = write(fd, &v, sizeof(v));
assert(r==sizeof(v));
}
......@@ -60,12 +60,12 @@ assert(sizeof(buf) == N_BIGINTS * BIGINT_SIZE);
assert(r==(ssize_t)compressed_len);
}
{
u_int32_t v = htonl(sizeof(buf));
u_int32_t v = toku_htod32(sizeof(buf));
ssize_t r = write(fd, &v, sizeof(v));
assert(r==sizeof(v));
}
{
u_int32_t v = htonl(compressed_len);
u_int32_t v = toku_htod32(compressed_len);
ssize_t r = write(fd, &v, sizeof(v));
assert(r==sizeof(v));
}
......
......@@ -51,7 +51,7 @@ static void wbuf_int (struct wbuf *w, int32_t i) {
w->buf[w->ndone+2] = i>>8;
w->buf[w->ndone+3] = i>>0;
#else
*(u_int32_t*)(&w->buf[w->ndone]) = toku_htonl(i);
*(u_int32_t*)(&w->buf[w->ndone]) = toku_htod32(i);
#endif
x1764_add(&w->checksum, &w->buf[w->ndone], 4);
w->ndone += 4;
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
/* Purpose of this file is to provide definitions of
* Host to Disk byte transposition functions, an abstraction of
* htod32()/dtoh32() and htod16()/dtoh16() functions.
*
* These htod/dtoh functions will only perform the transposition
* if the disk and host are defined to be in opposite endian-ness.
* If we define the disk to be in host order, then no byte
* transposition is performed. (We might do this to save the
* the time used for byte transposition.)
*
* This abstraction layer allows us to define the disk to be in
* any byte order with a single compile-time switch (in htod.c).
*
* NOTE: THIS FILE DOES NOT CURRENTLY SUPPORT A BIG-ENDIAN
* HOST AND A LITTLE-ENDIAN DISK.
*/
#ifndef HTOD_H
#define HTOD_H
#include "toku_htonl.h"
#if !defined(__BYTE_ORDER) || \
!defined(__LITTLE_ENDIAN) || \
!defined(__BIG_ENDIAN)
#error Standard endianness things not all defined
#endif
#define NETWORK_BYTE_ORDER (__BIG_ENDIAN)
#define INTEL_BYTE_ORDER (__LITTLE_ENDIAN)
#define HOST_BYTE_ORDER (__BYTE_ORDER)
//Switch DISK_BYTE_ORDER to INTEL_BYTE_ORDER to speed up intel.
//#define DISK_BYTE_ORDER (NETWORK_BYTE_ORDER)
#define DISK_BYTE_ORDER (INTEL_BYTE_ORDER)
#if defined(__PDP_ENDIAN) && (HOST_BYTE_ORDER==__PDP_ENDIAN)
#error "Are we in ancient Rome? You REALLY want support for PDP_ENDIAN?"
#elif (HOST_BYTE_ORDER!=__BIG_ENDIAN) && (HOST_BYTE_ORDER!=__LITTLE_ENDIAN)
#error HOST_BYTE_ORDER not well defined
#endif
#if HOST_BYTE_ORDER==DISK_BYTE_ORDER
#define HTOD_NEED_SWAP 0
#else
#define HTOD_NEED_SWAP 1
#if (HOST_BYTE_ORDER==__BIG_ENDIAN)
#error Byte swapping on Big Endian is not coded in htod.c
#endif
#endif
#if !HTOD_NEED_SWAP
static inline uint32_t
toku_dtoh32(uint32_t i) {
return i;
}
static inline uint32_t
toku_htod32(uint32_t i) {
return i;
}
#elif HOST_BYTE_ORDER == __LITTLE_ENDIAN //HTOD_NEED_SWAP
static inline uint32_t
toku_dtoh32(uint32_t i) {
return ntohl(i);
}
static inline uint32_t
toku_htod32(uint32_t i) {
return htonl(i);
}
#elif HOST_BYTE_ORDER == __BIG_ENDIAN //!HTOD_NEED_SWAP
#error Byte swapping in big endian not yet supported
#endif
#endif
......@@ -77,7 +77,7 @@ typedef int64_t toku_off_t;
#endif
#include "toku_os.h"
#include "toku_htonl.h"
#include "toku_htod.h"
#define UU(x) x __attribute__((__unused__))
......
......@@ -21,9 +21,7 @@ static inline uint32_t toku_ntohl(uint32_t i) {
return _bswap(i);
}
#endif
#if defined(_MSVC_VER)
#elif defined(_MSVC_VER)
#include <winsock.h>
static inline uint32_t toku_htonl(uint32_t i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment