changeset 1077:85c31697a99f

update to libjeffpc's new struct str API Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Tue, 15 Aug 2017 18:26:28 +0300
parents 695375ba679a
children 9f2eb71d116d
files comment.c pipeline.c post.c post_fmt3.y tag.c template.y
diffstat 6 files changed, 16 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/comment.c	Tue Aug 15 16:46:04 2017 +0300
+++ b/comment.c	Tue Aug 15 18:26:28 2017 +0300
@@ -92,12 +92,9 @@
 				   struct str *curdate, struct str *ip,
 				   struct str *url)
 {
-	struct val *url_val;
 	struct val *lv;
 	struct str *str;
 
-	url_val = url ? VAL_ALLOC_STR(url) : NULL;
-
 	/*
 	 * We're looking for a list looking something like:
 	 *
@@ -110,12 +107,12 @@
 	 */
 
 	lv = sexpr_args_to_list(6,
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("author"), VAL_ALLOC_STR(author)),
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("email"), VAL_ALLOC_STR(email)),
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("time"), VAL_ALLOC_STR(curdate)),
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("ip"), VAL_ALLOC_STR(ip)),
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("url"), url_val),
-				VAL_ALLOC_CONS(VAL_ALLOC_SYM_CSTR("moderated"), VAL_ALLOC_BOOL(false)));
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("author")), str_cast_to_val(author)),
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("email")), str_cast_to_val(email)),
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("time")), str_cast_to_val(curdate)),
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("ip")), str_cast_to_val(ip)),
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("url")), str_cast_to_val(url)),
+				VAL_ALLOC_CONS(str_cast_to_val(STATIC_STR("moderated")), VAL_ALLOC_BOOL(false)));
 
 	str = sexpr_dump(lv, false);
 
@@ -207,7 +204,7 @@
 		goto err;
 	}
 
-	ret = write_file(lisppath, meta->str, str_len(meta));
+	ret = write_file(lisppath, str_cstr(meta), str_len(meta));
 
 	str_putref(meta);
 
--- a/pipeline.c	Tue Aug 15 16:46:04 2017 +0300
+++ b/pipeline.c	Tue Aug 15 18:26:28 2017 +0300
@@ -133,11 +133,11 @@
 			out = str_of_int(val->i);
 			break;
 		case VT_STR:
-			out = cvt(str_cstr(val->str));
+			out = cvt(str_cstr(val_cast_to_str(val)));
 			break;
 		case VT_NULL:
 			val_putref(val);
-			return VAL_DUP_CSTR("");
+			return str_cast_to_val(str_empty_string());
 		case VT_SYM:
 		case VT_CONS:
 		case VT_BOOL:
@@ -150,7 +150,7 @@
 
 	ASSERT(out);
 
-	return VAL_ALLOC_CSTR(out);
+	return VAL_ALLOC_STR(out);
 }
 
 static struct val *urlescape_fxn(struct val *val)
@@ -177,7 +177,7 @@
 
 	val_putref(val);
 
-	return VAL_DUP_CSTR(buf);
+	return VAL_DUP_STR(buf);
 }
 
 static struct val *time_fxn(struct val *val)
--- a/post.c	Tue Aug 15 16:46:04 2017 +0300
+++ b/post.c	Tue Aug 15 18:26:28 2017 +0300
@@ -109,10 +109,7 @@
 		ASSERT3U(tagval->type, ==, VT_STR);
 
 		/* get the tag name */
-		tagname = str_getref(tagval->str);
-
-		/* release the tag value */
-		val_putref(tagval);
+		tagname = val_cast_to_str(tagval);
 
 		tag = malloc(sizeof(struct post_tag));
 		ASSERT(tag);
--- a/post_fmt3.y	Tue Aug 15 16:46:04 2017 +0300
+++ b/post_fmt3.y	Tue Aug 15 18:26:28 2017 +0300
@@ -128,13 +128,8 @@
 static void special_cmd_list(struct parser_output *data, struct val **var,
 			     struct str *value)
 {
-	struct val *new;
-
-	/* wrap the string in a value */
-	new = VAL_ALLOC_STR(value);
-
 	/* extend the list */
-	*var = VAL_ALLOC_CONS(new, *var);
+	*var = VAL_ALLOC_CONS(str_cast_to_val(value), *var);
 }
 
 %}
--- a/tag.c	Tue Aug 15 16:46:04 2017 +0300
+++ b/tag.c	Tue Aug 15 18:26:28 2017 +0300
@@ -170,7 +170,7 @@
 			goto out;
 	}
 
-	wordpress_cats[idx->i] = str_getref(name->str);
+	wordpress_cats[idx->i] = val_getref_str(name);
 
 	ret = 0;
 
--- a/template.y	Tue Aug 15 16:46:04 2017 +0300
+++ b/template.y	Tue Aug 15 18:26:28 2017 +0300
@@ -138,7 +138,7 @@
 
 	switch (val->type) {
 		case VT_STR:
-			tmp = str_cstr(val->str);
+			tmp = str_cstr(val_cast_to_str(val));
 			break;
 		case VT_INT:
 			snprintf(buf, sizeof(buf), "%"PRIu64, val->i);
@@ -202,7 +202,7 @@
 
 	switch (nvpair_type(var)) {
 		case NVT_STR:
-			val = VAL_ALLOC_STR(nvpair_value_str(var));
+			val = str_cast_to_val(nvpair_value_str(var));
 			break;
 		case NVT_INT:
 			val = VAL_ALLOC_INT(pair2int(var));