From b5b59bd57480b0fd859c098f9fc218d0dc28ccbd Mon Sep 17 00:00:00 2001 From: default Date: Wed, 30 Aug 2023 17:21:33 +0200 Subject: [PATCH] Backport from xs. --- xs.h | 16 +++++++++++++--- xs_version.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xs.h b/xs.h index ff86500..da9e2a7 100644 --- a/xs.h +++ b/xs.h @@ -603,6 +603,11 @@ xs_list *_xs_list_write_litem(xs_list *list, int offset, const char *mem, int ds { XS_ASSERT_TYPE(list, XSTYPE_LIST); + if (mem == NULL) { + mem = xs_stock_null; + dsz = sizeof(xs_stock_null); + } + list = xs_expand(list, offset, dsz + 1); list[offset] = XSTYPE_LITEM; @@ -899,13 +904,18 @@ xs_dict *xs_dict_new(void) } -xs_dict *xs_dict_insert_m(xs_dict *dict, int offset, const xs_str *key, +xs_dict *_xs_dict_write_ditem(xs_dict *dict, int offset, const xs_str *key, const xs_val *data, int dsz) /* inserts a memory block into the dict */ { XS_ASSERT_TYPE(dict, XSTYPE_DICT); XS_ASSERT_TYPE(key, XSTYPE_STRING); + if (data == NULL) { + data = xs_stock_null; + dsz = sizeof(xs_stock_null); + } + int ksz = xs_size(key); dict = xs_expand(dict, offset, 1 + ksz + dsz); @@ -921,14 +931,14 @@ xs_dict *xs_dict_insert_m(xs_dict *dict, int offset, const xs_str *key, xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) /* appends a memory block to the dict */ { - return xs_dict_insert_m(dict, xs_size(dict) - 1, key, mem, dsz); + return _xs_dict_write_ditem(dict, xs_size(dict) - 1, key, mem, dsz); } xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) /* prepends a memory block to the dict */ { - return xs_dict_insert_m(dict, 4, key, mem, dsz); + return _xs_dict_write_ditem(dict, 4, key, mem, dsz); } diff --git a/xs_version.h b/xs_version.h index 302245d..9ac34f0 100644 --- a/xs_version.h +++ b/xs_version.h @@ -1 +1 @@ -/* f42504297420abef44904644524207f8a1440494 */ +/* ce9e43569a7dd29a85c807e496c335cc4999bafd */