diff options
| author | 2023-08-30 17:21:33 +0200 | |
|---|---|---|
| committer | 2023-08-30 17:21:33 +0200 | |
| commit | b5b59bd57480b0fd859c098f9fc218d0dc28ccbd (patch) | |
| tree | 418c9c58efaa0f5088ba98ab1301b42e6a6107f5 /xs.h | |
| parent | Version 2.41 RELEASED. (diff) | |
| download | penes-snac2-b5b59bd57480b0fd859c098f9fc218d0dc28ccbd.tar.gz penes-snac2-b5b59bd57480b0fd859c098f9fc218d0dc28ccbd.tar.xz penes-snac2-b5b59bd57480b0fd859c098f9fc218d0dc28ccbd.zip | |
Backport from xs.
Diffstat (limited to '')
| -rw-r--r-- | xs.h | 16 |
1 files changed, 13 insertions, 3 deletions
| @@ -603,6 +603,11 @@ xs_list *_xs_list_write_litem(xs_list *list, int offset, const char *mem, int ds | |||
| 603 | { | 603 | { |
| 604 | XS_ASSERT_TYPE(list, XSTYPE_LIST); | 604 | XS_ASSERT_TYPE(list, XSTYPE_LIST); |
| 605 | 605 | ||
| 606 | if (mem == NULL) { | ||
| 607 | mem = xs_stock_null; | ||
| 608 | dsz = sizeof(xs_stock_null); | ||
| 609 | } | ||
| 610 | |||
| 606 | list = xs_expand(list, offset, dsz + 1); | 611 | list = xs_expand(list, offset, dsz + 1); |
| 607 | 612 | ||
| 608 | list[offset] = XSTYPE_LITEM; | 613 | list[offset] = XSTYPE_LITEM; |
| @@ -899,13 +904,18 @@ xs_dict *xs_dict_new(void) | |||
| 899 | } | 904 | } |
| 900 | 905 | ||
| 901 | 906 | ||
| 902 | xs_dict *xs_dict_insert_m(xs_dict *dict, int offset, const xs_str *key, | 907 | xs_dict *_xs_dict_write_ditem(xs_dict *dict, int offset, const xs_str *key, |
| 903 | const xs_val *data, int dsz) | 908 | const xs_val *data, int dsz) |
| 904 | /* inserts a memory block into the dict */ | 909 | /* inserts a memory block into the dict */ |
| 905 | { | 910 | { |
| 906 | XS_ASSERT_TYPE(dict, XSTYPE_DICT); | 911 | XS_ASSERT_TYPE(dict, XSTYPE_DICT); |
| 907 | XS_ASSERT_TYPE(key, XSTYPE_STRING); | 912 | XS_ASSERT_TYPE(key, XSTYPE_STRING); |
| 908 | 913 | ||
| 914 | if (data == NULL) { | ||
| 915 | data = xs_stock_null; | ||
| 916 | dsz = sizeof(xs_stock_null); | ||
| 917 | } | ||
| 918 | |||
| 909 | int ksz = xs_size(key); | 919 | int ksz = xs_size(key); |
| 910 | 920 | ||
| 911 | dict = xs_expand(dict, offset, 1 + ksz + dsz); | 921 | 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, | |||
| 921 | xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) | 931 | xs_dict *xs_dict_append_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) |
| 922 | /* appends a memory block to the dict */ | 932 | /* appends a memory block to the dict */ |
| 923 | { | 933 | { |
| 924 | return xs_dict_insert_m(dict, xs_size(dict) - 1, key, mem, dsz); | 934 | return _xs_dict_write_ditem(dict, xs_size(dict) - 1, key, mem, dsz); |
| 925 | } | 935 | } |
| 926 | 936 | ||
| 927 | 937 | ||
| 928 | xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) | 938 | xs_dict *xs_dict_prepend_m(xs_dict *dict, const xs_str *key, const xs_val *mem, int dsz) |
| 929 | /* prepends a memory block to the dict */ | 939 | /* prepends a memory block to the dict */ |
| 930 | { | 940 | { |
| 931 | return xs_dict_insert_m(dict, 4, key, mem, dsz); | 941 | return _xs_dict_write_ditem(dict, 4, key, mem, dsz); |
| 932 | } | 942 | } |
| 933 | 943 | ||
| 934 | 944 | ||