shithub: femtolisp

Download patch

ref: c019b3bf2d42f3a70c682cc517a45c8a77f7964d
parent: a7c0396a2f86ab8df652e8d8b2c80d2ce19d5b46
author: Jeff Bezanson <bezanson@post.harvard.edu>
date: Sun Feb 26 18:00:47 EST 2012

portability improvements

--- a/Makefile
+++ b/Makefile
@@ -29,8 +29,8 @@
 %.do: %.c
 	$(CC) $(DEBUGFLAGS) -c $< -o $@
 
-flisp.o:  flisp.c cvalues.c types.c flisp.h print.c read.c equal.c
-flisp.do: flisp.c cvalues.c types.c flisp.h print.c read.c equal.c
+flisp.o:  flisp.c cvalues.c operators.c types.c flisp.h print.c read.c equal.c
+flisp.do: flisp.c cvalues.c operators.c types.c flisp.h print.c read.c equal.c
 flmain.o: flmain.c flisp.h
 flmain.do: flmain.c flisp.h
 
--- a/llt/dirpath.c
+++ b/llt/dirpath.c
@@ -89,6 +89,21 @@
 
     return buf;
 }
+#elif defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+char *get_exename(char *buf, size_t size)
+{
+  int mib[4];
+  mib[0] = CTL_KERN;
+  mib[1] = KERN_PROC;
+  mib[2] = KERN_PROC_PATHNAME;
+  mib[3] = -1;
+  sysctl(mib, 4, buf, &size, NULL, 0);
+ 
+  return buf;
+}
 #elif defined(WIN32)
 char *get_exename(char *buf, size_t size)
 {
--- a/llt/utf8.c
+++ b/llt/utf8.c
@@ -25,7 +25,9 @@
 #include <malloc.h>
 #define snprintf _snprintf
 #else
+#ifndef __FreeBSD__
 #include <alloca.h>
+#endif /* __FreeBSD__ */
 #endif
 #include <assert.h>
 
--- a/operators.c
+++ b/operators.c
@@ -249,6 +249,7 @@
 int cmp_eq(void *a, numerictype_t atag, void *b, numerictype_t btag,
            int equalnans)
 {
+    union { double d; int64_t i64; } u, v;
     if (atag==btag && (!equalnans || atag < T_FLOAT))
         return cmp_same_eq(a, b, atag);
 
@@ -257,7 +258,8 @@
 
     if ((int)atag >= T_FLOAT && (int)btag >= T_FLOAT) {
         if (equalnans) {
-            return *(uint64_t*)&da == *(uint64_t*)&db;
+            u.d = da; v.d = db;
+            return u.i64 == v.i64;
         }
         return (da == db);
     }
--- a/string.c
+++ b/string.c
@@ -378,7 +378,7 @@
         argcount("string->number", nargs, 2);
     char *str = tostring(args[0], "string->number");
     value_t n;
-    ulong radix = 0;
+    unsigned long radix = 0;
     if (nargs == 2)
         radix = get_radix_arg(args[1], "string->number");
     if (!isnumtok_base(str, &n, (int)radix))