commit b5b59bd

default  ·  2023-08-30 15:21:33 +0000 UTC
parent 9279708
Backport from xs.
2 files changed,  +14, -4
M xs.h
M xs.h
+13, -3
 1@@ -603,6 +603,11 @@ xs_list *_xs_list_write_litem(xs_list *list, int offset, const char *mem, int ds
 2 {
 3     XS_ASSERT_TYPE(list, XSTYPE_LIST);
 4 
 5+    if (mem == NULL) {
 6+        mem = xs_stock_null;
 7+        dsz = sizeof(xs_stock_null);
 8+    }
 9+
10     list = xs_expand(list, offset, dsz + 1);
11 
12     list[offset] = XSTYPE_LITEM;
13@@ -899,13 +904,18 @@ xs_dict *xs_dict_new(void)
14 }
15 
16 
17-xs_dict *xs_dict_insert_m(xs_dict *dict, int offset, const xs_str *key,
18+xs_dict *_xs_dict_write_ditem(xs_dict *dict, int offset, const xs_str *key,
19                           const xs_val *data, int dsz)
20 /* inserts a memory block into the dict */
21 {
22     XS_ASSERT_TYPE(dict, XSTYPE_DICT);
23     XS_ASSERT_TYPE(key, XSTYPE_STRING);
24 
25+    if (data == NULL) {
26+        data = xs_stock_null;
27+        dsz = sizeof(xs_stock_null);
28+    }
29+
30     int ksz = xs_size(key);
31 
32     dict = xs_expand(dict, offset, 1 + ksz + dsz);
33@@ -921,14 +931,14 @@ xs_dict *xs_dict_insert_m(xs_dict *dict, int offset, const xs_str *key,
34 xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz)
35 /* appends a memory block to the dict */
36 {
37-    return xs_dict_insert_m(dict, xs_size(dict) - 1, key, mem, dsz);
38+    return _xs_dict_write_ditem(dict, xs_size(dict) - 1, key, mem, dsz);
39 }
40 
41 
42 xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz)
43 /* prepends a memory block to the dict */
44 {
45-    return xs_dict_insert_m(dict, 4, key, mem, dsz);
46+    return _xs_dict_write_ditem(dict, 4, key, mem, dsz);
47 }
48 
49 
+1, -1
1@@ -1 +1 @@
2-/* f42504297420abef44904644524207f8a1440494 */
3+/* ce9e43569a7dd29a85c807e496c335cc4999bafd */