~brenns10/funlisp

67007e416ccadf5155dbd198ab52cba644452bea — Stephen Brennan 3 years ago 858b0dc
Allow some strings to be not owned by the interpreter
2 files changed, 4 insertions(+), 1 deletions(-)

M src/funlisp_internal.h
M src/types.c
M src/funlisp_internal.h => src/funlisp_internal.h +1 -0
@@ 81,6 81,7 @@ struct lisp_integer {

struct lisp_string {
	LISP_VALUE_HEAD;
	char can_free;
	char *s;
};


M src/types.c => src/types.c +3 -1
@@ 424,13 424,15 @@ static lisp_value *string_new(void)
{
	lisp_string *str = malloc(sizeof(lisp_string));
	str->s = NULL;
	str->can_free = 1;
	return (lisp_value*)str;
}

static void string_free(void *v)
{
	lisp_string *str = (lisp_string*) v;
	free(str->s);
	if (str->can_free)
		free(str->s);
	free(str);
}