summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog35
-rw-r--r--gc.c18
-rw-r--r--lib.c27
-rw-r--r--lib.h4
-rw-r--r--match.c4
-rw-r--r--regex.c18
-rw-r--r--regex.h10
-rw-r--r--utf8.c7
8 files changed, 81 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index b7910fd9..aa75edf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,40 @@
2009-11-24 Kaz Kylheku <kkylheku@gmail.com>
+ Changes to make the code portable to C++ compilers, which
+ can be taken advantage of for better diagnostics.
+
+ * gc.c (more, mark_obj, sweep, unmark): Obey stricter C++ rules
+ with regard to enumerations.
+ (make_obj): Avoid using C++ keyword "try".
+
+ * lib.c: Removed duplicate definitions of objects, found by C++.
+ (chk_malloc, chk_realloc): Casts needed when converting from void *.
+ (list): Discovered and fixed lack of va_end.
+ (trim_str, acons_new_l): Avoid use of C++ keyword "new".
+ (make_sym): Follow rename of struct member.
+
+ * lib.h (struct sym): Renamed val member to value.
+ (null): Added missing declaration.
+
+ * match.c (enum fpip_close, struct fpip): Moved and named enum out of
+ struct.
+
+ * regex.c (L0_full): Cast added in signed/unsigned comparison.
+ (L1_fill_range, L2_fill_range, L3_fill_range, char_set_create):
+ Don't mark static blank structures const; then they need initializers
+ in C++.
+ (char_set_compl, char-set_destroy, char_set_contains, nfa_compile_set):
+ Avoid using the C++ keyword "compl".
+
+ * regex.h (struct any_char_set, struct small_char_set, struct
+ displaced_char_set, struct large_char_set, struct xlarge_char_set):
+ Renamed compl member to comp.
+
+ * utf8.c (utf8_from_uc, ut8_decode): Obey stricter C++ rules
+ with regard to enumerations.
+
+2009-11-24 Kaz Kylheku <kkylheku@gmail.com>
+
Fixed broken yyerrorf. It was still taking char *, and passing
that as an object to vformat, resulting in #<garbage: ...>
output.
diff --git a/gc.c b/gc.c
index ec192a9e..4503d894 100644
--- a/gc.c
+++ b/gc.c
@@ -111,7 +111,7 @@ static void more()
while (block < end) {
block->t.next = free_list;
- block->t.type = FREE;
+ block->t.type = (type_t) FREE;
free_list = block++;
}
@@ -123,12 +123,12 @@ static void more()
val make_obj(void)
{
- int try;
+ int tries;
if (opt_gc_debug)
gc();
- for (try = 0; try < 3; try++) {
+ for (tries = 0; tries < 3; tries++) {
if (free_list) {
val ret = free_list;
free_list = free_list->t.next;
@@ -137,7 +137,7 @@ val make_obj(void)
free_tail = &free_list;
- switch (try) {
+ switch (tries) {
case 0: gc(); break;
case 1: more(); break;
}
@@ -204,7 +204,7 @@ tail_call:
if ((t & FREE) != 0)
abort();
- obj->t.type |= REACHABLE;
+ obj->t.type = (type_t) (obj->t.type | REACHABLE);
switch (t) {
case CONS:
@@ -218,7 +218,7 @@ tail_call:
return;
case SYM:
mark_obj(obj->s.name);
- mark_obj(obj->s.val);
+ mark_obj(obj->s.value);
mark_obj_tail(obj->s.package);
case PKG:
mark_obj(obj->pk.name);
@@ -322,7 +322,7 @@ static void sweep(void)
abort();
if (block->t.type & REACHABLE) {
- block->t.type &= ~REACHABLE;
+ block->t.type = (type_t) (block->t.type & ~REACHABLE);
continue;
}
@@ -335,7 +335,7 @@ static void sweep(void)
put_char(std_error, chr('\n'));
}
finalize(block);
- block->t.type |= FREE;
+ block->t.type = (type_t) (block->t.type | FREE);
/* If debugging is turned on, we want to catch instances
where a reachable object is wrongly freed. This is difficult
to do if the object is recycled soon after.
@@ -410,7 +410,7 @@ void unmark(void)
block < end;
block++)
{
- block->t.type &= ~(FREE | REACHABLE);
+ block->t.type = (type_t) (block->t.type & ~(FREE | REACHABLE));
}
}
}
diff --git a/lib.c b/lib.c
index 18178ce2..b48fa41d 100644
--- a/lib.c
+++ b/lib.c
@@ -50,7 +50,6 @@ val packages;
val system_package, keyword_package, user_package;
val null, t, cons_s, str_s, chr_s, num_s, sym_s, pkg_s, fun_s, vec_s;
-val t, cons_s, str_s, chr_s, num_s, sym_s, pkg_s, fun_s, vec_s;
val stream_s, hash_s, lcons_s, lstr_s, cobj_s;
val var_s, regex_s, set_s, cset_s, wild_s, oneplus_s;
val zeroplus_s, optional_s, compound_s, or_s, quasi_s;
@@ -532,17 +531,17 @@ static val equal_tramp(val env, val left, val right)
unsigned char *chk_malloc(size_t size)
{
- unsigned char *ptr = malloc(size);
+ unsigned char *ptr = (unsigned char *) malloc(size);
if (size && ptr == 0)
- ptr = oom_realloc(0, size);
+ ptr = (unsigned char *) oom_realloc(0, size);
return ptr;
}
unsigned char *chk_realloc(void *old, size_t size)
{
- unsigned char *newptr = realloc(old, size);
+ unsigned char *newptr = (unsigned char *) realloc(old, size);
if (size != 0 && newptr == 0)
- newptr = oom_realloc(old, size);
+ newptr = (unsigned char *) oom_realloc(old, size);
return newptr;
}
@@ -582,6 +581,8 @@ val list(val first, ...)
next = va_arg(vl, val);
} while (next != nao);
+ va_end (vl);
+
while (ptr > array)
list = cons(*--ptr, list);
}
@@ -1003,10 +1004,10 @@ val trim_str(val str)
return null_string;
} else {
size_t len = end - start;
- wchar_t *new = (wchar_t *) chk_malloc((len + 1) * sizeof *new);
- wmemcpy(new, start, len);
- new[len] = 0;
- return string_own(new);
+ wchar_t *buf = (wchar_t *) chk_malloc((len + 1) * sizeof *buf);
+ wmemcpy(buf, start, len);
+ buf[len] = 0;
+ return string_own(buf);
}
}
@@ -1080,7 +1081,7 @@ val make_sym(val name)
obj->s.type = SYM;
obj->s.name = name;
obj->s.package = nil;
- obj->s.val = nil;
+ obj->s.value = nil;
return obj;
}
@@ -1661,11 +1662,11 @@ val *acons_new_l(val *list, val key, val *new_p)
*new_p = nil;
return cdr_l(existing);
} else {
- val new = cons(key, nil);
- *list = cons(new, *list);
+ val nc = cons(key, nil);
+ *list = cons(nc, *list);
if (new_p)
*new_p = t;
- return cdr_l(new);
+ return cdr_l(nc);
}
}
diff --git a/lib.h b/lib.h
index 00be0dc4..ac4fa576 100644
--- a/lib.h
+++ b/lib.h
@@ -72,7 +72,7 @@ struct sym {
type_t type;
val name;
val package;
- val val;
+ val value;
};
struct package {
@@ -193,7 +193,7 @@ inline wchar_t *litptr(val obj)
#define lit(strlit) lit_noex(strlit)
extern val keyword_package;
-extern val t, cons_s, str_s, chr_s, num_s, sym_s, pkg_s, fun_s, vec_s;
+extern val null, t, cons_s, str_s, chr_s, num_s, sym_s, pkg_s, fun_s, vec_s;
extern val stream_s, hash_s, lcons_s, lstr_s, cobj_s;
extern val var_s, regex_s, set_s, cset_s, wild_s, oneplus_s;
extern val zeroplus_s, optional_s, compound_s, or_s, quasi_s;
diff --git a/match.c b/match.c
index 7ae9691c..a9ca7d24 100644
--- a/match.c
+++ b/match.c
@@ -622,10 +622,12 @@ val eval_form(val form, val bindings)
return cons(t, form);
}
+enum fpip_close { fpip_fclose, fpip_pclose, fpip_closedir };
+
typedef struct fpip {
FILE *f;
DIR *d;
- enum { fpip_fclose, fpip_pclose, fpip_closedir } close;
+ enum fpip_close close;
} fpip_t;
fpip_t complex_open(val name, val output)
diff --git a/regex.c b/regex.c
index dc46d8eb..14ef13c6 100644
--- a/regex.c
+++ b/regex.c
@@ -60,7 +60,7 @@ static int L0_full(cset_L0_t *L0)
{
int i;
- for (i = 0; i < CHAR_SET_SIZE; i++)
+ for (i = 0; i < (int) CHAR_SET_SIZE; i++)
if ((*L0)[i] != ((bitcell_t) -1))
return 0;
return 1;
@@ -130,7 +130,7 @@ void L1_fill_range(cset_L1_t *L1, wchar_t ch0, wchar_t ch1)
continue;
if (L0 == 0) {
- static const cset_L0_t blank;
+ static cset_L0_t blank;
L0 = (*L1)[i1] = (cset_L0_t *) chk_malloc(sizeof *L0);
memcpy(L0, &blank, sizeof *L0);
}
@@ -209,7 +209,7 @@ void L2_fill_range(cset_L2_t *L2, wchar_t ch0, wchar_t ch1)
continue;
if (L1 == 0) {
- static const cset_L1_t blank;
+ static cset_L1_t blank;
L1 = (*L2)[i2] = (cset_L1_t *) chk_malloc(sizeof *L1);
memcpy(L1, &blank, sizeof *L1);
}
@@ -279,7 +279,7 @@ void L3_fill_range(cset_L3_t *L3, wchar_t ch0, wchar_t ch1)
continue;
if (L2 == 0) {
- static const cset_L2_t blank;
+ static cset_L2_t blank;
L2 = (*L3)[i3] = (cset_L2_t *) chk_malloc(sizeof *L2);
memcpy(L2, &blank, sizeof *L2);
}
@@ -320,7 +320,7 @@ void L3_free(cset_L3_t *L3)
char_set_t *char_set_create(chset_type_t type, wchar_t base)
{
- static const char_set_t blank;
+ static char_set_t blank;
char_set_t *cs = (char_set_t *) chk_malloc(sizeof *cs);
*cs = blank;
cs->any.type = type;
@@ -351,7 +351,7 @@ void char_set_destroy(char_set_t *set)
void char_set_compl(char_set_t *set)
{
- set->any.compl = 1;
+ set->any.comp = 1;
}
void char_set_add(char_set_t *set, wchar_t ch)
@@ -429,7 +429,7 @@ int char_set_contains(char_set_t *set, wchar_t ch)
break;
}
- return set->any.compl ? !result : result;
+ return set->any.comp ? !result : result;
}
nfa_state_t *nfa_state_accept(void)
@@ -551,7 +551,7 @@ nfa_t nfa_combine(nfa_t pred, nfa_t succ)
return ret;
}
-nfa_t nfa_compile_set(val args, int compl)
+nfa_t nfa_compile_set(val args, int comp)
{
val iter;
wchar_t min = WCHAR_MAX;
@@ -617,7 +617,7 @@ nfa_t nfa_compile_set(val args, int compl)
}
}
- if (compl)
+ if (comp)
char_set_compl(set);
return ret;
}
diff --git a/regex.h b/regex.h
index d33f5c84..56e375c9 100644
--- a/regex.h
+++ b/regex.h
@@ -42,18 +42,18 @@ typedef cset_L2_t *cset_L3_t[17];
struct any_char_set {
unsigned type : 3;
- unsigned compl : 1;
+ unsigned comp : 1;
};
struct small_char_set {
unsigned type : 3;
- unsigned compl : 1;
+ unsigned comp : 1;
cset_L0_t bitcell;
};
struct displaced_char_set {
unsigned type : 3;
- unsigned compl : 1;
+ unsigned comp : 1;
cset_L0_t bitcell;
wchar_t base;
};
@@ -61,13 +61,13 @@ struct displaced_char_set {
struct large_char_set {
unsigned type : 3;
- unsigned compl : 1;
+ unsigned comp : 1;
cset_L2_t dir;
};
struct xlarge_char_set {
unsigned type : 3;
- unsigned compl : 1;
+ unsigned comp : 1;
cset_L3_t dir;
};
diff --git a/utf8.c b/utf8.c
index eedd503d..c5c76761 100644
--- a/utf8.c
+++ b/utf8.c
@@ -80,8 +80,8 @@ size_t utf8_from_uc(wchar_t *wdst, const unsigned char *src)
case utf8_more3:
if (ch >= 0x80 && ch < 0xc0) {
wch <<= 6;
- wch |= (ch & 0x3f);
- if (--state == utf8_init) {
+ state = (enum utf8_state) (state - 1);
+ if (state == utf8_init) {
if (wdst)
*wdst++ = wch;
nchar++;
@@ -261,7 +261,8 @@ wint_t utf8_decode(utf8_decoder_t *ud, int (*get)(void *ctx), void *ctx)
if (ch >= 0x80 && ch < 0xc0) {
ud->wch <<= 6;
ud->wch |= (ch & 0x3f);
- if (--ud->state == utf8_init) {
+ ud->state = (enum utf8_state) (ud->state - 1);
+ if (ud->state == utf8_init) {
ud->back = ud->tail;
return ud->wch;
}