summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-07 07:34:42 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-11-07 07:34:42 -0800
commitfdf3fd788efb143631099c2e16636e27b3241ac3 (patch)
tree79f496a051aa29faf16d7530ca601adb3ad941a4 /regex.c
parent19dc84bcf137ed742e824e2b86e403b9f53031fb (diff)
downloadtxr-fdf3fd788efb143631099c2e16636e27b3241ac3.tar.gz
txr-fdf3fd788efb143631099c2e16636e27b3241ac3.tar.bz2
txr-fdf3fd788efb143631099c2e16636e27b3241ac3.zip
Better identify functions that misuse COBJ-s and hashes.
In this patch, the cobj_handle, cobj_ops and variants of gethash get an additional argument to identify the caller. Many functions are updated to pass this down. * buf.c (buf_strm): Pass self name to cobj_handle. * eval.c (env_fbind, env_vbind, rt_defvarl, me_case): Pass self name to gethash_c or gethash_e. (load): Pass self name to read_eval_stream and read_compiled_file. (reg_symacro): Pass situation-identifying string to gethash_c. * ffi.c (ffi_type_struct_checked, ffi_closure_struct_checked, ffi_call_desc_checked, uni_struct_checked): Take self name parameter, and pass down to cobj_handle. (ffi_get_type, ffi_get_lisp_type): Take self name and pass down to ffi_type_struct_checked. (union_get_ptr): Take self name and pass to uni_struct_checked. (ffi_union_in, ffi_union_put): Pass self name to union_get_ptr. (ffi_type_compile): Pass self name to ffi_get_lisp_type. (ffi_make_call_desc): Pass self name to ffi_type_struct_checked, ffi_get_type and ffi_call_desc_checked. (ffi_make_closure): Pass self name to ffi_call_desc_checked. (ffi_closure_get_fptr): Take self name, pass to ffi_closure_struct_checked. (ffi_typedef, ffi_size, ffi_alignof, ffi_offsetof, ffi_arraysize, ffi_elemsize, ffi_elemtype, ffi_put_into, ffi_put, ffi_in, ffi_get, ffi_out, make_carray): Pass self name to ffi_closure_struct_checked. (carray_struct_checked): Take self name, pass to cobj_handle. (carray_set_length, carray_dup, carray_own, carray_free, carray_type, length_carray, copy_carray, carray_ptr, buf_carray, vec_carray, list_carray, carray_ref, carray_refset, carray_sub, carray_replace, carray_get_common, carray_put_common, unum_carray, num_carray, put_carray, fill_carray): Pass self name to carray_struct_checked. (carray_blank, carray_buf, carray_cptr): Pass self name ffi_type_struct_checked. (carray_pun): Pass self name to carray_struct_checked and ffi_type_struct_checked. (make_union): Pass self name to ffi_type_struct_checked. (union_members, union_get, union_put, union_in, union_out): Pass self name to uni_struct_checked. (make_zstruct, zero_fill, put_obj, get_obj, fill_obj): Pass self-name to ffi_type_struct_checked. * ffi.h (ffi_closure_get_fptr, union_get_ptr): Declarations updated. * filter.c (trie_add): Pass self-name to gethash_l. * hash.c (make_similar_hash, copy_hash, hash_count, get_hash_userdata, set_hash_userdata, hash_begin, hash_next, hash_uni, hash_diff, hash_isec): Pass self name to cobj_handle. (gethash_c, gethash_e): Take self name parameter and pass down to cobj_handle. (gethash_f): Take self parameter and pass down to gethash_e. (gethash, inhash, gethash_n, sethash, pushhash, remhash, clearhash, hash_update_1): Pass self name to gethash_e or gethash_c. * hash.h (gethash_c, gethash_e, gethash_f): Declarations updated. (gethash_l): Take self name, and pass down to gethash_c. * lib.c (class_check): Take self name parameter and use in type mismatch diagnostic. (use_sym, unuse_sym, symbol_needs_prefix, find_symbol, intern, unintern, intern_fallback, unique, in, sel, obj_print_impl, populate_obj_hash, obj_hash_merge): Pass self name to gethash_f or gethash_l. (symbol_visible, obj_init): Pass situation-identifying string to gethash_e. (cobj_handle, cobj_ops): Take self name parameter and pass down to class_check. * lib.h (class_check, cobj_handle, cobj_ops): Declarations updated. * match.c (v_load): Pass self name to read_compiled_file and read_eval_stream. * parser.c (get_parser_impl): Take self name and pass to cobj_handle. (ensure_parser): Pass situation-identifying string to gethash_c. (parser_circ_def): Pass self-name to gethash_c. (lisp_parser_impl): Pass self name to get_parser_impl and class_check. (lisp_parse, nread, iread): Pass self-name to lisp_parser_impl. (read_file_common): Take self name parameter and pass down to get_parser_impl. (read_eval_stream, read_compiled_file): Take self name and pass down to read_file_common. (load_rcfile): Pass situation-identifying string to read_eval_streem. (get_visible_syms): Pass situation-identifying string to gethash_c. (parser_errors, parser_eof): Pass self name to cobj_handle. * parser.h (read_eval_stream, read_compiled_file): Declarations updated. * parser.y (rlset): Pass self name to gethash_c. * rand.c (make_random_state, random_state_get_vec,l random_fixnum, random_float): Pass self name to cobj_handle. * regex.c (regex_source, regex_print, regex_run): Pass self-name to cobj_handle. (regex_machine_init): Take self name param and pass to cobj_handle. (search_regex, match_regex, match_regex_right, regex_prefix_match, read_until_match): Pass self-name to regex_machine_init. * stream.c (stdio_get_fd): Pass self name to cobj_handle. (generic_get_line): Get COBJ operations via unsafe, diret object access rather than cobj_ops. (set_mode_props): Get object handle via unsafe, direct object access. (stream_fd, sock_family, sock_type, sock_peer, set_sock_peer, get_string_from_stream, get_list_from_stream, stream_set_prop, stream_get_prop, close_stream, get_error, get_error_str, clear_error, get_line, get_char, get_byte, unget_char, unget_byte, put_buf, fill_buf, put_string, put_char, put_byte, flush_stream, seek_stream, truncate_stream, get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check, force_break, get_set_ctx, get_ctx): Pass self name to cobj_ops. (make_delegate_stream): Take self name parameter, pass down to cobj_ops. (record_adapter): Pass self name down to make_delegate_stream. (format): Pass self name to class_check. * struct.c (stype_handle): Pass self name to cobj_handle. (make_struct_type): Pass self name to class_check. * txr.c (read_eval_stream_noerr): Take self name parameter, pass to read_eval_stream. (txr_main): Pass istuation-identifying string to read_compiled_file and read_eval_stream_noerr. * unwind.c (revive_cont): Pass self-name to cobj_handle. * vm.c (vm_desc_struct): Take self name parameter, pass to cobj_handle. (vm_desc_nlevels, vm_desc_nregs, vm_desc_bytecode, vm_desc_datavec, vm_desc_symvec, vm_execute_toplevel, vm_execute_closure, vm_closure_entry): Pass self name to vm_desc_struct. (vm_closure_struct): Take self name parameter, pass to cobj_handle.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/regex.c b/regex.c
index 9e413204..a911bf80 100644
--- a/regex.c
+++ b/regex.c
@@ -2245,7 +2245,9 @@ val regexp(val obj)
val regex_source(val compiled_regex)
{
- regex_t *regex = coerce(regex_t *, cobj_handle(compiled_regex, regex_s));
+ val self = lit("regex-source");
+ regex_t *regex = coerce(regex_t *,
+ cobj_handle(self, compiled_regex, regex_s));
return regex->source;
}
@@ -2416,7 +2418,8 @@ static void print_rec(val exp, val stream, int *semi_flag)
static void regex_print(val obj, val stream, val pretty, struct strm_ctx *ctx)
{
- regex_t *regex = coerce(regex_t *, cobj_handle(obj, regex_s));
+ val self = lit("regex-print");
+ regex_t *regex = coerce(regex_t *, cobj_handle(self, obj, regex_s));
int semi_flag = 0;
(void) pretty;
@@ -2429,7 +2432,8 @@ static void regex_print(val obj, val stream, val pretty, struct strm_ctx *ctx)
static cnum regex_run(val compiled_regex, const wchar_t *str)
{
- regex_t *regex = coerce(regex_t *, cobj_handle(compiled_regex, regex_s));
+ val self = lit("regex-run");
+ regex_t *regex = coerce(regex_t *, cobj_handle(self, compiled_regex, regex_s));
return if3(regex->kind == REGEX_DV,
dv_run(regex->r.dv, str),
@@ -2471,9 +2475,9 @@ static void regex_machine_reset(regex_machine_t *regm)
regm->n.last_accept_pos = regm->n.count;
}
-static void regex_machine_init(regex_machine_t *regm, val reg)
+static void regex_machine_init(val self, regex_machine_t *regm, val reg)
{
- regex_t *regex = coerce(regex_t *, cobj_handle(reg, regex_s));
+ regex_t *regex = coerce(regex_t *, cobj_handle(self, reg, regex_s));
if (regex->kind == REGEX_DV) {
regm->n.is_nfa = 0;
@@ -2566,6 +2570,7 @@ static regm_result_t regex_machine_feed(regex_machine_t *regm, wchar_t ch)
val search_regex(val haystack, val needle_regex, val start,
val from_end)
{
+ val self = lit("search-regex");
val slen = nil;
start = default_arg(start, zero);
from_end = default_null_arg(from_end);
@@ -2602,7 +2607,7 @@ val search_regex(val haystack, val needle_regex, val start,
if (length_str_lt(haystack, pos))
return nil;
- regex_machine_init(&regm, needle_regex);
+ regex_machine_init(self, &regm, needle_regex);
again:
for (i = pos; length_str_gt(haystack, i); i = plus(i, one)) {
@@ -2689,6 +2694,7 @@ val range_regex_all(val haystack, val needle_regex, val start, val end)
val match_regex(val str, val reg, val pos)
{
+ val self = lit("match-regex");
regex_machine_t regm;
val i, retval;
regm_result_t last_res = REGM_INCOMPLETE;
@@ -2703,7 +2709,7 @@ val match_regex(val str, val reg, val pos)
return nil;
}
- regex_machine_init(&regm, reg);
+ regex_machine_init(self, &regm, reg);
for (i = pos; length_str_gt(str, i); i = plus(i, one)) {
last_res = regex_machine_feed(&regm, c_chr(chr_str(str, i)));
@@ -2764,6 +2770,7 @@ static val match_regex_right_old(val str, val regex, val end)
val match_regex_right(val str, val regex, val end)
{
+ val self = lit("match-regex-right");
val pos = zero;
val len = length(str);
@@ -2782,7 +2789,7 @@ val match_regex_right(val str, val regex, val end)
val i ;
regm_result_t last_res = REGM_INCOMPLETE;
- regex_machine_init(&regm, regex);
+ regex_machine_init(self, &regm, regex);
for (i = pos; lt(i, end); i = plus(i, one)) {
last_res = regex_machine_feed(&regm, c_chr(chr_str(str, i)));
@@ -2810,6 +2817,7 @@ val match_regex_right(val str, val regex, val end)
val regex_prefix_match(val reg, val str, val pos)
{
+ val self = lit("regex-prefix-match");
regex_machine_t regm;
val i;
regm_result_t last_res;
@@ -2824,7 +2832,7 @@ val regex_prefix_match(val reg, val str, val pos)
return nil;
}
- regex_machine_init(&regm, reg);
+ regex_machine_init(self, &regm, reg);
last_res = regex_machine_infer_init_state(&regm);
@@ -3108,6 +3116,7 @@ val regex_range_search_fun(val regex, val start, val from_end)
val read_until_match(val regex, val stream_in, val include_match_in)
{
+ val self = lit("read-until-match");
regex_machine_t regm;
val out = nil;
val stack = nil;
@@ -3115,7 +3124,7 @@ val read_until_match(val regex, val stream_in, val include_match_in)
val stream = default_arg(stream_in, std_input);
val include_match = default_null_arg(include_match_in);
- regex_machine_init(&regm, regex);
+ regex_machine_init(self, &regm, regex);
for (;;) {
val ch = get_char(stream);