diff options
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | hash.c | 2 | ||||
-rw-r--r-- | lib.c | 23 | ||||
-rw-r--r-- | lib.h | 14 | ||||
-rw-r--r-- | regex.c | 2 | ||||
-rw-r--r-- | stream.c | 21 | ||||
-rw-r--r-- | txr.c | 2 |
7 files changed, 57 insertions, 31 deletions
@@ -1,3 +1,27 @@ +2009-12-04 Kaz Kylheku <kkylheku@gmail.com> + + Eliminate the void * disease. Generic pointers are of mem_t * + from now on, which is compatible with unsigned char *. + No implicit conversion to or from this type, in C or C++. + + * hash.c (make_hash): Convert void * to mem_t *. + + * lib.c (oom_realloc, chk_malloc, chk_realloc, vec_set_fill, + cobj, init): Convert to using mem_t *. + + * lib.h (mem_t): New typedef. + (struct cobj): Convert void * to mem_t *. + (oom_realloc, chk_malloc, chk_realloc, init): Declarations updated. + + * regex.c (regex_compile): Convert void * to mem_t *. + + * stream.c (snarf_line, string_out_put_string, make_stdio_stream, + make_pipe_stream, make_string_input_stream, + make_string_byte_input_stream, make_string_output_stream, + get_string_from_stream): Convert void * to mem_t *. + + * txr.c (oom_realloc_handler): Convert void * to mem_t *. + 2009-12-03 Kaz Kylheku <kkylheku@gmail.com> * gc.c (heap_min_bound, heap_max_bound): New static globals. @@ -229,7 +229,7 @@ val make_hash(val weak_keys, val weak_vals) struct hash *h = (struct hash *) chk_malloc(sizeof *h); val mod = num(256); val table = vector(mod); - val hash = cobj((void *) h, hash_s, &hash_ops); + val hash = cobj((mem_t *) h, hash_s, &hash_ops); vec_set_fill(table, mod); @@ -75,8 +75,7 @@ val equal_f; val prog_string; -void *(*oom_realloc)(void *, size_t); - +mem_t *(*oom_realloc)(mem_t *, size_t); val identity(val obj) { @@ -531,19 +530,19 @@ static val equal_tramp(val env, val left, val right) return equal(left, right); } -unsigned char *chk_malloc(size_t size) +mem_t *chk_malloc(size_t size) { - unsigned char *ptr = (unsigned char *) malloc(size); + mem_t *ptr = (mem_t *) malloc(size); if (size && ptr == 0) - ptr = (unsigned char *) oom_realloc(0, size); + ptr = (mem_t *) oom_realloc(0, size); return ptr; } -unsigned char *chk_realloc(void *old, size_t size) +mem_t *chk_realloc(mem_t *old, size_t size) { - unsigned char *newptr = (unsigned char *) realloc(old, size); + mem_t *newptr = (mem_t *) realloc(old, size); if (size != 0 && newptr == 0) - newptr = (unsigned char *) oom_realloc(old, size); + newptr = oom_realloc(old, size); return newptr; } @@ -1405,8 +1404,8 @@ val vec_set_fill(val vec, val fill) if (alloc_delta > 0) { cnum new_alloc = max(new_fill, 2*old_alloc); - val *newvec = (val *) chk_realloc(vec->v.vec - 2, - (new_alloc + 2)*sizeof *newvec); + val *newvec = (val *) chk_realloc((mem_t *) (vec->v.vec - 2), + (new_alloc + 2) * sizeof *newvec); vec->v.vec = newvec + 2; vec->v.vec[vec_alloc] = num(new_alloc); #ifdef HAVE_VALGRIND @@ -1622,7 +1621,7 @@ val lazy_str_get_trailing_list(val lstr, val index) } } -val cobj(void *handle, val cls_sym, struct cobj_ops *ops) +val cobj(mem_t *handle, val cls_sym, struct cobj_ops *ops) { val obj = make_obj(); obj->co.type = COBJ; @@ -2119,7 +2118,7 @@ void obj_pprint(val obj, val out) format(out, lit("#<garbage: ~p>"), (void *) obj, nao); } -void init(const wchar_t *pn, void *(*oom)(void *, size_t), +void init(const wchar_t *pn, mem_t *(*oom)(mem_t *, size_t), val *stack_bottom) { int gc_save; @@ -51,6 +51,8 @@ typedef union obj obj_t; typedef obj_t *val; +typedef unsigned char mem_t; + struct any { type_t type; void *dummy[2]; @@ -140,7 +142,7 @@ struct lazy_string { struct cobj { type_t type; - void *handle; + mem_t *handle; struct cobj_ops *ops; val cls; }; @@ -222,7 +224,7 @@ extern val equal_f; extern const wchar_t *progname; extern val prog_string; -extern void *(*oom_realloc)(void *, size_t); +extern mem_t *(*oom_realloc)(mem_t *, size_t); val identity(val obj); val typeof(val obj); @@ -257,8 +259,8 @@ val none_satisfy(val list, val pred, val key); cnum c_num(val num); val nump(val num); val equal(val left, val right); -unsigned char *chk_malloc(size_t size); -unsigned char *chk_realloc(void *, size_t size); +mem_t *chk_malloc(size_t size); +mem_t *chk_realloc(mem_t *, size_t size); wchar_t *chk_strdup(const wchar_t *str); val cons(val car, val cdr); val list(val first, ...); /* terminated by nao */ @@ -345,7 +347,7 @@ val length_str_gt(val str, val len); val length_str_ge(val str, val len); val length_str_lt(val str, val len); val length_str_le(val str, val len); -val cobj(void *handle, val cls_sym, struct cobj_ops *ops); +val cobj(mem_t *handle, val cls_sym, struct cobj_ops *ops); void cobj_print_op(val, val); /* Default function for struct cobj_ops */ val assoc(val list, val key); val acons_new(val list, val key, val value); @@ -361,7 +363,7 @@ val sort(val list, val lessfun, val keyfun); void obj_print(val obj, val stream); void obj_pprint(val obj, val stream); -void init(const wchar_t *progname, void *(*oom_realloc)(void *, size_t), +void init(const wchar_t *progname, mem_t *(*oom_realloc)(mem_t *, size_t), val *stack_bottom); void dump(val obj, val stream); void d(val obj); @@ -1157,7 +1157,7 @@ val regex_compile(val regex_sexp) { nfa_t *pnfa = (nfa_t *) chk_malloc(sizeof *pnfa); *pnfa = nfa_compile_regex(regex_sexp); - return cobj(pnfa, regex_s, ®ex_obj_ops); + return cobj((mem_t *) pnfa, regex_s, ®ex_obj_ops); } val regexp(val obj) @@ -159,7 +159,7 @@ static wchar_t *snarf_line(struct stdio_handle *h) if (fill >= size) { size_t newsize = size ? size * 2 : min_size; - buf = (wchar_t *) chk_realloc(buf, newsize * sizeof *buf); + buf = (wchar_t *) chk_realloc((mem_t *) buf, newsize * sizeof *buf); size = newsize; } @@ -171,7 +171,7 @@ static wchar_t *snarf_line(struct stdio_handle *h) } if (buf) - buf = (wchar_t *) chk_realloc(buf, fill * sizeof *buf); + buf = (wchar_t *) chk_realloc((mem_t *) buf, fill * sizeof *buf); return buf; } @@ -410,7 +410,8 @@ static val string_out_put_string(val stream, val str) } if (so->size != old_size) - so->buf = (wchar_t *) chk_realloc(so->buf, so->size * sizeof *so->buf); + so->buf = (wchar_t *) chk_realloc((mem_t *) so->buf, + so->size * sizeof *so->buf); wmemcpy(so->buf + so->fill, s, len + 1); so->fill += len; return t; @@ -486,7 +487,7 @@ static struct strm_ops dir_ops = { val make_stdio_stream(FILE *f, val descr, val input, val output) { struct stdio_handle *h = (struct stdio_handle *) chk_malloc(sizeof *h); - val stream = cobj((void *) h, stream_s, &stdio_ops.cobj_ops); + val stream = cobj((mem_t *) h, stream_s, &stdio_ops.cobj_ops); h->f = f; h->descr = descr; utf8_decoder_init(&h->ud); @@ -496,7 +497,7 @@ val make_stdio_stream(FILE *f, val descr, val input, val output) val make_pipe_stream(FILE *f, val descr, val input, val output) { struct stdio_handle *h = (struct stdio_handle *) chk_malloc(sizeof *h); - val stream = cobj((void *) h, stream_s, &pipe_ops.cobj_ops); + val stream = cobj((mem_t *) h, stream_s, &pipe_ops.cobj_ops); h->f = f; h->descr = descr; utf8_decoder_init(&h->ud); @@ -505,7 +506,7 @@ val make_pipe_stream(FILE *f, val descr, val input, val output) val make_string_input_stream(val string) { - return cobj((void *) cons(string, zero), stream_s, &string_in_ops.cobj_ops); + return cobj((mem_t *) cons(string, zero), stream_s, &string_in_ops.cobj_ops); } val make_string_byte_input_stream(val string) @@ -518,7 +519,7 @@ val make_string_byte_input_stream(val string) bi->buf = utf8; bi->size = strlen((char *) utf8); bi->index = 0; - return cobj(bi, stream_s, &byte_in_ops.cobj_ops); + return cobj((mem_t *) bi, stream_s, &byte_in_ops.cobj_ops); } } @@ -529,7 +530,7 @@ val make_string_output_stream(void) so->buf = (wchar_t *) chk_malloc(so->size * sizeof so->buf); so->fill = 0; so->buf[0] = 0; - return cobj((void *) so, stream_s, &string_out_ops.cobj_ops); + return cobj((mem_t *) so, stream_s, &string_out_ops.cobj_ops); } val get_string_from_stream(val stream) @@ -547,7 +548,7 @@ val get_string_from_stream(val stream) if (!so) return out; - so->buf = (wchar_t *) chk_realloc(so->buf, + so->buf = (wchar_t *) chk_realloc((mem_t *) so->buf, (so->fill + 1) * sizeof *so->buf); out = string_own(so->buf); free(so); @@ -562,7 +563,7 @@ val get_string_from_stream(val stream) val make_dir_stream(DIR *dir) { - return cobj((void *) dir, stream_s, &dir_ops.cobj_ops); + return cobj((mem_t *) dir, stream_s, &dir_ops.cobj_ops); } val close_stream(val stream, val throw_on_error) @@ -53,7 +53,7 @@ val spec_file_str; * pool, which sets an OOM flag. Program can check flag * and gracefully terminate instead of aborting like this. */ -static void *oom_realloc_handler(void *old, size_t size) +static mem_t *oom_realloc_handler(mem_t *old, size_t size) { format(std_error, lit("~a: out of memory\n"), prog_string, nao); put_line(std_error, lit("false")); |