pr0064-remove-gpl-code.patch 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. From fc516556e68b95d672bf146616a0967dd697a9a8 Mon Sep 17 00:00:00 2001
  2. From: Innokentii Mokin <innokentii@yandex-team.ru>
  3. Date: Tue, 20 Dec 2022 21:07:50 +0300
  4. Subject: [PATCH 1/3] replace fy-list with MIT one
  5. ---
  6. src/lib/fy-accel.h | 2 +-
  7. src/lib/fy-composer.c | 2 +-
  8. src/lib/fy-diag.h | 2 +-
  9. src/lib/fy-doc.c | 2 +-
  10. src/lib/fy-doc.h | 10 +-
  11. src/lib/fy-emit.c | 2 +-
  12. src/lib/fy-event.c | 6 +-
  13. src/lib/fy-event.h | 2 +-
  14. src/lib/fy-input.h | 2 +-
  15. src/lib/fy-list.h | 714 +++---------------------------------------
  16. src/lib/fy-parse.c | 4 +-
  17. src/lib/fy-parse.h | 8 +-
  18. src/lib/fy-path.h | 4 +-
  19. src/lib/fy-token.h | 2 +-
  20. src/lib/fy-typelist.h | 42 +--
  21. src/lib/fy-types.h | 2 +-
  22. src/lib/fy-walk.c | 2 +-
  23. src/lib/fy-walk.h | 4 +-
  24. 18 files changed, 94 insertions(+), 718 deletions(-)
  25. diff --git a/src/lib/fy-accel.h b/src/lib/fy-accel.h
  26. index 1531e8c..2e917ce 100644
  27. --- a/src/lib/fy-accel.h
  28. +++ b/src/lib/fy-accel.h
  29. @@ -20,7 +20,7 @@
  30. #include "fy-typelist.h"
  31. struct fy_accel_entry {
  32. - struct list_head node;
  33. + struct fy_list_head node;
  34. const void *key;
  35. const void *value;
  36. uint8_t hash[0];
  37. diff --git a/src/lib/fy-composer.c b/src/lib/fy-composer.c
  38. index 3e19017..2202497 100644
  39. --- a/src/lib/fy-composer.c
  40. +++ b/src/lib/fy-composer.c
  41. @@ -83,7 +83,7 @@ fy_composer_process_event_private(struct fy_composer *fyc, struct fy_event *fye,
  42. assert(fye);
  43. assert(fypp);
  44. - fyep = container_of(fye, struct fy_eventp, e);
  45. + fyep = fy_container_of(fye, struct fy_eventp, e);
  46. ops = fyc->cfg.ops;
  47. assert(ops);
  48. diff --git a/src/lib/fy-diag.h b/src/lib/fy-diag.h
  49. index f19861d..2171509 100644
  50. --- a/src/lib/fy-diag.h
  51. +++ b/src/lib/fy-diag.h
  52. @@ -73,7 +73,7 @@ struct fy_diag_report_ctx {
  53. FY_TYPE_FWD_DECL_LIST(diag_errorp);
  54. struct fy_diag_errorp {
  55. - struct list_head node;
  56. + struct fy_list_head node;
  57. char *space;
  58. struct fy_diag_error e;
  59. };
  60. diff --git a/src/lib/fy-doc.c b/src/lib/fy-doc.c
  61. index 602264b..31a99c7 100644
  62. --- a/src/lib/fy-doc.c
  63. +++ b/src/lib/fy-doc.c
  64. @@ -5951,7 +5951,7 @@ struct flow_reader_container {
  65. static struct fy_diag *flow_reader_get_diag(struct fy_reader *fyr)
  66. {
  67. - struct flow_reader_container *frc = container_of(fyr, struct flow_reader_container, reader);
  68. + struct flow_reader_container *frc = fy_container_of(fyr, struct flow_reader_container, reader);
  69. return frc->cfg ? frc->cfg->diag : NULL;
  70. }
  71. diff --git a/src/lib/fy-doc.h b/src/lib/fy-doc.h
  72. index 6c15024..205e604 100644
  73. --- a/src/lib/fy-doc.h
  74. +++ b/src/lib/fy-doc.h
  75. @@ -44,7 +44,7 @@ FY_TYPE_FWD_DECL_LIST(document);
  76. struct fy_node;
  77. struct fy_node_pair {
  78. - struct list_head node;
  79. + struct fy_list_head node;
  80. struct fy_node *key;
  81. struct fy_node *value;
  82. struct fy_document *fyd;
  83. @@ -55,7 +55,7 @@ FY_TYPE_DECL_LIST(node_pair);
  84. FY_TYPE_FWD_DECL_LIST(node);
  85. struct fy_node {
  86. - struct list_head node;
  87. + struct fy_list_head node;
  88. struct fy_token *tag;
  89. enum fy_node_style style;
  90. struct fy_node *parent;
  91. @@ -93,7 +93,7 @@ void fy_node_detach_and_free(struct fy_node *fyn);
  92. void fy_node_pair_detach_and_free(struct fy_node_pair *fynp);
  93. struct fy_anchor {
  94. - struct list_head node;
  95. + struct fy_list_head node;
  96. struct fy_node *fyn;
  97. struct fy_token *anchor;
  98. bool multiple : 1;
  99. @@ -102,7 +102,7 @@ FY_TYPE_FWD_DECL_LIST(anchor);
  100. FY_TYPE_DECL_LIST(anchor);
  101. struct fy_document {
  102. - struct list_head node;
  103. + struct fy_list_head node;
  104. struct fy_anchor_list anchors;
  105. struct fy_accel *axl; /* name -> anchor access accelerator */
  106. struct fy_accel *naxl; /* node -> anchor access accelerator */
  107. @@ -187,7 +187,7 @@ struct fy_node *fy_node_collection_iterate(struct fy_node *fyn, void **prevp);
  108. /* indirect node */
  109. FY_TYPE_FWD_DECL_LIST(ptr_node);
  110. struct fy_ptr_node {
  111. - struct list_head node;
  112. + struct fy_list_head node;
  113. struct fy_node *fyn;
  114. };
  115. FY_TYPE_DECL_LIST(ptr_node);
  116. diff --git a/src/lib/fy-emit.c b/src/lib/fy-emit.c
  117. index 36d8d8e..5b9b5f1 100644
  118. --- a/src/lib/fy-emit.c
  119. +++ b/src/lib/fy-emit.c
  120. @@ -3311,7 +3311,7 @@ int fy_emit_event_from_parser(struct fy_emitter *emit, struct fy_parser *fyp, st
  121. if (emit->state == FYES_NONE)
  122. emit->state = FYES_STREAM_START;
  123. - fyep = container_of(fye, struct fy_eventp, e);
  124. + fyep = fy_container_of(fye, struct fy_eventp, e);
  125. fy_eventp_list_add_tail(&emit->queued_events, fyep);
  126. diff --git a/src/lib/fy-event.c b/src/lib/fy-event.c
  127. index a359063..0e049b4 100644
  128. --- a/src/lib/fy-event.c
  129. +++ b/src/lib/fy-event.c
  130. @@ -169,7 +169,7 @@ void fy_parser_event_free(struct fy_parser *fyp, struct fy_event *fye)
  131. if (!fyp || !fye)
  132. return;
  133. - fyep = container_of(fye, struct fy_eventp, e);
  134. + fyep = fy_container_of(fye, struct fy_eventp, e);
  135. fy_parse_eventp_recycle(fyp, fyep);
  136. }
  137. @@ -195,7 +195,7 @@ void fy_emit_event_free(struct fy_emitter *emit, struct fy_event *fye)
  138. if (!emit || !fye)
  139. return;
  140. - fyep = container_of(fye, struct fy_eventp, e);
  141. + fyep = fy_container_of(fye, struct fy_eventp, e);
  142. fy_emit_eventp_recycle(emit, fyep);
  143. }
  144. @@ -908,7 +908,7 @@ void fy_document_iterator_event_free(struct fy_document_iterator *fydi, struct f
  145. if (!fydi || !fye)
  146. return;
  147. - fyep = container_of(fye, struct fy_eventp, e);
  148. + fyep = fy_container_of(fye, struct fy_eventp, e);
  149. fy_document_iterator_eventp_recycle(fydi, fyep);
  150. }
  151. diff --git a/src/lib/fy-event.h b/src/lib/fy-event.h
  152. index 75f20fb..4da3c8f 100644
  153. --- a/src/lib/fy-event.h
  154. +++ b/src/lib/fy-event.h
  155. @@ -22,7 +22,7 @@
  156. /* private event type */
  157. FY_TYPE_FWD_DECL_LIST(eventp);
  158. struct fy_eventp {
  159. - struct list_head node;
  160. + struct fy_list_head node;
  161. struct fy_event e;
  162. };
  163. FY_TYPE_DECL_LIST(eventp);
  164. diff --git a/src/lib/fy-input.h b/src/lib/fy-input.h
  165. index 6634fab..59b7888 100644
  166. --- a/src/lib/fy-input.h
  167. +++ b/src/lib/fy-input.h
  168. @@ -78,7 +78,7 @@ enum fy_input_state {
  169. FY_TYPE_FWD_DECL_LIST(input);
  170. struct fy_input {
  171. - struct list_head node;
  172. + struct fy_list_head node;
  173. enum fy_input_state state;
  174. struct fy_input_cfg cfg;
  175. int refs; /* number of referers */
  176. diff --git a/src/lib/fy-list.h b/src/lib/fy-list.h
  177. index 1a0b5f9..65e17f9 100644
  178. --- a/src/lib/fy-list.h
  179. +++ b/src/lib/fy-list.h
  180. @@ -1,705 +1,81 @@
  181. /*
  182. - * fy-list.h - slightly modified Linux kernel list.h
  183. + * fy-list.h - simple doubly linked list implementation
  184. *
  185. - * All copyrights owned by their respective holders.
  186. + * Copyright (c) 2022 Innokentii Mokin <iam@justregular.dev>
  187. *
  188. - * SPDX-License-Identifier: GPL-2.0
  189. + * SPDX-License-Identifier: MIT
  190. */
  191. -#ifndef _FY_LIST_H
  192. -#define _FY_LIST_H
  193. +#ifndef FY_LIST_H
  194. +#define FY_LIST_H
  195. #include <stddef.h>
  196. -/**
  197. - * container_of - cast a member of a structure out to the containing structure
  198. - * @ptr: the pointer to the member.
  199. - * @type: the type of the container struct this is embedded in.
  200. - * @member: the name of the member within the struct.
  201. - *
  202. - */
  203. -#define container_of(ptr, type, member) ({ \
  204. - const typeof( ((type *)0)->member ) *__mptr = (ptr); \
  205. - (type *)( (char *)__mptr - offsetof(type,member) );})
  206. -
  207. -#define LIST_POISON1 NULL
  208. -#define LIST_POISON2 NULL
  209. -
  210. -#ifndef ARCH_HAS_PREFETCH
  211. -#define ARCH_HAS_PREFETCH
  212. -static inline void prefetch(const void *x) {;}
  213. -#endif
  214. -
  215. -/*
  216. - * Simple doubly linked list implementation.
  217. - *
  218. - * Some of the internal functions ("__xxx") are useful when
  219. - * manipulating whole lists rather than single entries, as
  220. - * sometimes we already know the next/prev entries and we can
  221. - * generate better code by using them directly rather than
  222. - * using the generic single-entry routines.
  223. - */
  224. +#define fy_container_of(pointer, type, member) ({ \
  225. + const typeof(((type *)NULL)->member) *__## member ## _ptr = (pointer); \
  226. + (type *) ((char *)__ ## member ## _ptr - offsetof(type, member)); \
  227. + } \
  228. +)
  229. -struct list_head {
  230. - struct list_head *next, *prev;
  231. +struct fy_list_head {
  232. + struct fy_list_head *prev;
  233. + struct fy_list_head *next;
  234. };
  235. -#define LIST_HEAD_INIT(name) { &(name), &(name) }
  236. -
  237. -#define LIST_HEAD(name) \
  238. - struct list_head name = LIST_HEAD_INIT(name)
  239. -
  240. -static inline void INIT_LIST_HEAD(struct list_head *list)
  241. -{
  242. - list->next = list;
  243. - list->prev = list;
  244. -}
  245. -
  246. -/*
  247. - * Insert a new entry between two known consecutive entries.
  248. - *
  249. - * This is only for internal list manipulation where we know
  250. - * the prev/next entries already!
  251. - */
  252. -static inline void __list_add(struct list_head *new,
  253. - struct list_head *prev,
  254. - struct list_head *next)
  255. -{
  256. - next->prev = new;
  257. - new->next = next;
  258. - new->prev = prev;
  259. - prev->next = new;
  260. -}
  261. -
  262. -/**
  263. - * list_add - add a new entry
  264. - * @new: new entry to be added
  265. - * @head: list head to add it after
  266. - *
  267. - * Insert a new entry after the specified head.
  268. - * This is good for implementing stacks.
  269. - */
  270. -static inline void list_add(struct list_head *new, struct list_head *head)
  271. -{
  272. - __list_add(new, head, head->next);
  273. -}
  274. -
  275. -/**
  276. - * list_add_tail - add a new entry
  277. - * @new: new entry to be added
  278. - * @head: list head to add it before
  279. - *
  280. - * Insert a new entry before the specified head.
  281. - * This is useful for implementing queues.
  282. - */
  283. -static inline void list_add_tail(struct list_head *new, struct list_head *head)
  284. +static inline void fy_list_init_head(struct fy_list_head *lh)
  285. {
  286. - __list_add(new, head->prev, head);
  287. + lh->prev = lh;
  288. + lh->next = lh;
  289. }
  290. -/*
  291. - * Delete a list entry by making the prev/next entries
  292. - * point to each other.
  293. - *
  294. - * This is only for internal list manipulation where we know
  295. - * the prev/next entries already!
  296. - */
  297. -static inline void __list_del(struct list_head *prev, struct list_head *next)
  298. +static inline void fy_list_add_head(struct fy_list_head *ln, struct fy_list_head *lh)
  299. {
  300. - next->prev = prev;
  301. - prev->next = next;
  302. -}
  303. + struct fy_list_head *second = lh->next;
  304. -/**
  305. - * list_del - deletes entry from list.
  306. - * @entry: the element to delete from the list.
  307. - * Note: list_empty() on entry does not return true after this, the entry is
  308. - * in an undefined state.
  309. - */
  310. -static inline void list_del(struct list_head *entry)
  311. -{
  312. - __list_del(entry->prev, entry->next);
  313. - entry->next = LIST_POISON1;
  314. - entry->prev = LIST_POISON2;
  315. + second->prev = ln;
  316. + ln->next = second;
  317. + lh->next = ln;
  318. + ln->prev = lh;
  319. }
  320. -/**
  321. - * list_replace - replace old entry by new one
  322. - * @old : the element to be replaced
  323. - * @new : the new element to insert
  324. - *
  325. - * If @old was empty, it will be overwritten.
  326. - */
  327. -static inline void list_replace(struct list_head *old,
  328. - struct list_head *new)
  329. +static inline void fy_list_add_tail(struct fy_list_head *ln, struct fy_list_head *lh)
  330. {
  331. - new->next = old->next;
  332. - new->next->prev = new;
  333. - new->prev = old->prev;
  334. - new->prev->next = new;
  335. -}
  336. + struct fy_list_head *tail = lh->prev;
  337. -static inline void list_replace_init(struct list_head *old,
  338. - struct list_head *new)
  339. -{
  340. - list_replace(old, new);
  341. - INIT_LIST_HEAD(old);
  342. + lh->prev = ln;
  343. + ln->next = lh;
  344. + tail->next = ln;
  345. + ln->prev = tail;
  346. }
  347. -/**
  348. - * list_del_init - deletes entry from list and reinitialize it.
  349. - * @entry: the element to delete from the list.
  350. - */
  351. -static inline void list_del_init(struct list_head *entry)
  352. +static inline bool fy_list_is_empty(struct fy_list_head *lh)
  353. {
  354. - __list_del(entry->prev, entry->next);
  355. - INIT_LIST_HEAD(entry);
  356. + return lh == lh->next;
  357. }
  358. -/**
  359. - * list_move - delete from one list and add as another's head
  360. - * @list: the entry to move
  361. - * @head: the head that will precede our entry
  362. - */
  363. -static inline void list_move(struct list_head *list, struct list_head *head)
  364. +static inline bool fy_list_is_singular(struct fy_list_head *lh)
  365. {
  366. - __list_del(list->prev, list->next);
  367. - list_add(list, head);
  368. + return lh != lh->next && lh == lh->next->next;
  369. }
  370. -/**
  371. - * list_move_tail - delete from one list and add as another's tail
  372. - * @list: the entry to move
  373. - * @head: the head that will follow our entry
  374. - */
  375. -static inline void list_move_tail(struct list_head *list,
  376. - struct list_head *head)
  377. -{
  378. - __list_del(list->prev, list->next);
  379. - list_add_tail(list, head);
  380. +static inline void fy_list_del(struct fy_list_head *ln) {
  381. + ln->prev->next = ln->next;
  382. + ln->next->prev = ln->prev;
  383. + ln->prev = NULL;
  384. + ln->next = NULL;
  385. }
  386. -/**
  387. - * list_is_last - tests whether @list is the last entry in list @head
  388. - * @list: the entry to test
  389. - * @head: the head of the list
  390. - */
  391. -static inline int list_is_last(const struct list_head *list,
  392. - const struct list_head *head)
  393. -{
  394. - return list->next == head;
  395. -}
  396. +static inline void fy_list_splice(struct fy_list_head *nlh, struct fy_list_head *lh) {
  397. + struct fy_list_head *prev = lh, *next = lh->next,
  398. + *head = nlh->next, *tail = nlh->prev;
  399. -/**
  400. - * list_empty - tests whether a list is empty
  401. - * @head: the list to test.
  402. - */
  403. -static inline int list_empty(const struct list_head *head)
  404. -{
  405. - return head->next == head;
  406. -}
  407. -
  408. -/**
  409. - * list_empty_careful - tests whether a list is empty and not being modified
  410. - * @head: the list to test
  411. - *
  412. - * Description:
  413. - * tests whether a list is empty _and_ checks that no other CPU might be
  414. - * in the process of modifying either member (next or prev)
  415. - *
  416. - * NOTE: using list_empty_careful() without synchronization
  417. - * can only be safe if the only activity that can happen
  418. - * to the list entry is list_del_init(). Eg. it cannot be used
  419. - * if another CPU could re-list_add() it.
  420. - */
  421. -static inline int list_empty_careful(const struct list_head *head)
  422. -{
  423. - struct list_head *next = head->next;
  424. - return (next == head) && (next == head->prev);
  425. -}
  426. -
  427. -/**
  428. - * list_is_singular - tests whether a list has just one entry.
  429. - * @head: the list to test.
  430. - */
  431. -static inline int list_is_singular(const struct list_head *head)
  432. -{
  433. - return !list_empty(head) && (head->next == head->prev);
  434. -}
  435. -
  436. -static inline void __list_cut_position(struct list_head *list,
  437. - struct list_head *head, struct list_head *entry)
  438. -{
  439. - struct list_head *new_first = entry->next;
  440. - list->next = head->next;
  441. - list->next->prev = list;
  442. - list->prev = entry;
  443. - entry->next = list;
  444. - head->next = new_first;
  445. - new_first->prev = head;
  446. -}
  447. -
  448. -/**
  449. - * list_cut_position - cut a list into two
  450. - * @list: a new list to add all removed entries
  451. - * @head: a list with entries
  452. - * @entry: an entry within head, could be the head itself
  453. - * and if so we won't cut the list
  454. - *
  455. - * This helper moves the initial part of @head, up to and
  456. - * including @entry, from @head to @list. You should
  457. - * pass on @entry an element you know is on @head. @list
  458. - * should be an empty list or a list you do not care about
  459. - * losing its data.
  460. - *
  461. - */
  462. -static inline void list_cut_position(struct list_head *list,
  463. - struct list_head *head, struct list_head *entry)
  464. -{
  465. - if (list_empty(head))
  466. - return;
  467. - if (list_is_singular(head) &&
  468. - (head->next != entry && head != entry))
  469. + if (nlh == nlh->next) {
  470. return;
  471. - if (entry == head)
  472. - INIT_LIST_HEAD(list);
  473. - else
  474. - __list_cut_position(list, head, entry);
  475. -}
  476. -
  477. -static inline void __list_splice(const struct list_head *list,
  478. - struct list_head *prev,
  479. - struct list_head *next)
  480. -{
  481. - struct list_head *first = list->next;
  482. - struct list_head *last = list->prev;
  483. -
  484. - first->prev = prev;
  485. - prev->next = first;
  486. -
  487. - last->next = next;
  488. - next->prev = last;
  489. -}
  490. -
  491. -/**
  492. - * list_splice - join two lists, this is designed for stacks
  493. - * @list: the new list to add.
  494. - * @head: the place to add it in the first list.
  495. - */
  496. -static inline void list_splice(const struct list_head *list,
  497. - struct list_head *head)
  498. -{
  499. - if (!list_empty(list))
  500. - __list_splice(list, head, head->next);
  501. -}
  502. -
  503. -/**
  504. - * list_splice_tail - join two lists, each list being a queue
  505. - * @list: the new list to add.
  506. - * @head: the place to add it in the first list.
  507. - */
  508. -static inline void list_splice_tail(struct list_head *list,
  509. - struct list_head *head)
  510. -{
  511. - if (!list_empty(list))
  512. - __list_splice(list, head->prev, head);
  513. -}
  514. -
  515. -/**
  516. - * list_splice_init - join two lists and reinitialise the emptied list.
  517. - * @list: the new list to add.
  518. - * @head: the place to add it in the first list.
  519. - *
  520. - * The list at @list is reinitialised
  521. - */
  522. -static inline void list_splice_init(struct list_head *list,
  523. - struct list_head *head)
  524. -{
  525. - if (!list_empty(list)) {
  526. - __list_splice(list, head, head->next);
  527. - INIT_LIST_HEAD(list);
  528. - }
  529. -}
  530. -
  531. -/**
  532. - * list_splice_tail_init - join two lists and reinitialise the emptied list
  533. - * @list: the new list to add.
  534. - * @head: the place to add it in the first list.
  535. - *
  536. - * Each of the lists is a queue.
  537. - * The list at @list is reinitialised
  538. - */
  539. -static inline void list_splice_tail_init(struct list_head *list,
  540. - struct list_head *head)
  541. -{
  542. - if (!list_empty(list)) {
  543. - __list_splice(list, head->prev, head);
  544. - INIT_LIST_HEAD(list);
  545. - }
  546. -}
  547. -
  548. -/**
  549. - * list_entry - get the struct for this entry
  550. - * @ptr: the &struct list_head pointer.
  551. - * @type: the type of the struct this is embedded in.
  552. - * @member: the name of the list_struct within the struct.
  553. - */
  554. -#define list_entry(ptr, type, member) \
  555. - container_of(ptr, type, member)
  556. -
  557. -/**
  558. - * list_first_entry - get the first element from a list
  559. - * @ptr: the list head to take the element from.
  560. - * @type: the type of the struct this is embedded in.
  561. - * @member: the name of the list_struct within the struct.
  562. - *
  563. - * Note, that list is expected to be not empty.
  564. - */
  565. -#define list_first_entry(ptr, type, member) \
  566. - list_entry((ptr)->next, type, member)
  567. -
  568. -/**
  569. - * list_last_entry - get the last element from a list
  570. - * @ptr: the list head to take the element from.
  571. - * @type: the type of the struct this is embedded in.
  572. - * @member: the name of the list_struct within the struct.
  573. - *
  574. - * Note, that list is expected to be not empty.
  575. - */
  576. -#define list_last_entry(ptr, type, member) \
  577. - list_entry((ptr)->prev, type, member)
  578. -
  579. -/**
  580. - * list_for_each - iterate over a list
  581. - * @pos: the &struct list_head to use as a loop cursor.
  582. - * @head: the head for your list.
  583. - */
  584. -#define list_for_each(pos, head) \
  585. - for (pos = (head)->next; prefetch(pos->next), pos != (head); \
  586. - pos = pos->next)
  587. -
  588. -/**
  589. - * __list_for_each - iterate over a list
  590. - * @pos: the &struct list_head to use as a loop cursor.
  591. - * @head: the head for your list.
  592. - *
  593. - * This variant differs from list_for_each() in that it's the
  594. - * simplest possible list iteration code, no prefetching is done.
  595. - * Use this for code that knows the list to be very short (empty
  596. - * or 1 entry) most of the time.
  597. - */
  598. -#define __list_for_each(pos, head) \
  599. - for (pos = (head)->next; pos != (head); pos = pos->next)
  600. -
  601. -/**
  602. - * list_for_each_prev - iterate over a list backwards
  603. - * @pos: the &struct list_head to use as a loop cursor.
  604. - * @head: the head for your list.
  605. - */
  606. -#define list_for_each_prev(pos, head) \
  607. - for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
  608. - pos = pos->prev)
  609. -
  610. -/**
  611. - * list_for_each_safe - iterate over a list safe against removal of list entry
  612. - * @pos: the &struct list_head to use as a loop cursor.
  613. - * @n: another &struct list_head to use as temporary storage
  614. - * @head: the head for your list.
  615. - */
  616. -#define list_for_each_safe(pos, n, head) \
  617. - for (pos = (head)->next, n = pos->next; pos != (head); \
  618. - pos = n, n = pos->next)
  619. -
  620. -/**
  621. - * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
  622. - * @pos: the &struct list_head to use as a loop cursor.
  623. - * @n: another &struct list_head to use as temporary storage
  624. - * @head: the head for your list.
  625. - */
  626. -#define list_for_each_prev_safe(pos, n, head) \
  627. - for (pos = (head)->prev, n = pos->prev; \
  628. - prefetch(pos->prev), pos != (head); \
  629. - pos = n, n = pos->prev)
  630. -
  631. -/**
  632. - * list_for_each_entry - iterate over list of given type
  633. - * @pos: the type * to use as a loop cursor.
  634. - * @head: the head for your list.
  635. - * @member: the name of the list_struct within the struct.
  636. - */
  637. -#define list_for_each_entry(pos, head, member) \
  638. - for (pos = list_entry((head)->next, typeof(*pos), member); \
  639. - prefetch(pos->member.next), &pos->member != (head); \
  640. - pos = list_entry(pos->member.next, typeof(*pos), member))
  641. -
  642. -/**
  643. - * list_for_each_entry_reverse - iterate backwards over list of given type.
  644. - * @pos: the type * to use as a loop cursor.
  645. - * @head: the head for your list.
  646. - * @member: the name of the list_struct within the struct.
  647. - */
  648. -#define list_for_each_entry_reverse(pos, head, member) \
  649. - for (pos = list_entry((head)->prev, typeof(*pos), member); \
  650. - prefetch(pos->member.prev), &pos->member != (head); \
  651. - pos = list_entry(pos->member.prev, typeof(*pos), member))
  652. -
  653. -/**
  654. - * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
  655. - * @pos: the type * to use as a start point
  656. - * @head: the head of the list
  657. - * @member: the name of the list_struct within the struct.
  658. - *
  659. - * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
  660. - */
  661. -#define list_prepare_entry(pos, head, member) \
  662. - ((pos) ? : list_entry(head, typeof(*pos), member))
  663. -
  664. -/**
  665. - * list_for_each_entry_continue - continue iteration over list of given type
  666. - * @pos: the type * to use as a loop cursor.
  667. - * @head: the head for your list.
  668. - * @member: the name of the list_struct within the struct.
  669. - *
  670. - * Continue to iterate over list of given type, continuing after
  671. - * the current position.
  672. - */
  673. -#define list_for_each_entry_continue(pos, head, member) \
  674. - for (pos = list_entry(pos->member.next, typeof(*pos), member); \
  675. - prefetch(pos->member.next), &pos->member != (head); \
  676. - pos = list_entry(pos->member.next, typeof(*pos), member))
  677. -
  678. -/**
  679. - * list_for_each_entry_continue_reverse - iterate backwards from the given point
  680. - * @pos: the type * to use as a loop cursor.
  681. - * @head: the head for your list.
  682. - * @member: the name of the list_struct within the struct.
  683. - *
  684. - * Start to iterate over list of given type backwards, continuing after
  685. - * the current position.
  686. - */
  687. -#define list_for_each_entry_continue_reverse(pos, head, member) \
  688. - for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
  689. - prefetch(pos->member.prev), &pos->member != (head); \
  690. - pos = list_entry(pos->member.prev, typeof(*pos), member))
  691. -
  692. -/**
  693. - * list_for_each_entry_from - iterate over list of given type from the current point
  694. - * @pos: the type * to use as a loop cursor.
  695. - * @head: the head for your list.
  696. - * @member: the name of the list_struct within the struct.
  697. - *
  698. - * Iterate over list of given type, continuing from current position.
  699. - */
  700. -#define list_for_each_entry_from(pos, head, member) \
  701. - for (; prefetch(pos->member.next), &pos->member != (head); \
  702. - pos = list_entry(pos->member.next, typeof(*pos), member))
  703. -
  704. -/**
  705. - * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  706. - * @pos: the type * to use as a loop cursor.
  707. - * @n: another type * to use as temporary storage
  708. - * @head: the head for your list.
  709. - * @member: the name of the list_struct within the struct.
  710. - */
  711. -#define list_for_each_entry_safe(pos, n, head, member) \
  712. - for (pos = list_entry((head)->next, typeof(*pos), member), \
  713. - n = list_entry(pos->member.next, typeof(*pos), member); \
  714. - &pos->member != (head); \
  715. - pos = n, n = list_entry(n->member.next, typeof(*n), member))
  716. -
  717. -/**
  718. - * list_for_each_entry_safe_continue
  719. - * @pos: the type * to use as a loop cursor.
  720. - * @n: another type * to use as temporary storage
  721. - * @head: the head for your list.
  722. - * @member: the name of the list_struct within the struct.
  723. - *
  724. - * Iterate over list of given type, continuing after current point,
  725. - * safe against removal of list entry.
  726. - */
  727. -#define list_for_each_entry_safe_continue(pos, n, head, member) \
  728. - for (pos = list_entry(pos->member.next, typeof(*pos), member), \
  729. - n = list_entry(pos->member.next, typeof(*pos), member); \
  730. - &pos->member != (head); \
  731. - pos = n, n = list_entry(n->member.next, typeof(*n), member))
  732. -
  733. -/**
  734. - * list_for_each_entry_safe_from
  735. - * @pos: the type * to use as a loop cursor.
  736. - * @n: another type * to use as temporary storage
  737. - * @head: the head for your list.
  738. - * @member: the name of the list_struct within the struct.
  739. - *
  740. - * Iterate over list of given type from current point, safe against
  741. - * removal of list entry.
  742. - */
  743. -#define list_for_each_entry_safe_from(pos, n, head, member) \
  744. - for (n = list_entry(pos->member.next, typeof(*pos), member); \
  745. - &pos->member != (head); \
  746. - pos = n, n = list_entry(n->member.next, typeof(*n), member))
  747. -
  748. -/**
  749. - * list_for_each_entry_safe_reverse
  750. - * @pos: the type * to use as a loop cursor.
  751. - * @n: another type * to use as temporary storage
  752. - * @head: the head for your list.
  753. - * @member: the name of the list_struct within the struct.
  754. - *
  755. - * Iterate backwards over list of given type, safe against removal
  756. - * of list entry.
  757. - */
  758. -#define list_for_each_entry_safe_reverse(pos, n, head, member) \
  759. - for (pos = list_entry((head)->prev, typeof(*pos), member), \
  760. - n = list_entry(pos->member.prev, typeof(*pos), member); \
  761. - &pos->member != (head); \
  762. - pos = n, n = list_entry(n->member.prev, typeof(*n), member))
  763. -
  764. -/*
  765. - * Double linked lists with a single pointer list head.
  766. - * Mostly useful for hash tables where the two pointer list head is
  767. - * too wasteful.
  768. - * You lose the ability to access the tail in O(1).
  769. - */
  770. -
  771. -struct hlist_head {
  772. - struct hlist_node *first;
  773. -};
  774. -
  775. -struct hlist_node {
  776. - struct hlist_node *next, **pprev;
  777. -};
  778. -
  779. -#define HLIST_HEAD_INIT { .first = NULL }
  780. -#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
  781. -#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
  782. -static inline void INIT_HLIST_NODE(struct hlist_node *h)
  783. -{
  784. - h->next = NULL;
  785. - h->pprev = NULL;
  786. -}
  787. -
  788. -static inline int hlist_unhashed(const struct hlist_node *h)
  789. -{
  790. - return !h->pprev;
  791. -}
  792. -
  793. -static inline int hlist_empty(const struct hlist_head *h)
  794. -{
  795. - return !h->first;
  796. -}
  797. -
  798. -static inline void __hlist_del(struct hlist_node *n)
  799. -{
  800. - struct hlist_node *next = n->next;
  801. - struct hlist_node **pprev = n->pprev;
  802. - *pprev = next;
  803. - if (next)
  804. - next->pprev = pprev;
  805. -}
  806. -
  807. -static inline void hlist_del(struct hlist_node *n)
  808. -{
  809. - __hlist_del(n);
  810. - n->next = LIST_POISON1;
  811. - n->pprev = LIST_POISON2;
  812. -}
  813. -
  814. -static inline void hlist_del_init(struct hlist_node *n)
  815. -{
  816. - if (!hlist_unhashed(n)) {
  817. - __hlist_del(n);
  818. - INIT_HLIST_NODE(n);
  819. }
  820. -}
  821. -
  822. -static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
  823. -{
  824. - struct hlist_node *first = h->first;
  825. - n->next = first;
  826. - if (first)
  827. - first->pprev = &n->next;
  828. - h->first = n;
  829. - n->pprev = &h->first;
  830. -}
  831. -
  832. -/* next must be != NULL */
  833. -static inline void hlist_add_before(struct hlist_node *n,
  834. - struct hlist_node *next)
  835. -{
  836. - n->pprev = next->pprev;
  837. - n->next = next;
  838. - next->pprev = &n->next;
  839. - *(n->pprev) = n;
  840. -}
  841. -
  842. -static inline void hlist_add_after(struct hlist_node *n,
  843. - struct hlist_node *next)
  844. -{
  845. - next->next = n->next;
  846. - n->next = next;
  847. - next->pprev = &n->next;
  848. - if(next->next)
  849. - next->next->pprev = &next->next;
  850. + head->prev = prev;
  851. + tail->next = next;
  852. + prev->next = head;
  853. + next->prev = tail;
  854. }
  855. -#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
  856. -
  857. -#define hlist_for_each(pos, head) \
  858. - for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
  859. - pos = pos->next)
  860. -
  861. -#define hlist_for_each_safe(pos, n, head) \
  862. - for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
  863. - pos = n)
  864. -
  865. -/**
  866. - * hlist_for_each_entry - iterate over list of given type
  867. - * @tpos: the type * to use as a loop cursor.
  868. - * @pos: the &struct hlist_node to use as a loop cursor.
  869. - * @head: the head for your list.
  870. - * @member: the name of the hlist_node within the struct.
  871. - */
  872. -#define hlist_for_each_entry(tpos, pos, head, member) \
  873. - for (pos = (head)->first; \
  874. - pos && ({ prefetch(pos->next); 1;}) && \
  875. - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  876. - pos = pos->next)
  877. -
  878. -/**
  879. - * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
  880. - * @tpos: the type * to use as a loop cursor.
  881. - * @pos: the &struct hlist_node to use as a loop cursor.
  882. - * @member: the name of the hlist_node within the struct.
  883. - */
  884. -#define hlist_for_each_entry_continue(tpos, pos, member) \
  885. - for (pos = (pos)->next; \
  886. - pos && ({ prefetch(pos->next); 1;}) && \
  887. - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  888. - pos = pos->next)
  889. -
  890. -/**
  891. - * hlist_for_each_entry_from - iterate over a hlist continuing from current point
  892. - * @tpos: the type * to use as a loop cursor.
  893. - * @pos: the &struct hlist_node to use as a loop cursor.
  894. - * @member: the name of the hlist_node within the struct.
  895. - */
  896. -#define hlist_for_each_entry_from(tpos, pos, member) \
  897. - for (; pos && ({ prefetch(pos->next); 1;}) && \
  898. - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  899. - pos = pos->next)
  900. -
  901. -/**
  902. - * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  903. - * @tpos: the type * to use as a loop cursor.
  904. - * @pos: the &struct hlist_node to use as a loop cursor.
  905. - * @n: another &struct hlist_node to use as temporary storage
  906. - * @head: the head for your list.
  907. - * @member: the name of the hlist_node within the struct.
  908. - */
  909. -#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
  910. - for (pos = (head)->first; \
  911. - pos && ({ n = pos->next; 1; }) && \
  912. - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  913. - pos = n)
  914. -
  915. #endif
  916. diff --git a/src/lib/fy-parse.c b/src/lib/fy-parse.c
  917. index 16ce784..0cacdbc 100644
  918. --- a/src/lib/fy-parse.c
  919. +++ b/src/lib/fy-parse.c
  920. @@ -646,13 +646,13 @@ static const struct fy_parse_cfg default_parse_cfg = {
  921. static struct fy_diag *fy_parser_reader_get_diag(struct fy_reader *fyr)
  922. {
  923. - struct fy_parser *fyp = container_of(fyr, struct fy_parser, builtin_reader);
  924. + struct fy_parser *fyp = fy_container_of(fyr, struct fy_parser, builtin_reader);
  925. return fyp->diag;
  926. }
  927. static int fy_parser_reader_file_open(struct fy_reader *fyr, const char *name)
  928. {
  929. - struct fy_parser *fyp = container_of(fyr, struct fy_parser, builtin_reader);
  930. + struct fy_parser *fyp = fy_container_of(fyr, struct fy_parser, builtin_reader);
  931. char *sp, *s, *e, *t, *newp;
  932. size_t len, maxlen;
  933. int fd;
  934. diff --git a/src/lib/fy-parse.h b/src/lib/fy-parse.h
  935. index 11e71bf..dc43911 100644
  936. --- a/src/lib/fy-parse.h
  937. +++ b/src/lib/fy-parse.h
  938. @@ -49,7 +49,7 @@ enum fy_flow_type {
  939. };
  940. struct fy_flow {
  941. - struct list_head node;
  942. + struct fy_list_head node;
  943. enum fy_flow_type flow;
  944. int pending_complex_key_column;
  945. struct fy_mark pending_complex_key_mark;
  946. @@ -58,7 +58,7 @@ struct fy_flow {
  947. FY_PARSE_TYPE_DECL(flow);
  948. struct fy_indent {
  949. - struct list_head node;
  950. + struct fy_list_head node;
  951. int indent;
  952. int indent_line;
  953. bool generated_block_map : 1;
  954. @@ -68,7 +68,7 @@ FY_PARSE_TYPE_DECL(indent);
  955. struct fy_token;
  956. struct fy_simple_key {
  957. - struct list_head node;
  958. + struct fy_list_head node;
  959. struct fy_mark mark;
  960. struct fy_mark end_mark;
  961. struct fy_token *token; /* associated token */
  962. @@ -132,7 +132,7 @@ enum fy_parser_state {
  963. };
  964. struct fy_parse_state_log {
  965. - struct list_head node;
  966. + struct fy_list_head node;
  967. enum fy_parser_state state;
  968. };
  969. FY_PARSE_TYPE_DECL(parse_state_log);
  970. diff --git a/src/lib/fy-path.h b/src/lib/fy-path.h
  971. index 22dde9c..e551d5a 100644
  972. --- a/src/lib/fy-path.h
  973. +++ b/src/lib/fy-path.h
  974. @@ -57,7 +57,7 @@ struct fy_path_sequence_state {
  975. };
  976. struct fy_path_component {
  977. - struct list_head node;
  978. + struct fy_list_head node;
  979. enum fy_path_component_type type;
  980. union {
  981. struct fy_path_mapping_state map;
  982. @@ -87,7 +87,7 @@ fy_path_component_is_collection_root(struct fy_path_component *fypc)
  983. FY_TYPE_FWD_DECL_LIST(path);
  984. struct fy_path {
  985. - struct list_head node;
  986. + struct fy_list_head node;
  987. struct fy_path_component_list recycled_component;
  988. struct fy_path_component_list components;
  989. struct fy_document_builder *fydb; /* for complex keys */
  990. diff --git a/src/lib/fy-token.h b/src/lib/fy-token.h
  991. index a464955..8436e10 100644
  992. --- a/src/lib/fy-token.h
  993. +++ b/src/lib/fy-token.h
  994. @@ -81,7 +81,7 @@ static inline bool fy_token_type_is_mapping_marker(enum fy_token_type type)
  995. FY_TYPE_FWD_DECL_LIST(token);
  996. struct fy_token {
  997. - struct list_head node;
  998. + struct fy_list_head node;
  999. enum fy_token_type type;
  1000. int refs; /* when on document, we switch to reference counting */
  1001. int analyze_flags; /* cache of the analysis flags */
  1002. diff --git a/src/lib/fy-typelist.h b/src/lib/fy-typelist.h
  1003. index 7fd9148..12acd2d 100644
  1004. --- a/src/lib/fy-typelist.h
  1005. +++ b/src/lib/fy-typelist.h
  1006. @@ -24,24 +24,24 @@
  1007. #define FY_TYPE_FWD_DECL_LIST(_type) \
  1008. /* type safe list wrapper */ \
  1009. -struct fy_ ## _type ## _list { struct list_head _lh; }; \
  1010. +struct fy_ ## _type ## _list { struct fy_list_head _lh; }; \
  1011. \
  1012. struct __useless_struct_to_allow_semicolon
  1013. #define FY_TYPE_DECL_LIST(_type) \
  1014. static inline void fy_ ## _type ## _list_init(struct fy_ ## _type ## _list *_l) \
  1015. { \
  1016. - INIT_LIST_HEAD(&_l->_lh); \
  1017. + fy_list_init_head(&_l->_lh); \
  1018. } \
  1019. static inline void fy_ ## _type ## _list_add(struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n) \
  1020. { \
  1021. if (_l && _n) \
  1022. - list_add(&_n->node, &_l->_lh); \
  1023. + fy_list_add_head(&_n->node, &_l->_lh); \
  1024. } \
  1025. static inline void fy_ ## _type ## _list_add_tail(struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n) \
  1026. { \
  1027. if (_l && _n) \
  1028. - list_add_tail(&_n->node, &_l->_lh); \
  1029. + fy_list_add_tail(&_n->node, &_l->_lh); \
  1030. } \
  1031. static inline void fy_ ## _type ## _list_push(struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n) \
  1032. { \
  1033. @@ -55,38 +55,38 @@ static inline void fy_ ## _type ## _list_push_tail(struct fy_ ## _type ## _list
  1034. } \
  1035. static inline bool fy_ ## _type ## _list_empty(struct fy_ ## _type ## _list *_l) \
  1036. { \
  1037. - return _l ? list_empty(&_l->_lh) : true; \
  1038. + return _l ? fy_list_is_empty(&_l->_lh) : true; \
  1039. } \
  1040. static inline bool fy_ ## _type ## _list_is_singular(struct fy_ ## _type ## _list *_l) \
  1041. { \
  1042. - return _l ? list_is_singular(&_l->_lh) : true; \
  1043. + return _l ? fy_list_is_singular(&_l->_lh) : true; \
  1044. } \
  1045. static inline void fy_ ## _type ## _list_del(struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n) \
  1046. { \
  1047. if (_l && _n) { \
  1048. - list_del(&_n->node); \
  1049. - INIT_LIST_HEAD(&_n->node); \
  1050. + fy_list_del(&_n->node); \
  1051. + fy_list_init_head(&_n->node); \
  1052. } \
  1053. } \
  1054. static inline void fy_ ## _type ## _list_insert_after(struct fy_ ## _type ## _list *_l, \
  1055. struct fy_ ## _type *_p, struct fy_ ## _type *_n) \
  1056. { \
  1057. if (_l && _p && _n) \
  1058. - list_add(&_n->node, &_p->node); \
  1059. + fy_list_add_head(&_n->node, &_p->node); \
  1060. } \
  1061. static inline void fy_ ## _type ## _list_insert_before(struct fy_ ## _type ## _list *_l, \
  1062. struct fy_ ## _type *_p, struct fy_ ## _type *_n) \
  1063. { \
  1064. if (_l && _p && _n) \
  1065. - list_add_tail(&_n->node, &_p->node); \
  1066. + fy_list_add_tail(&_n->node, &_p->node); \
  1067. } \
  1068. static inline struct fy_ ## _type *fy_ ## _type ## _list_head(struct fy_ ## _type ## _list *_l) \
  1069. { \
  1070. - return !fy_ ## _type ## _list_empty(_l) ? list_first_entry(&_l->_lh, struct fy_ ## _type, node) : NULL; \
  1071. + return !fy_ ## _type ## _list_empty(_l) ? fy_container_of(_l->_lh.next, struct fy_ ## _type, node) : NULL; \
  1072. } \
  1073. static inline struct fy_ ## _type *fy_ ## _type ## _list_tail(struct fy_ ## _type ## _list *_l) \
  1074. { \
  1075. - return !fy_ ## _type ## _list_empty(_l) ? list_last_entry(&_l->_lh, struct fy_ ## _type, node) : NULL; \
  1076. + return !fy_ ## _type ## _list_empty(_l) ? fy_container_of(_l->_lh.prev, struct fy_ ## _type, node) : NULL; \
  1077. } \
  1078. static inline struct fy_ ## _type *fy_ ## _type ## _list_first(struct fy_ ## _type ## _list *_l) \
  1079. { \
  1080. @@ -120,13 +120,13 @@ static inline struct fy_ ## _type *fy_ ## _type ## _next(struct fy_ ## _type ##
  1081. { \
  1082. if (!_n || !_l || _n->node.next == &_l->_lh) \
  1083. return NULL; \
  1084. - return list_entry(_n->node.next, struct fy_ ## _type, node); \
  1085. + return fy_container_of(_n->node.next, struct fy_ ## _type, node); \
  1086. } \
  1087. static inline struct fy_ ## _type *fy_ ## _type ## _prev(struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n) \
  1088. { \
  1089. if (!_n || !_l || _n->node.prev == &_l->_lh) \
  1090. return NULL; \
  1091. - return list_entry(_n->node.prev, struct fy_ ## _type, node); \
  1092. + return fy_container_of(_n->node.prev, struct fy_ ## _type, node); \
  1093. } \
  1094. static inline void fy_ ## _type ## _lists_splice( \
  1095. struct fy_ ## _type ## _list *_l, \
  1096. @@ -134,9 +134,9 @@ static inline void fy_ ## _type ## _lists_splice( \
  1097. { \
  1098. /* check arguments for sanity and lists are not empty */ \
  1099. if (!_l || !_lfrom || \
  1100. - fy_ ## _type ## _list_empty(_lfrom)) \
  1101. + fy_ ## _type ## _list_empty(_lfrom)) \
  1102. return; \
  1103. - list_splice(&_lfrom->_lh, &_l->_lh); \
  1104. + fy_list_splice(&_lfrom->_lh, &_l->_lh); \
  1105. } \
  1106. static inline void fy_ ## _type ## _list_splice_after( \
  1107. struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n, \
  1108. @@ -144,19 +144,19 @@ static inline void fy_ ## _type ## _list_splice_after( \
  1109. { \
  1110. /* check arguments for sanity and lists are not empty */ \
  1111. if (!_l || !_n || !_lfrom || \
  1112. - fy_ ## _type ## _list_empty(_lfrom)) \
  1113. + fy_ ## _type ## _list_empty(_lfrom)) \
  1114. return; \
  1115. - list_splice(&_lfrom->_lh, &_n->node); \
  1116. + fy_list_splice(&_lfrom->_lh, &_n->node); \
  1117. } \
  1118. static inline void fy_ ## _type ## _list_splice_before( \
  1119. struct fy_ ## _type ## _list *_l, struct fy_ ## _type *_n, \
  1120. struct fy_ ## _type ## _list *_lfrom) \
  1121. { \
  1122. /* check arguments for sanity and lists are not empty */ \
  1123. - if (!_l || !_n || !_lfrom || \
  1124. - fy_ ## _type ## _list_empty(_lfrom)) \
  1125. + if (!_l || !_n || !_lfrom || \
  1126. + fy_ ## _type ## _list_empty(_lfrom)) \
  1127. return; \
  1128. - list_splice(&_lfrom->_lh, _n->node.prev); \
  1129. + fy_list_splice(&_lfrom->_lh, _n->node.prev); \
  1130. } \
  1131. struct __useless_struct_to_allow_semicolon
  1132. diff --git a/src/lib/fy-types.h b/src/lib/fy-types.h
  1133. index 6bddda3..889f2dc 100644
  1134. --- a/src/lib/fy-types.h
  1135. +++ b/src/lib/fy-types.h
  1136. @@ -35,7 +35,7 @@ struct fy_ ## _type *fy_ ## _type ## _alloc_simple_internal( \
  1137. return _n; \
  1138. _n = malloc(sizeof(*_n)); \
  1139. if (_n) \
  1140. - INIT_LIST_HEAD(&_n->node); \
  1141. + fy_list_init_head(&_n->node); \
  1142. return _n; \
  1143. } \
  1144. \
  1145. diff --git a/src/lib/fy-walk.c b/src/lib/fy-walk.c
  1146. index 736704d..8cd2ee6 100644
  1147. --- a/src/lib/fy-walk.c
  1148. +++ b/src/lib/fy-walk.c
  1149. @@ -717,7 +717,7 @@ const char *fy_expr_mode_txt[FYEM_COUNT] = {
  1150. static struct fy_diag *fy_path_parser_reader_get_diag(struct fy_reader *fyr)
  1151. {
  1152. - struct fy_path_parser *fypp = container_of(fyr, struct fy_path_parser, reader);
  1153. + struct fy_path_parser *fypp = fy_container_of(fyr, struct fy_path_parser, reader);
  1154. return fypp->cfg.diag;
  1155. }
  1156. diff --git a/src/lib/fy-walk.h b/src/lib/fy-walk.h
  1157. index e42a76f..bc200f6 100644
  1158. --- a/src/lib/fy-walk.h
  1159. +++ b/src/lib/fy-walk.h
  1160. @@ -49,7 +49,7 @@ struct fy_path_exec;
  1161. FY_TYPE_FWD_DECL_LIST(walk_result);
  1162. struct fy_walk_result {
  1163. - struct list_head node;
  1164. + struct fy_list_head node;
  1165. struct fy_path_exec *fypx;
  1166. enum fy_walk_result_type type;
  1167. union {
  1168. @@ -264,7 +264,7 @@ struct fy_method {
  1169. FY_TYPE_FWD_DECL_LIST(path_expr);
  1170. struct fy_path_expr {
  1171. - struct list_head node;
  1172. + struct fy_list_head node;
  1173. struct fy_path_expr *parent;
  1174. enum fy_path_expr_type type;
  1175. struct fy_token *fyt;
  1176. From 834d53848206ca9bf9caf92c4499b45ca8531acb Mon Sep 17 00:00:00 2001
  1177. From: Innokentii Mokin <innokentii@yandex-team.ru>
  1178. Date: Wed, 21 Dec 2022 17:38:37 +0300
  1179. Subject: [PATCH 2/3] add tests for list implementation
  1180. ---
  1181. test/libfyaml-test-private.c | 265 +++++++++++++++++++++++++++++++++++
  1182. 1 file changed, 265 insertions(+)
  1183. diff --git a/test/libfyaml-test-private.c b/test/libfyaml-test-private.c
  1184. index c428682..a233eb1 100644
  1185. --- a/test/libfyaml-test-private.c
  1186. +++ b/test/libfyaml-test-private.c
  1187. @@ -152,6 +152,268 @@ START_TEST(parse_simple)
  1188. }
  1189. END_TEST
  1190. +struct fy_test_struct_foo {
  1191. + int foo;
  1192. +};
  1193. +
  1194. +struct fy_test_struct_bar {
  1195. + int frooz;
  1196. +};
  1197. +
  1198. +struct fy_test_struct_baz {
  1199. + int one;
  1200. + struct fy_test_struct_bar two;
  1201. + struct fy_test_struct_foo three;
  1202. +};
  1203. +
  1204. +START_TEST(container_of)
  1205. +{
  1206. + struct fy_test_struct_baz ftsbaz;
  1207. + struct fy_test_struct_bar *ftsbar;
  1208. + struct fy_test_struct_baz *ftsbazp;
  1209. + ftsbar = &ftsbaz.two;
  1210. + ftsbazp = fy_container_of(ftsbar, struct fy_test_struct_baz, two);
  1211. + ck_assert_ptr_eq(&ftsbaz, ftsbazp);
  1212. +}
  1213. +END_TEST
  1214. +
  1215. +START_TEST(list)
  1216. +{
  1217. + struct fy_list_head head, other_head, one, two, three, four, five, six;
  1218. + bool ret;
  1219. +
  1220. + /* add head */
  1221. + fy_list_init_head(&head);
  1222. + ret = fy_list_is_empty(&head);
  1223. + ck_assert(ret == true);
  1224. + ret = fy_list_is_singular(&head);
  1225. + ck_assert(ret == false);
  1226. + ck_assert_ptr_eq(head.prev, &head);
  1227. + ck_assert_ptr_eq(head.next, &head);
  1228. +
  1229. + fy_list_add_head(&one, &head);
  1230. + ret = fy_list_is_singular(&head);
  1231. + ck_assert(ret == true);
  1232. + ret = fy_list_is_empty(&head);
  1233. + ck_assert(ret == false);
  1234. + ck_assert_ptr_eq(head.next, &one);
  1235. + ck_assert_ptr_eq(head.next->next, &head);
  1236. + ck_assert_ptr_eq(head.prev, &one);
  1237. + ck_assert_ptr_eq(head.prev->prev, &head);
  1238. +
  1239. + fy_list_add_head(&two, &head);
  1240. + ret = fy_list_is_singular(&head);
  1241. + ck_assert(ret == false);
  1242. + ret = fy_list_is_empty(&head);
  1243. + ck_assert(ret == false);
  1244. + ck_assert_ptr_eq(head.next, &two);
  1245. + ck_assert_ptr_eq(head.next->next, &one);
  1246. + ck_assert_ptr_eq(head.next->next->next, &head);
  1247. + ck_assert_ptr_eq(head.prev, &one);
  1248. + ck_assert_ptr_eq(head.prev->prev, &two);
  1249. + ck_assert_ptr_eq(head.prev->prev->prev, &head);
  1250. +
  1251. + fy_list_add_head(&three, &head);
  1252. + ret = fy_list_is_singular(&head);
  1253. + ck_assert(ret == false);
  1254. + ret = fy_list_is_empty(&head);
  1255. + ck_assert(ret == false);
  1256. + ck_assert_ptr_eq(head.next, &three);
  1257. + ck_assert_ptr_eq(head.next->next, &two);
  1258. + ck_assert_ptr_eq(head.next->next->next, &one);
  1259. + ck_assert_ptr_eq(head.next->next->next->next, &head);
  1260. + ck_assert_ptr_eq(head.prev, &one);
  1261. + ck_assert_ptr_eq(head.prev->prev, &two);
  1262. + ck_assert_ptr_eq(head.prev->prev->prev, &three);
  1263. + ck_assert_ptr_eq(head.prev->prev->prev->prev, &head);
  1264. +
  1265. + /* add tail */
  1266. + fy_list_init_head(&head);
  1267. + ret = fy_list_is_empty(&head);
  1268. + ck_assert(ret == true);
  1269. + ret = fy_list_is_singular(&head);
  1270. + ck_assert(ret == false);
  1271. + ck_assert_ptr_eq(head.prev, &head);
  1272. + ck_assert_ptr_eq(head.next, &head);
  1273. +
  1274. + fy_list_add_tail(&one, &head);
  1275. + ret = fy_list_is_singular(&head);
  1276. + ck_assert(ret == true);
  1277. + ret = fy_list_is_empty(&head);
  1278. + ck_assert(ret == false);
  1279. + ck_assert_ptr_eq(head.next, &one);
  1280. + ck_assert_ptr_eq(head.next->next, &head);
  1281. + ck_assert_ptr_eq(head.prev, &one);
  1282. + ck_assert_ptr_eq(head.prev->prev, &head);
  1283. +
  1284. + fy_list_add_tail(&two, &head);
  1285. + ret = fy_list_is_singular(&head);
  1286. + ck_assert(ret == false);
  1287. + ret = fy_list_is_empty(&head);
  1288. + ck_assert(ret == false);
  1289. + ck_assert_ptr_eq(head.next, &one);
  1290. + ck_assert_ptr_eq(head.next->next, &two);
  1291. + ck_assert_ptr_eq(head.next->next->next, &head);
  1292. + ck_assert_ptr_eq(head.prev, &two);
  1293. + ck_assert_ptr_eq(head.prev->prev, &one);
  1294. + ck_assert_ptr_eq(head.prev->prev->prev, &head);
  1295. +
  1296. + fy_list_add_tail(&three, &head);
  1297. + ret = fy_list_is_singular(&head);
  1298. + ck_assert(ret == false);
  1299. + ret = fy_list_is_empty(&head);
  1300. + ck_assert(ret == false);
  1301. + ck_assert_ptr_eq(head.next, &one);
  1302. + ck_assert_ptr_eq(head.next->next, &two);
  1303. + ck_assert_ptr_eq(head.next->next->next, &three);
  1304. + ck_assert_ptr_eq(head.next->next->next->next, &head);
  1305. + ck_assert_ptr_eq(head.prev, &three);
  1306. + ck_assert_ptr_eq(head.prev->prev, &two);
  1307. + ck_assert_ptr_eq(head.prev->prev->prev, &one);
  1308. + ck_assert_ptr_eq(head.prev->prev->prev->prev, &head);
  1309. +
  1310. + /* delete */
  1311. + fy_list_init_head(&head);
  1312. + fy_list_add_head(&one, &head);
  1313. + fy_list_del(&one);
  1314. + ret = fy_list_is_empty(&head);
  1315. + ck_assert(ret == true);
  1316. + ret = fy_list_is_singular(&head);
  1317. + ck_assert(ret == false);
  1318. + ck_assert_ptr_eq(head.next, &head);
  1319. + ck_assert_ptr_eq(head.prev, &head);
  1320. +
  1321. + fy_list_init_head(&head);
  1322. + fy_list_add_head(&one, &head);
  1323. + fy_list_add_head(&two, &head);
  1324. + fy_list_del(&one);
  1325. + ret = fy_list_is_singular(&head);
  1326. + ck_assert(ret == true);
  1327. + ret = fy_list_is_empty(&head);
  1328. + ck_assert(ret == false);
  1329. + ck_assert_ptr_eq(head.next, &two);
  1330. + ck_assert_ptr_eq(head.next->next, &head);
  1331. + ck_assert_ptr_eq(head.prev, &two);
  1332. + ck_assert_ptr_eq(head.prev->prev, &head);
  1333. +
  1334. + fy_list_init_head(&head);
  1335. + fy_list_add_head(&one, &head);
  1336. + fy_list_add_head(&two, &head);
  1337. + fy_list_del(&two);
  1338. + ret = fy_list_is_singular(&head);
  1339. + ck_assert(ret == true);
  1340. + ret = fy_list_is_empty(&head);
  1341. + ck_assert(ret == false);
  1342. + ck_assert_ptr_eq(head.next, &one);
  1343. + ck_assert_ptr_eq(head.next->next, &head);
  1344. + ck_assert_ptr_eq(head.prev, &one);
  1345. + ck_assert_ptr_eq(head.prev->prev, &head);
  1346. +
  1347. + fy_list_init_head(&head);
  1348. + fy_list_add_head(&one, &head);
  1349. + fy_list_add_head(&two, &head);
  1350. + fy_list_add_head(&three, &head);
  1351. + fy_list_del(&two);
  1352. + ret = fy_list_is_singular(&head);
  1353. + ck_assert(ret == false);
  1354. + ret = fy_list_is_empty(&head);
  1355. + ck_assert(ret == false);
  1356. + ck_assert_ptr_eq(head.next, &three);
  1357. + ck_assert_ptr_eq(head.next->next, &one);
  1358. + ck_assert_ptr_eq(head.next->next->next, &head);
  1359. + ck_assert_ptr_eq(head.prev, &one);
  1360. + ck_assert_ptr_eq(head.prev->prev, &three);
  1361. + ck_assert_ptr_eq(head.prev->prev->prev, &head);
  1362. +
  1363. + /* splice */
  1364. + fy_list_init_head(&head);
  1365. + fy_list_init_head(&other_head);
  1366. + fy_list_splice(&other_head, &one);
  1367. + ret = fy_list_is_singular(&head);
  1368. + ck_assert(ret == false);
  1369. + ret = fy_list_is_empty(&head);
  1370. + ck_assert(ret == true);
  1371. + ck_assert_ptr_eq(head.next, &head);
  1372. + ck_assert_ptr_eq(head.prev, &head);
  1373. +
  1374. + fy_list_init_head(&head);
  1375. + fy_list_add_head(&one, &head);
  1376. + fy_list_init_head(&other_head);
  1377. + fy_list_splice(&other_head, &one);
  1378. + ret = fy_list_is_singular(&head);
  1379. + ck_assert(ret == true);
  1380. + ret = fy_list_is_empty(&head);
  1381. + ck_assert(ret == false);
  1382. + ck_assert_ptr_eq(head.next, &one);
  1383. + ck_assert_ptr_eq(head.next->next, &head);
  1384. + ck_assert_ptr_eq(head.prev, &one);
  1385. + ck_assert_ptr_eq(head.prev->prev, &head);
  1386. +
  1387. + fy_list_init_head(&head);
  1388. + fy_list_init_head(&other_head);
  1389. + fy_list_add_head(&four, &head);
  1390. + fy_list_splice(&other_head, &one);
  1391. + ret = fy_list_is_singular(&head);
  1392. + ck_assert(ret == true);
  1393. + ret = fy_list_is_empty(&head);
  1394. + ck_assert(ret == false);
  1395. + ck_assert_ptr_eq(head.next, &four);
  1396. + ck_assert_ptr_eq(head.next->next, &head);
  1397. + ck_assert_ptr_eq(head.prev, &four);
  1398. + ck_assert_ptr_eq(head.prev->prev, &head);
  1399. +
  1400. + fy_list_init_head(&head);
  1401. + fy_list_add_head(&one, &head);
  1402. + fy_list_add_head(&two, &head);
  1403. + fy_list_init_head(&other_head);
  1404. + fy_list_add_head(&four, &other_head);
  1405. + fy_list_add_head(&five, &other_head);
  1406. + fy_list_splice(&other_head, &two);
  1407. + ret = fy_list_is_singular(&head);
  1408. + ck_assert(ret == false);
  1409. + ret = fy_list_is_empty(&head);
  1410. + ck_assert(ret == false);
  1411. + ck_assert_ptr_eq(head.next, &two);
  1412. + ck_assert_ptr_eq(head.next->next, &five);
  1413. + ck_assert_ptr_eq(head.next->next->next, &four);
  1414. + ck_assert_ptr_eq(head.next->next->next->next, &one);
  1415. + ck_assert_ptr_eq(head.next->next->next->next->next, &head);
  1416. + ck_assert_ptr_eq(head.prev, &one);
  1417. + ck_assert_ptr_eq(head.prev->prev, &four);
  1418. + ck_assert_ptr_eq(head.prev->prev->prev, &five);
  1419. + ck_assert_ptr_eq(head.prev->prev->prev->prev, &two);
  1420. + ck_assert_ptr_eq(head.prev->prev->prev->prev->prev, &head);
  1421. +
  1422. + fy_list_init_head(&head);
  1423. + fy_list_add_head(&one, &head);
  1424. + fy_list_add_head(&two, &head);
  1425. + fy_list_add_head(&three, &head);
  1426. + fy_list_init_head(&other_head);
  1427. + fy_list_add_head(&four, &other_head);
  1428. + fy_list_add_head(&five, &other_head);
  1429. + fy_list_add_head(&six, &other_head);
  1430. + fy_list_splice(&other_head, &two);
  1431. + ret = fy_list_is_singular(&head);
  1432. + ck_assert(ret == false);
  1433. + ret = fy_list_is_empty(&head);
  1434. + ck_assert(ret == false);
  1435. + ck_assert_ptr_eq(head.next, &three);
  1436. + ck_assert_ptr_eq(head.next->next, &two);
  1437. + ck_assert_ptr_eq(head.next->next->next, &six);
  1438. + ck_assert_ptr_eq(head.next->next->next->next, &five);
  1439. + ck_assert_ptr_eq(head.next->next->next->next->next, &four);
  1440. + ck_assert_ptr_eq(head.next->next->next->next->next->next, &one);
  1441. + ck_assert_ptr_eq(head.next->next->next->next->next->next->next, &head);
  1442. + ck_assert_ptr_eq(head.prev, &one);
  1443. + ck_assert_ptr_eq(head.prev->prev, &four);
  1444. + ck_assert_ptr_eq(head.prev->prev->prev, &five);
  1445. + ck_assert_ptr_eq(head.prev->prev->prev->prev, &six);
  1446. + ck_assert_ptr_eq(head.prev->prev->prev->prev->prev, &two);
  1447. + ck_assert_ptr_eq(head.prev->prev->prev->prev->prev->prev, &three);
  1448. + ck_assert_ptr_eq(head.prev->prev->prev->prev->prev->prev->prev, &head);
  1449. +}
  1450. +END_TEST
  1451. +
  1452. TCase *libfyaml_case_private(void)
  1453. {
  1454. TCase *tc;
  1455. @@ -162,5 +424,8 @@ TCase *libfyaml_case_private(void)
  1456. tcase_add_test(tc, scan_simple);
  1457. tcase_add_test(tc, parse_simple);
  1458. + tcase_add_test(tc, container_of);
  1459. + tcase_add_test(tc, list);
  1460. +
  1461. return tc;
  1462. }
  1463. From c157c9428b37eed6650cd8f2cce61d7978cbed31 Mon Sep 17 00:00:00 2001
  1464. From: Innokentii Mokin <innokentii@yandex-team.ru>
  1465. Date: Sun, 29 Jan 2023 00:27:22 +0300
  1466. Subject: [PATCH 3/3] replace unportable gcc extensions
  1467. ---
  1468. src/lib/fy-list.h | 8 +++-----
  1469. 1 file changed, 3 insertions(+), 5 deletions(-)
  1470. diff --git a/src/lib/fy-list.h b/src/lib/fy-list.h
  1471. index 65e17f9..df35cb2 100644
  1472. --- a/src/lib/fy-list.h
  1473. +++ b/src/lib/fy-list.h
  1474. @@ -10,11 +10,9 @@
  1475. #include <stddef.h>
  1476. -#define fy_container_of(pointer, type, member) ({ \
  1477. - const typeof(((type *)NULL)->member) *__## member ## _ptr = (pointer); \
  1478. - (type *) ((char *)__ ## member ## _ptr - offsetof(type, member)); \
  1479. - } \
  1480. -)
  1481. +#define fy_container_of(ptr, type, member) \
  1482. + ( (void)sizeof(0 ? (ptr) : &((type *)0)->member), \
  1483. + (type *)((char*)(ptr) - offsetof(type, member)) )
  1484. struct fy_list_head {
  1485. struct fy_list_head *prev;