From 8ea6157c157a1dedde97c50412f0d1a0105db269 Mon Sep 17 00:00:00 2001 From: JeffBezanson Date: Fri, 14 May 2010 21:01:00 +0000 Subject: [PATCH] some LLT fixes improve portability of byte order test --- femtolisp/Makefile | 5 ++++- femtolisp/flisp.c | 4 ++-- llt/bitvector.c | 2 +- llt/dtypes.h | 29 +++++++++++++++++++++++++++++ llt/ieee754.h | 26 -------------------------- llt/memalign.c | 6 +++--- 6 files changed, 39 insertions(+), 33 deletions(-) diff --git a/femtolisp/Makefile b/femtolisp/Makefile index 9d56abd..eb03b4e 100644 --- a/femtolisp/Makefile +++ b/femtolisp/Makefile @@ -9,7 +9,10 @@ LIBTARGET = lib$(NAME) LLTDIR = ../llt LLT = $(LLTDIR)/libllt.a -FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO +# OS flags: LINUX, WIN32, MACOSX +# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64 +CONFIG = -DLINUX -DARCH_X86 -D__CPU__=586 +FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO $(CONFIG) LIBFILES = $(LLT) LIBS = $(LIBFILES) -lm diff --git a/femtolisp/flisp.c b/femtolisp/flisp.c index b50ce68..0226419 100644 --- a/femtolisp/flisp.c +++ b/femtolisp/flisp.c @@ -888,7 +888,7 @@ static uint32_t process_keys(value_t kwtable, return nargs; } -#if _BYTE_ORDER == __BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN #define GET_INT32(a) \ ((int32_t) \ ((((int32_t)a[0])<<0) | \ @@ -2029,7 +2029,7 @@ static value_t fl_function(value_t *args, uint32_t nargs) data[i] -= 48; } else { -#if _BYTE_ORDER == __BIG_ENDIAN +#if BYTE_ORDER == BIG_ENDIAN swap = 1; #endif } diff --git a/llt/bitvector.c b/llt/bitvector.c index 871f40e..5e458ac 100644 --- a/llt/bitvector.c +++ b/llt/bitvector.c @@ -44,7 +44,7 @@ u_int32_t *bitvector_resize(u_int32_t *b, u_int64_t n, int initzero) { u_int32_t *p; size_t sz = ((n+31)>>5) * 4; - p = realloc(b, sz); + p = LLT_REALLOC(b, sz); if (p == NULL) return NULL; if (initzero) memset(p, 0, sz); return p; diff --git a/llt/dtypes.h b/llt/dtypes.h index eeccd89..cee00d7 100644 --- a/llt/dtypes.h +++ b/llt/dtypes.h @@ -16,6 +16,35 @@ We assume the LP64 convention for 64-bit platforms. */ +#ifdef LINUX +#include +#include +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#define PDP_ENDIAN __PDP_ENDIAN +#define BYTE_ORDER __BYTE_ORDER +#endif + +#ifdef MACOSX +#include +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#define __PDP_ENDIAN PDP_ENDIAN +#define __BYTE_ORDER BYTE_ORDER +#endif + +#ifdef WIN32 +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __PDP_ENDIAN 3412 +#define __BYTE_ORDER __LITTLE_ENDIAN +#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#define PDP_ENDIAN __PDP_ENDIAN +#define BYTE_ORDER __BYTE_ORDER +#endif + #ifdef BOEHM_GC // boehm GC allocator #include diff --git a/llt/ieee754.h b/llt/ieee754.h index 17a3126..44a1cd1 100644 --- a/llt/ieee754.h +++ b/llt/ieee754.h @@ -20,28 +20,6 @@ #define _IEEE754_H 1 -#ifdef LINUX - -#include -#include -__BEGIN_DECLS - -#else - -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 - -#if defined(WIN32) || defined(ARCH_X86) || defined(ARCH_X86_64) -#define __BYTE_ORDER __LITTLE_ENDIAN -#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN -#else -#define __BYTE_ORDER __BIG_ENDIAN -#define __FLOAT_WORD_ORDER __BIG_ENDIAN -#endif - -#endif //ifdef LINUX - union ieee754_float { float f; @@ -211,8 +189,4 @@ union ieee854_long_double #define IEEE854_LONG_DOUBLE_BIAS 0x3fff -#ifdef LINUX -__END_DECLS -#endif - #endif /* ieee754.h */ diff --git a/llt/memalign.c b/llt/memalign.c index 240972b..3b3231d 100644 --- a/llt/memalign.c +++ b/llt/memalign.c @@ -24,7 +24,7 @@ void *malloc_aligned(size_t size, size_t align_size) { char *ptr; - ptr = (char*)malloc(size + align_size-1 + sizeof(long)); + ptr = (char*)LLT_ALLOC(size + align_size-1 + sizeof(long)); if (ptr == NULL) return NULL; @@ -33,7 +33,7 @@ void *malloc_aligned(size_t size, size_t align_size) void free_aligned(void *ptr) { - free(ALIGNED_TO_ACTUAL(ptr)); + LLT_FREE(ALIGNED_TO_ACTUAL(ptr)); } void *realloc_aligned(void *ptr, size_t size, size_t align_size) @@ -42,7 +42,7 @@ void *realloc_aligned(void *ptr, size_t size, size_t align_size) if (ptr != NULL) ptr = ALIGNED_TO_ACTUAL(ptr); - pnew = realloc(ptr, size + align_size-1 + sizeof(long)); + pnew = LLT_REALLOC(ptr, size + align_size-1 + sizeof(long)); if (pnew == NULL) return NULL;