diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index ae728792..b8a2df83 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -175,8 +175,7 @@ bool pic_eq_p(pic_value, pic_value); bool pic_eqv_p(pic_value, pic_value); bool pic_equal_p(pic_state *, pic_value, pic_value); -pic_sym pic_intern(pic_state *, const char *, size_t); -pic_sym pic_intern_str(pic_state *, pic_str *); +pic_sym pic_intern(pic_state *, pic_str *); pic_sym pic_intern_cstr(pic_state *, const char *); const char *pic_symbol_name(pic_state *, pic_sym); pic_sym pic_gensym(pic_state *, pic_sym); diff --git a/extlib/benz/lib.c b/extlib/benz/lib.c index 0e603fe4..f75ca99e 100644 --- a/extlib/benz/lib.c +++ b/extlib/benz/lib.c @@ -104,7 +104,7 @@ import_table(pic_state *pic, pic_value spec, struct pic_dict *imports) prefix = pic_list_ref(pic, spec, 2); pic_dict_for_each (sym, table) { - id = pic_intern_str(pic, pic_format(pic, "~s~s", prefix, pic_sym_value(sym))); + id = pic_intern(pic, pic_format(pic, "~s~s", prefix, pic_sym_value(sym))); pic_dict_set(pic, imports, id, pic_dict_ref(pic, table, sym)); } return; diff --git a/extlib/benz/read.c b/extlib/benz/read.c index aed121a6..c416fa22 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -222,7 +222,8 @@ read_symbol(pic_state *pic, struct pic_port *port, const char *str) buf[len - 1] = (char)c; } - sym = pic_intern(pic, buf, len); + buf[len] = 0; + sym = pic_intern_cstr(pic, buf); pic_free(pic, buf); return pic_sym_value(sym); diff --git a/extlib/benz/symbol.c b/extlib/benz/symbol.c index c6d68c44..65c1e6d1 100644 --- a/extlib/benz/symbol.c +++ b/extlib/benz/symbol.c @@ -6,21 +6,20 @@ #include "picrin/string.h" pic_sym -pic_intern(pic_state *pic, const char *str, size_t len) +pic_intern(pic_state *pic, pic_str *str) { char *cstr; xh_entry *e; pic_sym id; - cstr = (char *)pic_malloc(pic, len + 1); - cstr[len] = '\0'; - memcpy(cstr, str, len); - - e = xh_get_str(&pic->syms, cstr); + e = xh_get_str(&pic->syms, pic_str_cstr(str)); if (e) { return xh_val(e, pic_sym); } + cstr = (char *)pic_malloc(pic, pic_strlen(str) + 1); + strcpy(cstr, pic_str_cstr(str)); + id = pic->sym_cnt++; xh_put_str(&pic->syms, cstr, &id); xh_put_int(&pic->sym_names, id, &cstr); @@ -30,13 +29,7 @@ pic_intern(pic_state *pic, const char *str, size_t len) pic_sym pic_intern_cstr(pic_state *pic, const char *str) { - return pic_intern(pic, str, strlen(str)); -} - -pic_sym -pic_intern_str(pic_state *pic, pic_str *str) -{ - return pic_intern_cstr(pic, pic_str_cstr(str)); + return pic_intern(pic, pic_make_str(pic, str, strlen(str))); } pic_sym