commit 7aa5250

default  ·  2024-03-15 03:10:11 +0000 UTC
parent b7eb534
Backport from xs.
6 files changed,  +138, -115
M html.c
M xs.h
+2, -2
 1@@ -1074,7 +1074,7 @@ xs_dict *msg_collection(snac *snac, char *id)
 2 
 3     msg = xs_dict_append(msg, "attributedTo", snac->actor);
 4     msg = xs_dict_append(msg, "orderedItems", ol);
 5-    msg = xs_dict_append(msg, "totalItems",   xs_stock_0);
 6+    msg = xs_dict_append(msg, "totalItems",   xs_stock(0));
 7 
 8     return msg;
 9 }
10@@ -1610,7 +1610,7 @@ int update_question(snac *user, const char *id)
11         const char *name = xs_dict_get(v, "name");
12         if (name) {
13             lopts = xs_list_append(lopts, name);
14-            rcnt  = xs_dict_set(rcnt, name, xs_stock_0);
15+            rcnt  = xs_dict_set(rcnt, name, xs_stock(0));
16         }
17     }
18 
M html.c
+14, -14
 1@@ -774,7 +774,7 @@ static xs_html *html_user_body(snac *user, int read_only)
 2 
 3             xs_dict *val_links = user->links;
 4             if (xs_is_null(val_links))
 5-                val_links = xs_stock_dict;
 6+                val_links = xs_stock(XSTYPE_DICT);
 7 
 8             xs_html *snac_metadata = xs_html_tag("div",
 9                 xs_html_attr("class", "snac-metadata"));
10@@ -852,8 +852,8 @@ xs_html *html_top_controls(snac *snac)
11             "new_post_div", "new_post_form",
12             L("What's on your mind?"), "",
13             NULL, NULL,
14-            xs_stock_false, "",
15-            xs_stock_false, NULL,
16+            xs_stock(XSTYPE_FALSE), "",
17+            xs_stock(XSTYPE_FALSE), NULL,
18             NULL, 1),
19 
20         /** operations **/
21@@ -1285,7 +1285,7 @@ xs_html *html_entry_controls(snac *snac, char *actor, const xs_dict *msg, const
22                 "", prev_src,
23                 id, NULL,
24                 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
25-                xs_stock_false, redir,
26+                xs_stock(XSTYPE_FALSE), redir,
27                 NULL, 0)),
28             xs_html_tag("p", NULL));
29     }
30@@ -1304,7 +1304,7 @@ xs_html *html_entry_controls(snac *snac, char *actor, const xs_dict *msg, const
31                 "", ct,
32                 NULL, NULL,
33                 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
34-                xs_stock_false, redir,
35+                xs_stock(XSTYPE_FALSE), redir,
36                 id, 0)),
37             xs_html_tag("p", NULL));
38     }
39@@ -2181,8 +2181,8 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
40                     dm_div_id, dm_form_id,
41                     "", "",
42                     NULL, actor_id,
43-                    xs_stock_false, "",
44-                    xs_stock_false, NULL,
45+                    xs_stock(XSTYPE_FALSE), "",
46+                    xs_stock(XSTYPE_FALSE), NULL,
47                     NULL, 0),
48                 xs_html_tag("p", NULL));
49 
50@@ -2802,7 +2802,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
51                 msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv);
52 
53             if (sensitive != NULL) {
54-                msg = xs_dict_set(msg, "sensitive", xs_stock_true);
55+                msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
56                 msg = xs_dict_set(msg, "summary",   xs_is_null(summary) ? "..." : summary);
57             }
58 
59@@ -3036,17 +3036,17 @@ int html_post_handler(const xs_dict *req, const char *q_path,
60             snac.config = xs_dict_set(snac.config, "purge_days", days);
61         }
62         if ((v = xs_dict_get(p_vars, "drop_dm_from_unknown")) != NULL && strcmp(v, "on") == 0)
63-            snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_true);
64+            snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock(XSTYPE_TRUE));
65         else
66-            snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_false);
67+            snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock(XSTYPE_FALSE));
68         if ((v = xs_dict_get(p_vars, "bot")) != NULL && strcmp(v, "on") == 0)
69-            snac.config = xs_dict_set(snac.config, "bot", xs_stock_true);
70+            snac.config = xs_dict_set(snac.config, "bot", xs_stock(XSTYPE_TRUE));
71         else
72-            snac.config = xs_dict_set(snac.config, "bot", xs_stock_false);
73+            snac.config = xs_dict_set(snac.config, "bot", xs_stock(XSTYPE_FALSE));
74         if ((v = xs_dict_get(p_vars, "private")) != NULL && strcmp(v, "on") == 0)
75-            snac.config = xs_dict_set(snac.config, "private", xs_stock_true);
76+            snac.config = xs_dict_set(snac.config, "private", xs_stock(XSTYPE_TRUE));
77         else
78-            snac.config = xs_dict_set(snac.config, "private", xs_stock_false);
79+            snac.config = xs_dict_set(snac.config, "private", xs_stock(XSTYPE_FALSE));
80         if ((v = xs_dict_get(p_vars, "metadata")) != NULL) {
81             /* split the metadata and store it as a dict */
82             xs_dict *md = xs_dict_new();
+1, -1
1@@ -814,7 +814,7 @@ void httpd(void)
2 
3     /* send as many exit jobs as working threads */
4     for (n = 1; n < p_state->n_threads; n++)
5-        job_post(xs_stock_false, 0);
6+        job_post(xs_stock(XSTYPE_FALSE), 0);
7 
8     /* wait for all the threads to exit */
9     for (n = 0; n < p_state->n_threads; n++)
+59, -59
  1@@ -522,12 +522,12 @@ xs_dict *mastoapi_account(const xs_dict *actor)
  2     acct = xs_dict_append(acct, "id",           acct_md5);
  3     acct = xs_dict_append(acct, "username",     prefu);
  4     acct = xs_dict_append(acct, "display_name", display_name);
  5-    acct = xs_dict_append(acct, "discoverable", xs_stock_true);
  6-    acct = xs_dict_append(acct, "group",        xs_stock_false);
  7-    acct = xs_dict_append(acct, "hide_collections", xs_stock_false);
  8-    acct = xs_dict_append(acct, "indexable",    xs_stock_true);
  9-    acct = xs_dict_append(acct, "noindex",      xs_stock_false);
 10-    acct = xs_dict_append(acct, "roles",        xs_stock_list);
 11+    acct = xs_dict_append(acct, "discoverable", xs_stock(XSTYPE_TRUE));
 12+    acct = xs_dict_append(acct, "group",        xs_stock(XSTYPE_FALSE));
 13+    acct = xs_dict_append(acct, "hide_collections", xs_stock(XSTYPE_FALSE));
 14+    acct = xs_dict_append(acct, "indexable",    xs_stock(XSTYPE_TRUE));
 15+    acct = xs_dict_append(acct, "noindex",      xs_stock(XSTYPE_FALSE));
 16+    acct = xs_dict_append(acct, "roles",        xs_stock(XSTYPE_LIST));
 17 
 18     {
 19         /* create the acct field as user@host */
 20@@ -549,9 +549,9 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 21         note = "";
 22 
 23     if (strcmp(xs_dict_get(actor, "type"), "Service") == 0)
 24-        acct = xs_dict_append(acct, "bot", xs_stock_true);
 25+        acct = xs_dict_append(acct, "bot", xs_stock(XSTYPE_TRUE));
 26     else
 27-        acct = xs_dict_append(acct, "bot", xs_stock_false);
 28+        acct = xs_dict_append(acct, "bot", xs_stock(XSTYPE_FALSE));
 29 
 30     acct = xs_dict_append(acct, "note", note);
 31 
 32@@ -609,7 +609,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 33                         d1 = xs_dict_append(d1, "shortcode",         nm);
 34                         d1 = xs_dict_append(d1, "url",               url);
 35                         d1 = xs_dict_append(d1, "static_url",        url);
 36-                        d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true);
 37+                        d1 = xs_dict_append(d1, "visible_in_picker", xs_stock(XSTYPE_TRUE));
 38 
 39                         eml = xs_list_append(eml, d1);
 40                     }
 41@@ -620,10 +620,10 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 42         acct = xs_dict_append(acct, "emojis", eml);
 43     }
 44 
 45-    acct = xs_dict_append(acct, "locked", xs_stock_false);
 46-    acct = xs_dict_append(acct, "followers_count", xs_stock_0);
 47-    acct = xs_dict_append(acct, "following_count", xs_stock_0);
 48-    acct = xs_dict_append(acct, "statuses_count", xs_stock_0);
 49+    acct = xs_dict_append(acct, "locked", xs_stock(XSTYPE_FALSE));
 50+    acct = xs_dict_append(acct, "followers_count", xs_stock(0));
 51+    acct = xs_dict_append(acct, "following_count", xs_stock(0));
 52+    acct = xs_dict_append(acct, "statuses_count", xs_stock(0));
 53 
 54     xs *fields = xs_list_new();
 55     p = xs_dict_get(actor, "attachment");
 56@@ -631,19 +631,19 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 57 
 58     /* dict of validated links */
 59     xs_dict *val_links = NULL;
 60-    xs_dict *metadata  = xs_stock_dict;
 61+    xs_dict *metadata  = xs_stock(XSTYPE_DICT);
 62     snac user = {0};
 63 
 64     if (xs_startswith(id, srv_baseurl)) {
 65         /* if it's a local user, open it and pick its validated links */
 66         if (user_open(&user, prefu)) {
 67             val_links = user.links;
 68-            metadata  = xs_dict_get_def(user.config, "metadata", xs_stock_dict);
 69+            metadata  = xs_dict_get_def(user.config, "metadata", xs_stock(XSTYPE_DICT));
 70         }
 71     }
 72 
 73     if (xs_is_null(val_links))
 74-        val_links = xs_stock_dict;
 75+        val_links = xs_stock(XSTYPE_DICT);
 76 
 77     while (xs_list_iter(&p, &v)) {
 78         char *type  = xs_dict_get(v, "type");
 79@@ -672,7 +672,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 80             d = xs_dict_append(d, "value", value);
 81             d = xs_dict_append(d, "verified_at",
 82                 xs_type(val_date) == XSTYPE_STRING && *val_date ?
 83-                    val_date : xs_stock_null);
 84+                    val_date : xs_stock(XSTYPE_NULL));
 85 
 86             fields = xs_list_append(fields, d);
 87         }
 88@@ -710,13 +710,13 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
 89     xs *fd = mastoapi_date(xs_dict_get(msg, "endTime"));
 90     poll = xs_dict_append(poll, "expires_at", fd);
 91     poll = xs_dict_append(poll, "expired",
 92-            xs_dict_get(msg, "closed") != NULL ? xs_stock_true : xs_stock_false);
 93+            xs_dict_get(msg, "closed") != NULL ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
 94 
 95     if ((opts = xs_dict_get(msg, "oneOf")) != NULL)
 96-        poll = xs_dict_append(poll, "multiple", xs_stock_false);
 97+        poll = xs_dict_append(poll, "multiple", xs_stock(XSTYPE_FALSE));
 98     else {
 99         opts = xs_dict_get(msg, "anyOf");
100-        poll = xs_dict_append(poll, "multiple", xs_stock_true);
101+        poll = xs_dict_append(poll, "multiple", xs_stock(XSTYPE_TRUE));
102     }
103 
104     while (xs_list_iter(&opts, &v)) {
105@@ -743,7 +743,7 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
106 
107     poll = xs_dict_append(poll, "voted",
108             (snac && was_question_voted(snac, xs_dict_get(msg, "id"))) ?
109-                xs_stock_true : xs_stock_false);
110+                xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
111 
112     return poll;
113 }
114@@ -809,7 +809,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
115 
116     tmp = xs_dict_get(msg, "sensitive");
117     if (xs_is_null(tmp))
118-        tmp = xs_stock_false;
119+        tmp = xs_stock(XSTYPE_FALSE);
120 
121     st = xs_dict_append(st, "sensitive",    tmp);
122 
123@@ -928,7 +928,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
124                         d1 = xs_dict_append(d1, "shortcode", nm);
125                         d1 = xs_dict_append(d1, "url", url);
126                         d1 = xs_dict_append(d1, "static_url", url);
127-                        d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true);
128+                        d1 = xs_dict_append(d1, "visible_in_picker", xs_stock(XSTYPE_TRUE));
129                         d1 = xs_dict_append(d1, "category", "Emojis");
130 
131                         eml = xs_list_append(eml, d1);
132@@ -949,7 +949,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
133 
134     st = xs_dict_append(st, "favourites_count", ixc);
135     st = xs_dict_append(st, "favourited",
136-        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false);
137+        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
138 
139     xs_free(idx);
140     xs_free(ixc);
141@@ -958,7 +958,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
142 
143     st = xs_dict_append(st, "reblogs_count", ixc);
144     st = xs_dict_append(st, "reblogged",
145-        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false);
146+        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
147 
148     /* get the last person who boosted this */
149     xs *boosted_by_md5 = NULL;
150@@ -973,8 +973,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
151     st = xs_dict_append(st, "replies_count", ixc);
152 
153     /* default in_reply_to values */
154-    st = xs_dict_append(st, "in_reply_to_id",         xs_stock_null);
155-    st = xs_dict_append(st, "in_reply_to_account_id", xs_stock_null);
156+    st = xs_dict_append(st, "in_reply_to_id",         xs_stock(XSTYPE_NULL));
157+    st = xs_dict_append(st, "in_reply_to_account_id", xs_stock(XSTYPE_NULL));
158 
159     tmp = xs_dict_get(msg, "inReplyTo");
160     if (!xs_is_null(tmp)) {
161@@ -992,9 +992,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
162         }
163     }
164 
165-    st = xs_dict_append(st, "reblog",   xs_stock_null);
166-    st = xs_dict_append(st, "card",     xs_stock_null);
167-    st = xs_dict_append(st, "language", xs_stock_null);
168+    st = xs_dict_append(st, "reblog",   xs_stock(XSTYPE_NULL));
169+    st = xs_dict_append(st, "card",     xs_stock(XSTYPE_NULL));
170+    st = xs_dict_append(st, "language", xs_stock(XSTYPE_NULL));
171 
172     tmp = xs_dict_get(msg, "sourceContent");
173     if (xs_is_null(tmp))
174@@ -1005,7 +1005,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
175     tmp = xs_dict_get(msg, "updated");
176     xs *fd2 = NULL;
177     if (xs_is_null(tmp))
178-        tmp = xs_stock_null;
179+        tmp = xs_stock(XSTYPE_NULL);
180     else {
181         fd2 = mastoapi_date(tmp);
182         tmp = fd2;
183@@ -1018,12 +1018,12 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
184         st = xs_dict_append(st, "poll", poll);
185     }
186     else
187-        st = xs_dict_append(st, "poll", xs_stock_null);
188+        st = xs_dict_append(st, "poll", xs_stock(XSTYPE_NULL));
189 
190-    st = xs_dict_append(st, "bookmarked", xs_stock_false);
191+    st = xs_dict_append(st, "bookmarked", xs_stock(XSTYPE_FALSE));
192 
193     st = xs_dict_append(st, "pinned",
194-        (snac && is_pinned(snac, id)) ? xs_stock_true : xs_stock_false);
195+        (snac && is_pinned(snac, id)) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
196 
197     /* is it a boost? */
198     if (!xs_is_null(boosted_by_md5)) {
199@@ -1067,21 +1067,21 @@ xs_dict *mastoapi_relationship(snac *snac, const char *md5)
200 
201         rel = xs_dict_append(rel, "id",                   md5);
202         rel = xs_dict_append(rel, "following",
203-            following_check(snac, actor) ? xs_stock_true : xs_stock_false);
204+            following_check(snac, actor) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
205 
206-        rel = xs_dict_append(rel, "showing_reblogs",      xs_stock_true);
207-        rel = xs_dict_append(rel, "notifying",            xs_stock_false);
208+        rel = xs_dict_append(rel, "showing_reblogs",      xs_stock(XSTYPE_TRUE));
209+        rel = xs_dict_append(rel, "notifying",            xs_stock(XSTYPE_FALSE));
210         rel = xs_dict_append(rel, "followed_by",
211-            follower_check(snac, actor) ? xs_stock_true : xs_stock_false);
212+            follower_check(snac, actor) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
213 
214         rel = xs_dict_append(rel, "blocking",
215-            is_muted(snac, actor) ? xs_stock_true : xs_stock_false);
216+            is_muted(snac, actor) ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE));
217 
218-        rel = xs_dict_append(rel, "muting",               xs_stock_false);
219-        rel = xs_dict_append(rel, "muting_notifications", xs_stock_false);
220-        rel = xs_dict_append(rel, "requested",            xs_stock_false);
221-        rel = xs_dict_append(rel, "domain_blocking",      xs_stock_false);
222-        rel = xs_dict_append(rel, "endorsed",             xs_stock_false);
223+        rel = xs_dict_append(rel, "muting",               xs_stock(XSTYPE_FALSE));
224+        rel = xs_dict_append(rel, "muting_notifications", xs_stock(XSTYPE_FALSE));
225+        rel = xs_dict_append(rel, "requested",            xs_stock(XSTYPE_FALSE));
226+        rel = xs_dict_append(rel, "domain_blocking",      xs_stock(XSTYPE_FALSE));
227+        rel = xs_dict_append(rel, "endorsed",             xs_stock(XSTYPE_FALSE));
228         rel = xs_dict_append(rel, "note",                 "");
229     }
230 
231@@ -1149,7 +1149,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
232             acct = xs_dict_append(acct, "last_status_at", xs_dict_get(snac1.config, "published"));
233             acct = xs_dict_append(acct, "note",         xs_dict_get(snac1.config, "bio"));
234             acct = xs_dict_append(acct, "url",          snac1.actor);
235-            acct = xs_dict_append(acct, "locked",       xs_stock_false);
236+            acct = xs_dict_append(acct, "locked",       xs_stock(XSTYPE_FALSE));
237             acct = xs_dict_append(acct, "bot",          xs_dict_get(snac1.config, "bot"));
238 
239             xs *src = xs_json_loads("{\"privacy\":\"public\","
240@@ -1186,7 +1186,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
241 
242                 xs_dict *val_links = snac1.links;
243                 if (xs_is_null(val_links))
244-                    val_links = xs_stock_dict;
245+                    val_links = xs_stock(XSTYPE_DICT);
246 
247                 int c = 0;
248                 while (xs_dict_next(metadata, &k, &v, &c)) {
249@@ -1206,7 +1206,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
250                     d = xs_dict_append(d, "value", v);
251                     d = xs_dict_append(d, "verified_at",
252                         xs_type(val_date) == XSTYPE_STRING && *val_date ?
253-                            val_date : xs_stock_null);
254+                            val_date : xs_stock(XSTYPE_NULL));
255 
256                     fields = xs_list_append(fields, d);
257                 }
258@@ -1214,9 +1214,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
259                 acct = xs_dict_set(acct, "fields", fields);
260             }
261 
262-            acct = xs_dict_append(acct, "followers_count", xs_stock_0);
263-            acct = xs_dict_append(acct, "following_count", xs_stock_0);
264-            acct = xs_dict_append(acct, "statuses_count", xs_stock_0);
265+            acct = xs_dict_append(acct, "followers_count", xs_stock(0));
266+            acct = xs_dict_append(acct, "following_count", xs_stock(0));
267+            acct = xs_dict_append(acct, "statuses_count", xs_stock(0));
268 
269             *body  = xs_json_dumps(acct, 4);
270             *ctype = "application/json";
271@@ -1813,7 +1813,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
272 
273         ins = xs_dict_append(ins, "email", v);
274 
275-        ins = xs_dict_append(ins, "rules", xs_stock_list);
276+        ins = xs_dict_append(ins, "rules", xs_stock(XSTYPE_LIST));
277 
278         xs *l1 = xs_list_append(xs_list_new(), "en");
279         ins = xs_dict_append(ins, "languages", l1);
280@@ -1824,14 +1824,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
281 
282         ins = xs_dict_append(ins, "urls", urls);
283 
284-        xs *d2 = xs_dict_append(xs_dict_new(), "user_count", xs_stock_0);
285-        d2 = xs_dict_append(d2, "status_count", xs_stock_0);
286-        d2 = xs_dict_append(d2, "domain_count", xs_stock_0);
287+        xs *d2 = xs_dict_append(xs_dict_new(), "user_count", xs_stock(0));
288+        d2 = xs_dict_append(d2, "status_count", xs_stock(0));
289+        d2 = xs_dict_append(d2, "domain_count", xs_stock(0));
290         ins = xs_dict_append(ins, "stats", d2);
291 
292-        ins = xs_dict_append(ins, "registrations",     xs_stock_false);
293-        ins = xs_dict_append(ins, "approval_required", xs_stock_false);
294-        ins = xs_dict_append(ins, "invites_enabled",   xs_stock_false);
295+        ins = xs_dict_append(ins, "registrations",     xs_stock(XSTYPE_FALSE));
296+        ins = xs_dict_append(ins, "approval_required", xs_stock(XSTYPE_FALSE));
297+        ins = xs_dict_append(ins, "invites_enabled",   xs_stock(XSTYPE_FALSE));
298 
299         xs *cfg = xs_dict_new();
300 
301@@ -2079,7 +2079,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
302                             d = xs_dict_append(d, "name", q);
303                             xs *url = xs_fmt("%s?t=%s", srv_baseurl, q);
304                             d = xs_dict_append(d, "url", url);
305-                            d = xs_dict_append(d, "history", xs_stock_list);
306+                            d = xs_dict_append(d, "history", xs_stock(XSTYPE_LIST));
307 
308                             htl = xs_list_append(htl, d);
309                         }
310@@ -2257,7 +2257,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
311                         strcmp(visibility, "public") == 0 ? 0 : 1);
312 
313             if (!xs_is_null(summary) && *summary) {
314-                msg = xs_dict_set(msg, "sensitive", xs_stock_true);
315+                msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
316                 msg = xs_dict_set(msg, "summary",   summary);
317             }
318 
M xs.h
+61, -38
  1@@ -61,6 +61,7 @@ xs_val *xs_collapse(xs_val *data, int offset, int size);
  2 xs_val *xs_insert_m(xs_val *data, int offset, const char *mem, int size);
  3 #define xs_insert(data, offset, data2) xs_insert_m(data, offset, data2, xs_size(data2))
  4 #define xs_append_m(data, mem, size) xs_insert_m(data, xs_size(data) - 1, mem, size)
  5+xs_val *xs_stock(int type);
  6 
  7 xs_str *xs_str_new(const char *str);
  8 xs_str *xs_str_new_sz(const char *mem, int sz);
  9@@ -137,34 +138,11 @@ unsigned int xs_hash_func(const char *data, int size);
 10 #define XS_ASSERT_TYPE_NULL(v, t) (void)(0)
 11 #endif
 12 
 13-extern xs_val xs_stock_null[];
 14-extern xs_val xs_stock_true[];
 15-extern xs_val xs_stock_false[];
 16-extern xs_val xs_stock_0[];
 17-extern xs_val xs_stock_1[];
 18-extern xs_val xs_stock_list[];
 19-extern xs_val xs_stock_dict[];
 20-
 21 #define xs_return(v) xs_val *__r = v; v = NULL; return __r
 22 
 23 
 24 #ifdef XS_IMPLEMENTATION
 25 
 26-xs_val xs_stock_null[]  = { XSTYPE_NULL };
 27-xs_val xs_stock_true[]  = { XSTYPE_TRUE };
 28-xs_val xs_stock_false[] = { XSTYPE_FALSE };
 29-xs_val xs_stock_0[]     = { XSTYPE_NUMBER, '0', '\0' };
 30-xs_val xs_stock_1[]     = { XSTYPE_NUMBER, '1', '\0' };
 31-
 32-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 33-xs_val xs_stock_list[]  = { XSTYPE_LIST, 0, 0, 0, 1 + _XS_TYPE_SIZE + 1, XSTYPE_EOM };
 34-xs_val xs_stock_dict[]  = { XSTYPE_DICT, 0, 0, 0, 1 + _XS_TYPE_SIZE + 1, XSTYPE_EOM };
 35-#else
 36-xs_val xs_stock_list[]  = { XSTYPE_LIST, 1 + _XS_TYPE_SIZE + 1, 0, 0, 0, XSTYPE_EOM };
 37-xs_val xs_stock_dict[]  = { XSTYPE_DICT, 1 + _XS_TYPE_SIZE + 1, 0, 0, 0, XSTYPE_EOM };
 38-#endif
 39-
 40-
 41 void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func)
 42 {
 43     xs_val *ndata = realloc(ptr, size);
 44@@ -369,10 +347,14 @@ int xs_cmp(const xs_val *v1, const xs_val *v2)
 45 xs_val *xs_dup(const xs_val *data)
 46 /* creates a duplicate of data */
 47 {
 48-    int sz = xs_size(data);
 49-    xs_val *s = xs_realloc(NULL, _xs_blk_size(sz));
 50+    xs_val *s = NULL;
 51+
 52+    if (data) {
 53+        int sz = xs_size(data);
 54+        s = xs_realloc(NULL, _xs_blk_size(sz));
 55 
 56-    memcpy(s, data, sz);
 57+        memcpy(s, data, sz);
 58+    }
 59 
 60     return s;
 61 }
 62@@ -437,6 +419,39 @@ xs_val *xs_insert_m(xs_val *data, int offset, const char *mem, int size)
 63 }
 64 
 65 
 66+xs_val *xs_stock(int type)
 67+/* returns stock values */
 68+{
 69+    static xs_val stock_null[]  = { XSTYPE_NULL };
 70+    static xs_val stock_true[]  = { XSTYPE_TRUE };
 71+    static xs_val stock_false[] = { XSTYPE_FALSE };
 72+    static xs_val stock_0[]     = { XSTYPE_NUMBER, '0', '\0' };
 73+    static xs_val stock_1[]     = { XSTYPE_NUMBER, '1', '\0' };
 74+    static xs_list *stock_list = NULL;
 75+    static xs_dict *stock_dict = NULL;
 76+
 77+    switch (type) {
 78+    case 0:            return stock_0;
 79+    case 1:            return stock_1;
 80+    case XSTYPE_NULL:  return stock_null;
 81+    case XSTYPE_TRUE:  return stock_true;
 82+    case XSTYPE_FALSE: return stock_false;
 83+
 84+    case XSTYPE_LIST:
 85+        if (stock_list == NULL)
 86+            stock_list = xs_list_new();
 87+        return stock_list;
 88+
 89+    case XSTYPE_DICT:
 90+        if (stock_dict == NULL)
 91+            stock_dict = xs_dict_new();
 92+        return stock_dict;
 93+    }
 94+
 95+    return NULL;
 96+}
 97+
 98+
 99 /** strings **/
100 
101 xs_str *xs_str_new(const char *str)
102@@ -647,10 +662,14 @@ xs_str *xs_tolower_i(xs_str *str)
103 xs_list *xs_list_new(void)
104 /* creates a new list */
105 {
106-    return memcpy(
107-        xs_realloc(NULL, _xs_blk_size(sizeof(xs_stock_list))),
108-        xs_stock_list, sizeof(xs_stock_list)
109-    );
110+    int sz = 1 + _XS_TYPE_SIZE + 1;
111+    xs_list *l = xs_realloc(NULL, sz);
112+    memset(l, '\0', sz);
113+
114+    l[0] = XSTYPE_LIST;
115+    _xs_put_size(&l[1], sz);
116+
117+    return l;
118 }
119 
120 
121@@ -660,8 +679,8 @@ xs_list *_xs_list_write_litem(xs_list *list, int offset, const char *mem, int ds
122     XS_ASSERT_TYPE(list, XSTYPE_LIST);
123 
124     if (mem == NULL) {
125-        mem = xs_stock_null;
126-        dsz = sizeof(xs_stock_null);
127+        mem = xs_stock(XSTYPE_NULL);
128+        dsz = xs_size(mem);
129     }
130 
131     list = xs_expand(list, offset, dsz + 1);
132@@ -947,10 +966,14 @@ xs_list *xs_list_cat(xs_list *l1, const xs_list *l2)
133 xs_dict *xs_dict_new(void)
134 /* creates a new dict */
135 {
136-    return memcpy(
137-        xs_realloc(NULL, _xs_blk_size(sizeof(xs_stock_dict))),
138-        xs_stock_dict, sizeof(xs_stock_dict)
139-    );
140+    int sz = 1 + _XS_TYPE_SIZE + 1;
141+    xs_dict *d = xs_realloc(NULL, sz);
142+    memset(d, '\0', sz);
143+
144+    d[0] = XSTYPE_DICT;
145+    _xs_put_size(&d[1], sz);
146+
147+    return d;
148 }
149 
150 
151@@ -962,8 +985,8 @@ xs_dict *_xs_dict_write_ditem(xs_dict *dict, int offset, const xs_str *key,
152     XS_ASSERT_TYPE(key, XSTYPE_STRING);
153 
154     if (data == NULL) {
155-        data = xs_stock_null;
156-        dsz = sizeof(xs_stock_null);
157+        data = xs_stock(XSTYPE_NULL);
158+        dsz  = xs_size(data);
159     }
160 
161     int ksz = xs_size(key);
+1, -1
1@@ -1 +1 @@
2-/* f46d5b29627b20a6e9ec4ef60c01df1d2d778520 2024-03-09T08:26:31+01:00 */
3+/* 0df383371d207b0adfda40912ee54b37e5b01152 2024-03-15T03:45:39+01:00 */