shithub: femtolisp

Download patch

ref: 8ea6157c157a1dedde97c50412f0d1a0105db269
parent: 46009027c2dc5478c1f7a627d08e66f78849180a
author: JeffBezanson <jeff.bezanson@gmail.com>
date: Fri May 14 17:01:00 EDT 2010

some LLT fixes
improve portability of byte order test


--- a/femtolisp/Makefile
+++ b/femtolisp/Makefile
@@ -9,7 +9,10 @@
 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
 
--- a/femtolisp/flisp.c
+++ b/femtolisp/flisp.c
@@ -888,7 +888,7 @@
     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 @@
             data[i] -= 48;
     }
     else {
-#if _BYTE_ORDER == __BIG_ENDIAN
+#if BYTE_ORDER == BIG_ENDIAN
         swap = 1;
 #endif
     }
--- a/llt/bitvector.c
+++ b/llt/bitvector.c
@@ -44,7 +44,7 @@
 {
     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;
--- a/llt/dtypes.h
+++ b/llt/dtypes.h
@@ -16,6 +16,35 @@
   We assume the LP64 convention for 64-bit platforms.
 */
 
+#ifdef LINUX
+#include <features.h>
+#include <endian.h>
+#define LITTLE_ENDIAN  __LITTLE_ENDIAN
+#define BIG_ENDIAN     __BIG_ENDIAN
+#define PDP_ENDIAN     __PDP_ENDIAN
+#define BYTE_ORDER     __BYTE_ORDER
+#endif
+
+#ifdef MACOSX
+#include <machine/endian.h>
+#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 <gc.h>
--- a/llt/ieee754.h
+++ b/llt/ieee754.h
@@ -20,28 +20,6 @@
 
 #define _IEEE754_H 1
 
-#ifdef LINUX
-
-#include <features.h>
-#include <endian.h>
-__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;
@@ -210,9 +188,5 @@
   };
 
 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
-
-#ifdef LINUX
-__END_DECLS
-#endif
 
 #endif /* ieee754.h */
--- a/llt/memalign.c
+++ b/llt/memalign.c
@@ -24,7 +24,7 @@
 {
     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 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 @@
 
     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;