From 11d15842ba004e551c4324a2621151cff8ba8c72 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 9 Oct 2015 23:30:47 -0400 Subject: [PATCH] Added more make string macros and fixed related bugs --- include/cyclone/types.h | 13 ++++++++----- runtime.c | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 54c26127..660ab958 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -189,13 +189,16 @@ typedef struct {gc_header_type hdr; tag_type tag; int len; char *str;} string_ty //// TODO: new way to allocate strings, but this requires changes to //// all functions that allocate strings, the GC, cgen, and maybe more. //// Because these strings are (at least for now) allocaed on the stack. -#define make_string(cs, len, s) string_type cs; \ -{ cs.tag = string_tag; cs.len = len; \ +#define make_string(cs, s) string_type cs; \ +{ int len = strlen(s); cs.tag = string_tag; cs.len = len; \ cs.str = alloca(sizeof(char) * (len + 1)); \ strcpy(cs.str, s);} -TODO: make_string_with_len, remove len from above args -#define make_string_noalloc(cs, len, s) string_type cs \ -{ cs.tag = string_tag; cs.len = len; \ +#define make_string_with_len(cs, length, s) string_type cs; \ +{ cs.tag = string_tag; cs.len = length; \ + cs.str = alloca(sizeof(char) * (len + 1)); \ + strcpy(cs.str, s);} +#define make_string_noalloc(cs, length, s) string_type cs; \ +{ cs.tag = string_tag; cs.len = length; \ cs.str = s; } // TODO: all of the dhalloc below needs to go away... //#define make_string(cv,s) string_type cv; cv.tag = string_tag; \ diff --git a/runtime.c b/runtime.c index 7d7e6d0b..cd4de26f 100644 --- a/runtime.c +++ b/runtime.c @@ -286,7 +286,7 @@ void Cyc_rt_raise(object err) { exit(1); } void Cyc_rt_raise2(const char *msg, object err) { - make_string(s, strlen(msg), msg); + make_string(s, msg); make_cons(c3, err, nil); make_cons(c2, &s, &c3); make_cons(c1, boolean_f, &c2); @@ -297,7 +297,7 @@ void Cyc_rt_raise2(const char *msg, object err) { exit(1); } void Cyc_rt_raise_msg(const char *err) { - make_string(s, strlen(err), err); + make_string(s, err); Cyc_rt_raise(&s); } /* END exception handler */ @@ -857,14 +857,14 @@ object Cyc_number2string(object cont, object n) { Cyc_rt_raise2("number->string - Unexpected object", n); } make_string_noalloc(str, strlen(buffer), buffer); - return_closcall1(cont, str); + return_closcall1(cont, &str); } object Cyc_symbol2string(object cont, object sym) { Cyc_check_sym(sym); - { char *pname = symbol_pname(sym); - make_string(str, strlen(pname), pname); - return_closcall1(cont, str); }} + { const char *pname = symbol_pname(sym); + make_string(str, pname); + return_closcall1(cont, &str); }} object Cyc_string2symbol(object str) { object sym;