shithub: sl

Download patch

ref: c6421a8f496a920c9c2e28659ac893e84dda3695
parent: ad50f75a7c9276fa04a0e91c54be24d2cec74b28
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Mar 7 21:55:14 EST 2025

fix cross-compilation

--- a/3rd/dlmalloc.h
+++ b/3rd/dlmalloc.h
@@ -3995,14 +3995,14 @@
   char* old_top = (char*)m->top;
   msegmentptr oldsp = segment_holding(m, old_top);
   char* old_end = oldsp->base + oldsp->size;
-  usize ssize = pad_request(sizeof(struct malloc_segment));
-  char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
+  usize size = pad_request(sizeof(struct malloc_segment));
+  char* rawsp = old_end - (size + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK);
   usize offset = align_offset(chunk2mem(rawsp));
   char* asp = rawsp + offset;
   char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp;
   mchunkptr sp = (mchunkptr)csp;
   msegmentptr ss = (msegmentptr)(chunk2mem(sp));
-  mchunkptr tnext = chunk_plus_offset(sp, ssize);
+  mchunkptr tnext = chunk_plus_offset(sp, size);
   mchunkptr p = tnext;
   int nfences = 0;
 
@@ -4011,7 +4011,7 @@
 
   /* Set up segment record */
   assert(is_aligned(ss));
-  set_size_and_pinuse_of_inuse_chunk(m, sp, ssize);
+  set_size_and_pinuse_of_inuse_chunk(m, sp, size);
   *ss = m->seg; /* Push current record */
   m->seg.base = tbase;
   m->seg.size = tsize;
@@ -4093,7 +4093,7 @@
 
   if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) {
     char* br = CMFAIL;
-    usize ssize = asize; /* sbrk call size */
+    usize size = asize; /* sbrk call size */
     msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top);
     ACQUIRE_MALLOC_GLOBAL_LOCK();
 
@@ -4103,39 +4103,39 @@
         usize fp;
         /* Adjust to end on a page boundary */
         if (!is_page_aligned(base))
-          ssize += (page_align((usize)base) - (usize)base);
-        fp = m->footprint + ssize; /* recheck limits */
-        if (ssize > nb && ssize < HALF_MAX_SIZE_T &&
+          size += (page_align((usize)base) - (usize)base);
+        fp = m->footprint + size; /* recheck limits */
+        if (size > nb && size < HALF_MAX_SIZE_T &&
             (m->footprint_limit == 0 ||
              (fp > m->footprint && fp <= m->footprint_limit)) &&
-            (br = (char*)(CALL_MORECORE(ssize))) == base) {
+            (br = (char*)(CALL_MORECORE(size))) == base) {
           tbase = base;
-          tsize = ssize;
+          tsize = size;
         }
       }
     }
     else {
       /* Subtract out existing available top space from MORECORE request. */
-      ssize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING);
+      size = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING);
       /* Use mem here only if it did continuously extend old space */
-      if (ssize < HALF_MAX_SIZE_T &&
-          (br = (char*)(CALL_MORECORE(ssize))) == ss->base+ss->size) {
+      if (size < HALF_MAX_SIZE_T &&
+          (br = (char*)(CALL_MORECORE(size))) == ss->base+ss->size) {
         tbase = br;
-        tsize = ssize;
+        tsize = size;
       }
     }
 
     if (tbase == CMFAIL) {    /* Cope with partial failure */
       if (br != CMFAIL) {    /* Try to use/extend the space we did get */
-        if (ssize < HALF_MAX_SIZE_T &&
-            ssize < nb + SYS_ALLOC_PADDING) {
-          usize esize = granularity_align(nb + SYS_ALLOC_PADDING - ssize);
+        if (size < HALF_MAX_SIZE_T &&
+            size < nb + SYS_ALLOC_PADDING) {
+          usize esize = granularity_align(nb + SYS_ALLOC_PADDING - size);
           if (esize < HALF_MAX_SIZE_T) {
             char* end = (char*)CALL_MORECORE(esize);
             if (end != CMFAIL)
-              ssize += esize;
+              size += esize;
             else {            /* Can't use; try to release */
-              (void) CALL_MORECORE(-ssize);
+              (void) CALL_MORECORE(-size);
               br = CMFAIL;
             }
           }
@@ -4143,7 +4143,7 @@
       }
       if (br != CMFAIL) {    /* Use the space we did get */
         tbase = br;
-        tsize = ssize;
+        tsize = size;
       }
       else
         disable_contiguous(m); /* Don't try contiguous path in the future */
@@ -4170,10 +4170,10 @@
       end = (char*)(CALL_MORECORE(0));
       RELEASE_MALLOC_GLOBAL_LOCK();
       if (br != CMFAIL && end != CMFAIL && br < end) {
-        usize ssize = end - br;
-        if (ssize > nb + TOP_FOOT_SIZE) {
+        usize size = end - br;
+        if (size > nb + TOP_FOOT_SIZE) {
           tbase = br;
-          tsize = ssize;
+          tsize = size;
         }
       }
     }
--- a/meson.build
+++ b/meson.build
@@ -157,12 +157,11 @@
 lzpack = executable(
 	'lzpack',
 	sources: [
+		'3rd/brieflz/brieflz.c',
+		'3rd/brieflz/depacks.c',
 		'tools/lzpack.c',
 	],
 	include_directories: inc,
-	link_with: [
-		brieflz,
-	],
 	native: true,
 )
 
--- a/src/cc_gnuc.h
+++ b/src/cc_gnuc.h
@@ -32,3 +32,19 @@
 #define sadd_overflow __builtin_add_overflow
 #define sadd_overflow_64 __builtin_add_overflow
 #define smul_overflow_64 __builtin_mul_overflow
+
+#if !defined(BYTE_ORDER)
+#if !defined(__BYTE_ORDER)
+#define LITTLE_ENDIAN 1234
+#define BIG_ENDIAN 4321
+#if defined(__LITTLE_ENDIAN__)
+#define BYTE_ORDER LITTLE_ENDIAN
+#else
+#define BYTE_ORDER BIG_ENDIAN
+#endif
+#else
+#define LITTLE_ENDIAN __LITTLE_ENDIAN
+#define BIG_ENDIAN __BIG_ENDIAN
+#define BYTE_ORDER __BYTE_ORDER
+#endif
+#endif
--- a/src/dos/platform.h
+++ b/src/dos/platform.h
@@ -3,7 +3,6 @@
 #define _XOPEN_SOURCE 700
 #include <assert.h>
 #include <ctype.h>
-#include <machine/endian.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <float.h>
@@ -42,6 +41,9 @@
 #define ISPATHSEP(c) ((c) == '\\')
 
 #define MEM_UNALIGNED_ACCESS
+#define sl_segalloc(sz) MEM_ALLOC((usize)sz)
+#define sl_segfree(s, sz) MEM_FREE(s)
+#define sl_segused(s, sz, used) do{}while(0)
 
 #include "cc_gnuc.h"
 #include "mem.h"
--- a/src/macos/platform.h
+++ b/src/macos/platform.h
@@ -43,15 +43,11 @@
 #define PATHLISTSEPSTRING ":"
 #define ISPATHSEP(c) ((c) == '/')
 
-#ifndef BYTE_ORDER
-#error unknown byte order
-#endif
-
 #define HEAP_SIZE0 128*1024
 #define STACK_SIZE0 8*1024
 
 #include "cc_gnuc.h"
-#include "mem.h"
 #include "mem_dlmalloc.h"
+#include "mem.h"
 #include "mp.h"
 #include "utf.h"
--- a/src/mem.h
+++ b/src/mem.h
@@ -16,7 +16,9 @@
 #define MEM_REALLOC(p, n) realloc((p), (usize)(n))
 #define MEM_FREE(x) free(x)
 #define MEM_STRDUP(s) strdup(s)
+#if !defined(sl_segalloc)
 void *sl_segalloc(usize sz);
 void sl_segfree(void *s, usize sz);
 void sl_segused(void *s, usize sz, usize used);
+#endif
 #endif
--- a/src/posix/platform.h
+++ b/src/posix/platform.h
@@ -74,22 +74,6 @@
 #define PATHLISTSEPSTRING ":"
 #define ISPATHSEP(c) ((c) == '/')
 
-#if !defined(BYTE_ORDER)
-#if !defined(__BYTE_ORDER)
-#define LITTLE_ENDIAN 1234
-#define BIG_ENDIAN 4321
-#if defined(__LITTLE_ENDIAN__)
-#define BYTE_ORDER LITTLE_ENDIAN
-#else
-#define BYTE_ORDER BIG_ENDIAN
-#endif
-#else
-#define LITTLE_ENDIAN __LITTLE_ENDIAN
-#define BIG_ENDIAN __BIG_ENDIAN
-#define BYTE_ORDER __BYTE_ORDER
-#endif
-#endif
-
 // FIXME: __clang__ because no idea how to check if ubsan is enabled.
 #if !defined(__clang__) && (defined(__386__) || defined(__x86_64__) || defined(__aarch64__))
 #define MEM_UNALIGNED_ACCESS
--- a/src/sl.c
+++ b/src/sl.c
@@ -170,7 +170,7 @@
 _Noreturn void
 arity_error(int nargs, int c)
 {
-	lerrorf(sl_errarg, "arity mismatch: wanted %"PRId32", got %"PRId32, c, nargs);
+	lerrorf(sl_errarg, "arity mismatch: wanted %d, got %d", c, nargs);
 }
 
 // safe cast operators --------------------------------------------------------
--- a/tools/lzpack.c
+++ b/tools/lzpack.c
@@ -18,10 +18,10 @@
 	}
 	if(sz == sizeof(in))
 		abort();
-	u8int *out = MEM_ALLOC(1+4+blz_max_packed_size(sz));
+	u8int *out = malloc(1+4+blz_max_packed_size(sz));
 	if(out == nil)
 		abort();
-	u8int *w = MEM_ALLOC(blz_workmem_size_level(sz, 10));
+	u8int *w = malloc(blz_workmem_size_level(sz, 10));
 	if(w == nil)
 		abort();
 	unsigned long osz = blz_pack_level(in, out+1+4, sz, w, 10);
@@ -35,7 +35,7 @@
 	osz += 1+4;
 	if((unsigned long)write(1, out, osz) != osz)
 		abort();
-	MEM_FREE(w);
-	MEM_FREE(out);
+	free(w);
+	free(out);
 	exit(0);
 }