summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog28
-rw-r--r--lib.c25
-rw-r--r--lib.h6
-rw-r--r--parser.h2
-rw-r--r--regex.c16
-rw-r--r--stream.c9
6 files changed, 61 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 29d3e4ac..a1c7c3ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,33 @@
2009-11-18 Kaz Kylheku <kkylheku@gmail.com>
+ Following-up on diagnostics obtained by running code through C++
+ compiler. Idea: allocator functions return char * instead of void *,
+ like malloc did in classic pre-ANSI C. That way we are forced to
+ use a cast except when the target pointer is char * already.
+
+ * lib.c (progname): Duplicate definition of global removed.
+ (equal): Some default: cases to switch statements added.
+ (chk_malloc): Returns char *.
+ (chk_realloc): Returns char *, but takes void * on the way in.
+ That way we get C++-like behavior.
+ (chk_strdup): Oops, this returned void * instead of wchar_t *.
+ c++ catches boo boo.
+ (stringp): Added default: case to switch.
+ (vec_set_fill): Cast return value of chk_realloc.
+
+ * lib.h (chk_malloc, chk_realloc, chk_strdup): Declarations updated.
+
+ * parser.h (lineno): extern qualifier added to prevent duplicate
+ definitions of.
+
+ * regex.c (nfa_free, nfa_run, nfa_machine_init, regex_compile): Cast
+ return value of chk_malloc.
+
+ * stream.c (snarf_line, get_string_from_stream): Cast return value of
+ chk_realloc.
+
+2009-11-18 Kaz Kylheku <kkylheku@gmail.com>
+
* match.c (match_line, match_files): Fix broken behavior of collect
that doesn't match anything. It is not a failed match, as the
documentation makes perfectly clear. Collect/coll were introduced
diff --git a/lib.c b/lib.c
index 3d5cbf19..f2451ec1 100644
--- a/lib.c
+++ b/lib.c
@@ -65,7 +65,6 @@ obj_t *null_list;
obj_t *identity_f;
obj_t *equal_f;
-const wchar_t *progname;
obj_t *prog_string;
void *(*oom_realloc)(void *, size_t);
@@ -440,6 +439,8 @@ obj_t *equal(obj_t *left, obj_t *right)
case LSTR:
lazy_str_force(right);
return equal(left, right->ls.prefix);
+ default:
+ break;
}
return nil;
case STR:
@@ -451,6 +452,8 @@ obj_t *equal(obj_t *left, obj_t *right)
case LSTR:
lazy_str_force(right);
return equal(left, right->ls.prefix);
+ default:
+ break;
}
return nil;
case SYM:
@@ -496,6 +499,8 @@ obj_t *equal(obj_t *left, obj_t *right)
case LSTR:
lazy_str_force(left);
return equal(left->ls.prefix, right);
+ default:
+ break;
}
return nil;
case COBJ:
@@ -513,23 +518,23 @@ static obj_t *equal_tramp(obj_t *env, obj_t *left, obj_t *right)
return equal(left, right);
}
-void *chk_malloc(size_t size)
+char *chk_malloc(size_t size)
{
- void *ptr = malloc(size);
+ char *ptr = malloc(size);
if (size && ptr == 0)
ptr = oom_realloc(0, size);
return ptr;
}
-void *chk_realloc(void *old, size_t size)
+char *chk_realloc(void *old, size_t size)
{
- void *newptr = realloc(old, size);
+ char *newptr = realloc(old, size);
if (size != 0 && newptr == 0)
newptr = oom_realloc(old, size);
return newptr;
}
-void *chk_strdup(const wchar_t *str)
+wchar_t *chk_strdup(const wchar_t *str)
{
size_t nchar = wcslen(str) + 1;
wchar_t *copy = (wchar_t *) chk_malloc(nchar * sizeof *copy);
@@ -715,7 +720,7 @@ obj_t *string(const wchar_t *str)
{
obj_t *obj = make_obj();
obj->st.type = STR;
- obj->st.str = chk_strdup(str);
+ obj->st.str = (wchar_t *) chk_strdup(str);
obj->st.len = nil;
return obj;
}
@@ -769,6 +774,8 @@ obj_t *stringp(obj_t *str)
switch (type(str)) {
case STR: case LSTR:
return t;
+ default:
+ break;
}
}
return nil;
@@ -1337,8 +1344,8 @@ obj_t *vec_set_fill(obj_t *vec, obj_t *fill)
if (alloc_delta > 0) {
long new_alloc = max(new_fill, 2*old_alloc);
- obj_t **newvec = chk_realloc(vec->v.vec - 2,
- (new_alloc + 2)*sizeof *newvec);
+ obj_t **newvec = (obj_t **) chk_realloc(vec->v.vec - 2,
+ (new_alloc + 2)*sizeof *newvec);
vec->v.vec = newvec + 2;
vec->v.vec[vec_alloc] = num(new_alloc);
}
diff --git a/lib.h b/lib.h
index 47f33e1a..a11888cc 100644
--- a/lib.h
+++ b/lib.h
@@ -222,9 +222,9 @@ obj_t *none_satisfy(obj_t *list, obj_t *pred, obj_t *key);
long c_num(obj_t *num);
obj_t *nump(obj_t *num);
obj_t *equal(obj_t *left, obj_t *right);
-void *chk_malloc(size_t size);
-void *chk_realloc(void*, size_t size);
-void *chk_strdup(const wchar_t *str);
+char *chk_malloc(size_t size);
+char *chk_realloc(void *, size_t size);
+wchar_t *chk_strdup(const wchar_t *str);
obj_t *cons(obj_t *car, obj_t *cdr);
obj_t *list(obj_t *first, ...); /* terminated by nao */
obj_t *consp(obj_t *obj);
diff --git a/parser.h b/parser.h
index 85f0f582..af858a53 100644
--- a/parser.h
+++ b/parser.h
@@ -25,7 +25,7 @@
*/
#include <stdio.h>
-long lineno;
+extern long lineno;
extern int errors;
extern obj_t *yyin_stream;
extern const wchar_t *spec_file;
diff --git a/regex.c b/regex.c
index 64ec2f00..d6cb0f96 100644
--- a/regex.c
+++ b/regex.c
@@ -766,7 +766,7 @@ int nfa_all_states(nfa_state_t **inout, int num, unsigned visited)
void nfa_free(nfa_t nfa)
{
- nfa_state_t **all = chk_malloc(NFA_SET_SIZE * sizeof *all);
+ nfa_state_t **all = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *all);
int nstates, i;
all[0] = nfa.start;
@@ -916,9 +916,9 @@ long nfa_run(nfa_t nfa, const wchar_t *str)
{
const wchar_t *last_accept_pos = 0, *ptr = str;
unsigned visited = nfa.start->a.visited + 1;
- nfa_state_t **move = chk_malloc(NFA_SET_SIZE * sizeof *move);
- nfa_state_t **clos = chk_malloc(NFA_SET_SIZE * sizeof *clos);
- nfa_state_t **stack = chk_malloc(NFA_SET_SIZE * sizeof *stack);
+ nfa_state_t **move = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *move);
+ nfa_state_t **clos = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *clos);
+ nfa_state_t **stack = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *stack);
int nmove = 1, nclos;
int accept = 0;
@@ -984,9 +984,9 @@ void nfa_machine_reset(nfa_machine_t *nfam)
void nfa_machine_init(nfa_machine_t *nfam, nfa_t nfa)
{
nfam->nfa = nfa;
- nfam->move = chk_malloc(NFA_SET_SIZE * sizeof *nfam->move);
- nfam->clos = chk_malloc(NFA_SET_SIZE * sizeof *nfam->clos);
- nfam->stack = chk_malloc(NFA_SET_SIZE * sizeof *nfam->stack);
+ nfam->move = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *nfam->move);
+ nfam->clos = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *nfam->clos);
+ nfam->stack = (nfa_state_t **) chk_malloc(NFA_SET_SIZE * sizeof *nfam->stack);
nfa_machine_reset(nfam);
}
@@ -1054,7 +1054,7 @@ static struct cobj_ops regex_obj_ops = {
obj_t *regex_compile(obj_t *regex_sexp)
{
- nfa_t *pnfa = chk_malloc(sizeof *pnfa);
+ nfa_t *pnfa = (nfa_t *) chk_malloc(sizeof *pnfa);
*pnfa = nfa_compile_regex(regex_sexp);
return cobj(pnfa, regex, &regex_obj_ops);
}
diff --git a/stream.c b/stream.c
index 21b3806f..d3168eec 100644
--- a/stream.c
+++ b/stream.c
@@ -158,7 +158,7 @@ static wchar_t *snarf_line(struct stdio_handle *h)
if (fill >= size) {
size_t newsize = size ? size * 2 : min_size;
- buf = chk_realloc(buf, newsize * sizeof *buf);
+ buf = (wchar_t *) chk_realloc(buf, newsize * sizeof *buf);
size = newsize;
}
@@ -170,7 +170,7 @@ static wchar_t *snarf_line(struct stdio_handle *h)
}
if (buf)
- buf = chk_realloc(buf, fill * sizeof *buf);
+ buf = (wchar_t *) chk_realloc(buf, fill * sizeof *buf);
return buf;
}
@@ -409,7 +409,7 @@ static obj_t *string_out_put_string(obj_t *stream, obj_t *str)
}
if (so->size != old_size)
- so->buf = chk_realloc(so->buf, so->size * sizeof *so->buf);
+ so->buf = (wchar_t *) chk_realloc(so->buf, so->size * sizeof *so->buf);
wmemcpy(so->buf + so->fill, s, len + 1);
so->fill += len;
return t;
@@ -546,7 +546,8 @@ obj_t *get_string_from_stream(obj_t *stream)
if (!so)
return out;
- so->buf = chk_realloc(so->buf, (so->fill + 1) * sizeof *so->buf);
+ so->buf = (wchar_t *) chk_realloc(so->buf,
+ (so->fill + 1) * sizeof *so->buf);
out = string_own(so->buf);
free(so);
return out;