diff options
-rw-r--r-- | src/builtins.c | 4 | ||||
-rw-r--r-- | src/stem.c | 15 | ||||
-rw-r--r-- | stemlib/unsafe.stem | 7 |
3 files changed, 15 insertions, 11 deletions
diff --git a/src/builtins.c b/src/builtins.c index 301104d..5d7752c 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -1100,7 +1100,7 @@ void stemsleep(value_t *v) { value_free(v1); } -void stemcut(value_t *v) {} +void stemcut(value_t *v) { value_t *v1 = array_pop(STACK); } void undef(value_t *v) { value_t *v1 = array_pop(STACK); @@ -1114,7 +1114,7 @@ void undef(value_t *v) { return; } ht_delete(WORD_TABLE, v1->str_word, value_free); - ht_delete(FLIT, v1->str_word, value_free); + ht_delete(FLIT, v1->str_word, func_free); value_free(v1); } @@ -106,6 +106,8 @@ value_t *value_copy(value_t *v) { void value_free(void *vtmp) { value_t *v = (value_t *)vtmp; + if (v == NULL) + return; if (v->type == VSTR || v->type == VWORD || v->type == VERR) { string_free(v->str_word); } @@ -245,6 +247,7 @@ value_t *parse_quote(parser_t *p) { parser_skip_whitespace(p); while (p->c != ']') { if (p->c == '\0') { + value_free(retv); parser_error(p); } array_append(retv->quote, parser_get_next(p)); @@ -255,17 +258,26 @@ value_t *parse_quote(parser_t *p) { } void parser_error(parser_t *p) { - fprintf(stderr, "PARSER ERROR!\n"); + fprintf(stderr, "PARSER ERROR: unclosed `[` or `\"` \n"); + free(PARSER->source); + ht_free(WORD_TABLE, value_free); + ht_free(FLIT, func_free); + ht_free(OBJ_TABLE, custom_free); + array_free(STACK); + free(PARSER); + array_free(EVAL_STACK); exit(1); } value_t *parse_word(parser_t *p) { value_t *retv = init_value(VWORD); string_t *s = init_string(NULL); + retv->str_word = s; if (p->c == '\\') { retv->escaped = true; parser_move(p); if (isspace(p->c) || p->c == '\0') { + value_free(retv); parser_error(p); } } @@ -273,7 +285,6 @@ value_t *parse_word(parser_t *p) { string_append(s, p->c); parser_move(p); } - retv->str_word = s; return retv; } diff --git a/stemlib/unsafe.stem b/stemlib/unsafe.stem deleted file mode 100644 index 8c9e43e..0000000 --- a/stemlib/unsafe.stem +++ /dev/null @@ -1,7 +0,0 @@ -"./stdlib.stem" fread strquote eval - -unQstack [ map [ len vat ] ] func - -[ 1 2 3 4 ] unQstack -? - |