From d6a4029dde15344606f384b99c3b62a01d770f68 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 9 Aug 2019 21:00:03 +0300 Subject: [PATCH] Replace idiosyncratic C types with standard ones For number types, we rely on classic C types (char, short, int, long) to be the correct sizes. For precise bit widths, use standard intN_t and uintN_t. For size_t, just use system size_t. --- c/bitvector-ops.c | 147 +++++++++++++++++++++++----------------------- c/bitvector.c | 16 ++--- c/bitvector.h | 71 +++++++++++----------- c/builtins.c | 48 +++++++-------- c/cvalues.h | 76 ++++++++++++------------ c/dtypes.h | 43 +++----------- c/dump.c | 2 + c/equal.h | 2 +- c/flisp.c | 12 ++-- c/flisp.h | 24 +------- c/hashing.c | 18 +++--- c/hashing.h | 10 ++-- c/iostream.c | 40 ++++++------- c/print.h | 2 +- c/ptrhash.c | 4 +- c/random.c | 2 +- c/random.h | 2 +- c/read.h | 14 ++--- c/string.c | 38 ++++++------ c/timefuncs.c | 8 +-- c/timefuncs.h | 2 +- c/utf8.c | 62 +++++++++---------- c/utf8.h | 26 ++++---- c/utils.h | 16 ++--- 24 files changed, 320 insertions(+), 365 deletions(-) diff --git a/c/bitvector-ops.c b/c/bitvector-ops.c index 5f50315..8365851 100644 --- a/c/bitvector-ops.c +++ b/c/bitvector-ops.c @@ -1,21 +1,21 @@ -#include #include +#include #include -#include "dtypes.h" -#include "bitvector.h" - #ifdef WIN32 #include #define alloca _alloca #endif +#include "dtypes.h" +#include "bitvector.h" + // greater than this # of words we use malloc instead of alloca #define MALLOC_CUTOFF 2000 -u_int32_t bitreverse(u_int32_t x) +uint32_t bitreverse(uint32_t x) { - u_int32_t m; + uint32_t m; #ifdef __INTEL_COMPILER x = _bswap(x); @@ -38,9 +38,9 @@ u_int32_t bitreverse(u_int32_t x) // n is # of int32s to consider, s is shift distance // lowest bit-index is bit 0 of word 0 // TODO: handle boundary case of shift distance >= data size? -void bitvector_shr(u_int32_t *b, size_t n, u_int32_t s) +void bitvector_shr(uint32_t *b, size_t n, uint32_t s) { - u_int32_t i; + uint32_t i; if (s == 0 || n == 0) return; i = (s >> 5); @@ -60,9 +60,9 @@ void bitvector_shr(u_int32_t *b, size_t n, u_int32_t s) // linear representation when a copy is needed // assumes that dest has the same amount of space as source, even if it // wouldn't have been necessary to hold the shifted bits -void bitvector_shr_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s) +void bitvector_shr_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s) { - u_int32_t i, j; + uint32_t i, j; if (n == 0) return; if (s == 0) { @@ -82,9 +82,9 @@ void bitvector_shr_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s) dest[i] = b[i] >> s; } -void bitvector_shl(u_int32_t *b, size_t n, u_int32_t s) +void bitvector_shl(uint32_t *b, size_t n, uint32_t s) { - u_int32_t i, scrap = 0, temp; + uint32_t i, scrap = 0, temp; if (s == 0 || n == 0) return; i = (s >> 5); @@ -104,10 +104,10 @@ void bitvector_shl(u_int32_t *b, size_t n, u_int32_t s) // if dest has more space than source, set scrap to true to keep the // top bits that would otherwise be shifted out -void bitvector_shl_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s, +void bitvector_shl_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s, bool_t scrap) { - u_int32_t i, j, sc = 0; + uint32_t i, j, sc = 0; if (n == 0) return; if (s == 0) { @@ -131,12 +131,11 @@ void bitvector_shl_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s, // set nbits to c, starting at given bit offset // assumes offs < 32 -void bitvector_fill(u_int32_t *b, u_int32_t offs, u_int32_t c, - u_int32_t nbits) +void bitvector_fill(uint32_t *b, uint32_t offs, uint32_t c, uint32_t nbits) { index_t i; - u_int32_t nw, tail; - u_int32_t mask; + uint32_t nw, tail; + uint32_t mask; if (nbits == 0) return; @@ -176,11 +175,11 @@ void bitvector_fill(u_int32_t *b, u_int32_t offs, u_int32_t c, } } -void bitvector_not(u_int32_t *b, u_int32_t offs, u_int32_t nbits) +void bitvector_not(uint32_t *b, uint32_t offs, uint32_t nbits) { index_t i; - u_int32_t nw, tail; - u_int32_t mask; + uint32_t nw, tail; + uint32_t mask; if (nbits == 0) return; @@ -210,12 +209,12 @@ void bitvector_not(u_int32_t *b, u_int32_t offs, u_int32_t nbits) // constant-space bit vector copy in a single pass, with arbitrary // offsets and lengths. to get this right, there are 16 cases to handle! #define BITVECTOR_COPY_OP(name, OP) \ - void bitvector_##name(u_int32_t *dest, u_int32_t doffs, u_int32_t *src, \ - u_int32_t soffs, u_int32_t nbits) \ + void bitvector_##name(uint32_t *dest, uint32_t doffs, uint32_t *src, \ + uint32_t soffs, uint32_t nbits) \ { \ index_t i; \ - u_int32_t s, nw, tail, snw; \ - u_int32_t mask, scrap; \ + uint32_t s, nw, tail, snw; \ + uint32_t mask, scrap; \ \ if (nbits == 0) \ return; \ @@ -319,7 +318,7 @@ BITVECTOR_COPY_OP(not_to, BV_NOT) // right-shift the bits in one logical "row" of a long 2d bit vector /* -void bitvector_shr_row(u_int32_t *b, u_int32_t offs, size_t nbits, u_int32_t +void bitvector_shr_row(uint32_t *b, uint32_t offs, size_t nbits, uint32_t s) { } @@ -329,11 +328,11 @@ s) // assumes dest offset == 0 // assumes source and dest don't overlap // assumes offset < 32 -void bitvector_reverse_to(u_int32_t *dest, u_int32_t *src, u_int32_t soffs, - u_int32_t nbits) +void bitvector_reverse_to(uint32_t *dest, uint32_t *src, uint32_t soffs, + uint32_t nbits) { index_t i; - u_int32_t nw, tail; + uint32_t nw, tail; if (nbits == 0) return; @@ -352,11 +351,11 @@ void bitvector_reverse_to(u_int32_t *dest, u_int32_t *src, u_int32_t soffs, bitvector_shr(dest, nw, 32 - tail); } -void bitvector_reverse(u_int32_t *b, u_int32_t offs, u_int32_t nbits) +void bitvector_reverse(uint32_t *b, uint32_t offs, uint32_t nbits) { index_t i; - u_int32_t nw, tail; - u_int32_t *temp; + uint32_t nw, tail; + uint32_t *temp; if (nbits == 0) return; @@ -376,15 +375,15 @@ void bitvector_reverse(u_int32_t *b, u_int32_t offs, u_int32_t nbits) free(temp); } -u_int64_t bitvector_count(u_int32_t *b, u_int32_t offs, u_int64_t nbits) +uint64_t bitvector_count(uint32_t *b, uint32_t offs, uint64_t nbits) { size_t i, nw; - u_int32_t ntail; - u_int64_t ans; + uint32_t ntail; + uint64_t ans; if (nbits == 0) return 0; - nw = ((u_int64_t)offs + nbits + 31) >> 5; + nw = ((uint64_t)offs + nbits + 31) >> 5; if (nw == 1) { return count_bits(b[0] & (lomask(nbits) << offs)); @@ -406,18 +405,18 @@ u_int64_t bitvector_count(u_int32_t *b, u_int32_t offs, u_int64_t nbits) ans += count_bits(b[i]); } - ntail = (offs + (u_int32_t)nbits) & 31; + ntail = (offs + (uint32_t)nbits) & 31; ans += count_bits(b[i] & (ntail > 0 ? lomask(ntail) : ONES32)); // last end cap return ans; } -u_int32_t bitvector_any0(u_int32_t *b, u_int32_t offs, u_int32_t nbits) +uint32_t bitvector_any0(uint32_t *b, uint32_t offs, uint32_t nbits) { index_t i; - u_int32_t nw, tail; - u_int32_t mask; + uint32_t nw, tail; + uint32_t mask; if (nbits == 0) return 0; @@ -451,11 +450,11 @@ u_int32_t bitvector_any0(u_int32_t *b, u_int32_t offs, u_int32_t nbits) return 0; } -u_int32_t bitvector_any1(u_int32_t *b, u_int32_t offs, u_int32_t nbits) +uint32_t bitvector_any1(uint32_t *b, uint32_t offs, uint32_t nbits) { index_t i; - u_int32_t nw, tail; - u_int32_t mask; + uint32_t nw, tail; + uint32_t mask; if (nbits == 0) return 0; @@ -489,8 +488,8 @@ u_int32_t bitvector_any1(u_int32_t *b, u_int32_t offs, u_int32_t nbits) return 0; } -static void adjust_offset_to(u_int32_t *dest, u_int32_t *src, u_int32_t nw, - u_int32_t soffs, u_int32_t newoffs) +static void adjust_offset_to(uint32_t *dest, uint32_t *src, uint32_t nw, + uint32_t soffs, uint32_t newoffs) { if (newoffs > soffs) bitvector_shl_to(dest, src, nw, newoffs - soffs, 1); @@ -498,35 +497,35 @@ static void adjust_offset_to(u_int32_t *dest, u_int32_t *src, u_int32_t nw, bitvector_shr_to(dest, src, nw, soffs - newoffs); } -#define BITVECTOR_BINARY_OP_TO(opname, OP) \ - void bitvector_##opname##_to( \ - u_int32_t *dest, u_int32_t doffs, u_int32_t *a, u_int32_t aoffs, \ - u_int32_t *b, u_int32_t boffs, u_int32_t nbits) \ - { \ - u_int32_t nw = (doffs + nbits + 31) >> 5; \ - u_int32_t *temp = \ - nw > MALLOC_CUTOFF ? malloc((nw + 1) * 4) : alloca((nw + 1) * 4); \ - u_int32_t i, anw, bnw; \ - if (aoffs == boffs) { \ - anw = (aoffs + nbits + 31) >> 5; \ - } else if (aoffs == doffs) { \ - bnw = (boffs + nbits + 31) >> 5; \ - adjust_offset_to(temp, b, bnw, boffs, aoffs); \ - b = temp; \ - anw = nw; \ - } else { \ - anw = (aoffs + nbits + 31) >> 5; \ - bnw = (boffs + nbits + 31) >> 5; \ - adjust_offset_to(temp, a, anw, aoffs, boffs); \ - a = temp; \ - aoffs = boffs; \ - anw = bnw; \ - } \ - for (i = 0; i < anw; i++) \ - temp[i] = OP(a[i], b[i]); \ - bitvector_copy(dest, doffs, temp, aoffs, nbits); \ - if (nw > MALLOC_CUTOFF) \ - free(temp); \ +#define BITVECTOR_BINARY_OP_TO(opname, OP) \ + void bitvector_##opname##_to(uint32_t *dest, uint32_t doffs, \ + uint32_t *a, uint32_t aoffs, uint32_t *b, \ + uint32_t boffs, uint32_t nbits) \ + { \ + uint32_t nw = (doffs + nbits + 31) >> 5; \ + uint32_t *temp = \ + nw > MALLOC_CUTOFF ? malloc((nw + 1) * 4) : alloca((nw + 1) * 4); \ + uint32_t i, anw, bnw; \ + if (aoffs == boffs) { \ + anw = (aoffs + nbits + 31) >> 5; \ + } else if (aoffs == doffs) { \ + bnw = (boffs + nbits + 31) >> 5; \ + adjust_offset_to(temp, b, bnw, boffs, aoffs); \ + b = temp; \ + anw = nw; \ + } else { \ + anw = (aoffs + nbits + 31) >> 5; \ + bnw = (boffs + nbits + 31) >> 5; \ + adjust_offset_to(temp, a, anw, aoffs, boffs); \ + a = temp; \ + aoffs = boffs; \ + anw = bnw; \ + } \ + for (i = 0; i < anw; i++) \ + temp[i] = OP(a[i], b[i]); \ + bitvector_copy(dest, doffs, temp, aoffs, nbits); \ + if (nw > MALLOC_CUTOFF) \ + free(temp); \ } #define BV_AND(a, b) ((a) & (b)) diff --git a/c/bitvector.c b/c/bitvector.c index 46f9177..3d5b91c 100644 --- a/c/bitvector.c +++ b/c/bitvector.c @@ -29,8 +29,8 @@ and_to, or_to, and xor_to allow overlap. */ -#include #include +#include #include #include "dtypes.h" @@ -40,10 +40,10 @@ #include #endif -u_int32_t *bitvector_resize(u_int32_t *b, uint64_t oldsz, uint64_t newsz, - int initzero) +uint32_t *bitvector_resize(uint32_t *b, uint64_t oldsz, uint64_t newsz, + int initzero) { - u_int32_t *p; + uint32_t *p; size_t sz = ((newsz + 31) >> 5) * sizeof(uint32_t); p = LLT_REALLOC(b, sz); if (p == NULL) @@ -55,14 +55,14 @@ u_int32_t *bitvector_resize(u_int32_t *b, uint64_t oldsz, uint64_t newsz, return p; } -u_int32_t *bitvector_new(u_int64_t n, int initzero) +uint32_t *bitvector_new(uint64_t n, int initzero) { return bitvector_resize(NULL, 0, n, initzero); } -size_t bitvector_nwords(u_int64_t nbits) { return ((nbits + 31) >> 5); } +size_t bitvector_nwords(uint64_t nbits) { return ((nbits + 31) >> 5); } -void bitvector_set(u_int32_t *b, u_int64_t n, u_int32_t c) +void bitvector_set(uint32_t *b, uint64_t n, uint32_t c) { if (c) b[n >> 5] |= (1 << (n & 31)); @@ -70,7 +70,7 @@ void bitvector_set(u_int32_t *b, u_int64_t n, u_int32_t c) b[n >> 5] &= ~(1 << (n & 31)); } -u_int32_t bitvector_get(u_int32_t *b, u_int64_t n) +uint32_t bitvector_get(uint32_t *b, uint64_t n) { return b[n >> 5] & (1 << (n & 31)); } diff --git a/c/bitvector.h b/c/bitvector.h index f711d00..627d87b 100644 --- a/c/bitvector.h +++ b/c/bitvector.h @@ -1,12 +1,12 @@ // a mask with n set lo or hi bits -#define lomask(n) (u_int32_t)((((u_int32_t)1) << (n)) - 1) +#define lomask(n) (uint32_t)((((uint32_t)1) << (n)) - 1) #define himask(n) (~lomask(32 - n)) -#define ONES32 ((u_int32_t)0xffffffff) +#define ONES32 ((uint32_t)0xffffffff) #ifdef __INTEL_COMPILER #define count_bits(b) _popcnt32(b) #else -static inline u_int32_t count_bits(u_int32_t b) +static inline uint32_t count_bits(uint32_t b) { b = b - ((b >> 1) & 0x55555555); b = ((b >> 2) & 0x33333333) + (b & 0x33333333); @@ -26,41 +26,40 @@ static inline u_int32_t count_bits(u_int32_t b) } #endif -u_int32_t bitreverse(u_int32_t x); +uint32_t bitreverse(uint32_t x); -u_int32_t *bitvector_new(u_int64_t n, int initzero); -u_int32_t *bitvector_resize(u_int32_t *b, uint64_t oldsz, uint64_t newsz, - int initzero); -size_t bitvector_nwords(u_int64_t nbits); -void bitvector_set(u_int32_t *b, u_int64_t n, u_int32_t c); -u_int32_t bitvector_get(u_int32_t *b, u_int64_t n); +uint32_t *bitvector_new(uint64_t n, int initzero); +uint32_t *bitvector_resize(uint32_t *b, uint64_t oldsz, uint64_t newsz, + int initzero); +size_t bitvector_nwords(uint64_t nbits); +void bitvector_set(uint32_t *b, uint64_t n, uint32_t c); +uint32_t bitvector_get(uint32_t *b, uint64_t n); uint32_t bitvector_next(uint32_t *b, uint64_t n0, uint64_t n); -void bitvector_shr(u_int32_t *b, size_t n, u_int32_t s); -void bitvector_shr_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s); -void bitvector_shl(u_int32_t *b, size_t n, u_int32_t s); -void bitvector_shl_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s, +void bitvector_shr(uint32_t *b, size_t n, uint32_t s); +void bitvector_shr_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s); +void bitvector_shl(uint32_t *b, size_t n, uint32_t s); +void bitvector_shl_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s, bool_t scrap); -void bitvector_fill(u_int32_t *b, u_int32_t offs, u_int32_t c, - u_int32_t nbits); -void bitvector_copy(u_int32_t *dest, u_int32_t doffs, u_int32_t *a, - u_int32_t aoffs, u_int32_t nbits); -void bitvector_not(u_int32_t *b, u_int32_t offs, u_int32_t nbits); -void bitvector_not_to(u_int32_t *dest, u_int32_t doffs, u_int32_t *a, - u_int32_t aoffs, u_int32_t nbits); -void bitvector_reverse(u_int32_t *b, u_int32_t offs, u_int32_t nbits); -void bitvector_reverse_to(u_int32_t *dest, u_int32_t *src, u_int32_t soffs, - u_int32_t nbits); -void bitvector_and_to(u_int32_t *dest, u_int32_t doffs, u_int32_t *a, - u_int32_t aoffs, u_int32_t *b, u_int32_t boffs, - u_int32_t nbits); -void bitvector_or_to(u_int32_t *dest, u_int32_t doffs, u_int32_t *a, - u_int32_t aoffs, u_int32_t *b, u_int32_t boffs, - u_int32_t nbits); -void bitvector_xor_to(u_int32_t *dest, u_int32_t doffs, u_int32_t *a, - u_int32_t aoffs, u_int32_t *b, u_int32_t boffs, - u_int32_t nbits); -u_int64_t bitvector_count(u_int32_t *b, u_int32_t offs, u_int64_t nbits); -u_int32_t bitvector_any0(u_int32_t *b, u_int32_t offs, u_int32_t nbits); -u_int32_t bitvector_any1(u_int32_t *b, u_int32_t offs, u_int32_t nbits); +void bitvector_fill(uint32_t *b, uint32_t offs, uint32_t c, uint32_t nbits); +void bitvector_copy(uint32_t *dest, uint32_t doffs, uint32_t *a, + uint32_t aoffs, uint32_t nbits); +void bitvector_not(uint32_t *b, uint32_t offs, uint32_t nbits); +void bitvector_not_to(uint32_t *dest, uint32_t doffs, uint32_t *a, + uint32_t aoffs, uint32_t nbits); +void bitvector_reverse(uint32_t *b, uint32_t offs, uint32_t nbits); +void bitvector_reverse_to(uint32_t *dest, uint32_t *src, uint32_t soffs, + uint32_t nbits); +void bitvector_and_to(uint32_t *dest, uint32_t doffs, uint32_t *a, + uint32_t aoffs, uint32_t *b, uint32_t boffs, + uint32_t nbits); +void bitvector_or_to(uint32_t *dest, uint32_t doffs, uint32_t *a, + uint32_t aoffs, uint32_t *b, uint32_t boffs, + uint32_t nbits); +void bitvector_xor_to(uint32_t *dest, uint32_t doffs, uint32_t *a, + uint32_t aoffs, uint32_t *b, uint32_t boffs, + uint32_t nbits); +uint64_t bitvector_count(uint32_t *b, uint32_t offs, uint64_t nbits); +uint32_t bitvector_any0(uint32_t *b, uint32_t offs, uint32_t nbits); +uint32_t bitvector_any1(uint32_t *b, uint32_t offs, uint32_t nbits); diff --git a/c/builtins.c b/c/builtins.c index 8748b1d..045a2e9 100644 --- a/c/builtins.c +++ b/c/builtins.c @@ -43,7 +43,7 @@ size_t llength(value_t v) return n; } -static value_t fl_nconc(value_t *args, u_int32_t nargs) +static value_t fl_nconc(value_t *args, uint32_t nargs) { if (nargs == 0) return FL_NIL; @@ -69,7 +69,7 @@ static value_t fl_nconc(value_t *args, u_int32_t nargs) return first; } -static value_t fl_assq(value_t *args, u_int32_t nargs) +static value_t fl_assq(value_t *args, uint32_t nargs) { argcount("assq", nargs, 2); value_t item = args[0]; @@ -85,7 +85,7 @@ static value_t fl_assq(value_t *args, u_int32_t nargs) return FL_F; } -static value_t fl_memq(value_t *args, u_int32_t nargs) +static value_t fl_memq(value_t *args, uint32_t nargs) { argcount("memq", nargs, 2); while (iscons(args[1])) { @@ -97,7 +97,7 @@ static value_t fl_memq(value_t *args, u_int32_t nargs) return FL_F; } -static value_t fl_length(value_t *args, u_int32_t nargs) +static value_t fl_length(value_t *args, uint32_t nargs) { argcount("length", nargs, 1); value_t a = args[0]; @@ -123,13 +123,13 @@ static value_t fl_length(value_t *args, u_int32_t nargs) type_error("length", "sequence", a); } -static value_t fl_f_raise(value_t *args, u_int32_t nargs) +static value_t fl_f_raise(value_t *args, uint32_t nargs) { argcount("raise", nargs, 1); fl_raise(args[0]); } -static value_t fl_exit(value_t *args, u_int32_t nargs) +static value_t fl_exit(value_t *args, uint32_t nargs) { if (nargs > 0) exit(tofixnum(args[0], "exit")); @@ -137,7 +137,7 @@ static value_t fl_exit(value_t *args, u_int32_t nargs) return FL_NIL; } -static value_t fl_symbol(value_t *args, u_int32_t nargs) +static value_t fl_symbol(value_t *args, uint32_t nargs) { argcount("symbol", nargs, 1); if (!fl_isstring(args[0])) @@ -145,7 +145,7 @@ static value_t fl_symbol(value_t *args, u_int32_t nargs) return symbol(cvalue_data(args[0])); } -static value_t fl_keywordp(value_t *args, u_int32_t nargs) +static value_t fl_keywordp(value_t *args, uint32_t nargs) { argcount("keyword?", nargs, 1); return (issymbol(args[0]) && iskeyword((struct symbol *)ptr(args[0]))) @@ -153,7 +153,7 @@ static value_t fl_keywordp(value_t *args, u_int32_t nargs) : FL_F; } -static value_t fl_top_level_value(value_t *args, u_int32_t nargs) +static value_t fl_top_level_value(value_t *args, uint32_t nargs) { argcount("top-level-value", nargs, 1); struct symbol *sym = tosymbol(args[0], "top-level-value"); @@ -162,7 +162,7 @@ static value_t fl_top_level_value(value_t *args, u_int32_t nargs) return sym->binding; } -static value_t fl_set_top_level_value(value_t *args, u_int32_t nargs) +static value_t fl_set_top_level_value(value_t *args, uint32_t nargs) { argcount("set-top-level-value!", nargs, 2); struct symbol *sym = tosymbol(args[0], "set-top-level-value!"); @@ -184,7 +184,7 @@ static void global_env_list(struct symbol *root, value_t *pv) extern struct symbol *symtab; -value_t fl_global_env(value_t *args, u_int32_t nargs) +value_t fl_global_env(value_t *args, uint32_t nargs) { (void)args; argcount("environment", nargs, 0); @@ -197,7 +197,7 @@ value_t fl_global_env(value_t *args, u_int32_t nargs) extern value_t QUOTE; -static value_t fl_constantp(value_t *args, u_int32_t nargs) +static value_t fl_constantp(value_t *args, uint32_t nargs) { argcount("constant?", nargs, 1); if (issymbol(args[0])) @@ -210,7 +210,7 @@ static value_t fl_constantp(value_t *args, u_int32_t nargs) return FL_T; } -static value_t fl_integer_valuedp(value_t *args, u_int32_t nargs) +static value_t fl_integer_valuedp(value_t *args, uint32_t nargs) { argcount("integer-valued?", nargs, 1); value_t v = args[0]; @@ -239,7 +239,7 @@ static value_t fl_integer_valuedp(value_t *args, u_int32_t nargs) return FL_F; } -static value_t fl_integerp(value_t *args, u_int32_t nargs) +static value_t fl_integerp(value_t *args, uint32_t nargs) { argcount("integer?", nargs, 1); value_t v = args[0]; @@ -249,7 +249,7 @@ static value_t fl_integerp(value_t *args, u_int32_t nargs) : FL_F; } -static value_t fl_fixnum(value_t *args, u_int32_t nargs) +static value_t fl_fixnum(value_t *args, uint32_t nargs) { argcount("fixnum", nargs, 1); if (isfixnum(args[0])) { @@ -261,7 +261,7 @@ static value_t fl_fixnum(value_t *args, u_int32_t nargs) type_error("fixnum", "number", args[0]); } -static value_t fl_truncate(value_t *args, u_int32_t nargs) +static value_t fl_truncate(value_t *args, uint32_t nargs) { argcount("truncate", nargs, 1); if (isfixnum(args[0])) @@ -289,7 +289,7 @@ static value_t fl_truncate(value_t *args, u_int32_t nargs) type_error("truncate", "number", args[0]); } -static value_t fl_vector_alloc(value_t *args, u_int32_t nargs) +static value_t fl_vector_alloc(value_t *args, uint32_t nargs) { fixnum_t i; value_t f, v; @@ -309,7 +309,7 @@ static value_t fl_vector_alloc(value_t *args, u_int32_t nargs) return v; } -static value_t fl_time_now(value_t *args, u_int32_t nargs) +static value_t fl_time_now(value_t *args, uint32_t nargs) { argcount("time.now", nargs, 0); (void)args; @@ -409,7 +409,7 @@ static value_t fl_os_setenv(value_t *args, uint32_t nargs) return FL_T; } -static value_t fl_rand(value_t *args, u_int32_t nargs) +static value_t fl_rand(value_t *args, uint32_t nargs) { (void)args; (void)nargs; @@ -421,7 +421,7 @@ static value_t fl_rand(value_t *args, u_int32_t nargs) #endif return fixnum(r); } -static value_t fl_rand32(value_t *args, u_int32_t nargs) +static value_t fl_rand32(value_t *args, uint32_t nargs) { (void)args; (void)nargs; @@ -432,20 +432,20 @@ static value_t fl_rand32(value_t *args, u_int32_t nargs) return mk_uint32(r); #endif } -static value_t fl_rand64(value_t *args, u_int32_t nargs) +static value_t fl_rand64(value_t *args, uint32_t nargs) { (void)args; (void)nargs; uint64_t r = (((uint64_t)random()) << 32) | random(); return mk_uint64(r); } -static value_t fl_randd(value_t *args, u_int32_t nargs) +static value_t fl_randd(value_t *args, uint32_t nargs) { (void)args; (void)nargs; return mk_double(rand_double()); } -static value_t fl_randf(value_t *args, u_int32_t nargs) +static value_t fl_randf(value_t *args, uint32_t nargs) { (void)args; (void)nargs; @@ -453,7 +453,7 @@ static value_t fl_randf(value_t *args, u_int32_t nargs) } #define MATH_FUNC_1ARG(name) \ - static value_t fl_##name(value_t *args, u_int32_t nargs) \ + static value_t fl_##name(value_t *args, uint32_t nargs) \ { \ argcount(#name, nargs, 1); \ if (iscprim(args[0])) { \ diff --git a/c/cvalues.h b/c/cvalues.h index 064b976..49efc37 100644 --- a/c/cvalues.h +++ b/c/cvalues.h @@ -31,9 +31,9 @@ struct fltype *builtintype; static void cvalue_init(struct fltype *type, value_t v, void *dest); // cvalues-specific builtins -value_t cvalue_new(value_t *args, u_int32_t nargs); -value_t cvalue_sizeof(value_t *args, u_int32_t nargs); -value_t cvalue_typeof(value_t *args, u_int32_t nargs); +value_t cvalue_new(value_t *args, uint32_t nargs); +value_t cvalue_sizeof(value_t *args, uint32_t nargs); +value_t cvalue_typeof(value_t *args, uint32_t nargs); // trigger unconditional GC after this many bytes are allocated #define ALLOC_LIMIT_TRIGGER 67108864 @@ -241,18 +241,18 @@ void cv_pin(struct cvalue *cv) static int cvalue_##ctype##_init(struct fltype *type, value_t arg, \ void *dest) \ { \ - fl_##ctype##_t n = 0; \ + ctype##_t n = 0; \ (void)type; \ if (isfixnum(arg)) { \ n = numval(arg); \ } else if (iscprim(arg)) { \ struct cprim *cp = (struct cprim *)ptr(arg); \ void *p = cp_data(cp); \ - n = (fl_##ctype##_t)conv_to_##cnvt(p, cp_numtype(cp)); \ + n = (ctype##_t)conv_to_##cnvt(p, cp_numtype(cp)); \ } else { \ return 1; \ } \ - *((fl_##ctype##_t *)dest) = n; \ + *((ctype##_t *)dest) = n; \ return 0; \ } num_init(int8, int32, T_INT8) num_init(uint8, uint32, T_UINT8) @@ -262,25 +262,25 @@ num_init(int64, int64, T_INT64) num_init(uint64, uint64, T_UINT64) num_init(float, double, T_FLOAT) num_init(double, double, T_DOUBLE) #define num_ctor_init(typenam, ctype, tag) \ - value_t cvalue_##typenam(value_t *args, u_int32_t nargs) \ + value_t cvalue_##typenam(value_t *args, uint32_t nargs) \ { \ if (nargs == 0) { \ PUSH(fixnum(0)); \ args = &Stack[SP - 1]; \ } \ - value_t cp = cprim(typenam##type, sizeof(fl_##ctype##_t)); \ + value_t cp = cprim(typenam##type, sizeof(ctype##_t)); \ if (cvalue_##ctype##_init(typenam##type, args[0], \ cp_data((struct cprim *)ptr(cp)))) \ type_error(#typenam, "number", args[0]); \ return cp; \ } -#define num_ctor_ctor(typenam, ctype, tag) \ - value_t mk_##typenam(fl_##ctype##_t n) \ - { \ - value_t cp = cprim(typenam##type, sizeof(fl_##ctype##_t)); \ - *(fl_##ctype##_t *)cp_data((struct cprim *)ptr(cp)) = n; \ - return cp; \ +#define num_ctor_ctor(typenam, ctype, tag) \ + value_t mk_##typenam(ctype##_t n) \ + { \ + value_t cp = cprim(typenam##type, sizeof(ctype##_t)); \ + *(ctype##_t *)cp_data((struct cprim *)ptr(cp)) = n; \ + return cp; \ } #define num_ctor(typenam, ctype, tag) \ @@ -350,7 +350,7 @@ static int cvalue_enum_init(struct fltype *ft, value_t arg, void *dest) return 0; } -value_t cvalue_enum(value_t *args, u_int32_t nargs) +value_t cvalue_enum(value_t *args, uint32_t nargs) { argcount("enum", nargs, 2); value_t type = fl_list2(enumsym, args[0]); @@ -440,7 +440,7 @@ static int cvalue_array_init(struct fltype *ft, value_t arg, void *dest) return 0; } -value_t cvalue_array(value_t *args, u_int32_t nargs) +value_t cvalue_array(value_t *args, uint32_t nargs) { size_t elsize, cnt, sz, i; value_t arg; @@ -595,7 +595,7 @@ void to_sized_ptr(value_t v, char *fname, char **pdata, size_t *psz) type_error(fname, "plain-old-data", v); } -value_t cvalue_sizeof(value_t *args, u_int32_t nargs) +value_t cvalue_sizeof(value_t *args, uint32_t nargs) { argcount("sizeof", nargs, 1); if (issymbol(args[0]) || iscons(args[0])) { @@ -608,7 +608,7 @@ value_t cvalue_sizeof(value_t *args, u_int32_t nargs) return size_wrap(n); } -value_t cvalue_typeof(value_t *args, u_int32_t nargs) +value_t cvalue_typeof(value_t *args, uint32_t nargs) { argcount("typeof", nargs, 1); switch (tag(args[0])) { @@ -684,7 +684,7 @@ value_t cvalue_copy(value_t v) return tagptr(ncv, TAG_CVALUE); } -value_t fl_copy(value_t *args, u_int32_t nargs) +value_t fl_copy(value_t *args, uint32_t nargs) { argcount("copy", nargs, 1); if (iscons(args[0]) || isvector(args[0])) @@ -696,7 +696,7 @@ value_t fl_copy(value_t *args, u_int32_t nargs) return cvalue_copy(args[0]); } -value_t fl_podp(value_t *args, u_int32_t nargs) +value_t fl_podp(value_t *args, uint32_t nargs) { argcount("plain-old-data?", nargs, 1); return (iscprim(args[0]) || @@ -760,7 +760,7 @@ static numerictype_t sym_to_numtype(value_t type) // this provides (1) a way to allocate values with a shared type for // efficiency, (2) a uniform interface for allocating cvalues of any // type, including user-defined. -value_t cvalue_new(value_t *args, u_int32_t nargs) +value_t cvalue_new(value_t *args, uint32_t nargs) { if (nargs < 1 || nargs > 2) argcount("c-value", nargs, 2); @@ -810,7 +810,7 @@ value_t cvalue_compare(value_t a, value_t b) } static void check_addr_args(char *fname, value_t arr, value_t ind, - char **data, ulong_t *index) + char **data, unsigned long *index) { size_t numel; struct cvalue *cv = (struct cvalue *)ptr(arr); @@ -824,7 +824,7 @@ static void check_addr_args(char *fname, value_t arr, value_t ind, static value_t cvalue_array_aref(value_t *args) { char *data; - ulong_t index; + unsigned long index; struct fltype *eltype = cv_class((struct cvalue *)ptr(args[0]))->eltype; value_t el = 0; numerictype_t nt = eltype->numtype; @@ -858,7 +858,7 @@ static value_t cvalue_array_aref(value_t *args) static value_t cvalue_array_aset(value_t *args) { char *data; - ulong_t index; + unsigned long index; struct fltype *eltype = cv_class((struct cvalue *)ptr(args[0]))->eltype; check_addr_args("aset!", args[0], args[1], &data, &index); char *dest = data + index * eltype->size; @@ -866,7 +866,7 @@ static value_t cvalue_array_aset(value_t *args) return args[2]; } -value_t fl_builtin(value_t *args, u_int32_t nargs) +value_t fl_builtin(value_t *args, uint32_t nargs) { argcount("builtin", nargs, 1); struct symbol *name = tosymbol(args[0], "builtin"); @@ -893,11 +893,11 @@ value_t cbuiltin(char *name, builtin_t f) return tagptr(cv, TAG_CVALUE); } -static value_t fl_logand(value_t *args, u_int32_t nargs); -static value_t fl_logior(value_t *args, u_int32_t nargs); -static value_t fl_logxor(value_t *args, u_int32_t nargs); -static value_t fl_lognot(value_t *args, u_int32_t nargs); -static value_t fl_ash(value_t *args, u_int32_t nargs); +static value_t fl_logand(value_t *args, uint32_t nargs); +static value_t fl_logior(value_t *args, uint32_t nargs); +static value_t fl_logxor(value_t *args, uint32_t nargs); +static value_t fl_lognot(value_t *args, uint32_t nargs); +static value_t fl_ash(value_t *args, uint32_t nargs); static struct builtinspec cvalues_builtin_info[] = { { "c-value", cvalue_new }, @@ -1017,7 +1017,7 @@ static void cvalues_init(void) setc(emptystringsym, cvalue_static_cstring("")); } -#define RETURN_NUM_AS(var, type) return (mk_##type((fl_##type##_t)var)) +#define RETURN_NUM_AS(var, type) return (mk_##type((type##_t)var)) value_t return_from_uint64(uint64_t Uaccum) { @@ -1047,7 +1047,7 @@ value_t return_from_int64(int64_t Saccum) RETURN_NUM_AS(Saccum, int32); } -static value_t fl_add_any(value_t *args, u_int32_t nargs, fixnum_t carryIn) +static value_t fl_add_any(value_t *args, uint32_t nargs, fixnum_t carryIn) { uint64_t Uaccum = 0; int64_t Saccum = carryIn; @@ -1185,7 +1185,7 @@ static value_t fl_neg(value_t n) type_error("-", "number", n); } -static value_t fl_mul_any(value_t *args, u_int32_t nargs, int64_t Saccum) +static value_t fl_mul_any(value_t *args, uint32_t nargs, int64_t Saccum) { uint64_t Uaccum = 1; double Faccum = 1; @@ -1501,7 +1501,7 @@ static value_t fl_bitwise_op(value_t a, value_t b, int opcode, char *fname) return NIL; } -static value_t fl_logand(value_t *args, u_int32_t nargs) +static value_t fl_logand(value_t *args, uint32_t nargs) { value_t v, e; int i; @@ -1518,7 +1518,7 @@ static value_t fl_logand(value_t *args, u_int32_t nargs) return v; } -static value_t fl_logior(value_t *args, u_int32_t nargs) +static value_t fl_logior(value_t *args, uint32_t nargs) { value_t v, e; int i; @@ -1535,7 +1535,7 @@ static value_t fl_logior(value_t *args, u_int32_t nargs) return v; } -static value_t fl_logxor(value_t *args, u_int32_t nargs) +static value_t fl_logxor(value_t *args, uint32_t nargs) { value_t v, e; int i; @@ -1552,7 +1552,7 @@ static value_t fl_logxor(value_t *args, u_int32_t nargs) return v; } -static value_t fl_lognot(value_t *args, u_int32_t nargs) +static value_t fl_lognot(value_t *args, uint32_t nargs) { argcount("lognot", nargs, 1); value_t a = args[0]; @@ -1588,7 +1588,7 @@ static value_t fl_lognot(value_t *args, u_int32_t nargs) type_error("lognot", "integer", a); } -static value_t fl_ash(value_t *args, u_int32_t nargs) +static value_t fl_ash(value_t *args, uint32_t nargs) { fixnum_t n; int64_t accum; diff --git a/c/dtypes.h b/c/dtypes.h index 9e94d39..0835f18 100644 --- a/c/dtypes.h +++ b/c/dtypes.h @@ -96,62 +96,35 @@ typedef int bool_t; #if defined(__INTEL_COMPILER) && defined(WIN32) #define STATIC_INLINE static #define INLINE -#ifdef BITS64 -typedef unsigned long size_t; -#else -typedef unsigned int size_t; -#endif #else #define STATIC_INLINE static inline #define INLINE inline #endif -typedef unsigned char byte_t; /* 1 byte */ -#if defined(WIN32) -typedef short int16_t; -typedef int int32_t; -typedef long long int64_t; -typedef unsigned char u_int8_t; -typedef unsigned short u_int16_t; -typedef unsigned int u_int32_t; -#ifdef BITS64 -typedef unsigned long u_int64_t; -#else -typedef unsigned long long u_int64_t; -#endif -#ifdef __INTEL_COMPILER -typedef signed char int8_t; -typedef short int16_t; -typedef int int32_t; -#endif -#else -#include -#endif - #ifdef BITS64 #define TOP_BIT 0x8000000000000000 #define NBITS 64 typedef unsigned long uint_t; // preferred int type on platform typedef long int_t; typedef int64_t offset_t; -typedef u_int64_t index_t; +typedef uint64_t index_t; typedef int64_t ptrint_t; // pointer-size int -typedef u_int64_t u_ptrint_t; +typedef uint64_t u_ptrint_t; #else #define TOP_BIT 0x80000000 #define NBITS 32 typedef unsigned long uint_t; typedef long int_t; typedef int32_t offset_t; -typedef u_int32_t index_t; +typedef uint32_t index_t; typedef int32_t ptrint_t; -typedef u_int32_t u_ptrint_t; +typedef uint32_t u_ptrint_t; #endif -typedef u_int8_t uint8_t; -typedef u_int16_t uint16_t; -typedef u_int32_t uint32_t; -typedef u_int64_t uint64_t; +typedef uint8_t uint8_t; +typedef uint16_t uint16_t; +typedef uint32_t uint32_t; +typedef uint64_t uint64_t; typedef u_ptrint_t uptrint_t; #define LLT_ALIGN(x, sz) (((x) + (sz - 1)) & (-sz)) diff --git a/c/dump.c b/c/dump.c index c4b150c..0ed229f 100644 --- a/c/dump.c +++ b/c/dump.c @@ -1,3 +1,5 @@ +#include + #include #include diff --git a/c/equal.h b/c/equal.h index 09583d1..e440127 100644 --- a/c/equal.h +++ b/c/equal.h @@ -395,7 +395,7 @@ uptrint_t hash_lispvalue(value_t a) return n; } -value_t fl_hash(value_t *args, u_int32_t nargs) +value_t fl_hash(value_t *args, uint32_t nargs) { argcount("hash", nargs, 1); return fixnum(hash_lispvalue(args[0])); diff --git a/c/flisp.c b/c/flisp.c index 93b5ff6..21cd954 100644 --- a/c/flisp.c +++ b/c/flisp.c @@ -333,7 +333,7 @@ value_t fl_gensym(value_t *args, uint32_t nargs) int fl_isgensym(value_t v) { return isgensym(v); } -static value_t fl_gensymp(value_t *args, u_int32_t nargs) +static value_t fl_gensymp(value_t *args, uint32_t nargs) { argcount("gensym?", nargs, 1); return isgensym(args[0]) ? FL_T : FL_F; @@ -2307,13 +2307,13 @@ static value_t fl_function_name(value_t *args, uint32_t nargs) return fn_name(v); } -value_t fl_copylist(value_t *args, u_int32_t nargs) +value_t fl_copylist(value_t *args, uint32_t nargs) { argcount("copy-list", nargs, 1); return copy_list(args[0]); } -value_t fl_append(value_t *args, u_int32_t nargs) +value_t fl_append(value_t *args, uint32_t nargs) { if (nargs == 0) return NIL; @@ -2344,7 +2344,7 @@ value_t fl_append(value_t *args, u_int32_t nargs) return first; } -value_t fl_liststar(value_t *args, u_int32_t nargs) +value_t fl_liststar(value_t *args, uint32_t nargs) { if (nargs == 1) return args[0]; @@ -2353,14 +2353,14 @@ value_t fl_liststar(value_t *args, u_int32_t nargs) return _list(args, nargs, 1); } -value_t fl_stacktrace(value_t *args, u_int32_t nargs) +value_t fl_stacktrace(value_t *args, uint32_t nargs) { (void)args; argcount("stacktrace", nargs, 0); return _stacktrace(fl_throwing_frame ? fl_throwing_frame : curr_frame); } -value_t fl_map1(value_t *args, u_int32_t nargs) +value_t fl_map1(value_t *args, uint32_t nargs) { if (nargs < 2) lerror(ArgError, "map: too few arguments"); diff --git a/c/flisp.h b/c/flisp.h index 1f3e374..8b418dd 100644 --- a/c/flisp.h +++ b/c/flisp.h @@ -313,24 +313,6 @@ struct function { (iscprim(v) ? cp_data((struct cprim *)ptr(v)) \ : cv_data((struct cvalue *)ptr(v))) -/* C type names corresponding to cvalues type names */ -typedef int8_t fl_int8_t; -typedef uint8_t fl_uint8_t; -typedef int16_t fl_int16_t; -typedef uint16_t fl_uint16_t; -typedef int32_t fl_int32_t; -typedef uint32_t fl_uint32_t; -typedef int64_t fl_int64_t; -typedef uint64_t fl_uint64_t; -typedef char fl_char_t; -typedef char char_t; -typedef long fl_long_t; -typedef long long_t; -typedef unsigned long fl_ulong_t; -typedef unsigned long ulong_t; -typedef double fl_double_t; -typedef float fl_float_t; - typedef value_t (*builtin_t)(value_t *, uint32_t); extern value_t QUOTE; @@ -377,8 +359,8 @@ struct fltype *get_array_type(value_t eltype); struct fltype *define_opaque_type(value_t sym, size_t sz, struct cvtable *vtab, cvinitfunc_t init); -value_t mk_double(fl_double_t n); -value_t mk_float(fl_float_t n); +value_t mk_double(double n); +value_t mk_float(float n); value_t mk_uint32(uint32_t n); value_t mk_uint64(uint64_t n); value_t mk_wchar(int32_t n); @@ -408,7 +390,7 @@ struct builtinspec { void assign_global_builtins(struct builtinspec *b); /* builtins */ -value_t fl_hash(value_t *args, u_int32_t nargs); +value_t fl_hash(value_t *args, uint32_t nargs); value_t cvalue_byte(value_t *args, uint32_t nargs); value_t cvalue_wchar(value_t *args, uint32_t nargs); diff --git a/c/hashing.c b/c/hashing.c index c67545c..42a1ba1 100644 --- a/c/hashing.c +++ b/c/hashing.c @@ -43,7 +43,7 @@ uint_t nextipow2(uint_t i) return i << 1; } -u_int32_t int32hash(u_int32_t a) +uint32_t int32hash(uint32_t a) { a = (a + 0x7ed55d16) + (a << 12); a = (a ^ 0xc761c23c) ^ (a >> 19); @@ -54,7 +54,7 @@ u_int32_t int32hash(u_int32_t a) return a; } -u_int64_t int64hash(u_int64_t key) +uint64_t int64hash(uint64_t key) { key = (~key) + (key << 21); // key = (key << 21) - key - 1; key = key ^ (key >> 24); @@ -66,7 +66,7 @@ u_int64_t int64hash(u_int64_t key) return key; } -u_int32_t int64to32hash(u_int64_t key) +uint32_t int64to32hash(uint64_t key) { key = (~key) + (key << 18); // key = (key << 18) - key - 1; key = key ^ (key >> 31); @@ -74,22 +74,22 @@ u_int32_t int64to32hash(u_int64_t key) key = key ^ (key >> 11); key = key + (key << 6); key = key ^ (key >> 22); - return (u_int32_t)key; + return (uint32_t)key; } #include "lookup3.h" -u_int64_t memhash(const char *buf, size_t n) +uint64_t memhash(const char *buf, size_t n) { - u_int32_t c = 0xcafe8881, b = 0x4d6a087c; + uint32_t c = 0xcafe8881, b = 0x4d6a087c; hashlittle2(buf, n, &c, &b); - return (u_int64_t)c | (((u_int64_t)b) << 32); + return (uint64_t)c | (((uint64_t)b) << 32); } -u_int32_t memhash32(const char *buf, size_t n) +uint32_t memhash32(const char *buf, size_t n) { - u_int32_t c = 0xcafe8881, b = 0x4d6a087c; + uint32_t c = 0xcafe8881, b = 0x4d6a087c; hashlittle2(buf, n, &c, &b); return c; diff --git a/c/hashing.h b/c/hashing.h index 6764641..ced1e07 100644 --- a/c/hashing.h +++ b/c/hashing.h @@ -1,11 +1,11 @@ uint_t nextipow2(uint_t i); -u_int32_t int32hash(u_int32_t a); -u_int64_t int64hash(u_int64_t key); -u_int32_t int64to32hash(u_int64_t key); +uint32_t int32hash(uint32_t a); +uint64_t int64hash(uint64_t key); +uint32_t int64to32hash(uint64_t key); #ifdef BITS64 #define inthash int64hash #else #define inthash int32hash #endif -u_int64_t memhash(const char *buf, size_t n); -u_int32_t memhash32(const char *buf, size_t n); +uint64_t memhash(const char *buf, size_t n); +uint32_t memhash32(const char *buf, size_t n); diff --git a/c/iostream.c b/c/iostream.c index 78cf4f9..6a47718 100644 --- a/c/iostream.c +++ b/c/iostream.c @@ -119,7 +119,7 @@ value_t fl_file(value_t *args, uint32_t nargs) return f; } -value_t fl_buffer(value_t *args, u_int32_t nargs) +value_t fl_buffer(value_t *args, uint32_t nargs) { argcount("buffer", nargs, 0); (void)args; @@ -130,7 +130,7 @@ value_t fl_buffer(value_t *args, u_int32_t nargs) return f; } -value_t fl_read(value_t *args, u_int32_t nargs) +value_t fl_read(value_t *args, uint32_t nargs) { value_t arg = 0; if (nargs > 1) { @@ -149,7 +149,7 @@ value_t fl_read(value_t *args, u_int32_t nargs) return v; } -value_t fl_iogetc(value_t *args, u_int32_t nargs) +value_t fl_iogetc(value_t *args, uint32_t nargs) { argcount("io.getc", nargs, 1); struct ios *s = toiostream(args[0], "io.getc"); @@ -160,7 +160,7 @@ value_t fl_iogetc(value_t *args, u_int32_t nargs) return mk_wchar(wc); } -value_t fl_iopeekc(value_t *args, u_int32_t nargs) +value_t fl_iopeekc(value_t *args, uint32_t nargs) { argcount("io.peekc", nargs, 1); struct ios *s = toiostream(args[0], "io.peekc"); @@ -170,7 +170,7 @@ value_t fl_iopeekc(value_t *args, u_int32_t nargs) return mk_wchar(wc); } -value_t fl_ioputc(value_t *args, u_int32_t nargs) +value_t fl_ioputc(value_t *args, uint32_t nargs) { argcount("io.putc", nargs, 2); struct ios *s = toiostream(args[0], "io.putc"); @@ -181,7 +181,7 @@ value_t fl_ioputc(value_t *args, u_int32_t nargs) return fixnum(ios_pututf8(s, wc)); } -value_t fl_ioungetc(value_t *args, u_int32_t nargs) +value_t fl_ioungetc(value_t *args, uint32_t nargs) { argcount("io.ungetc", nargs, 2); struct ios *s = toiostream(args[0], "io.ungetc"); @@ -195,7 +195,7 @@ value_t fl_ioungetc(value_t *args, u_int32_t nargs) return fixnum(ios_ungetc((int)wc, s)); } -value_t fl_ioflush(value_t *args, u_int32_t nargs) +value_t fl_ioflush(value_t *args, uint32_t nargs) { argcount("io.flush", nargs, 1); struct ios *s = toiostream(args[0], "io.flush"); @@ -204,7 +204,7 @@ value_t fl_ioflush(value_t *args, u_int32_t nargs) return FL_T; } -value_t fl_ioclose(value_t *args, u_int32_t nargs) +value_t fl_ioclose(value_t *args, uint32_t nargs) { argcount("io.close", nargs, 1); struct ios *s = toiostream(args[0], "io.close"); @@ -212,7 +212,7 @@ value_t fl_ioclose(value_t *args, u_int32_t nargs) return FL_T; } -value_t fl_iopurge(value_t *args, u_int32_t nargs) +value_t fl_iopurge(value_t *args, uint32_t nargs) { argcount("io.discardbuffer", nargs, 1); struct ios *s = toiostream(args[0], "io.discardbuffer"); @@ -220,14 +220,14 @@ value_t fl_iopurge(value_t *args, u_int32_t nargs) return FL_T; } -value_t fl_ioeof(value_t *args, u_int32_t nargs) +value_t fl_ioeof(value_t *args, uint32_t nargs) { argcount("io.eof?", nargs, 1); struct ios *s = toiostream(args[0], "io.eof?"); return (ios_eof(s) ? FL_T : FL_F); } -value_t fl_ioseek(value_t *args, u_int32_t nargs) +value_t fl_ioseek(value_t *args, uint32_t nargs) { argcount("io.seek", nargs, 2); struct ios *s = toiostream(args[0], "io.seek"); @@ -238,7 +238,7 @@ value_t fl_ioseek(value_t *args, u_int32_t nargs) return FL_T; } -value_t fl_iopos(value_t *args, u_int32_t nargs) +value_t fl_iopos(value_t *args, uint32_t nargs) { argcount("io.pos", nargs, 1); struct ios *s = toiostream(args[0], "io.pos"); @@ -248,7 +248,7 @@ value_t fl_iopos(value_t *args, u_int32_t nargs) return size_wrap((size_t)res); } -value_t fl_write(value_t *args, u_int32_t nargs) +value_t fl_write(value_t *args, uint32_t nargs) { if (nargs < 1 || nargs > 2) argcount("write", nargs, 1); @@ -261,7 +261,7 @@ value_t fl_write(value_t *args, u_int32_t nargs) return args[0]; } -value_t fl_ioread(value_t *args, u_int32_t nargs) +value_t fl_ioread(value_t *args, uint32_t nargs) { if (nargs != 3) argcount("io.read", nargs, 2); @@ -306,7 +306,7 @@ static void get_start_count_args(value_t *args, uint32_t nargs, size_t sz, } } -value_t fl_iowrite(value_t *args, u_int32_t nargs) +value_t fl_iowrite(value_t *args, uint32_t nargs) { if (nargs < 2 || nargs > 4) argcount("io.write", nargs, 2); @@ -330,7 +330,7 @@ value_t fl_iowrite(value_t *args, u_int32_t nargs) return size_wrap(ios_write(s, data, nb)); } -value_t fl_dump(value_t *args, u_int32_t nargs) +value_t fl_dump(value_t *args, uint32_t nargs) { if (nargs < 1 || nargs > 3) argcount("dump", nargs, 1); @@ -360,7 +360,7 @@ static char get_delim_arg(value_t arg, char *fname) return (char)uldelim; } -value_t fl_ioreaduntil(value_t *args, u_int32_t nargs) +value_t fl_ioreaduntil(value_t *args, uint32_t nargs) { argcount("io.readuntil", nargs, 2); value_t str = cvalue_string(80); @@ -384,7 +384,7 @@ value_t fl_ioreaduntil(value_t *args, u_int32_t nargs) return str; } -value_t fl_iocopyuntil(value_t *args, u_int32_t nargs) +value_t fl_iocopyuntil(value_t *args, uint32_t nargs) { argcount("io.copyuntil", nargs, 3); struct ios *dest = toiostream(args[0], "io.copyuntil"); @@ -393,7 +393,7 @@ value_t fl_iocopyuntil(value_t *args, u_int32_t nargs) return size_wrap(ios_copyuntil(dest, src, delim)); } -value_t fl_iocopy(value_t *args, u_int32_t nargs) +value_t fl_iocopy(value_t *args, uint32_t nargs) { if (nargs < 2 || nargs > 3) argcount("io.copy", nargs, 2); @@ -426,7 +426,7 @@ value_t stream_to_string(value_t *ps) return str; } -value_t fl_iotostring(value_t *args, u_int32_t nargs) +value_t fl_iotostring(value_t *args, uint32_t nargs) { argcount("io.tostring!", nargs, 1); struct ios *src = toiostream(args[0], "io.tostring!"); diff --git a/c/print.h b/c/print.h index eec3d14..a7e97b4 100644 --- a/c/print.h +++ b/c/print.h @@ -1,7 +1,7 @@ extern void *memrchr(const void *s, int c, size_t n); static struct htable printconses; -static u_int32_t printlabel; +static uint32_t printlabel; static int print_pretty; static int print_princ; static fixnum_t print_length; diff --git a/c/ptrhash.c b/c/ptrhash.c index 86d3d5d..6c6e570 100644 --- a/c/ptrhash.c +++ b/c/ptrhash.c @@ -16,7 +16,7 @@ #define OP_EQ(x, y) ((x) == (y)) #ifdef BITS64 -static u_int64_t _pinthash(u_int64_t key) +static uint64_t _pinthash(uint64_t key) { key = (~key) + (key << 21); // key = (key << 21) - key - 1; key = key ^ (key >> 24); @@ -28,7 +28,7 @@ static u_int64_t _pinthash(u_int64_t key) return key; } #else -static u_int32_t _pinthash(u_int32_t a) +static uint32_t _pinthash(uint32_t a) { a = (a + 0x7ed55d16) + (a << 12); a = (a ^ 0xc761c23c) ^ (a >> 19); diff --git a/c/random.c b/c/random.c index ac6d344..00faa55 100644 --- a/c/random.c +++ b/c/random.c @@ -59,6 +59,6 @@ double randn() void randomize() { - u_int64_t tm = i64time(); + uint64_t tm = i64time(); init_by_array((uint32_t *)&tm, 2); } diff --git a/c/random.h b/c/random.h index da1bffb..383fa67 100644 --- a/c/random.h +++ b/c/random.h @@ -6,4 +6,4 @@ double randn(); void randomize(); uint32_t genrand_int32(); void init_genrand(uint32_t s); -u_int64_t i64time(); +uint64_t i64time(); diff --git a/c/read.h b/c/read.h index 746c250..1d1f896 100644 --- a/c/read.h +++ b/c/read.h @@ -113,7 +113,7 @@ static int read_numtok(char *tok, value_t *pval, int base) return result; } -static u_int32_t toktype = TOK_NONE; +static uint32_t toktype = TOK_NONE; static value_t tokval; static char buf[256]; @@ -190,7 +190,7 @@ terminate: static value_t do_read_sexpr(value_t label); -static u_int32_t peek(void) +static uint32_t peek(void) { char c, *end; fixnum_t x; @@ -405,10 +405,10 @@ static value_t vector_grow(value_t v) return POP(); } -static value_t read_vector(value_t label, u_int32_t closer) +static value_t read_vector(value_t label, uint32_t closer) { value_t v = the_empty_vector, elt; - u_int32_t i = 0; + uint32_t i = 0; PUSH(v); if (label != UNBOUND) ptrhash_put(&readstate->backrefs, (void *)label, (void *)v); @@ -439,7 +439,7 @@ static value_t read_string(void) size_t i = 0, j, sz = 64, ndig; int c; value_t s; - u_int32_t wc = 0; + uint32_t wc = 0; buf = malloc(sz); while (1) { @@ -516,7 +516,7 @@ static value_t read_string(void) static void read_list(value_t *pval, value_t label) { value_t c, *pc; - u_int32_t t; + uint32_t t; PUSH(NIL); pc = &Stack[SP - 1]; // to keep track of current cons cell @@ -560,7 +560,7 @@ static value_t do_read_sexpr(value_t label) { value_t v, sym, oldtokval, *head; value_t *pv; - u_int32_t t; + uint32_t t; char c; t = peek(); diff --git a/c/string.c b/c/string.c index 48cdb36..9552ce4 100644 --- a/c/string.c +++ b/c/string.c @@ -32,13 +32,13 @@ #include "flisp.h" -value_t fl_stringp(value_t *args, u_int32_t nargs) +value_t fl_stringp(value_t *args, uint32_t nargs) { argcount("string?", nargs, 1); return fl_isstring(args[0]) ? FL_T : FL_F; } -value_t fl_string_count(value_t *args, u_int32_t nargs) +value_t fl_string_count(value_t *args, uint32_t nargs) { size_t start = 0; if (nargs < 1 || nargs > 3) @@ -63,7 +63,7 @@ value_t fl_string_count(value_t *args, u_int32_t nargs) return size_wrap(u8_charnum(str + start, stop - start)); } -value_t fl_string_width(value_t *args, u_int32_t nargs) +value_t fl_string_width(value_t *args, uint32_t nargs) { argcount("string.width", nargs, 1); if (iscprim(args[0])) { @@ -79,7 +79,7 @@ value_t fl_string_width(value_t *args, u_int32_t nargs) return size_wrap(u8_strwidth(s)); } -value_t fl_string_reverse(value_t *args, u_int32_t nargs) +value_t fl_string_reverse(value_t *args, uint32_t nargs) { argcount("string.reverse", nargs, 1); if (!fl_isstring(args[0])) @@ -90,7 +90,7 @@ value_t fl_string_reverse(value_t *args, u_int32_t nargs) return ns; } -value_t fl_string_encode(value_t *args, u_int32_t nargs) +value_t fl_string_encode(value_t *args, uint32_t nargs) { argcount("string.encode", nargs, 1); if (iscvalue(args[0])) { @@ -110,7 +110,7 @@ value_t fl_string_encode(value_t *args, u_int32_t nargs) type_error("string.encode", "wchar array", args[0]); } -value_t fl_string_decode(value_t *args, u_int32_t nargs) +value_t fl_string_decode(value_t *args, uint32_t nargs) { int term = 0; if (nargs == 2) { @@ -136,10 +136,10 @@ value_t fl_string_decode(value_t *args, u_int32_t nargs) return wcstr; } -extern value_t fl_buffer(value_t *args, u_int32_t nargs); +extern value_t fl_buffer(value_t *args, uint32_t nargs); extern value_t stream_to_string(value_t *ps); -value_t fl_string(value_t *args, u_int32_t nargs) +value_t fl_string(value_t *args, uint32_t nargs) { if (nargs == 1 && fl_isstring(args[0])) return args[0]; @@ -159,7 +159,7 @@ value_t fl_string(value_t *args, u_int32_t nargs) return outp; } -value_t fl_string_split(value_t *args, u_int32_t nargs) +value_t fl_string_split(value_t *args, uint32_t nargs) { argcount("string.split", nargs, 2); char *s = tostring(args[0], "string.split"); @@ -203,7 +203,7 @@ value_t fl_string_split(value_t *args, u_int32_t nargs) return first; } -value_t fl_string_sub(value_t *args, u_int32_t nargs) +value_t fl_string_sub(value_t *args, uint32_t nargs) { if (nargs != 2) argcount("string.sub", nargs, 3); @@ -227,7 +227,7 @@ value_t fl_string_sub(value_t *args, u_int32_t nargs) return ns; } -value_t fl_string_char(value_t *args, u_int32_t nargs) +value_t fl_string_char(value_t *args, uint32_t nargs) { argcount("string.char", nargs, 2); char *s = tostring(args[0], "string.char"); @@ -241,7 +241,7 @@ value_t fl_string_char(value_t *args, u_int32_t nargs) return mk_wchar(u8_nextchar(s, &i)); } -value_t fl_char_upcase(value_t *args, u_int32_t nargs) +value_t fl_char_upcase(value_t *args, uint32_t nargs) { argcount("char.upcase", nargs, 1); struct cprim *cp = (struct cprim *)ptr(args[0]); @@ -249,7 +249,7 @@ value_t fl_char_upcase(value_t *args, u_int32_t nargs) type_error("char.upcase", "wchar", args[0]); return mk_wchar(towupper(*(int32_t *)cp_data(cp))); } -value_t fl_char_downcase(value_t *args, u_int32_t nargs) +value_t fl_char_downcase(value_t *args, uint32_t nargs) { argcount("char.downcase", nargs, 1); struct cprim *cp = (struct cprim *)ptr(args[0]); @@ -258,7 +258,7 @@ value_t fl_char_downcase(value_t *args, u_int32_t nargs) return mk_wchar(towlower(*(int32_t *)cp_data(cp))); } -value_t fl_char_alpha(value_t *args, u_int32_t nargs) +value_t fl_char_alpha(value_t *args, uint32_t nargs) { argcount("char-alphabetic?", nargs, 1); struct cprim *cp = (struct cprim *)ptr(args[0]); @@ -275,7 +275,7 @@ static value_t mem_find_byte(char *s, char c, size_t start, size_t len) return size_wrap((size_t)(p - s)); } -value_t fl_string_find(value_t *args, u_int32_t nargs) +value_t fl_string_find(value_t *args, uint32_t nargs) { char cbuf[8]; size_t start = 0; @@ -323,7 +323,7 @@ value_t fl_string_find(value_t *args, u_int32_t nargs) return FL_F; } -value_t fl_string_inc(value_t *args, u_int32_t nargs) +value_t fl_string_inc(value_t *args, uint32_t nargs) { if (nargs < 2 || nargs > 3) argcount("string.inc", nargs, 2); @@ -341,7 +341,7 @@ value_t fl_string_inc(value_t *args, u_int32_t nargs) return size_wrap(i); } -value_t fl_string_dec(value_t *args, u_int32_t nargs) +value_t fl_string_dec(value_t *args, uint32_t nargs) { if (nargs < 2 || nargs > 3) argcount("string.dec", nargs, 2); @@ -370,7 +370,7 @@ static unsigned long get_radix_arg(value_t arg, char *fname) return radix; } -value_t fl_numbertostring(value_t *args, u_int32_t nargs) +value_t fl_numbertostring(value_t *args, uint32_t nargs) { if (nargs < 1 || nargs > 2) argcount("number->string", nargs, 2); @@ -412,7 +412,7 @@ value_t fl_stringtonumber(value_t *args, uint32_t nargs) return n; } -value_t fl_string_isutf8(value_t *args, u_int32_t nargs) +value_t fl_string_isutf8(value_t *args, uint32_t nargs) { argcount("string.isutf8", nargs, 1); char *s = tostring(args[0], "string.isutf8"); diff --git a/c/timefuncs.c b/c/timefuncs.c index 9496c28..b3c204a 100644 --- a/c/timefuncs.c +++ b/c/timefuncs.c @@ -50,17 +50,17 @@ double diff_time(struct timeval *tv1, struct timeval *tv2) #endif // return as many bits of system randomness as we can get our hands on -u_int64_t i64time() +uint64_t i64time() { - u_int64_t a; + uint64_t a; #ifdef WIN32 struct timeb tstruct; ftime(&tstruct); - a = (((u_int64_t)tstruct.time) << 32) + (u_int64_t)tstruct.millitm; + a = (((uint64_t)tstruct.time) << 32) + (uint64_t)tstruct.millitm; #else struct timeval now; gettimeofday(&now, NULL); - a = (((u_int64_t)now.tv_sec) << 32) + (u_int64_t)now.tv_usec; + a = (((uint64_t)now.tv_sec) << 32) + (uint64_t)now.tv_usec; #endif return a; diff --git a/c/timefuncs.h b/c/timefuncs.h index a166063..f33568b 100644 --- a/c/timefuncs.h +++ b/c/timefuncs.h @@ -1,4 +1,4 @@ -u_int64_t i64time(); +uint64_t i64time(); double clock_now(); void timestring(double seconds, char *buffer, size_t len); double parsetime(const char *str); diff --git a/c/utf8.c b/c/utf8.c index 56ad796..8d5bb25 100644 --- a/c/utf8.c +++ b/c/utf8.c @@ -36,9 +36,9 @@ #include "utf8.h" -static const u_int32_t offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, - 0x000E2080UL, 0x03C82080UL, - 0xFA082080UL, 0x82082080UL }; +static const uint32_t offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, + 0x000E2080UL, 0x03C82080UL, + 0xFA082080UL, 0x82082080UL }; static const char trailingBytesForUTF8[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -62,7 +62,7 @@ size_t u8_seqlen(const char *s) /* returns the # of bytes needed to encode a certain character 0 means the character cannot (or should not) be encoded. */ -size_t u8_charlen(u_int32_t ch) +size_t u8_charlen(uint32_t ch) { if (ch < 0x80) return 1; @@ -75,7 +75,7 @@ size_t u8_charlen(u_int32_t ch) return 0; } -size_t u8_codingsize(u_int32_t *wcstr, size_t n) +size_t u8_codingsize(uint32_t *wcstr, size_t n) { size_t i, c = 0; @@ -92,9 +92,9 @@ size_t u8_codingsize(u_int32_t *wcstr, size_t n) returns # characters converted if sz == srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space. */ -size_t u8_toucs(u_int32_t *dest, size_t sz, const char *src, size_t srcsz) +size_t u8_toucs(uint32_t *dest, size_t sz, const char *src, size_t srcsz) { - u_int32_t ch; + uint32_t ch; const char *src_end = src + srcsz; size_t nb; size_t i = 0; @@ -146,9 +146,9 @@ size_t u8_toucs(u_int32_t *dest, size_t sz, const char *src, size_t srcsz) returns # bytes stored in dest the destination string will never be bigger than the source string. */ -size_t u8_toutf8(char *dest, size_t sz, const u_int32_t *src, size_t srcsz) +size_t u8_toutf8(char *dest, size_t sz, const uint32_t *src, size_t srcsz) { - u_int32_t ch; + uint32_t ch; size_t i = 0; char *dest0 = dest; char *dest_end = dest + sz; @@ -183,7 +183,7 @@ size_t u8_toutf8(char *dest, size_t sz, const u_int32_t *src, size_t srcsz) return (dest - dest0); } -size_t u8_wc_toutf8(char *dest, u_int32_t ch) +size_t u8_wc_toutf8(char *dest, uint32_t ch) { if (ch < 0x80) { dest[0] = (char)ch; @@ -263,7 +263,7 @@ size_t u8_strlen(const char *s) size_t u8_strwidth(const char *s) { - u_int32_t ch; + uint32_t ch; size_t nb, tot = 0; int w; signed char sc; @@ -311,9 +311,9 @@ size_t u8_strwidth(const char *s) } /* reads the next utf-8 sequence out of a string, updating an index */ -u_int32_t u8_nextchar(const char *s, size_t *i) +uint32_t u8_nextchar(const char *s, size_t *i) { - u_int32_t ch = 0; + uint32_t ch = 0; size_t sz = 0; do { @@ -327,9 +327,9 @@ u_int32_t u8_nextchar(const char *s, size_t *i) } /* next character without NUL character terminator */ -u_int32_t u8_nextmemchar(const char *s, size_t *i) +uint32_t u8_nextmemchar(const char *s, size_t *i) { - u_int32_t ch = 0; + uint32_t ch = 0; size_t sz = 0; do { @@ -385,10 +385,10 @@ char read_escape_control_char(char c) /* assumes that src points to the character after a backslash returns number of input characters processed, 0 if error */ -size_t u8_read_escape_sequence(const char *str, size_t ssz, u_int32_t *dest) +size_t u8_read_escape_sequence(const char *str, size_t ssz, uint32_t *dest) { assert(ssz > 0); - u_int32_t ch; + uint32_t ch; char digs[10]; int dno = 0, ndig; size_t i = 1; @@ -411,7 +411,7 @@ size_t u8_read_escape_sequence(const char *str, size_t ssz, u_int32_t *dest) digs[dno] = '\0'; ch = strtol(digs, NULL, 16); } else { - ch = (u_int32_t)read_escape_control_char(c0); + ch = (uint32_t)read_escape_control_char(c0); } *dest = ch; @@ -424,7 +424,7 @@ size_t u8_read_escape_sequence(const char *str, size_t ssz, u_int32_t *dest) size_t u8_unescape(char *buf, size_t sz, const char *src) { size_t c = 0, amt; - u_int32_t ch; + uint32_t ch; char temp[4]; while (*src && c < sz) { @@ -432,7 +432,7 @@ size_t u8_unescape(char *buf, size_t sz, const char *src) src++; amt = u8_read_escape_sequence(src, 1000, &ch); } else { - ch = (u_int32_t)*src; + ch = (uint32_t)*src; amt = 1; } src += amt; @@ -455,7 +455,7 @@ static inline int buf_put2c(char *buf, const char *src) return 2; } -int u8_escape_wchar(char *buf, size_t sz, u_int32_t ch) +int u8_escape_wchar(char *buf, size_t sz, uint32_t ch) { assert(sz > 2); if (ch == L'\n') @@ -479,7 +479,7 @@ int u8_escape_wchar(char *buf, size_t sz, u_int32_t ch) else if (ch < 32 || ch == 0x7f) return snprintf(buf, sz, "\\x%.2hhx", (unsigned char)ch); else if (ch > 0xFFFF) - return snprintf(buf, sz, "\\U%.8x", (u_int32_t)ch); + return snprintf(buf, sz, "\\U%.8x", (uint32_t)ch); else if (ch >= 0x80) return snprintf(buf, sz, "\\u%.4hx", (unsigned short)ch); @@ -492,7 +492,7 @@ size_t u8_escape(char *buf, size_t sz, const char *src, size_t *pi, size_t end, int escape_quotes, int ascii) { size_t i = *pi, i0; - u_int32_t ch; + uint32_t ch; char *start = buf; char *blim = start + sz - 11; assert(sz > 11); @@ -523,10 +523,10 @@ size_t u8_escape(char *buf, size_t sz, const char *src, size_t *pi, return (buf - start); } -char *u8_strchr(const char *s, u_int32_t ch, size_t *charn) +char *u8_strchr(const char *s, uint32_t ch, size_t *charn) { size_t i = 0, lasti = 0; - u_int32_t c; + uint32_t c; *charn = 0; while (s[i]) { @@ -541,10 +541,10 @@ char *u8_strchr(const char *s, u_int32_t ch, size_t *charn) return NULL; } -char *u8_memchr(const char *s, u_int32_t ch, size_t sz, size_t *charn) +char *u8_memchr(const char *s, uint32_t ch, size_t sz, size_t *charn) { size_t i = 0, lasti = 0; - u_int32_t c; + uint32_t c; int csz; *charn = 0; @@ -566,10 +566,10 @@ char *u8_memchr(const char *s, u_int32_t ch, size_t sz, size_t *charn) return NULL; } -char *u8_memrchr(const char *s, u_int32_t ch, size_t sz) +char *u8_memrchr(const char *s, uint32_t ch, size_t sz) { size_t i = sz - 1, tempi = 0; - u_int32_t c; + uint32_t c; if (sz == 0) return NULL; @@ -620,7 +620,7 @@ size_t u8_vprintf(const char *fmt, va_list ap) { size_t cnt, sz = 0, nc, needfree = 0; char *buf; - u_int32_t *wcs; + uint32_t *wcs; sz = 512; buf = (char *)alloca(sz); @@ -632,7 +632,7 @@ size_t u8_vprintf(const char *fmt, va_list ap) needfree = 1; vsnprintf(buf, cnt + 1, fmt, ap); } - wcs = (u_int32_t *)alloca((cnt + 1) * sizeof(u_int32_t)); + wcs = (uint32_t *)alloca((cnt + 1) * sizeof(uint32_t)); nc = u8_toucs(wcs, cnt + 1, buf, cnt); wcs[nc] = 0; printf("%ls", (wchar_t *)wcs); diff --git a/c/utf8.h b/c/utf8.h index 3f8314a..c534e4e 100644 --- a/c/utf8.h +++ b/c/utf8.h @@ -7,16 +7,16 @@ extern int wcwidth(uint32_t); /* is c the start of a utf8 sequence? */ #define isutf(c) (((c)&0xC0) != 0x80) -#define UEOF ((u_int32_t)-1) +#define UEOF ((uint32_t)-1) /* convert UTF-8 data to wide character */ -size_t u8_toucs(u_int32_t *dest, size_t sz, const char *src, size_t srcsz); +size_t u8_toucs(uint32_t *dest, size_t sz, const char *src, size_t srcsz); /* the opposite conversion */ -size_t u8_toutf8(char *dest, size_t sz, const u_int32_t *src, size_t srcsz); +size_t u8_toutf8(char *dest, size_t sz, const uint32_t *src, size_t srcsz); /* single character to UTF-8, returns # bytes written */ -size_t u8_wc_toutf8(char *dest, u_int32_t ch); +size_t u8_wc_toutf8(char *dest, uint32_t ch); /* character number to byte offset */ size_t u8_offset(const char *str, size_t charnum); @@ -25,10 +25,10 @@ size_t u8_offset(const char *str, size_t charnum); size_t u8_charnum(const char *s, size_t offset); /* return next character, updating an index variable */ -u_int32_t u8_nextchar(const char *s, size_t *i); +uint32_t u8_nextchar(const char *s, size_t *i); /* next character without NUL character terminator */ -u_int32_t u8_nextmemchar(const char *s, size_t *i); +uint32_t u8_nextmemchar(const char *s, size_t *i); /* move to next character */ void u8_inc(const char *s, size_t *i); @@ -40,22 +40,22 @@ void u8_dec(const char *s, size_t *i); size_t u8_seqlen(const char *s); /* returns the # of bytes needed to encode a certain character */ -size_t u8_charlen(u_int32_t ch); +size_t u8_charlen(uint32_t ch); /* computes the # of bytes needed to encode a WC string as UTF-8 */ -size_t u8_codingsize(u_int32_t *wcstr, size_t n); +size_t u8_codingsize(uint32_t *wcstr, size_t n); char read_escape_control_char(char c); /* assuming src points to the character after a backslash, read an escape sequence, storing the result in dest and returning the number of input characters processed */ -size_t u8_read_escape_sequence(const char *src, size_t ssz, u_int32_t *dest); +size_t u8_read_escape_sequence(const char *src, size_t ssz, uint32_t *dest); /* given a wide character, convert it to an ASCII escape sequence stored in buf, where buf is "sz" bytes. returns the number of characters output. sz must be at least 3. */ -int u8_escape_wchar(char *buf, size_t sz, u_int32_t ch); +int u8_escape_wchar(char *buf, size_t sz, uint32_t ch); /* convert a string "src" containing escape sequences to UTF-8 */ size_t u8_unescape(char *buf, size_t sz, const char *src); @@ -84,13 +84,13 @@ int hex_digit(char c); /* return a pointer to the first occurrence of ch in s, or NULL if not found. character index of found character returned in *charn. */ -char *u8_strchr(const char *s, u_int32_t ch, size_t *charn); +char *u8_strchr(const char *s, uint32_t ch, size_t *charn); /* same as the above, but searches a buffer of a given size instead of a NUL-terminated string. */ -char *u8_memchr(const char *s, u_int32_t ch, size_t sz, size_t *charn); +char *u8_memchr(const char *s, uint32_t ch, size_t sz, size_t *charn); -char *u8_memrchr(const char *s, u_int32_t ch, size_t sz); +char *u8_memrchr(const char *s, uint32_t ch, size_t sz); /* count the number of characters in a UTF-8 string */ size_t u8_strlen(const char *s); diff --git a/c/utils.h b/c/utils.h index 42e42ba..4a19b3c 100644 --- a/c/utils.h +++ b/c/utils.h @@ -34,14 +34,14 @@ int isdigit_base(char c, int base); #endif #if !defined(__INTEL_COMPILER) && (defined(ARCH_X86) || defined(ARCH_X86_64)) -STATIC_INLINE u_int16_t ByteSwap16(u_int16_t x) +STATIC_INLINE uint16_t ByteSwap16(uint16_t x) { __asm("xchgb %b0,%h0" : LEGACY_REGS(x) : "0"(x)); return x; } #define bswap_16(x) ByteSwap16(x) -STATIC_INLINE u_int32_t ByteSwap32(u_int32_t x) +STATIC_INLINE uint32_t ByteSwap32(uint32_t x) { #if __CPU__ > 386 __asm("bswap %0" @@ -60,15 +60,15 @@ STATIC_INLINE u_int32_t ByteSwap32(u_int32_t x) #define bswap_32(x) ByteSwap32(x) -STATIC_INLINE u_int64_t ByteSwap64(u_int64_t x) +STATIC_INLINE uint64_t ByteSwap64(uint64_t x) { #ifdef ARCH_X86_64 __asm("bswap %0" : "=r"(x) : "0"(x)); return x; #else register union { - __extension__ u_int64_t __ll; - u_int32_t __l[2]; + __extension__ uint64_t __ll; + uint32_t __l[2]; } __x; asm("xchgl %0,%1" : "=r"(__x.__l[0]), "=r"(__x.__l[1]) @@ -91,11 +91,11 @@ STATIC_INLINE u_int64_t ByteSwap64(u_int64_t x) (((x)&0x0000ff00) << 8) | (((x)&0x000000ff) << 24)) #endif -STATIC_INLINE u_int64_t ByteSwap64(u_int64_t x) +STATIC_INLINE uint64_t ByteSwap64(uint64_t x) { union { - u_int64_t ll; - u_int32_t l[2]; + uint64_t ll; + uint32_t l[2]; } w, r; w.ll = x; r.l[0] = bswap_32(w.l[1]);