pr0067-add-basic-win-support.patch 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. From 7c01e0b98f4b5024aa6a155772bebd51fe4c4946 Mon Sep 17 00:00:00 2001
  2. From: Innokentii Mokin <innokentii@yandex-team.ru>
  3. Date: Sun, 29 Jan 2023 00:06:37 +0300
  4. Subject: [PATCH 1/7] replace unportable gcc extensions
  5. ---
  6. include/libfyaml.h | 124 ++++++++++++++--------------
  7. src/internal/libfyaml-parser.c | 142 ++++++++++++++++++---------------
  8. src/lib/fy-atom.c | 8 +-
  9. src/lib/fy-atom.h | 6 +-
  10. src/lib/fy-ctype.h | 16 ++--
  11. src/lib/fy-diag.c | 58 ++++++++++----
  12. src/lib/fy-diag.h | 28 +++----
  13. src/lib/fy-doc.c | 79 ++++++++++--------
  14. src/lib/fy-dump.c | 2 +-
  15. src/lib/fy-emit.c | 8 +-
  16. src/lib/fy-parse.c | 34 +++++---
  17. src/lib/fy-parse.h | 2 +-
  18. src/lib/fy-token.h | 10 +--
  19. src/lib/fy-utf8.h | 20 ++---
  20. src/lib/fy-walk.c | 12 ++-
  21. src/tool/fy-tool.c | 8 +-
  22. src/valgrind/fy-valgrind.h | 8 +-
  23. test/libfyaml-test-core.c | 18 ++---
  24. 18 files changed, 323 insertions(+), 260 deletions(-)
  25. diff --git a/include/libfyaml.h b/include/libfyaml.h
  26. index 828f077..3baa3f4 100644
  27. --- a/include/libfyaml.h
  28. +++ b/include/libfyaml.h
  29. @@ -41,6 +41,11 @@ extern "C" {
  30. #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  31. #include <unistd.h>
  32. +#define FY_ALLOCA(x) alloca(x)
  33. +#elif defined(_MSC_VER)
  34. +#include <BaseTsd.h>
  35. +typedef SSIZE_T ssize_t;
  36. +#define FY_ALLOCA(x) _alloca(x)
  37. #endif
  38. /* opaque types for the user */
  39. @@ -71,9 +76,11 @@ struct fy_document_iterator;
  40. #define FY_NT ((size_t)-1)
  41. #if defined(__GNUC__) && __GNUC__ >= 4
  42. +#define FY_ATTRIBUTE(attr) __attribute ((attr))
  43. #define FY_EXPORT __attribute__ ((visibility ("default")))
  44. #define FY_DEPRECATED __attribute__ ((deprecated))
  45. #else
  46. +#define FY_ATTRIBUTE(attr) /* nothing */
  47. #define FY_EXPORT /* nothing */
  48. #define FY_DEPRECATED /* nothing */
  49. #endif
  50. @@ -84,34 +91,32 @@ struct fy_document_iterator;
  51. * If the _str pointer is NULL, then NULL will be returned
  52. */
  53. #ifndef FY_ALLOCA_COPY_FREE
  54. -#define FY_ALLOCA_COPY_FREE(_str, _len) \
  55. - ({ \
  56. - char *__str = (_str), *__stra = NULL; \
  57. - size_t __len = (size_t)(_len); \
  58. +#define FY_ALLOCA_COPY_FREE(_str, _len, _res) \
  59. + do { \
  60. + char *__res, *__str = (char*)(_str); \
  61. + size_t __len = (size_t)(_len); \
  62. + __res = NULL; \
  63. \
  64. if (__str) { \
  65. - if (__len == FY_NT) \
  66. + if (__len == FY_NT) \
  67. __len = strlen(__str); \
  68. - __stra = alloca(__len + 1); \
  69. - memcpy(__stra, __str, __len); \
  70. - __stra[__len] = '\0'; \
  71. + __res = FY_ALLOCA(__len + 1); \
  72. + memcpy(__res, __str, __len); \
  73. + (__res[__len]) = '\0'; \
  74. free(__str); \
  75. } \
  76. - (const char *)__stra; \
  77. - })
  78. + *(_res) = __res; \
  79. + } while(false)
  80. #endif
  81. /* same as above but when _str == NULL return "" */
  82. #ifndef FY_ALLOCA_COPY_FREE_NO_NULL
  83. -#define FY_ALLOCA_COPY_FREE_NO_NULL(_str, _len) \
  84. - ({ \
  85. - const char *__strb; \
  86. - \
  87. - __strb = FY_ALLOCA_COPY_FREE(_str, _len); \
  88. - if (!__strb) \
  89. - __strb = ""; \
  90. - __strb; \
  91. - })
  92. +#define FY_ALLOCA_COPY_FREE_NO_NULL(_str, _len, _res) \
  93. + do { \
  94. + FY_ALLOCA_COPY_FREE(_str, _len, _res); \
  95. + if (!*(_res)) \
  96. + *(_res) = ""; \
  97. + } while(false)
  98. #endif
  99. /**
  100. @@ -2022,8 +2027,8 @@ fy_emit_document_to_string(struct fy_document *fyd,
  101. enum fy_emitter_cfg_flags flags)
  102. FY_EXPORT;
  103. -#define fy_emit_document_to_string_alloca(_fyd, _flags) \
  104. - FY_ALLOCA_COPY_FREE(fy_emit_document_to_string((_fyd), (_flags)), FY_NT)
  105. +#define fy_emit_document_to_string_alloca(_fyd, _flags, _res) \
  106. + FY_ALLOCA_COPY_FREE(fy_emit_document_to_string((_fyd), (_flags)), FY_NT, (_res))
  107. /**
  108. * fy_emit_node_to_buffer() - Emit a node (recursively) to a buffer
  109. @@ -2061,8 +2066,8 @@ char *
  110. fy_emit_node_to_string(struct fy_node *fyn, enum fy_emitter_cfg_flags flags)
  111. FY_EXPORT;
  112. -#define fy_emit_node_to_string_alloca(_fyn, _flags) \
  113. - FY_ALLOCA_COPY_FREE(fy_emit_node_to_string((_fyn), (_flags)), FY_NT)
  114. +#define fy_emit_node_to_string_alloca(_fyn, _flags, _res) \
  115. + FY_ALLOCA_COPY_FREE(fy_emit_node_to_string((_fyn), (_flags)), FY_NT, (_res))
  116. /**
  117. * fy_emit_to_buffer() - Create an emitter for buffer output.
  118. @@ -2669,7 +2674,7 @@ fy_document_vbuildf(const struct fy_parse_cfg *cfg,
  119. */
  120. struct fy_document *
  121. fy_document_buildf(const struct fy_parse_cfg *cfg, const char *fmt, ...)
  122. - __attribute__((format(printf, 2, 3)))
  123. + FY_ATTRIBUTE(format(printf, 2, 3))
  124. FY_EXPORT;
  125. /**
  126. @@ -3054,7 +3059,7 @@ fy_node_vbuildf(struct fy_document *fyd, const char *fmt, va_list ap)
  127. */
  128. struct fy_node *
  129. fy_node_buildf(struct fy_document *fyd, const char *fmt, ...)
  130. - __attribute__((format(printf, 2, 3)))
  131. + FY_ATTRIBUTE(format(printf, 2, 3))
  132. FY_EXPORT;
  133. /**
  134. @@ -3110,8 +3115,8 @@ char *
  135. fy_node_get_path(struct fy_node *fyn)
  136. FY_EXPORT;
  137. -#define fy_node_get_path_alloca(_fyn) \
  138. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path((_fyn)), FY_NT)
  139. +#define fy_node_get_path_alloca(_fyn, _res) \
  140. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path((_fyn)), FY_NT, (_res))
  141. /**
  142. * fy_node_get_parent() - Get the parent node of a node
  143. @@ -3162,8 +3167,8 @@ char *
  144. fy_node_get_parent_address(struct fy_node *fyn)
  145. FY_EXPORT;
  146. -#define fy_node_get_parent_address_alloca(_fyn) \
  147. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_parent_address((_fyn)), FY_NT)
  148. +#define fy_node_get_parent_address_alloca(_fyn, _res) \
  149. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_parent_address((_fyn)), FY_NT, (_res))
  150. /**
  151. * fy_node_get_path_relative_to() - Get a path address of a node
  152. @@ -3184,8 +3189,8 @@ char *
  153. fy_node_get_path_relative_to(struct fy_node *fyn_parent, struct fy_node *fyn)
  154. FY_EXPORT;
  155. -#define fy_node_get_path_relative_to_alloca(_fynp, _fyn) \
  156. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path_relative_to((_fynp), (_fyn)), FY_NT)
  157. +#define fy_node_get_path_relative_to_alloca(_fynp, _fyn, _res) \
  158. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path_relative_to((_fynp), (_fyn)), FY_NT, (_res))
  159. /**
  160. * fy_node_get_short_path() - Get a path address of a node in the shortest
  161. @@ -3217,8 +3222,8 @@ char *
  162. fy_node_get_short_path(struct fy_node *fyn)
  163. FY_EXPORT;
  164. -#define fy_node_get_short_path_alloca(_fyn) \
  165. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_short_path((_fyn)), FY_NT)
  166. +#define fy_node_get_short_path_alloca(_fyn, _res) \
  167. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_short_path((_fyn)), FY_NT, (_res))
  168. /**
  169. * fy_node_get_reference() - Get a textual reference to a node
  170. @@ -3240,8 +3245,8 @@ char *
  171. fy_node_get_reference(struct fy_node *fyn)
  172. FY_EXPORT;
  173. -#define fy_node_get_reference_alloca(_fyn) \
  174. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_reference((_fyn)), FY_NT)
  175. +#define fy_node_get_reference_alloca(_fyn, _res) \
  176. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_reference((_fyn)), FY_NT, (_res))
  177. /**
  178. * fy_node_create_reference() - Create an alias reference node
  179. @@ -3284,8 +3289,8 @@ char *
  180. fy_node_get_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)
  181. FY_EXPORT;
  182. -#define fy_node_get_relative_reference_alloca(_fynb, _fyn) \
  183. - FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_relative_reference((_fynb), (_fyn)), FY_NT)
  184. +#define fy_node_get_relative_reference_alloca(_fynb, _fyn, _res) \
  185. + FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_relative_reference((_fynb), (_fyn)), FY_NT, (_res))
  186. /**
  187. * fy_node_create_relative_reference() - Create an alias reference node
  188. @@ -3389,7 +3394,7 @@ fy_node_create_vscalarf(struct fy_document *fyd, const char *fmt, va_list ap)
  189. struct fy_node *
  190. fy_node_create_scalarf(struct fy_document *fyd, const char *fmt, ...)
  191. FY_EXPORT
  192. - __attribute__((format(printf, 2, 3)));
  193. + FY_ATTRIBUTE(format(printf, 2, 3));
  194. /**
  195. * fy_node_create_sequence() - Create an empty sequence node.
  196. @@ -4224,7 +4229,7 @@ int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap);
  197. */
  198. int
  199. fy_node_scanf(struct fy_node *fyn, const char *fmt, ...)
  200. - __attribute__((format(scanf, 2, 3)))
  201. + FY_ATTRIBUTE(format(scanf, 2, 3))
  202. FY_EXPORT;
  203. /**
  204. @@ -4275,7 +4280,7 @@ fy_document_vscanf(struct fy_document *fyd, const char *fmt, va_list ap)
  205. */
  206. int
  207. fy_document_scanf(struct fy_document *fyd, const char *fmt, ...)
  208. - __attribute__((format(scanf, 2, 3)))
  209. + FY_ATTRIBUTE(format(scanf, 2, 3))
  210. FY_EXPORT;
  211. /**
  212. @@ -4571,7 +4576,7 @@ fy_node_set_vanchorf(struct fy_node *fyn, const char *fmt, va_list ap)
  213. */
  214. int
  215. fy_node_set_anchorf(struct fy_node *fyn, const char *fmt, ...)
  216. - FY_EXPORT __attribute__((format(printf, 2, 3)));
  217. + FY_EXPORT FY_ATTRIBUTE(format(printf, 2, 3));
  218. /**
  219. * fy_node_remove_anchor() - Remove an anchor
  220. @@ -4839,7 +4844,7 @@ fy_node_vreport(struct fy_node *fyn, enum fy_error_type type,
  221. void
  222. fy_node_report(struct fy_node *fyn, enum fy_error_type type,
  223. const char *fmt, ...)
  224. - __attribute__((format(printf, 3, 4)))
  225. + FY_ATTRIBUTE(format(printf, 3, 4))
  226. FY_EXPORT;
  227. /**
  228. @@ -4890,7 +4895,7 @@ void
  229. fy_node_override_report(struct fy_node *fyn, enum fy_error_type type,
  230. const char *file, int line, int column,
  231. const char *fmt, ...)
  232. - __attribute__((format(printf, 6, 7)))
  233. + FY_ATTRIBUTE(format(printf, 6, 7))
  234. FY_EXPORT;
  235. typedef void (*fy_diag_output_fn)(struct fy_diag *diag, void *user,
  236. @@ -5170,7 +5175,7 @@ fy_diag_vprintf(struct fy_diag *diag, const char *fmt, va_list ap)
  237. int
  238. fy_diag_printf(struct fy_diag *diag, const char *fmt, ...)
  239. FY_EXPORT
  240. - __attribute__((format(printf, 2, 3)));
  241. + FY_ATTRIBUTE(format(printf, 2, 3));
  242. /**
  243. * struct fy_diag_ctx - The diagnostics context
  244. @@ -5237,22 +5242,9 @@ int
  245. fy_diagf(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  246. const char *fmt, ...)
  247. FY_EXPORT
  248. - __attribute__((format(printf, 3, 4)));
  249. -
  250. -#define fy_diag_diag(_diag, _level, _fmt, ...) \
  251. - ({ \
  252. - struct fy_diag_ctx _ctx = { \
  253. - .level = (_level), \
  254. - .module = FYEM_UNKNOWN, \
  255. - .source_func = __func__, \
  256. - .source_file = __FILE__, \
  257. - .source_line = __LINE__, \
  258. - .file = NULL, \
  259. - .line = 0, \
  260. - .column = 0, \
  261. - }; \
  262. - fy_diagf((_diag), &_ctx, (_fmt) , ## __VA_ARGS__); \
  263. - })
  264. + FY_ATTRIBUTE(format(printf, 3, 4));
  265. +
  266. +int fy_diag_diag(struct fy_diag *diag, enum fy_error_type level, const char* fmt, ...);
  267. #ifndef NDEBUG
  268. @@ -5310,7 +5302,7 @@ fy_diag_node_vreport(struct fy_diag *diag, struct fy_node *fyn,
  269. void
  270. fy_diag_node_report(struct fy_diag *diag, struct fy_node *fyn,
  271. enum fy_error_type type, const char *fmt, ...)
  272. - __attribute__((format(printf, 4, 5)))
  273. + FY_ATTRIBUTE(format(printf, 4, 5))
  274. FY_EXPORT;
  275. /**
  276. @@ -5365,7 +5357,7 @@ void
  277. fy_diag_node_override_report(struct fy_diag *diag, struct fy_node *fyn,
  278. enum fy_error_type type, const char *file,
  279. int line, int column, const char *fmt, ...)
  280. - __attribute__((format(printf, 7, 8)))
  281. + FY_ATTRIBUTE(format(printf, 7, 8))
  282. FY_EXPORT;
  283. /**
  284. @@ -6889,8 +6881,8 @@ char *
  285. fy_path_component_get_text(struct fy_path_component *fypc)
  286. FY_EXPORT;
  287. -#define fy_path_component_get_text_alloca(_fypc) \
  288. - FY_ALLOCA_COPY_FREE(fy_path_component_get_text((_fypc)), FY_NT)
  289. +#define fy_path_component_get_text_alloca(_fypc, _res) \
  290. + FY_ALLOCA_COPY_FREE(fy_path_component_get_text((_fypc)), FY_NT, (_res))
  291. /**
  292. * fy_path_depth() - Get the depth of a path
  293. *
  294. @@ -6937,8 +6929,8 @@ char *
  295. fy_path_get_text(struct fy_path *fypp)
  296. FY_EXPORT;
  297. -#define fy_path_get_text_alloca(_fypp) \
  298. - FY_ALLOCA_COPY_FREE(fy_path_get_text((_fypp)), FY_NT)
  299. +#define fy_path_get_text_alloca(_fypp, _res) \
  300. + FY_ALLOCA_COPY_FREE(fy_path_get_text((_fypp)), FY_NT, (_res))
  301. /**
  302. * fy_path_in_root() - Check if the path is in the root of the document
  303. diff --git a/src/internal/libfyaml-parser.c b/src/internal/libfyaml-parser.c
  304. index 9764cf9..9563208 100644
  305. --- a/src/internal/libfyaml-parser.c
  306. +++ b/src/internal/libfyaml-parser.c
  307. @@ -144,7 +144,9 @@ static void display_usage(FILE *fp, char *progname)
  308. void print_escaped(FILE *fp, const char *str, int length)
  309. {
  310. - fprintf(fp, "%s", fy_utf8_format_text_a(str, length, fyue_doublequote));
  311. + char* str2;
  312. + fy_utf8_format_text_a(str, length, fyue_doublequote, &str2);
  313. + fprintf(fp, "%s", str2);
  314. }
  315. static int txt2esc_internal(const char *s, int l, char *out, int *outszp, int delim)
  316. @@ -248,8 +250,8 @@ static char *txt2esc_format(const char *s, int l, char *buf, int maxsz, int deli
  317. return buf;
  318. }
  319. -#define fy_atom_get_text_a(_atom) \
  320. - ({ \
  321. +#define fy_atom_get_text_a(_atom, _res) \
  322. + do { \
  323. struct fy_atom *_a = (_atom); \
  324. int _len; \
  325. char *_buf; \
  326. @@ -258,7 +260,7 @@ static char *txt2esc_format(const char *s, int l, char *buf, int maxsz, int deli
  327. if (!_a->direct_output) { \
  328. _len = fy_atom_format_text_length(_a); \
  329. if (_len > 0) { \
  330. - _buf = alloca(_len + 1); \
  331. + _buf = FY_ALLOCA(_len + 1); \
  332. memset(_buf, 0, _len + 1); \
  333. fy_atom_format_text(_a, _buf, _len + 1); \
  334. _buf[_len] = '\0'; \
  335. @@ -266,25 +268,25 @@ static char *txt2esc_format(const char *s, int l, char *buf, int maxsz, int deli
  336. } \
  337. } else { \
  338. _len = fy_atom_size(_a); \
  339. - _buf = alloca(_len + 1); \
  340. + _buf = FY_ALLOCA(_len + 1); \
  341. memset(_buf, 0, _len + 1); \
  342. memcpy(_buf, fy_atom_data(_a), _len); \
  343. _buf[_len] = '\0'; \
  344. _txt = _buf; \
  345. } \
  346. - _txt; \
  347. - })
  348. + *(_res) = _txt; \
  349. + } while(false)
  350. -#define txt2esc_a(_s, _l) \
  351. - ({ \
  352. +#define txt2esc_a(_s, _l, _res) \
  353. + do { \
  354. const char *__s = (const void *)(_s); \
  355. int __l = (_l); \
  356. int _ll = txt2esc_length(__s, __l, '\''); \
  357. - txt2esc_format(__s, __l, alloca(_ll + 1), _ll + 1, '\''); \
  358. - })
  359. + (*res) = txt2esc_format(__s, __l, FY_ALLOCA(_ll + 1), _ll + 1, '\''); \
  360. + } while(false)
  361. -#define fy_atom_get_esc_text_a(_atom) txt2esc_a(fy_atom_get_text_a(_atom), -1)
  362. -#define fy_token_get_esc_text_a(_atom) txt2esc_a(fy_token_get_text0(_atom), -1)
  363. +#define fy_atom_get_esc_text_a(_atom, _res) txt2esc_a(fy_atom_get_text_a(_atom), -1, (_res))
  364. +#define fy_token_get_esc_text_a(_atom, _res) txt2esc_a(fy_token_get_text0(_atom), -1, (_res))
  365. void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  366. {
  367. @@ -314,16 +316,16 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  368. printf("%-14s%s|\n", "DOCUMENT_END", mm);
  369. break;
  370. case FYET_ALIAS:
  371. - anchor = fy_token_get_esc_text_a(fye->alias.anchor);
  372. + fy_token_get_esc_text_a(fye->alias.anchor, &anchor);
  373. printf("%-14s%s| '%s'\n", "ALIAS", mm, anchor);
  374. break;
  375. case FYET_SCALAR:
  376. if (fye->scalar.anchor)
  377. - anchor = fy_token_get_esc_text_a(fye->scalar.anchor);
  378. + fy_token_get_esc_text_a(fye->scalar.anchor, &anchor);
  379. if (fye->scalar.tag)
  380. - tag = fy_token_get_esc_text_a(fye->scalar.tag);
  381. + fy_token_get_esc_text_a(fye->scalar.tag, &tag);
  382. if (fye->scalar.value)
  383. - value = fy_token_get_esc_text_a(fye->scalar.value);
  384. + fy_token_get_esc_text_a(fye->scalar.value, &value);
  385. printf("%-14s%s|%s%s%s%s%s%s '%s'\n", "SCALAR", mm,
  386. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  387. tag ? " tag='" : "", tag ? : "", tag ? "'" : "",
  388. @@ -331,9 +333,9 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  389. break;
  390. case FYET_SEQUENCE_START:
  391. if (fye->sequence_start.anchor)
  392. - anchor = fy_token_get_esc_text_a(fye->sequence_start.anchor);
  393. + fy_token_get_esc_text_a(fye->sequence_start.anchor, &anchor);
  394. if (fye->sequence_start.tag)
  395. - tag = fy_token_get_esc_text_a(fye->sequence_start.tag);
  396. + fy_token_get_esc_text_a(fye->sequence_start.tag, &tag);
  397. printf("%-14s%s|%s%s%s%s%s%s\n", "SEQUENCE_START", mm,
  398. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  399. tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  400. @@ -343,9 +345,9 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  401. break;
  402. case FYET_MAPPING_START:
  403. if (fye->mapping_start.anchor)
  404. - anchor = fy_token_get_esc_text_a(fye->mapping_start.anchor);
  405. + fy_token_get_esc_text_a(fye->mapping_start.anchor, &anchor);
  406. if (fye->mapping_start.tag)
  407. - tag = fy_token_get_esc_text_a(fye->mapping_start.tag);
  408. + fy_token_get_esc_text_a(fye->mapping_start.tag, &tag);
  409. printf("%-14s%s|%s%s%s%s%s%s\n", "MAPPING_START", mm,
  410. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  411. tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  412. @@ -488,6 +490,7 @@ static void dump_token(struct fy_token *fyt)
  413. const struct fy_version *vers;
  414. const char *handle, *prefix, *suffix;
  415. const char *typetxt;
  416. + char *tmp1, tmp2;
  417. typetxt = fy_token_type_txt[fyt->type];
  418. assert(typetxt);
  419. @@ -506,9 +509,11 @@ static void dump_token(struct fy_token *fyt)
  420. prefix = fy_tag_directive_token_prefix0(fyt);
  421. if (!prefix)
  422. prefix = "";
  423. + txt2esc_a(handle, -1, &tmp1);
  424. + txt2esc_a(prefix, -1, &tmp2);
  425. printf("%s handle='%s' prefix='%s'\n", typetxt,
  426. - txt2esc_a(handle, -1),
  427. - txt2esc_a(prefix, -1));
  428. + tmp1,
  429. + tmp2);
  430. break;
  431. case FYTT_ALIAS:
  432. printf("%s value='%s'\n", typetxt,
  433. @@ -525,9 +530,11 @@ static void dump_token(struct fy_token *fyt)
  434. suffix = fy_tag_token_suffix0(fyt);
  435. if (!suffix)
  436. suffix = "";
  437. + txt2esc_a(handle, -1, &tmp1);
  438. + txt2esc_a(prefix, -1, &tmp2);
  439. printf("%s handle='%s' suffix='%s'\n", typetxt,
  440. - txt2esc_a(handle, -1),
  441. - txt2esc_a(suffix, -1));
  442. + tmp1,
  443. + tmp2);
  444. break;
  445. case FYTT_SCALAR:
  446. switch (fy_token_scalar_style(fyt)) {
  447. @@ -553,19 +560,20 @@ static void dump_token(struct fy_token *fyt)
  448. style = "*illegal*";
  449. break;
  450. }
  451. + fy_atom_get_esc_text_a(&fyt->handle, &tmp1);
  452. printf("%s value='%s' style=%s\n", typetxt,
  453. - fy_atom_get_esc_text_a(&fyt->handle),
  454. + tmp1,
  455. style);
  456. break;
  457. case FYTT_INPUT_MARKER:
  458. - printf("%s value='%s'\n", typetxt,
  459. - fy_atom_get_esc_text_a(&fyt->handle));
  460. + fy_atom_get_esc_text_a(&fyt->handle, &tmp1);
  461. + printf("%s value='%s'\n", typetxt, tmp1);
  462. break;
  463. case FYTT_PE_MAP_KEY:
  464. - printf("%s value='%s'\n", typetxt,
  465. - fy_atom_get_esc_text_a(&fyt->handle));
  466. + fy_atom_get_esc_text_a(&fyt->handle, &tmp1);
  467. + printf("%s value='%s'\n", typetxt, tmp1);
  468. break;
  469. case FYTT_PE_SEQ_INDEX:
  470. @@ -579,8 +587,8 @@ static void dump_token(struct fy_token *fyt)
  471. break;
  472. case FYTT_PE_ALIAS:
  473. - printf("%s value='%s'\n", "PE-ALIAS",
  474. - fy_atom_get_esc_text_a(&fyt->handle));
  475. + fy_atom_get_esc_text_a(&fyt->handle, &tmp1);
  476. + printf("%s value='%s'\n", "PE-ALIAS", tmp1);
  477. break;
  478. default:
  479. @@ -751,10 +759,12 @@ process_event(struct fy_parser *fyp, struct fy_event *fye, struct fy_path *path,
  480. struct fy_node_pair *fynp;
  481. char tbuf[80];
  482. int rc;
  483. + char *path_text;
  484. if (cd->null_output)
  485. return FYCR_OK_CONTINUE;
  486. + fy_path_get_text_alloca(path, &path_text);
  487. fyp_info(fyp, "%s: %c%c%c%c%c %3d - %-32s: %s\n", fy_event_type_txt[fye->type],
  488. fy_path_in_root(path) ? 'R' : '-',
  489. fy_path_in_sequence(path) ? 'S' : '-',
  490. @@ -763,7 +773,7 @@ process_event(struct fy_parser *fyp, struct fy_event *fye, struct fy_path *path,
  491. fy_path_in_mapping_value(path) ? 'V' : '-',
  492. fy_path_in_collection_root(path) ? '/' : '-',
  493. fy_path_depth(path),
  494. - fy_path_get_text_alloca(path),
  495. + path_text,
  496. fy_token_dump_format(fy_event_get_token(fye), tbuf, sizeof(tbuf)));
  497. switch (fye->type) {
  498. @@ -1078,6 +1088,7 @@ int do_comment(struct fy_parser *fyp)
  499. void dump_libyaml_token(yaml_token_t *token)
  500. {
  501. const char *style;
  502. + char *tmp1, *tmp2;
  503. switch (token->type) {
  504. case YAML_NO_TOKEN:
  505. @@ -1095,9 +1106,9 @@ void dump_libyaml_token(yaml_token_t *token)
  506. token->data.version_directive.minor);
  507. break;
  508. case YAML_TAG_DIRECTIVE_TOKEN:
  509. - printf("TAG_DIRECTIVE handle='%s' prefix='%s'\n",
  510. - txt2esc_a(token->data.tag_directive.handle, -1),
  511. - txt2esc_a(token->data.tag_directive.prefix, -1));
  512. + txt2esc_a(token->data.tag_directive.handle, -1, &tmp1);
  513. + txt2esc_a(token->data.tag_directive.prefix, -1, &tmp2);
  514. + printf("TAG_DIRECTIVE handle='%s' prefix='%s'\n", tmp1, tmp2);
  515. break;
  516. case YAML_DOCUMENT_START_TOKEN:
  517. printf("DOCUMENT_START\n");
  518. @@ -1139,17 +1150,19 @@ void dump_libyaml_token(yaml_token_t *token)
  519. printf("VALUE\n");
  520. break;
  521. case YAML_ALIAS_TOKEN:
  522. + txt2esc_a(token->data.alias.value, -1, &tmp1);
  523. printf("ALIAS value='%s'\n",
  524. - txt2esc_a(token->data.alias.value, -1));
  525. + tmp1);
  526. break;
  527. case YAML_ANCHOR_TOKEN:
  528. + txt2esc_a(token->data.anchor.value, -1, &tmp1);
  529. printf("ANCHOR value='%s'\n",
  530. - txt2esc_a(token->data.anchor.value, -1));
  531. + tmp1);
  532. break;
  533. case YAML_TAG_TOKEN:
  534. - printf("TAG handle='%s' suffix='%s'\n",
  535. - txt2esc_a(token->data.tag.handle, -1),
  536. - txt2esc_a(token->data.tag.suffix, -1));
  537. + txt2esc_a(token->data.tag.handle, -1, &tmp1);
  538. + txt2esc_a(token->data.tag.suffix, -1, &tmp2);
  539. + printf("TAG handle='%s' suffix='%s'\n", tmp1, tmp2);
  540. break;
  541. case YAML_SCALAR_TOKEN:
  542. switch (token->data.scalar.style) {
  543. @@ -1175,9 +1188,9 @@ void dump_libyaml_token(yaml_token_t *token)
  544. style = "*ERROR*";
  545. break;
  546. }
  547. + txt2esc_a(token->data.scalar.value, token->data.scalar.length, &tmp1);
  548. printf("SCALAR value='%s' style=%s\n",
  549. - txt2esc_a(token->data.scalar.value, token->data.scalar.length),
  550. - style);
  551. + style, tmp1);
  552. break;
  553. }
  554. }
  555. @@ -1202,23 +1215,24 @@ int do_libyaml_scan(yaml_parser_t *parser)
  556. return 0;
  557. }
  558. -#define mark_a(_m) \
  559. - ({ \
  560. +#define mark_a(_m, _res) \
  561. + do { \
  562. yaml_mark_t *__m = (_m); \
  563. - char *_s = alloca(30); \
  564. + char *_s = FY_ALLOCA(30); \
  565. snprintf(_s, 30, "%zu/%zu/%zu", __m->index, __m->line, __m->column); \
  566. - _s; \
  567. - })
  568. + *(_res) = _s; \
  569. + } while(false)
  570. void dump_libyaml_event(yaml_event_t *event)
  571. {
  572. char mbuf[40];
  573. char *mm;
  574. char *anchor = NULL, *tag = NULL, *value = NULL;
  575. + char *tmp1, *tmp2;
  576. - snprintf(mbuf, sizeof(mbuf), " %10s-%-10s ",
  577. - mark_a(&event->start_mark),
  578. - mark_a(&event->end_mark));
  579. + mark_a(&event->start_mark, &tmp1);
  580. + mark_a(&event->end_mark, &tmp2);
  581. + snprintf(mbuf, sizeof(mbuf), " %10s-%-10s ", tmp1, tmp2);
  582. mm = mbuf;
  583. mm = " ";
  584. @@ -1239,15 +1253,15 @@ void dump_libyaml_event(yaml_event_t *event)
  585. printf("%-14s%s|\n", "DOCUMENT_END", mm);
  586. break;
  587. case YAML_ALIAS_EVENT:
  588. - anchor = txt2esc_a((char *)event->data.alias.anchor, -1);
  589. + txt2esc_a((char *)event->data.alias.anchor, -1, &anchor);
  590. printf("%-14s%s| '%s'\n", "ALIAS", mm, anchor);
  591. break;
  592. case YAML_SCALAR_EVENT:
  593. if (event->data.scalar.anchor)
  594. - anchor = txt2esc_a((char *)event->data.scalar.anchor, -1);
  595. + txt2esc_a((char *)event->data.scalar.anchor, -1, &anchor);
  596. if (event->data.scalar.tag)
  597. - tag = txt2esc_a((char *)event->data.scalar.tag, -1);
  598. - value = txt2esc_a((char *)event->data.scalar.value, -1);
  599. + txt2esc_a((char *)event->data.scalar.tag, -1, &tag);
  600. + txt2esc_a((char *)event->data.scalar.value, -1, &value);
  601. printf("%-14s%s|%s%s%s%s%s%s '%s'\n", "SCALAR", mm,
  602. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  603. tag ? " tag='" : "", tag ? : "", tag ? "'" : "",
  604. @@ -1255,9 +1269,9 @@ void dump_libyaml_event(yaml_event_t *event)
  605. break;
  606. case YAML_SEQUENCE_START_EVENT:
  607. if (event->data.sequence_start.anchor)
  608. - anchor = txt2esc_a((char *)event->data.sequence_start.anchor, -1);
  609. + txt2esc_a((char *)event->data.sequence_start.anchor, -1, &anchor);
  610. if (event->data.sequence_start.tag)
  611. - tag = txt2esc_a((char *)event->data.sequence_start.tag, -1);
  612. + txt2esc_a((char *)event->data.sequence_start.tag, -1, &tag);
  613. printf("%-14s%s|%s%s%s%s%s%s\n", "SEQUENCE_START", mm,
  614. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  615. tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  616. @@ -1267,9 +1281,9 @@ void dump_libyaml_event(yaml_event_t *event)
  617. break;
  618. case YAML_MAPPING_START_EVENT:
  619. if (event->data.mapping_start.anchor)
  620. - anchor = txt2esc_a((char *)event->data.mapping_start.anchor, -1);
  621. + txt2esc_a((char *)event->data.mapping_start.anchor, -1, &anchor);
  622. if (event->data.mapping_start.tag)
  623. - tag = txt2esc_a((char *)event->data.mapping_start.tag, -1);
  624. + txt2esc_a((char *)event->data.mapping_start.tag, -1, &tag);
  625. printf("%-14s%s|%s%s%s%s%s%s\n", "MAPPING_START", mm,
  626. anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  627. tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  628. @@ -3820,8 +3834,8 @@ int do_bad_utf8(const struct fy_parse_cfg *cfg, int argc, char *argv[])
  629. len = strlen(key);
  630. - fwd = alloca(sizeof(*fwd) * len);
  631. - bwd = alloca(sizeof(*bwd) * len);
  632. + fwd = FY_ALLOCA(sizeof(*fwd) * len);
  633. + bwd = FY_ALLOCA(sizeof(*bwd) * len);
  634. memset(fwd, 0, sizeof(*fwd) * len);
  635. memset(bwd, 0, sizeof(*bwd) * len);
  636. @@ -3911,7 +3925,7 @@ int apply_flags_option(const char *arg, unsigned int *flagsp,
  637. sn = e;
  638. len = sn - s;
  639. - targ = alloca(len + 1);
  640. + targ = FY_ALLOCA(len + 1);
  641. memcpy(targ, s, len);
  642. targ[len] = '\0';
  643. @@ -3959,7 +3973,7 @@ int main(int argc, char *argv[])
  644. while ((opt = getopt_long_only(argc, argv, "I:m:i:w:d:rsc:C:D:M:W:S:qh", lopts, &lidx)) != -1) {
  645. switch (opt) {
  646. case 'I':
  647. - tmp = alloca(strlen(cfg.search_path) + 1 + strlen(optarg) + 1);
  648. + tmp = FY_ALLOCA(strlen(cfg.search_path) + 1 + strlen(optarg) + 1);
  649. s = tmp;
  650. strcpy(s, cfg.search_path);
  651. if (cfg.search_path && cfg.search_path[0]) {
  652. @@ -4213,7 +4227,7 @@ int main(int argc, char *argv[])
  653. if (!icount)
  654. icount++;
  655. - fyic_array = alloca(sizeof(*fyic_array) * icount);
  656. + fyic_array = FY_ALLOCA(sizeof(*fyic_array) * icount);
  657. memset(fyic_array, 0, sizeof(*fyic_array) * icount);
  658. j = 0;
  659. diff --git a/src/lib/fy-atom.c b/src/lib/fy-atom.c
  660. index 4086d92..efeabbe 100644
  661. --- a/src/lib/fy-atom.c
  662. +++ b/src/lib/fy-atom.c
  663. @@ -372,7 +372,7 @@ fy_atom_iter_line_analyze(struct fy_atom_iter *iter, struct fy_atom_iter_line_in
  664. last_was_ws = false;
  665. - ts = atom->tabsize ? : 8; /* pick it up from the atom (if there is) */
  666. + ts = atom->tabsize ? atom->tabsize : 8; /* pick it up from the atom (if there is) */
  667. /* consecutive whitespace */
  668. cws = 0;
  669. @@ -642,7 +642,7 @@ void fy_atom_iter_start(const struct fy_atom *atom, struct fy_atom_iter *iter)
  670. iter->chomp = atom->increment;
  671. /* default tab size is 8 */
  672. - iter->tabsize = atom->tabsize ? : 8;
  673. + iter->tabsize = atom->tabsize ? atom->tabsize: 8;
  674. memset(iter->li, 0, sizeof(iter->li));
  675. li = &iter->li[1];
  676. @@ -965,7 +965,7 @@ fy_atom_iter_format(struct fy_atom_iter *iter)
  677. case FYAC_CLIP:
  678. pending_lb_size = 16;
  679. - pending_lb = alloca(sizeof(*pending_lb) * pending_lb_size);
  680. + pending_lb = FY_ALLOCA(sizeof(*pending_lb) * pending_lb_size);
  681. pending_nl = 0;
  682. if (!li->empty) {
  683. @@ -987,7 +987,7 @@ fy_atom_iter_format(struct fy_atom_iter *iter)
  684. }
  685. if (li->lb_end && !iter->empty) {
  686. if (pending_nl >= pending_lb_size) {
  687. - pending_lb_new = alloca(sizeof(*pending_lb) * pending_lb_size * 2);
  688. + pending_lb_new = FY_ALLOCA(sizeof(*pending_lb) * pending_lb_size * 2);
  689. memcpy(pending_lb_new, pending_lb, sizeof(*pending_lb) * pending_lb_size);
  690. pending_lb_size *= 2;
  691. pending_lb = pending_lb_new;
  692. diff --git a/src/lib/fy-atom.h b/src/lib/fy-atom.h
  693. index 9041f21..2a8b563 100644
  694. --- a/src/lib/fy-atom.h
  695. +++ b/src/lib/fy-atom.h
  696. @@ -185,11 +185,11 @@ struct fy_atom *fy_reader_fill_atom_mark(struct fy_reader *fyr, const struct fy_
  697. const struct fy_mark *end_mark, struct fy_atom *handle);
  698. struct fy_atom *fy_reader_fill_atom_at(struct fy_reader *fyr, int advance, int count, struct fy_atom *handle);
  699. -#define fy_reader_fill_atom_a(_fyr, _advance) fy_reader_fill_atom((_fyr), (_advance), alloca(sizeof(struct fy_atom)))
  700. +#define fy_reader_fill_atom_a(_fyr, _advance) fy_reader_fill_atom((_fyr), (_advance), FY_ALLOCA(sizeof(struct fy_atom)))
  701. struct fy_atom *fy_fill_node_atom(struct fy_node *fyn, struct fy_atom *handle);
  702. -#define fy_fill_node_atom_a(_fyn) fy_fill_node_atom((_fyn), alloca(sizeof(struct fy_atom)))
  703. +#define fy_fill_node_atom_a(_fyn) fy_fill_node_atom((_fyn), FY_ALLOCA(sizeof(struct fy_atom)))
  704. struct fy_atom_iter_line_info {
  705. const char *start;
  706. @@ -275,7 +275,7 @@ static inline const char *fy_atom_data(const struct fy_atom *atom)
  707. if (!atom)
  708. return NULL;
  709. - return fy_input_start(atom->fyi) + atom->start_mark.input_pos;
  710. + return (char *)fy_input_start(atom->fyi) + atom->start_mark.input_pos;
  711. }
  712. static inline size_t fy_atom_size(const struct fy_atom *atom)
  713. diff --git a/src/lib/fy-ctype.h b/src/lib/fy-ctype.h
  714. index 89ab12c..8a8e7fb 100644
  715. --- a/src/lib/fy-ctype.h
  716. +++ b/src/lib/fy-ctype.h
  717. @@ -239,24 +239,26 @@ static inline bool fy_is_flow_ws_m(int c, enum fy_flow_ws_mode fws_mode)
  718. static inline const void * \
  719. fy_find_ ## _kind (const void *s, size_t len) \
  720. { \
  721. - const void *e = s + len; \
  722. + const char *cs = (char *)s; \
  723. + const char *e = cs + len; \
  724. int c, w; \
  725. - for (; s < e && (c = fy_utf8_get(s, e - s, &w)) >= 0; s += w) { \
  726. + for (; cs < e && (c = fy_utf8_get(cs, e - cs, &w)) >= 0; cs += w) { \
  727. assert(w); \
  728. if (fy_is_ ## _kind (c)) \
  729. - return s; \
  730. + return cs; \
  731. } \
  732. return NULL; \
  733. } \
  734. static inline const void * \
  735. fy_find_non_ ## _kind (const void *s, size_t len) \
  736. { \
  737. - const void *e = s + len; \
  738. + const char *cs = (char *)s; \
  739. + const char *e = cs + len; \
  740. int c, w; \
  741. - for (; s < e && (c = fy_utf8_get(s, e - s, &w)) >= 0; s += w) { \
  742. + for (; cs < e && (c = fy_utf8_get(cs, e - cs, &w)) >= 0; cs += w) { \
  743. assert(w); \
  744. if (!(fy_is_ ## _kind (c))) \
  745. - return s; \
  746. + return cs; \
  747. assert(w); \
  748. } \
  749. return NULL; \
  750. @@ -308,7 +310,7 @@ static inline const void *fy_skip_lb(const void *ptr, int left)
  751. if (c == '\r' && left > width && *(char *)ptr == '\n')
  752. width++;
  753. - return ptr + width;
  754. + return (char *)ptr + width;
  755. }
  756. /* given a pointer to a chunk of memory, return pointer to first
  757. diff --git a/src/lib/fy-diag.c b/src/lib/fy-diag.c
  758. index 5488c08..aa1e4cd 100644
  759. --- a/src/lib/fy-diag.c
  760. +++ b/src/lib/fy-diag.c
  761. @@ -11,13 +11,15 @@
  762. #include <stdio.h>
  763. #include <string.h>
  764. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  765. #include <sys/types.h>
  766. #include <sys/stat.h>
  767. +#include <unistd.h>
  768. +#endif
  769. #include <assert.h>
  770. #include <stdlib.h>
  771. #include <errno.h>
  772. #include <stdarg.h>
  773. -#include <unistd.h>
  774. #include <ctype.h>
  775. #include <libfyaml.h>
  776. @@ -32,6 +34,25 @@ static const char *error_type_txt[] = {
  777. [FYET_ERROR] = "error",
  778. };
  779. +int fy_diag_diag(struct fy_diag *diag, enum fy_error_type level, const char* fmt, ...)
  780. +{
  781. + va_list args;
  782. + struct fy_diag_ctx ctx = {
  783. + .level = level,
  784. + .module = FYEM_UNKNOWN,
  785. + .source_func = __func__,
  786. + .source_file = __FILE__,
  787. + .source_line = __LINE__,
  788. + .file = NULL,
  789. + .line = 0,
  790. + .column = 0,
  791. + };
  792. +
  793. + va_start(args, fmt);
  794. + fy_diagf(diag, &ctx, fmt, args);
  795. + va_end(args);
  796. +}
  797. +
  798. const char *fy_error_type_to_string(enum fy_error_type type)
  799. {
  800. @@ -184,6 +205,7 @@ static void fy_diag_update_term_info(struct fy_diag *diag)
  801. goto out;
  802. rows = columns = 0;
  803. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  804. ret = fy_term_query_size(fd, &rows, &columns);
  805. if (ret != 0)
  806. goto out;
  807. @@ -192,6 +214,7 @@ static void fy_diag_update_term_info(struct fy_diag *diag)
  808. diag->term_info.rows = rows;
  809. diag->term_info.columns = columns;
  810. }
  811. +#endif
  812. out:
  813. diag->terminal_probed = true;
  814. }
  815. @@ -455,7 +478,7 @@ int fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  816. goto out;
  817. }
  818. - msg = alloca_vsprintf(fmt, ap);
  819. + alloca_vsprintf(&msg, fmt, ap);
  820. /* source part */
  821. if (diag->cfg.show_source) {
  822. @@ -467,21 +490,21 @@ int fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  823. file_stripped++;
  824. } else
  825. file_stripped = "";
  826. - source = alloca_sprintf("%s:%d @%s()%s",
  827. + alloca_sprintf(&source, "%s:%d @%s()%s",
  828. file_stripped, fydc->source_line, fydc->source_func, " ");
  829. }
  830. /* position part */
  831. if (diag->cfg.show_position && fydc->line >= 0 && fydc->column >= 0)
  832. - position = alloca_sprintf("<%3d:%2d>%s", fydc->line, fydc->column, ": ");
  833. + alloca_sprintf(&position, "<%3d:%2d>%s", fydc->line, fydc->column, ": ");
  834. /* type part */
  835. if (diag->cfg.show_type)
  836. - typestr = alloca_sprintf("[%s]%s", fy_error_level_str(level), ": ");
  837. + alloca_sprintf(&typestr, "[%s]%s", fy_error_level_str(level), ": ");
  838. /* module part */
  839. if (diag->cfg.show_module)
  840. - modulestr = alloca_sprintf("<%s>%s", fy_error_module_str(fydc->module), ": ");
  841. + alloca_sprintf(&modulestr, "<%s>%s", fy_error_module_str(fydc->module), ": ");
  842. if (diag->cfg.colorize) {
  843. switch (level) {
  844. @@ -508,13 +531,13 @@ int fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  845. }
  846. rc = fy_diag_printf(diag, "%s" "%*s" "%*s" "%*s" "%*s" "%s" "%s\n",
  847. - color_start ? : "",
  848. - source ? diag->cfg.source_width : 0, source ? : "",
  849. - position ? diag->cfg.position_width : 0, position ? : "",
  850. - typestr ? diag->cfg.type_width : 0, typestr ? : "",
  851. - modulestr ? diag->cfg.module_width : 0, modulestr ? : "",
  852. + color_start ? color_start : "",
  853. + source ? diag->cfg.source_width : 0, source ? source : "",
  854. + position ? diag->cfg.position_width : 0, position ? position : "",
  855. + typestr ? diag->cfg.type_width : 0, typestr ? typestr : "",
  856. + modulestr ? diag->cfg.module_width : 0, modulestr ? modulestr : "",
  857. msg,
  858. - color_end ? : "");
  859. + color_end ? color_end : "");
  860. if (rc > 0)
  861. rc++;
  862. @@ -638,7 +661,7 @@ void fy_diag_error_atom_display(struct fy_diag *diag, enum fy_error_type type, s
  863. /* worse case utf8 + 2 color sequences + zero terminated */
  864. rowbufsz = cols * 4 + 2 * 16 + 1;
  865. - rowbuf = alloca(rowbufsz);
  866. + rowbuf = FY_ALLOCA(rowbufsz);
  867. rbe = rowbuf + rowbufsz;
  868. /* if the maximum column number is less than the terminal
  869. @@ -837,15 +860,16 @@ void fy_diag_vreport(struct fy_diag *diag,
  870. }
  871. /* it will strip trailing newlines */
  872. - msg_str = alloca_vsprintf(fmt, ap);
  873. + alloca_vsprintf(&msg_str, fmt, ap);
  874. /* get the colors */
  875. fy_diag_get_error_colors(diag, fydrc->type, &color_start, &color_end, &white);
  876. if (name || (line > 0 && column > 0))
  877. - name_str = (line > 0 && column > 0) ?
  878. - alloca_sprintf("%s%s:%d:%d: ", white, name, line, column) :
  879. - alloca_sprintf("%s%s: ", white, name);
  880. + if (line > 0 && column > 0)
  881. + alloca_sprintf(&name_str, "%s%s:%d:%d: ", white, name, line, column);
  882. + else
  883. + alloca_sprintf(&name_str, "%s%s: ", white, name);
  884. if (!diag->collect_errors) {
  885. fy_diag_printf(diag, "%s" "%s%s: %s" "%s\n",
  886. diff --git a/src/lib/fy-diag.h b/src/lib/fy-diag.h
  887. index f19861d..bcf6568 100644
  888. --- a/src/lib/fy-diag.h
  889. +++ b/src/lib/fy-diag.h
  890. @@ -192,14 +192,14 @@ void fy_parser_diag_report(struct fy_parser *fyp,
  891. _FYP_TOKEN_DIAG(_fyp, \
  892. fy_token_create(FYTT_INPUT_MARKER, \
  893. fy_fill_atom_at((_fyp), (_adv), (_cnt), \
  894. - alloca(sizeof(struct fy_atom)))), \
  895. + FY_ALLOCA(sizeof(struct fy_atom)))), \
  896. _type, _module, _fmt, ## __VA_ARGS__)
  897. #define FYP_MARK_DIAG(_fyp, _sm, _em, _type, _module, _fmt, ...) \
  898. _FYP_TOKEN_DIAG(_fyp, \
  899. fy_token_create(FYTT_INPUT_MARKER, \
  900. fy_fill_atom_mark(((_fyp)), (_sm), (_em), \
  901. - alloca(sizeof(struct fy_atom)))), \
  902. + FY_ALLOCA(sizeof(struct fy_atom)))), \
  903. _type, _module, _fmt, ## __VA_ARGS__)
  904. #define FYP_NODE_DIAG(_fyp, _fyn, _type, _module, _fmt, ...) \
  905. @@ -333,14 +333,14 @@ void fy_reader_diag_report(struct fy_reader *fyr,
  906. _FYR_TOKEN_DIAG(_fyr, \
  907. fy_token_create(FYTT_INPUT_MARKER, \
  908. fy_reader_fill_atom_at((_fyr), (_adv), (_cnt), \
  909. - alloca(sizeof(struct fy_atom)))), \
  910. + FY_ALLOCA(sizeof(struct fy_atom)))), \
  911. _type, _module, _fmt, ## __VA_ARGS__)
  912. #define FYR_MARK_DIAG(_fyr, _sm, _em, _type, _module, _fmt, ...) \
  913. _FYR_TOKEN_DIAG(_fyr, \
  914. fy_token_create(FYTT_INPUT_MARKER, \
  915. fy_reader_fill_atom_mark(((_fyr)), (_sm), (_em), \
  916. - alloca(sizeof(struct fy_atom)))), \
  917. + FY_ALLOCA(sizeof(struct fy_atom)))), \
  918. _type, _module, _fmt, ## __VA_ARGS__)
  919. #define FYR_NODE_DIAG(_fyr, _fyn, _type, _module, _fmt, ...) \
  920. @@ -686,8 +686,8 @@ void fy_document_builder_diag_report(struct fy_document_builder *fydb,
  921. FYDB_TOKEN_DIAG(_fydb, _fyt, FYET_WARNING, _module, _fmt, ## __VA_ARGS__)
  922. /* alloca formatted print methods */
  923. -#define alloca_vsprintf(_fmt, _ap) \
  924. - ({ \
  925. +#define alloca_vsprintf(_res, _fmt, _ap) \
  926. + do { \
  927. const char *__fmt = (_fmt); \
  928. va_list _ap_orig; \
  929. int _size; \
  930. @@ -698,18 +698,18 @@ void fy_document_builder_diag_report(struct fy_document_builder *fydb,
  931. _size = vsnprintf(NULL, 0, __fmt, _ap_orig); \
  932. va_end(_ap_orig); \
  933. if (_size != -1) { \
  934. - _buf = alloca(_size + 1); \
  935. + _buf = FY_ALLOCA(_size + 1); \
  936. _sizew = vsnprintf(_buf, _size + 1, __fmt, _ap); \
  937. assert(_size == _sizew); \
  938. _s = _buf + strlen(_buf); \
  939. while (_s > _buf && _s[-1] == '\n') \
  940. *--_s = '\0'; \
  941. } \
  942. - _buf; \
  943. - })
  944. + *(_res) = _buf; \
  945. + } while(false)
  946. -#define alloca_sprintf(_fmt, ...) \
  947. - ({ \
  948. +#define alloca_sprintf(_res, _fmt, ...) \
  949. + do { \
  950. const char *__fmt = (_fmt); \
  951. int _size; \
  952. int _sizew __FY_DEBUG_UNUSED__; \
  953. @@ -717,14 +717,14 @@ void fy_document_builder_diag_report(struct fy_document_builder *fydb,
  954. \
  955. _size = snprintf(NULL, 0, __fmt, ## __VA_ARGS__); \
  956. if (_size != -1) { \
  957. - _buf = alloca(_size + 1); \
  958. + _buf = FY_ALLOCA(_size + 1); \
  959. _sizew = snprintf(_buf, _size + 1, __fmt, __VA_ARGS__); \
  960. assert(_size == _sizew); \
  961. _s = _buf + strlen(_buf); \
  962. while (_s > _buf && _s[-1] == '\n') \
  963. *--_s = '\0'; \
  964. } \
  965. - _buf; \
  966. - })
  967. + *(_res) = _buf; \
  968. + } while(false)
  969. #endif
  970. diff --git a/src/lib/fy-doc.c b/src/lib/fy-doc.c
  971. index 602264b..60768e6 100644
  972. --- a/src/lib/fy-doc.c
  973. +++ b/src/lib/fy-doc.c
  974. @@ -15,7 +15,9 @@
  975. #include <stdlib.h>
  976. #include <ctype.h>
  977. #include <errno.h>
  978. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  979. #include <unistd.h>
  980. +#endif
  981. #include <libfyaml.h>
  982. @@ -274,10 +276,13 @@ int fy_node_set_anchor_copy(struct fy_node *fyn, const char *text, size_t len)
  983. int fy_node_set_vanchorf(struct fy_node *fyn, const char *fmt, va_list ap)
  984. {
  985. + char *str;
  986. +
  987. if (!fyn || !fmt)
  988. return -1;
  989. - return fy_document_set_anchor_internal(fyn->fyd, fyn, alloca_vsprintf(fmt, ap), FY_NT, FYDSAF_COPY);
  990. + alloca_vsprintf(&str, fmt, ap);
  991. + return fy_document_set_anchor_internal(fyn->fyd, fyn, str, FY_NT, FYDSAF_COPY);
  992. }
  993. int fy_node_set_anchorf(struct fy_node *fyn, const char *fmt, ...)
  994. @@ -1264,11 +1269,11 @@ bool fy_node_compare_user(struct fy_node *fyn1, struct fy_node *fyn2,
  995. break;
  996. }
  997. - fynpp1 = alloca(sizeof(*fynpp1) * (count1 + 1));
  998. + fynpp1 = FY_ALLOCA(sizeof(*fynpp1) * (count1 + 1));
  999. fy_node_mapping_fill_array(fyn1, fynpp1, count1);
  1000. fy_node_mapping_perform_sort(fyn1, sort_fn, sort_fn_arg, fynpp1, count1);
  1001. - fynpp2 = alloca(sizeof(*fynpp2) * (count2 + 1));
  1002. + fynpp2 = FY_ALLOCA(sizeof(*fynpp2) * (count2 + 1));
  1003. fy_node_mapping_fill_array(fyn2, fynpp2, count2);
  1004. fy_node_mapping_perform_sort(fyn2, sort_fn, sort_fn_arg, fynpp2, count2);
  1005. @@ -3862,17 +3867,17 @@ bool fy_node_is_empty(struct fy_node *fyn)
  1006. return true;
  1007. }
  1008. -#define fy_node_walk_ctx_create_a(_max_depth, _mark) \
  1009. - ({ \
  1010. +#define fy_node_walk_ctx_create_a(_max_depth, _mark, _res) \
  1011. + do { \
  1012. unsigned int __max_depth = (_max_depth); \
  1013. struct fy_node_walk_ctx *_ctx; \
  1014. \
  1015. - _ctx = alloca(sizeof(*_ctx) + sizeof(struct fy_node *) * __max_depth); \
  1016. + _ctx = FY_ALLOCA(sizeof(*_ctx) + sizeof(struct fy_node *) * __max_depth); \
  1017. _ctx->max_depth = _max_depth; \
  1018. _ctx->next_slot = 0; \
  1019. _ctx->mark = (_mark); \
  1020. - _ctx; \
  1021. - })
  1022. + *(_res) = _ctx; \
  1023. + } while(false)
  1024. static inline void fy_node_walk_mark_start(struct fy_node_walk_ctx *ctx)
  1025. {
  1026. @@ -3944,7 +3949,7 @@ fy_node_follow_aliases(struct fy_node *fyn, enum fy_node_walk_flags flags, bool
  1027. while (fyn && fy_node_is_alias(fyn)) {
  1028. - // fprintf(stderr, "%s: %s\n", __func__, fy_node_get_path_alloca(fyn));
  1029. + // fprintf(stderr, "%s: %s\n", __func__, fy_node_get_path_FY_ALLOCA(fyn));
  1030. /* check for loops */
  1031. if (fy_ptr_node_list_contains(&nl, fyn)) {
  1032. @@ -4250,7 +4255,7 @@ fy_node_by_path_internal(struct fy_node *fyn,
  1033. if (has_json_key_esc) {
  1034. /* note that the escapes reduce the length, so allocating the
  1035. * same size is guaranteed safe */
  1036. - json_key = alloca(len + 1);
  1037. + json_key = FY_ALLOCA(len + 1);
  1038. ss = path;
  1039. ee = s;
  1040. @@ -4275,7 +4280,7 @@ fy_node_by_path_internal(struct fy_node *fyn,
  1041. /* URI encoded escaped */
  1042. if ((flags & FYNWF_URI_ENCODED) && memchr(path, '%', len)) {
  1043. /* escapes shrink, so safe to allocate as much */
  1044. - uri_path = alloca(len + 1);
  1045. + uri_path = FY_ALLOCA(len + 1);
  1046. ss = path;
  1047. ee = path + len;
  1048. @@ -4501,7 +4506,7 @@ fy_node_get_reference_internal(struct fy_node *fyn_base, struct fy_node *fyn, bo
  1049. text = fy_anchor_get_text(fya, &len);
  1050. if (!text)
  1051. return NULL;
  1052. - path2 = alloca(1 + len + 1);
  1053. + path2 = FY_ALLOCA(1 + len + 1);
  1054. path2[0] = '*';
  1055. memcpy(path2 + 1, text, len);
  1056. path2[len + 1] = '\0';
  1057. @@ -4513,10 +4518,10 @@ fy_node_get_reference_internal(struct fy_node *fyn_base, struct fy_node *fyn, bo
  1058. fya = fy_node_get_nearest_anchor(fyn);
  1059. if (!fya) {
  1060. /* no anchor, direct reference (ie return *\/foo\/bar */
  1061. - path = fy_node_get_path_alloca(fyn);
  1062. + fy_node_get_path_alloca(fyn, &path);
  1063. if (!*path)
  1064. return NULL;
  1065. - path2 = alloca(1 + strlen(path) + 1);
  1066. + path2 = FY_ALLOCA(1 + strlen(path) + 1);
  1067. path2[0] = '*';
  1068. strcpy(path2 + 1, path);
  1069. } else {
  1070. @@ -4524,25 +4529,25 @@ fy_node_get_reference_internal(struct fy_node *fyn_base, struct fy_node *fyn, bo
  1071. if (!text)
  1072. return NULL;
  1073. if (fy_anchor_node(fya) != fyn) {
  1074. - path = fy_node_get_path_relative_to_alloca(fy_anchor_node(fya), fyn);
  1075. + fy_node_get_path_relative_to_alloca(fy_anchor_node(fya), fyn, &path);
  1076. if (*path) {
  1077. /* we have a relative path */
  1078. - path2 = alloca(1 + len + 1 + strlen(path) + 1);
  1079. + path2 = FY_ALLOCA(1 + len + 1 + strlen(path) + 1);
  1080. path2[0] = '*';
  1081. memcpy(path2 + 1, text, len);
  1082. path2[len + 1] = '/';
  1083. memcpy(1 + path2 + len + 1, path, strlen(path) + 1);
  1084. } else {
  1085. /* absolute path */
  1086. - path = fy_node_get_path_alloca(fyn);
  1087. + fy_node_get_path_alloca(fyn, &path);
  1088. if (!*path)
  1089. return NULL;
  1090. - path2 = alloca(1 + strlen(path) + 1);
  1091. + path2 = FY_ALLOCA(1 + strlen(path) + 1);
  1092. path2[0] = '*';
  1093. strcpy(path2 + 1, path);
  1094. }
  1095. } else {
  1096. - path2 = alloca(1 + len + 1);
  1097. + path2 = FY_ALLOCA(1 + len + 1);
  1098. path2[0] = '*';
  1099. memcpy(path2 + 1, text, len);
  1100. path2[len + 1] = '\0';
  1101. @@ -4640,9 +4645,9 @@ bool fy_check_ref_loop(struct fy_document *fyd, struct fy_node *fyn,
  1102. break;
  1103. ctxn = ctx;
  1104. - if (!ctxn)
  1105. - ctxn = fy_node_walk_ctx_create_a(
  1106. - fy_node_walk_max_depth_from_flags(flags), FYNWF_REF_MARKER);
  1107. + if (!ctxn)
  1108. + fy_node_walk_ctx_create_a(
  1109. + fy_node_walk_max_depth_from_flags(flags), FYNWF_REF_MARKER, &ctxn);
  1110. if (!ctx) {
  1111. @@ -4816,7 +4821,7 @@ char *fy_node_get_path(struct fy_node *fyn)
  1112. track = NULL;
  1113. len = 0;
  1114. while ((path = fy_node_get_parent_address(fyn))) {
  1115. - newtrack = alloca(sizeof(*newtrack));
  1116. + newtrack = FY_ALLOCA(sizeof(*newtrack));
  1117. newtrack->prev = track;
  1118. newtrack->path = path;
  1119. @@ -4887,13 +4892,13 @@ char *fy_node_get_path_relative_to(struct fy_node *fyn_parent, struct fy_node *f
  1120. ppathlen = strlen(ppath);
  1121. if (pathlen > 0) {
  1122. - path2 = alloca(pathlen + 1 + ppathlen + 1);
  1123. + path2 = FY_ALLOCA(pathlen + 1 + ppathlen + 1);
  1124. memcpy(path2, ppath, ppathlen);
  1125. path2[ppathlen] = '/';
  1126. memcpy(path2 + ppathlen + 1, path, pathlen);
  1127. path2[ppathlen + 1 + pathlen] = '\0';
  1128. } else {
  1129. - path2 = alloca(ppathlen + 1);
  1130. + path2 = FY_ALLOCA(ppathlen + 1);
  1131. memcpy(path2, ppath, ppathlen);
  1132. path2[ppathlen] = '\0';
  1133. }
  1134. @@ -4935,11 +4940,12 @@ char *fy_node_get_short_path(struct fy_node *fyn)
  1135. if (!text)
  1136. return NULL;
  1137. - if (fyn_anchor == fyn)
  1138. - str = alloca_sprintf("*%.*s", (int)len, text);
  1139. - else
  1140. - str = alloca_sprintf("*%.*s/%s", (int)len, text,
  1141. - fy_node_get_path_relative_to_alloca(fyn_anchor, fyn));
  1142. + if (fyn_anchor == fyn) {
  1143. + alloca_sprintf(&str, "*%.*s", (int)len, text);
  1144. + } else {
  1145. + fy_node_get_path_relative_to_alloca(fyn_anchor, fyn, &path);
  1146. + alloca_sprintf(&str, "*%.*s/%s", (int)len, text, path);
  1147. + }
  1148. path = strdup(str);
  1149. return path;
  1150. @@ -5242,10 +5248,13 @@ struct fy_node *fy_node_create_alias_copy(struct fy_document *fyd, const char *d
  1151. struct fy_node *fy_node_create_vscalarf(struct fy_document *fyd, const char *fmt, va_list ap)
  1152. {
  1153. + char *str;
  1154. +
  1155. if (!fyd || !fmt)
  1156. return NULL;
  1157. - return fy_node_create_scalar_internal(fyd, alloca_vsprintf(fmt, ap), FY_NT, FYNCSIF_COPY);
  1158. + alloca_vsprintf(&str, fmt, ap);
  1159. + return fy_node_create_scalar_internal(fyd, str, FY_NT, FYNCSIF_COPY);
  1160. }
  1161. struct fy_node *fy_node_create_scalarf(struct fy_document *fyd, const char *fmt, ...)
  1162. @@ -5774,7 +5783,7 @@ void fy_node_mapping_perform_sort(struct fy_node *fyn_map,
  1163. def_arg.cmp_fn = NULL;
  1164. def_arg.arg = NULL;
  1165. }
  1166. - ctx.key_cmp = key_cmp ? : fy_node_mapping_sort_cmp_default;
  1167. + ctx.key_cmp = key_cmp ? key_cmp : fy_node_mapping_sort_cmp_default;
  1168. ctx.arg = key_cmp ? arg : &def_arg;
  1169. ctx.fynpp = fynpp;
  1170. ctx.count = count;
  1171. @@ -6043,7 +6052,7 @@ int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap)
  1172. goto err_out;
  1173. len = strlen(fmt);
  1174. - fmt_cpy = alloca(len + 1);
  1175. + fmt_cpy = FY_ALLOCA(len + 1);
  1176. memcpy(fmt_cpy, fmt, len + 1);
  1177. s = fmt_cpy;
  1178. e = s + len;
  1179. @@ -6110,7 +6119,7 @@ int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap)
  1180. /* allocate buffer it's smaller than the one we have already */
  1181. if (!value0 || value0_len < value_len) {
  1182. - value0 = alloca(value_len + 1);
  1183. + value0 = FY_ALLOCA(value_len + 1);
  1184. value0_len = value_len;
  1185. }
  1186. @@ -6461,7 +6470,7 @@ fy_node_hash_internal(struct fy_node *fyn, fy_hash_update_fn update_fn, void *st
  1187. case FYNT_MAPPING:
  1188. count = fy_node_mapping_item_count(fyn);
  1189. - fynpp = alloca(sizeof(*fynpp) * (count + 1));
  1190. + fynpp = FY_ALLOCA(sizeof(*fynpp) * (count + 1));
  1191. fy_node_mapping_fill_array(fyn, fynpp, count);
  1192. fy_node_mapping_perform_sort(fyn, NULL, NULL, fynpp, count);
  1193. diff --git a/src/lib/fy-dump.c b/src/lib/fy-dump.c
  1194. index 24fb8c9..fe6a231 100644
  1195. --- a/src/lib/fy-dump.c
  1196. +++ b/src/lib/fy-dump.c
  1197. @@ -134,7 +134,7 @@ char *fy_token_dump_format(struct fy_token *fyt, char *buf, size_t bufsz)
  1198. /* not too large */
  1199. if (size > 20)
  1200. size = 20;
  1201. - text = fy_utf8_format_text_a(text, size, fyue_doublequote);
  1202. + fy_utf8_format_text_a(text, size, fyue_doublequote, &text);
  1203. size = strlen(text);
  1204. if (size > 10) {
  1205. sfx = "...\"";
  1206. diff --git a/src/lib/fy-emit.c b/src/lib/fy-emit.c
  1207. index 36d8d8e..9f2e27e 100644
  1208. --- a/src/lib/fy-emit.c
  1209. +++ b/src/lib/fy-emit.c
  1210. @@ -236,7 +236,7 @@ void fy_emit_vprintf(struct fy_emitter *emit, enum fy_emitter_write_type type, c
  1211. if (size < 0)
  1212. return;
  1213. - str = alloca(size + 1);
  1214. + str = FY_ALLOCA(size + 1);
  1215. size = vsnprintf(str, size + 1, fmt, ap2);
  1216. if (size < 0)
  1217. return;
  1218. @@ -272,7 +272,7 @@ void fy_emit_write_indent(struct fy_emitter *emit, int indent)
  1219. if (emit->column < indent) {
  1220. len = indent - emit->column;
  1221. - ws = alloca(len + 1);
  1222. + ws = FY_ALLOCA(len + 1);
  1223. memset(ws, ' ', len);
  1224. ws[len] = '\0';
  1225. fy_emit_write(emit, fyewt_indent, ws, len);
  1226. @@ -541,7 +541,7 @@ void fy_emit_token_comment(struct fy_emitter *emit, struct fy_token *fyt, int fl
  1227. if (len < 0)
  1228. return;
  1229. - text = alloca(len + 1);
  1230. + text = FY_ALLOCA(len + 1);
  1231. if (placement == fycp_top || placement == fycp_bottom) {
  1232. fy_emit_write_indent(emit, indent);
  1233. @@ -1659,7 +1659,7 @@ void fy_emit_mapping(struct fy_emitter *emit, struct fy_node *fyn, int flags, in
  1234. "malloc() failed");
  1235. used_malloc = true;
  1236. } else
  1237. - fynpp = alloca((count + 1) * sizeof(*fynpp));
  1238. + fynpp = FY_ALLOCA((count + 1) * sizeof(*fynpp));
  1239. /* fill (removing empty KVs) */
  1240. i = 0;
  1241. diff --git a/src/lib/fy-parse.c b/src/lib/fy-parse.c
  1242. index 16ce784..3a65a8c 100644
  1243. --- a/src/lib/fy-parse.c
  1244. +++ b/src/lib/fy-parse.c
  1245. @@ -548,7 +548,7 @@ int fy_parse_version_directive(struct fy_parser *fyp, struct fy_token *fyt, bool
  1246. vs = fy_token_get_text(fyt, &vs_len);
  1247. fyp_error_check(fyp, vs, err_out,
  1248. "fy_token_get_text() failed");
  1249. - vs0 = alloca(vs_len + 1);
  1250. + vs0 = FY_ALLOCA(vs_len + 1);
  1251. memcpy(vs0, vs, vs_len);
  1252. vs0[vs_len] = '\0';
  1253. @@ -671,7 +671,7 @@ static int fy_parser_reader_file_open(struct fy_reader *fyr, const char *name)
  1254. }
  1255. len = strlen(fyp->cfg.search_path);
  1256. - sp = alloca(len + 1);
  1257. + sp = FY_ALLOCA(len + 1);
  1258. memcpy(sp, fyp->cfg.search_path, len + 1);
  1259. /* allocate the maximum possible so that we don't deal with reallocations */
  1260. @@ -1031,6 +1031,7 @@ int fy_scan_to_next_token(struct fy_parser *fyp)
  1261. ssize_t offset;
  1262. struct fy_atom *handle;
  1263. struct fy_reader *fyr;
  1264. + char *str;
  1265. fyr = fyp->reader;
  1266. @@ -1163,8 +1164,8 @@ int fy_scan_to_next_token(struct fy_parser *fyp)
  1267. fyp_error_check(fyp, !rc, err_out_rc,
  1268. "fy_reader_input_scan_token_mark() failed");
  1269. - fyp_scan_debug(fyp, "%s: next token starts with c='%s'", __func__,
  1270. - fy_utf8_format_a(fy_parse_peek(fyp), fyue_singlequote));
  1271. + fy_utf8_format_a(fy_parse_peek(fyp), fyue_singlequote, &str);
  1272. + fyp_scan_debug(fyp, "%s: next token starts with c='%s'", __func__, str);
  1273. return 0;
  1274. }
  1275. @@ -3171,13 +3172,15 @@ int fy_fetch_block_scalar(struct fy_parser *fyp, bool is_literal, int c)
  1276. int actual_lb_length, pending_lb_length;
  1277. struct fy_mark indicator_mark;
  1278. bool generated_indent;
  1279. + char *str;
  1280. #ifdef ATOM_SIZE_CHECK
  1281. size_t tlength;
  1282. #endif
  1283. + fy_utf8_format_a(c, fyue_singlequote, &str);
  1284. fyp_error_check(fyp, c == '|' || c == '>', err_out,
  1285. "bad start of block scalar ('%s')",
  1286. - fy_utf8_format_a(c, fyue_singlequote));
  1287. + str);
  1288. fy_get_mark(fyp, &indicator_mark);
  1289. @@ -3565,9 +3568,10 @@ int fy_fetch_block_scalar(struct fy_parser *fyp, bool is_literal, int c)
  1290. #ifdef ATOM_SIZE_CHECK
  1291. tlength = fy_atom_format_text_length(&handle);
  1292. if (tlength != length) {
  1293. + fy_utf8_format_text_a(fy_atom_data(&handle), fy_atom_size(&handle), fyue_doublequote, &str);
  1294. fyp_warning(fyp, "%s: storage hint calculation failed real %zu != hint %zu - \"%s\"", __func__,
  1295. tlength, length,
  1296. - fy_utf8_format_text_a(fy_atom_data(&handle), fy_atom_size(&handle), fyue_doublequote));
  1297. + str);
  1298. length = tlength;
  1299. }
  1300. #endif
  1301. @@ -3618,6 +3622,7 @@ int fy_reader_fetch_flow_scalar_handle(struct fy_reader *fyr, int c, int indent,
  1302. size_t escbuf_len;
  1303. enum fy_utf8_escape esc_mode;
  1304. const char *ep;
  1305. + char *str;
  1306. #ifdef ATOM_SIZE_CHECK
  1307. size_t tlength;
  1308. #endif
  1309. @@ -3627,9 +3632,10 @@ int fy_reader_fetch_flow_scalar_handle(struct fy_reader *fyr, int c, int indent,
  1310. is_single = c == '\'';
  1311. end_c = c;
  1312. + fy_utf8_format_a(c, fyue_singlequote, &str);
  1313. fyr_error_check(fyr, c == '\'' || c == '"', err_out,
  1314. "bad start of flow scalar ('%s')",
  1315. - fy_utf8_format_a(c, fyue_singlequote));
  1316. + str);
  1317. fy_reader_get_mark(fyr, &mark);
  1318. @@ -3876,11 +3882,12 @@ int fy_reader_fetch_flow_scalar_handle(struct fy_reader *fyr, int c, int indent,
  1319. ep = escbuf;
  1320. + fy_utf8_format_a(c, fyue_singlequote, &str);
  1321. value = fy_utf8_parse_escape(&ep, escbuf_len, esc_mode);
  1322. FYR_PARSE_ERROR_CHECK(fyr, 0, 2, FYEM_SCAN,
  1323. value >= 0, err_out,
  1324. "invalid escape '%s' in %s string",
  1325. - fy_utf8_format_a(c, fyue_singlequote),
  1326. + str,
  1327. is_single ? "single-quoted" : "double-quoted");
  1328. fy_reader_advance_by(fyr, 2);
  1329. @@ -4003,10 +4010,11 @@ int fy_reader_fetch_flow_scalar_handle(struct fy_reader *fyr, int c, int indent,
  1330. #ifdef ATOM_SIZE_CHECK
  1331. tlength = fy_atom_format_text_length(handle);
  1332. + fy_utf8_format_text_a(fy_atom_data(handle), fy_atom_size(handle), fyue_doublequote, &str);
  1333. if (tlength != length) {
  1334. fyr_warning(fyr, "%s: storage hint calculation failed real %zu != hint %zu - \"%s\"", __func__,
  1335. tlength, length,
  1336. - fy_utf8_format_text_a(fy_atom_data(handle), fy_atom_size(handle), fyue_doublequote));
  1337. + str);
  1338. length = tlength;
  1339. }
  1340. #endif
  1341. @@ -4034,6 +4042,7 @@ int fy_reader_fetch_plain_scalar_handle(struct fy_reader *fyr, int c, int indent
  1342. struct fy_mark mark, last_mark;
  1343. bool is_multiline, has_lb, has_ws, ends_with_eof;
  1344. bool has_json_esc;
  1345. + char *str;
  1346. #ifdef ATOM_SIZE_CHECK
  1347. size_t tlength;
  1348. #endif
  1349. @@ -4290,9 +4299,10 @@ int fy_reader_fetch_plain_scalar_handle(struct fy_reader *fyr, int c, int indent
  1350. #ifdef ATOM_SIZE_CHECK
  1351. tlength = fy_atom_format_text_length(handle);
  1352. if (tlength != length) {
  1353. + fy_utf8_format_text_a(fy_atom_data(handle), fy_atom_size(handle), fyue_doublequote, &str);
  1354. fyr_warning(fyr, "%s: storage hint calculation failed real %zu != hint %zu - \"%s\"", __func__,
  1355. tlength, length,
  1356. - fy_utf8_format_text_a(fy_atom_data(handle), fy_atom_size(handle), fyue_doublequote));
  1357. + str);
  1358. length = tlength;
  1359. }
  1360. #endif
  1361. @@ -4330,12 +4340,14 @@ int fy_fetch_flow_scalar(struct fy_parser *fyp, int c)
  1362. struct fy_simple_key_mark skm;
  1363. struct fy_token *fyt;
  1364. int i = 0, rc = -1;
  1365. + char *str;
  1366. is_single = c == '\'';
  1367. + fy_utf8_format_a(c, fyue_singlequote, &str);
  1368. fyp_error_check(fyp, c == '\'' || c == '"', err_out,
  1369. "bad start of flow scalar ('%s')",
  1370. - fy_utf8_format_a(c, fyue_singlequote));
  1371. + str);
  1372. FYP_PARSE_ERROR_CHECK(fyp, 0, 1, FYEM_SCAN,
  1373. fy_flow_indent_check(fyp), err_out,
  1374. diff --git a/src/lib/fy-parse.h b/src/lib/fy-parse.h
  1375. index 11e71bf..899800a 100644
  1376. --- a/src/lib/fy-parse.h
  1377. +++ b/src/lib/fy-parse.h
  1378. @@ -534,7 +534,7 @@ fy_parser_set_flow_only_mode(struct fy_parser *fyp, bool flow_only_mode)
  1379. }
  1380. #define fy_fill_atom_a(_fyp, _advance) \
  1381. - fy_fill_atom((_fyp), (_advance), alloca(sizeof(struct fy_atom)))
  1382. + fy_fill_atom((_fyp), (_advance), FY_ALLOCA(sizeof(struct fy_atom)))
  1383. struct fy_token *fy_token_vqueue(struct fy_parser *fyp, enum fy_token_type type, va_list ap);
  1384. struct fy_token *fy_token_queue(struct fy_parser *fyp, enum fy_token_type type, ...);
  1385. diff --git a/src/lib/fy-token.h b/src/lib/fy-token.h
  1386. index a464955..8cd4383 100644
  1387. --- a/src/lib/fy-token.h
  1388. +++ b/src/lib/fy-token.h
  1389. @@ -448,20 +448,20 @@ unsigned int fy_analyze_scalar_content(const char *data, size_t size,
  1390. /* must be freed */
  1391. char *fy_token_debug_text(struct fy_token *fyt);
  1392. -#define fy_token_debug_text_a(_fyt) \
  1393. - ({ \
  1394. +#define fy_token_debug_text_a(_fyt, _res) \
  1395. + do { \
  1396. struct fy_token *__fyt = (_fyt); \
  1397. char *_buf, *_rbuf = ""; \
  1398. size_t _len; \
  1399. _buf = fy_token_debug_text(__fyt); \
  1400. if (_buf) { \
  1401. _len = strlen(_buf); \
  1402. - _rbuf = alloca(_len + 1); \
  1403. + _rbuf = FY_ALLOCA(_len + 1); \
  1404. memcpy(_rbuf, _buf, _len + 1); \
  1405. free(_buf); \
  1406. } \
  1407. - _rbuf; \
  1408. - })
  1409. + *(_res) = _rbuf; \
  1410. + } while(false)
  1411. int fy_token_memcmp(struct fy_token *fyt, const void *ptr, size_t len);
  1412. int fy_token_strcmp(struct fy_token *fyt, const char *str);
  1413. diff --git a/src/lib/fy-utf8.h b/src/lib/fy-utf8.h
  1414. index b879706..9dc0825 100644
  1415. --- a/src/lib/fy-utf8.h
  1416. +++ b/src/lib/fy-utf8.h
  1417. @@ -148,11 +148,11 @@ static inline bool fy_utf8_escape_is_any_doublequote(enum fy_utf8_escape esc)
  1418. char *fy_utf8_format(int c, char *buf, enum fy_utf8_escape esc);
  1419. -#define fy_utf8_format_a(_c, _esc) \
  1420. - ({ \
  1421. - char *_buf = alloca(FY_UTF8_FORMAT_BUFMIN); \
  1422. - fy_utf8_format((_c), _buf, _esc); \
  1423. - })
  1424. +#define fy_utf8_format_a(_c, _esc, _res) \
  1425. + do { \
  1426. + char *_buf = FY_ALLOCA(FY_UTF8_FORMAT_BUFMIN); \
  1427. + *(_res) = fy_utf8_format((_c), _buf, _esc); \
  1428. + } while(false)
  1429. int fy_utf8_format_text_length(const char *buf, size_t len,
  1430. enum fy_utf8_escape esc);
  1431. @@ -160,15 +160,15 @@ char *fy_utf8_format_text(const char *buf, size_t len,
  1432. char *out, size_t maxsz,
  1433. enum fy_utf8_escape esc);
  1434. -#define fy_utf8_format_text_a(_buf, _len, _esc) \
  1435. - ({ \
  1436. +#define fy_utf8_format_text_a(_buf, _len, _esc, _res) \
  1437. + do { \
  1438. const char *__buf = (_buf); \
  1439. size_t __len = (_len); \
  1440. enum fy_utf8_escape __esc = (_esc); \
  1441. size_t _outsz = fy_utf8_format_text_length(__buf, __len, __esc); \
  1442. - char *_out = alloca(_outsz + 1); \
  1443. - fy_utf8_format_text(__buf, __len, _out, _outsz, __esc); \
  1444. - })
  1445. + char *_out = FY_ALLOCA(_outsz + 1); \
  1446. + *(_res) = fy_utf8_format_text(__buf, __len, _out, _outsz, __esc); \
  1447. + } while(false)
  1448. char *fy_utf8_format_text_alloc(const char *buf, size_t len, enum fy_utf8_escape esc);
  1449. diff --git a/src/lib/fy-walk.c b/src/lib/fy-walk.c
  1450. index 736704d..5e7cda3 100644
  1451. --- a/src/lib/fy-walk.c
  1452. +++ b/src/lib/fy-walk.c
  1453. @@ -3092,6 +3092,9 @@ fy_path_parse_expression(struct fy_path_parser *fypp)
  1454. struct fy_path_expr *expr, *expr_top, *exprt;
  1455. enum fy_expr_mode old_scan_mode, prev_scan_mode;
  1456. int ret, rc;
  1457. +#ifdef DEBUG_EXPR
  1458. + char *dbg;
  1459. +#endif
  1460. /* the parser must be in the correct state */
  1461. if (!fypp || fy_expr_stack_size(&fypp->operators) > 0 || fy_expr_stack_size(&fypp->operands) > 0)
  1462. @@ -3117,7 +3120,8 @@ fy_path_parse_expression(struct fy_path_parser *fypp)
  1463. break;
  1464. #ifdef DEBUG_EXPR
  1465. - FYR_TOKEN_DIAG(fyr, fyt, FYET_NOTICE, FYEM_PARSE, "next token %s", fy_token_debug_text_a(fyt));
  1466. + fy_token_debug_text_a(fyt, &dbg);
  1467. + FYR_TOKEN_DIAG(fyr, fyt, FYET_NOTICE, FYEM_PARSE, "next token %s", dbg);
  1468. #endif
  1469. fytt = fyt->type;
  1470. @@ -4663,7 +4667,7 @@ fy_path_expr_execute(struct fy_path_exec *fypx, int level, struct fy_path_expr *
  1471. /* execute the arguments */
  1472. nargs = expr->fym->nargs;
  1473. if (nargs > 0) {
  1474. - fwr_args = alloca(sizeof(*fwr_args) * nargs);
  1475. + fwr_args = FY_ALLOCA(sizeof(*fwr_args) * nargs);
  1476. memset(fwr_args, 0, sizeof(*fwr_args) * nargs);
  1477. for (i = 0, exprt = fy_path_expr_list_head(&expr->children); exprt;
  1478. exprt = fy_path_expr_next(&expr->children, exprt), i++) {
  1479. @@ -4995,6 +4999,7 @@ fy_node_alias_resolve_by_ypath_result(struct fy_node *fyn)
  1480. struct fy_anchor *fya;
  1481. struct fy_path_exec *fypx = NULL;
  1482. int rc;
  1483. + char* path;
  1484. if (!fyn || !fy_node_is_alias(fyn))
  1485. return NULL;
  1486. @@ -5026,9 +5031,10 @@ fy_node_alias_resolve_by_ypath_result(struct fy_node *fyn)
  1487. assert(pxdd);
  1488. if (pxnd->traversals++ > 0) {
  1489. + fy_node_get_path_alloca(fyn, &path);
  1490. FYD_NODE_ERROR(fyd, fyn, FYEM_DOC,
  1491. "recursive reference detected at %s\n",
  1492. - fy_node_get_path_alloca(fyn));
  1493. + path);
  1494. pxnd->traversals--;
  1495. return NULL;
  1496. }
  1497. diff --git a/src/tool/fy-tool.c b/src/tool/fy-tool.c
  1498. index a975bec..1c7b26c 100644
  1499. --- a/src/tool/fy-tool.c
  1500. +++ b/src/tool/fy-tool.c
  1501. @@ -431,7 +431,7 @@ int apply_flags_option(const char *arg, unsigned int *flagsp,
  1502. sn = e;
  1503. len = sn - s;
  1504. - targ = alloca(len + 1);
  1505. + targ = FY_ALLOCA(len + 1);
  1506. memcpy(targ, s, len);
  1507. targ[len] = '\0';
  1508. @@ -1256,8 +1256,10 @@ compose_process_event(struct fy_parser *fyp, struct fy_event *fye, struct fy_pat
  1509. struct fy_node *fyn, *fyn_parent;
  1510. struct fy_node_pair *fynp;
  1511. int rc;
  1512. + char* path_text;
  1513. if (cd->verbose) {
  1514. + fy_path_get_text_alloca(path, &path_text);
  1515. fprintf(stderr, "%s: %c%c%c%c%c %3d - %-32s\n",
  1516. fy_event_type_get_text(fye->type),
  1517. fy_path_in_root(path) ? 'R' : '-',
  1518. @@ -1267,7 +1269,7 @@ compose_process_event(struct fy_parser *fyp, struct fy_event *fye, struct fy_pat
  1519. fy_path_in_mapping_value(path) ? 'V' : '-',
  1520. fy_path_in_collection_root(path) ? '/' : '-',
  1521. fy_path_depth(path),
  1522. - fy_path_get_text_alloca(path));
  1523. + path_text);
  1524. }
  1525. switch (fye->type) {
  1526. @@ -1543,7 +1545,7 @@ int main(int argc, char *argv[])
  1527. lopts, &lidx)) != -1) {
  1528. switch (opt) {
  1529. case 'I':
  1530. - tmp = alloca(strlen(cfg.search_path) + 1 + strlen(optarg) + 1);
  1531. + tmp = FY_ALLOCA(strlen(cfg.search_path) + 1 + strlen(optarg) + 1);
  1532. s = tmp;
  1533. strcpy(s, cfg.search_path);
  1534. if (cfg.search_path && cfg.search_path[0]) {
  1535. diff --git a/src/valgrind/fy-valgrind.h b/src/valgrind/fy-valgrind.h
  1536. index 0c7074b..263b262 100644
  1537. --- a/src/valgrind/fy-valgrind.h
  1538. +++ b/src/valgrind/fy-valgrind.h
  1539. @@ -21,6 +21,8 @@
  1540. #include <limits.h>
  1541. #include <stdio.h>
  1542. +#include <libfyaml.h>
  1543. +
  1544. enum fy_valgrind_tool {
  1545. fyvt_none,
  1546. fyvt_valgrind,
  1547. @@ -106,7 +108,7 @@ static inline void fy_valgrind_check(int *argcp, char ***argvp)
  1548. case fyvt_valgrind:
  1549. va_argc = 1 + 4 + argc - 1;
  1550. - va_argv = alloca(sizeof(*va_argv) * (va_argc + 1));
  1551. + va_argv = FY_ALLOCA(sizeof(*va_argv) * (va_argc + 1));
  1552. va_argv[0] = valgrind;
  1553. va_argv[1] = "--leak-check=full";
  1554. va_argv[2] = "--track-origins=yes";
  1555. @@ -117,7 +119,7 @@ static inline void fy_valgrind_check(int *argcp, char ***argvp)
  1556. case fyvt_callgrind:
  1557. va_argc = 1 + 5 + argc - 1;
  1558. - va_argv = alloca(sizeof(*va_argv) * (va_argc + 1));
  1559. + va_argv = FY_ALLOCA(sizeof(*va_argv) * (va_argc + 1));
  1560. va_argv[0] = valgrind;
  1561. va_argv[1] = "--tool=callgrind";
  1562. va_argv[2] = "--dump-instr=yes";
  1563. @@ -129,7 +131,7 @@ static inline void fy_valgrind_check(int *argcp, char ***argvp)
  1564. case fyvt_massif:
  1565. va_argc = 1 + 2 + argc - 1;
  1566. - va_argv = alloca(sizeof(*va_argv) * (va_argc + 1));
  1567. + va_argv = FY_ALLOCA(sizeof(*va_argv) * (va_argc + 1));
  1568. va_argv[0] = valgrind;
  1569. va_argv[1] = "--tool=massif";
  1570. va_argv[2] = argv0;
  1571. diff --git a/test/libfyaml-test-core.c b/test/libfyaml-test-core.c
  1572. index d4cd39f..e9aa7dd 100644
  1573. --- a/test/libfyaml-test-core.c
  1574. +++ b/test/libfyaml-test-core.c
  1575. @@ -461,27 +461,27 @@ START_TEST(doc_short_path)
  1576. fyn_baz = fy_node_by_path(fyn_root, "/foo/bar/2/baz", FY_NT, FYNWF_DONT_FOLLOW);
  1577. ck_assert_ptr_ne(fyn_baz, NULL);
  1578. - str = fy_node_get_short_path_alloca(fyn_root);
  1579. + fy_node_get_short_path_alloca(fyn_root, &str);
  1580. ck_assert_ptr_ne(str, NULL);
  1581. ck_assert_str_eq(str, "*r");
  1582. ck_assert_ptr_eq(fy_node_by_path(fy_document_root(fyd), str, FY_NT, FYNWF_FOLLOW), fyn_root);
  1583. - str = fy_node_get_short_path_alloca(fyn_foo);
  1584. + fy_node_get_short_path_alloca(fyn_foo, &str);
  1585. ck_assert_ptr_ne(str, NULL);
  1586. ck_assert_str_eq(str, "*f");
  1587. ck_assert_ptr_eq(fy_node_by_path(fy_document_root(fyd), str, FY_NT, FYNWF_FOLLOW), fyn_foo);
  1588. - str = fy_node_get_short_path_alloca(fyn_notfoo);
  1589. + fy_node_get_short_path_alloca(fyn_notfoo, &str);
  1590. ck_assert_ptr_ne(str, NULL);
  1591. ck_assert_str_eq(str, "*r/notfoo");
  1592. ck_assert_ptr_eq(fy_node_by_path(fy_document_root(fyd), str, FY_NT, FYNWF_FOLLOW), fyn_notfoo);
  1593. - str = fy_node_get_short_path_alloca(fyn_bar);
  1594. + fy_node_get_short_path_alloca(fyn_bar, &str);
  1595. ck_assert_ptr_ne(str, NULL);
  1596. ck_assert_str_eq(str, "*f/bar");
  1597. ck_assert_ptr_eq(fy_node_by_path(fy_document_root(fyd), str, FY_NT, FYNWF_FOLLOW), fyn_bar);
  1598. - str = fy_node_get_short_path_alloca(fyn_baz);
  1599. + fy_node_get_short_path_alloca(fyn_baz, &str);
  1600. ck_assert_ptr_ne(str, NULL);
  1601. ck_assert_str_eq(str, "*f/bar/2/baz");
  1602. ck_assert_ptr_eq(fy_node_by_path(fy_document_root(fyd), str, FY_NT, FYNWF_FOLLOW), fyn_baz);
  1603. @@ -1843,7 +1843,7 @@ START_TEST(alloca_check)
  1604. /* fy_emit_document_to_string*() */
  1605. buf = fy_emit_document_to_string(fyd, FYECF_MODE_FLOW_ONELINE);
  1606. ck_assert_ptr_ne(buf, NULL);
  1607. - abuf = fy_emit_document_to_string_alloca(fyd, FYECF_MODE_FLOW_ONELINE);
  1608. + fy_emit_document_to_string_alloca(fyd, FYECF_MODE_FLOW_ONELINE, &abuf);
  1609. ck_assert_ptr_ne(abuf, NULL);
  1610. ck_assert_str_eq(buf, abuf);
  1611. free(buf);
  1612. @@ -1851,7 +1851,7 @@ START_TEST(alloca_check)
  1613. /* fy_emit_node_to_string*() */
  1614. buf = fy_emit_node_to_string(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW), FYECF_MODE_FLOW_ONELINE);
  1615. ck_assert_ptr_ne(buf, NULL);
  1616. - abuf = fy_emit_node_to_string_alloca(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW), FYECF_MODE_FLOW_ONELINE);
  1617. + fy_emit_node_to_string_alloca(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW), FYECF_MODE_FLOW_ONELINE, &abuf);
  1618. ck_assert_ptr_ne(abuf, NULL);
  1619. ck_assert_str_eq(buf, abuf);
  1620. free(buf);
  1621. @@ -1860,14 +1860,14 @@ START_TEST(alloca_check)
  1622. buf = fy_node_get_path(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW));
  1623. ck_assert_ptr_ne(buf, NULL);
  1624. ck_assert_str_eq(buf, "/foo");
  1625. - abuf = fy_node_get_path_alloca(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW));
  1626. + fy_node_get_path_alloca(fy_node_by_path(fy_document_root(fyd), "/foo", FY_NT, FYNWF_DONT_FOLLOW), &abuf);
  1627. ck_assert_ptr_ne(abuf, NULL);
  1628. ck_assert_str_eq(abuf, "/foo");
  1629. ck_assert_str_eq(buf, abuf);
  1630. free(buf);
  1631. /* check that a bad path is "" */
  1632. - abuf = fy_node_get_path_alloca(NULL);
  1633. + fy_node_get_path_alloca(NULL, &abuf);
  1634. ck_assert_ptr_ne(abuf, NULL);
  1635. ck_assert_str_eq(abuf, "");
  1636. From 67a4075058e69cc7c8360223df8d973b83ff1543 Mon Sep 17 00:00:00 2001
  1637. From: Innokentii Mokin <innokentii@yandex-team.ru>
  1638. Date: Sun, 29 Jan 2023 00:26:36 +0300
  1639. Subject: [PATCH 2/7] replace unportable gcc extensions
  1640. ---
  1641. src/internal/libfyaml-parser.c | 26 ++++++++++-----------
  1642. src/lib/fy-diag.c | 2 +-
  1643. src/lib/fy-doc.c | 4 ++--
  1644. src/lib/fy-doc.h | 4 ++++
  1645. src/lib/fy-docbuilder.c | 2 ++
  1646. src/lib/fy-dump.c | 2 ++
  1647. src/lib/fy-emit.c | 8 +++++--
  1648. src/lib/fy-input.c | 42 +++++++++++++++++++++-------------
  1649. src/lib/fy-input.h | 2 +-
  1650. src/lib/fy-parse.c | 2 +-
  1651. src/lib/fy-parse.h | 2 +-
  1652. 11 files changed, 59 insertions(+), 37 deletions(-)
  1653. diff --git a/src/internal/libfyaml-parser.c b/src/internal/libfyaml-parser.c
  1654. index 9563208..14847d6 100644
  1655. --- a/src/internal/libfyaml-parser.c
  1656. +++ b/src/internal/libfyaml-parser.c
  1657. @@ -327,9 +327,9 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  1658. if (fye->scalar.value)
  1659. fy_token_get_esc_text_a(fye->scalar.value, &value);
  1660. printf("%-14s%s|%s%s%s%s%s%s '%s'\n", "SCALAR", mm,
  1661. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1662. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "",
  1663. - value ? : "");
  1664. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1665. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "",
  1666. + value ? value : "");
  1667. break;
  1668. case FYET_SEQUENCE_START:
  1669. if (fye->sequence_start.anchor)
  1670. @@ -337,8 +337,8 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  1671. if (fye->sequence_start.tag)
  1672. fy_token_get_esc_text_a(fye->sequence_start.tag, &tag);
  1673. printf("%-14s%s|%s%s%s%s%s%s\n", "SEQUENCE_START", mm,
  1674. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1675. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  1676. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1677. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "");
  1678. break;
  1679. case FYET_SEQUENCE_END:
  1680. printf("%-14s%s|\n", "SEQUENCE_END", mm);
  1681. @@ -349,8 +349,8 @@ void dump_event(struct fy_parser *fyp, struct fy_event *fye)
  1682. if (fye->mapping_start.tag)
  1683. fy_token_get_esc_text_a(fye->mapping_start.tag, &tag);
  1684. printf("%-14s%s|%s%s%s%s%s%s\n", "MAPPING_START", mm,
  1685. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1686. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  1687. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1688. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "");
  1689. break;
  1690. case FYET_MAPPING_END:
  1691. printf("%-14s%s|\n", "MAPPING_END", mm);
  1692. @@ -1263,8 +1263,8 @@ void dump_libyaml_event(yaml_event_t *event)
  1693. txt2esc_a((char *)event->data.scalar.tag, -1, &tag);
  1694. txt2esc_a((char *)event->data.scalar.value, -1, &value);
  1695. printf("%-14s%s|%s%s%s%s%s%s '%s'\n", "SCALAR", mm,
  1696. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1697. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "",
  1698. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1699. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "",
  1700. value);
  1701. break;
  1702. case YAML_SEQUENCE_START_EVENT:
  1703. @@ -1273,8 +1273,8 @@ void dump_libyaml_event(yaml_event_t *event)
  1704. if (event->data.sequence_start.tag)
  1705. txt2esc_a((char *)event->data.sequence_start.tag, -1, &tag);
  1706. printf("%-14s%s|%s%s%s%s%s%s\n", "SEQUENCE_START", mm,
  1707. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1708. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  1709. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1710. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "");
  1711. break;
  1712. case YAML_SEQUENCE_END_EVENT:
  1713. printf("%-14s%s|\n", "SEQUENCE_END", mm);
  1714. @@ -1285,8 +1285,8 @@ void dump_libyaml_event(yaml_event_t *event)
  1715. if (event->data.mapping_start.tag)
  1716. txt2esc_a((char *)event->data.mapping_start.tag, -1, &tag);
  1717. printf("%-14s%s|%s%s%s%s%s%s\n", "MAPPING_START", mm,
  1718. - anchor ? " anchor='" : "", anchor ? : "", anchor ? "'" : "",
  1719. - tag ? " tag='" : "", tag ? : "", tag ? "'" : "");
  1720. + anchor ? " anchor='" : "", anchor ? anchor : "", anchor ? "'" : "",
  1721. + tag ? " tag='" : "", tag ? tag : "", tag ? "'" : "");
  1722. break;
  1723. case YAML_MAPPING_END_EVENT:
  1724. printf("%-14s%s|\n", "MAPPING_END", mm);
  1725. diff --git a/src/lib/fy-diag.c b/src/lib/fy-diag.c
  1726. index aa1e4cd..ee6a77c 100644
  1727. --- a/src/lib/fy-diag.c
  1728. +++ b/src/lib/fy-diag.c
  1729. @@ -873,7 +873,7 @@ void fy_diag_vreport(struct fy_diag *diag,
  1730. if (!diag->collect_errors) {
  1731. fy_diag_printf(diag, "%s" "%s%s: %s" "%s\n",
  1732. - name_str ? : "",
  1733. + name_str ? name_str : "",
  1734. color_start, fy_error_type_to_string(fydrc->type), color_end,
  1735. msg_str);
  1736. diff --git a/src/lib/fy-doc.c b/src/lib/fy-doc.c
  1737. index 60768e6..22e0c51 100644
  1738. --- a/src/lib/fy-doc.c
  1739. +++ b/src/lib/fy-doc.c
  1740. @@ -5666,7 +5666,7 @@ const void *a, const void *b, void *arg
  1741. }
  1742. /* not! thread safe! */
  1743. -#if !defined(HAVE_QSORT_R) || !HAVE_QSORT_R || defined(__EMSCRIPTEN__)
  1744. +#if !defined(HAVE_QSORT_R) || !HAVE_QSORT_R || defined(__EMSCRIPTEN__) || defined(_MSC_VER)
  1745. static struct fy_node_mapping_sort_ctx *fy_node_mapping_sort_ctx_no_qsort_r;
  1746. static int fy_node_mapping_sort_cmp_no_qsort_r(const void *a, const void *b)
  1747. @@ -5787,7 +5787,7 @@ void fy_node_mapping_perform_sort(struct fy_node *fyn_map,
  1748. ctx.arg = key_cmp ? arg : &def_arg;
  1749. ctx.fynpp = fynpp;
  1750. ctx.count = count;
  1751. -#if defined(HAVE_QSORT_R) && HAVE_QSORT_R && !defined(__EMSCRIPTEN__)
  1752. +#if defined(HAVE_QSORT_R) && HAVE_QSORT_R && !defined(__EMSCRIPTEN__) && !defined(_MSC_VER)
  1753. #ifdef __APPLE__
  1754. qsort_r(fynpp, count, sizeof(*fynpp), &ctx, fy_node_mapping_sort_cmp);
  1755. #else
  1756. diff --git a/src/lib/fy-doc.h b/src/lib/fy-doc.h
  1757. index 6c15024..916b66a 100644
  1758. --- a/src/lib/fy-doc.h
  1759. +++ b/src/lib/fy-doc.h
  1760. @@ -61,7 +61,11 @@ struct fy_node {
  1761. struct fy_node *parent;
  1762. struct fy_document *fyd;
  1763. unsigned int marks;
  1764. +#if !defined(_MSC_VER)
  1765. enum fy_node_type type : 2; /* 2 bits are enough for 3 types */
  1766. +#else
  1767. + enum fy_node_type type; /* it converted incorrectly and can't be used as supposed to be */
  1768. +#endif
  1769. bool has_meta : 1;
  1770. bool attached : 1; /* when it's attached somewhere */
  1771. bool synthetic : 1; /* node has been modified programmaticaly */
  1772. diff --git a/src/lib/fy-docbuilder.c b/src/lib/fy-docbuilder.c
  1773. index 94f6606..08152f0 100644
  1774. --- a/src/lib/fy-docbuilder.c
  1775. +++ b/src/lib/fy-docbuilder.c
  1776. @@ -15,7 +15,9 @@
  1777. #include <stdlib.h>
  1778. #include <ctype.h>
  1779. #include <errno.h>
  1780. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  1781. #include <unistd.h>
  1782. +#endif
  1783. #include <libfyaml.h>
  1784. diff --git a/src/lib/fy-dump.c b/src/lib/fy-dump.c
  1785. index fe6a231..ac1980d 100644
  1786. --- a/src/lib/fy-dump.c
  1787. +++ b/src/lib/fy-dump.c
  1788. @@ -11,11 +11,13 @@
  1789. #include <stdio.h>
  1790. #include <string.h>
  1791. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  1792. #include <sys/mman.h>
  1793. #include <sys/types.h>
  1794. #include <sys/stat.h>
  1795. #include <fcntl.h>
  1796. #include <unistd.h>
  1797. +#endif
  1798. #include <assert.h>
  1799. #include <stdlib.h>
  1800. #include <errno.h>
  1801. diff --git a/src/lib/fy-emit.c b/src/lib/fy-emit.c
  1802. index 9f2e27e..8da29ce 100644
  1803. --- a/src/lib/fy-emit.c
  1804. +++ b/src/lib/fy-emit.c
  1805. @@ -14,7 +14,11 @@
  1806. #include <assert.h>
  1807. #include <stdlib.h>
  1808. #include <limits.h>
  1809. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  1810. #include <unistd.h>
  1811. +#elif defined (_MSC_VER)
  1812. +#define STDOUT_FILENO _fileno(stdin)
  1813. +#endif
  1814. #include <ctype.h>
  1815. #include <errno.h>
  1816. @@ -1844,7 +1848,7 @@ int fy_emit_document_start(struct fy_emitter *emit, struct fy_document *fyd,
  1817. if (!emit || !fyd || !fyd->fyds)
  1818. return -1;
  1819. - root = fyn_root ? : fy_document_root(fyd);
  1820. + root = fyn_root ? fyn_root : fy_document_root(fyd);
  1821. root_tag_or_anchor = root && (root->tag || fy_document_lookup_anchor_by_node(fyd, root));
  1822. @@ -2283,7 +2287,7 @@ static int do_buffer_output(struct fy_emitter *emit, enum fy_emitter_write_type
  1823. if (!state->allocate_buffer)
  1824. return 0;
  1825. - pagesize = sysconf(_SC_PAGESIZE);
  1826. + pagesize = fy_get_pagesize();
  1827. size = state->need + pagesize - 1;
  1828. size = size - size % pagesize;
  1829. diff --git a/src/lib/fy-input.c b/src/lib/fy-input.c
  1830. index 5d16ce6..ac021ad 100644
  1831. --- a/src/lib/fy-input.c
  1832. +++ b/src/lib/fy-input.c
  1833. @@ -15,11 +15,15 @@
  1834. #include <stdlib.h>
  1835. #include <stdarg.h>
  1836. #include <fcntl.h>
  1837. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  1838. #include <unistd.h>
  1839. #include <sys/mman.h>
  1840. +#endif
  1841. #include <sys/types.h>
  1842. #include <sys/stat.h>
  1843. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  1844. #include <sys/ioctl.h>
  1845. +#endif
  1846. #include <errno.h>
  1847. #include <libfyaml.h>
  1848. @@ -216,10 +220,12 @@ void fy_input_close(struct fy_input *fyi)
  1849. case fyit_file:
  1850. case fyit_fd:
  1851. +#if !defined(_MSC_VER)
  1852. if (fyi->addr) {
  1853. munmap(fyi->addr, fyi->length);
  1854. fyi->addr = NULL;
  1855. }
  1856. +#endif
  1857. if (fyi->fd != -1) {
  1858. if (!fyi->cfg.no_close_fd)
  1859. @@ -408,6 +414,7 @@ int fy_reader_input_open(struct fy_reader *fyr, struct fy_input *fyi, const stru
  1860. fyi->length = sb.st_size;
  1861. /* only map if not zero (and is not disabled) */
  1862. +#if !defined(_MSC_VER)
  1863. if (sb.st_size > 0 && !fyr->current_input_cfg.disable_mmap_opt) {
  1864. fyi->addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fyi->fd, 0);
  1865. @@ -418,6 +425,7 @@ int fy_reader_input_open(struct fy_reader *fyr, struct fy_input *fyi, const stru
  1866. fyi->addr = NULL;
  1867. }
  1868. }
  1869. +#endif
  1870. /* if we've managed to mmap, we' good */
  1871. if (fyi->addr)
  1872. break;
  1873. @@ -464,12 +472,14 @@ int fy_reader_input_open(struct fy_reader *fyr, struct fy_input *fyi, const stru
  1874. /* all the rest need it */
  1875. default:
  1876. /* if we're not in mmap mode */
  1877. +#if !defined(_MSC_VER)
  1878. if (fyi->addr && !fyr->current_input_cfg.disable_mmap_opt)
  1879. break;
  1880. +#endif
  1881. fyi->chunk = fyi->cfg.chunk;
  1882. if (!fyi->chunk)
  1883. - fyi->chunk = sysconf(_SC_PAGESIZE);
  1884. + fyi->chunk = fy_get_pagesize();
  1885. fyi->chop = fyi->chunk * FYI_CHOP_MULT;
  1886. fyi->buffer = malloc(fyi->chunk);
  1887. fyr_error_check(fyr, fyi->buffer, err_out,
  1888. @@ -585,7 +595,7 @@ int fy_reader_input_scan_token_mark_slow_path(struct fy_reader *fyr)
  1889. assert(fyi->read >= fyr->current_input_pos);
  1890. fyi_new->read = fyi->read - fyr->current_input_pos;
  1891. if (fyi_new->read > 0)
  1892. - memcpy(fyi_new->buffer, fyi->buffer + fyr->current_input_pos, fyi_new->read);
  1893. + memcpy(fyi_new->buffer, (char *)fyi->buffer + fyr->current_input_pos, fyi_new->read);
  1894. fyr->this_input_start += fyr->current_input_pos;
  1895. @@ -629,7 +639,7 @@ const void *fy_reader_ptr_slow_path(struct fy_reader *fyr, size_t *leftp)
  1896. case fyit_fd:
  1897. if (fyi->addr) {
  1898. left = fyi->length - (fyr->this_input_start + fyr->current_input_pos);
  1899. - p = fyi->addr + fyr->current_input_pos;
  1900. + p = (char *)fyi->addr + fyr->current_input_pos;
  1901. break;
  1902. }
  1903. @@ -638,17 +648,17 @@ const void *fy_reader_ptr_slow_path(struct fy_reader *fyr, size_t *leftp)
  1904. case fyit_stream:
  1905. case fyit_callback:
  1906. left = fyi->read - (fyr->this_input_start + fyr->current_input_pos);
  1907. - p = fyi->buffer + fyr->current_input_pos;
  1908. + p = (char *)fyi->buffer + fyr->current_input_pos;
  1909. break;
  1910. case fyit_memory:
  1911. left = fyi->cfg.memory.size - fyr->current_input_pos;
  1912. - p = fyi->cfg.memory.data + fyr->current_input_pos;
  1913. + p = (char *)fyi->cfg.memory.data + fyr->current_input_pos;
  1914. break;
  1915. case fyit_alloc:
  1916. left = fyi->cfg.alloc.size - fyr->current_input_pos;
  1917. - p = fyi->cfg.alloc.data + fyr->current_input_pos;
  1918. + p = (char *)fyi->cfg.alloc.data + fyr->current_input_pos;
  1919. break;
  1920. @@ -700,7 +710,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1921. fyr_debug(fyr, "file input exhausted");
  1922. break;
  1923. }
  1924. - p = fyi->addr + pos;
  1925. + p = (char *)fyi->addr + pos;
  1926. break;
  1927. }
  1928. @@ -712,7 +722,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1929. assert(fyi->read >= pos);
  1930. left = fyi->read - pos;
  1931. - p = fyi->buffer + pos;
  1932. + p = (char *)fyi->buffer + pos;
  1933. /* enough to satisfy directly */
  1934. if (left >= pull)
  1935. @@ -756,7 +766,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1936. fyi->generation++;
  1937. space = fyi->allocated - pos;
  1938. - p = fyi->buffer + pos;
  1939. + p = (char *)fyi->buffer + pos;
  1940. }
  1941. /* always try to read up to the allocated space */
  1942. @@ -768,7 +778,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1943. fyr_debug(fyr, "performing callback request of %zu", nreadreq);
  1944. - nread = fyi->cfg.callback.input(fyi->cfg.userdata, fyi->buffer + fyi->read, nreadreq);
  1945. + nread = fyi->cfg.callback.input(fyi->cfg.userdata, (char *)fyi->buffer + fyi->read, nreadreq);
  1946. fyr_debug(fyr, "callback returned %zu", nread);
  1947. @@ -787,7 +797,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1948. fyr_debug(fyr, "performing fread request of %zu", nreadreq);
  1949. - nread = fread(fyi->buffer + fyi->read, 1, nreadreq, fyi->fp);
  1950. + nread = fread((char *)fyi->buffer + fyi->read, 1, nreadreq, fyi->fp);
  1951. fyr_debug(fyr, "fread returned %zu", nread);
  1952. @@ -811,7 +821,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1953. fyr_debug(fyr, "performing read request of %zu", nreadreq);
  1954. do {
  1955. - snread = read(fyi->fd, fyi->buffer + fyi->read, nreadreq);
  1956. + snread = read(fyi->fd, (char *)fyi->buffer + fyi->read, nreadreq);
  1957. } while (snread == -1 && errno == EAGAIN);
  1958. fyr_debug(fyr, "read returned %zd", snread);
  1959. @@ -859,7 +869,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1960. fyr_debug(fyr, "memory input exhausted");
  1961. break;
  1962. }
  1963. - p = fyi->cfg.memory.data + pos;
  1964. + p = (char *)fyi->cfg.memory.data + pos;
  1965. break;
  1966. case fyit_alloc:
  1967. @@ -870,7 +880,7 @@ const void *fy_reader_input_try_pull(struct fy_reader *fyr, struct fy_input *fyi
  1968. fyr_debug(fyr, "alloc input exhausted");
  1969. break;
  1970. }
  1971. - p = fyi->cfg.alloc.data + pos;
  1972. + p = (char *)fyi->cfg.alloc.data + pos;
  1973. break;
  1974. @@ -952,13 +962,13 @@ struct fy_input *fy_input_create(const struct fy_input_cfg *fyic)
  1975. break;
  1976. case fyit_memory:
  1977. ret = asprintf(&fyi->name, "<memory-@%p-%p>",
  1978. - fyic->memory.data, fyic->memory.data + fyic->memory.size - 1);
  1979. + fyic->memory.data, (char *)fyic->memory.data + fyic->memory.size - 1);
  1980. if (ret == -1)
  1981. fyi->name = NULL;
  1982. break;
  1983. case fyit_alloc:
  1984. ret = asprintf(&fyi->name, "<alloc-@%p-%p>",
  1985. - fyic->memory.data, fyic->memory.data + fyic->memory.size - 1);
  1986. + fyic->memory.data, (char *)fyic->memory.data + fyic->memory.size - 1);
  1987. if (ret == -1)
  1988. fyi->name = NULL;
  1989. break;
  1990. diff --git a/src/lib/fy-input.h b/src/lib/fy-input.h
  1991. index 6634fab..e61f273 100644
  1992. --- a/src/lib/fy-input.h
  1993. +++ b/src/lib/fy-input.h
  1994. @@ -602,7 +602,7 @@ fy_reader_advance_octets(struct fy_reader *fyr, size_t advance)
  1995. assert(fyr->current_left >= advance);
  1996. fyr->current_input_pos += advance;
  1997. - fyr->current_ptr += advance;
  1998. + fyr->current_ptr = (char *)fyr->current_ptr + advance;
  1999. fyr->current_left -= advance;
  2000. fyr->current_c = fy_utf8_get(fyr->current_ptr, fyr->current_left, &fyr->current_w);
  2001. diff --git a/src/lib/fy-parse.c b/src/lib/fy-parse.c
  2002. index 3a65a8c..839e4b7 100644
  2003. --- a/src/lib/fy-parse.c
  2004. +++ b/src/lib/fy-parse.c
  2005. @@ -6641,7 +6641,7 @@ int fy_parser_set_input_fp(struct fy_parser *fyp, const char *name, FILE *fp)
  2006. memset(&fyic, 0, sizeof(fyic));
  2007. fyic.type = fyit_stream;
  2008. - fyic.stream.name = name ? : "<stream>";
  2009. + fyic.stream.name = name ? name : "<stream>";
  2010. fyic.stream.fp = fp;
  2011. fyic.ignore_stdio = !!(fyp->cfg.flags & FYPCF_DISABLE_BUFFERING);
  2012. diff --git a/src/lib/fy-parse.h b/src/lib/fy-parse.h
  2013. index 899800a..b3b1ab7 100644
  2014. --- a/src/lib/fy-parse.h
  2015. +++ b/src/lib/fy-parse.h
  2016. @@ -524,7 +524,7 @@ fy_parser_set_reader(struct fy_parser *fyp, struct fy_reader *fyr)
  2017. {
  2018. if (!fyp)
  2019. return;
  2020. - fyp->reader = fyr ? : &fyp->builtin_reader;
  2021. + fyp->reader = fyr ? fyr : &fyp->builtin_reader;
  2022. }
  2023. static inline void
  2024. From 55f7773f2f4b19a26fe362a291c28ae387fb0f44 Mon Sep 17 00:00:00 2001
  2025. From: Innokentii Mokin <innokentii@yandex-team.ru>
  2026. Date: Sun, 29 Jan 2023 00:38:49 +0300
  2027. Subject: [PATCH 3/7] fix unportable headers
  2028. ---
  2029. src/lib/fy-parse.c | 6 ++++
  2030. src/lib/fy-token.c | 4 +--
  2031. src/lib/fy-types.c | 2 ++
  2032. src/lib/fy-utf8.c | 6 ++--
  2033. src/lib/fy-utf8.h | 4 +--
  2034. src/lib/fy-utils.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
  2035. src/lib/fy-utils.h | 9 +++++
  2036. src/lib/fy-walk.c | 2 ++
  2037. 8 files changed, 113 insertions(+), 7 deletions(-)
  2038. diff --git a/src/lib/fy-parse.c b/src/lib/fy-parse.c
  2039. index 839e4b7..79edd41 100644
  2040. --- a/src/lib/fy-parse.c
  2041. +++ b/src/lib/fy-parse.c
  2042. @@ -11,12 +11,18 @@
  2043. #include <stdio.h>
  2044. #include <string.h>
  2045. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2046. #include <sys/mman.h>
  2047. +#endif
  2048. #include <sys/types.h>
  2049. #include <sys/stat.h>
  2050. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2051. #include <sys/ioctl.h>
  2052. +#endif
  2053. #include <fcntl.h>
  2054. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2055. #include <unistd.h>
  2056. +#endif
  2057. #include <assert.h>
  2058. #include <stdlib.h>
  2059. #include <errno.h>
  2060. diff --git a/src/lib/fy-token.c b/src/lib/fy-token.c
  2061. index 2a75004..91efa89 100644
  2062. --- a/src/lib/fy-token.c
  2063. +++ b/src/lib/fy-token.c
  2064. @@ -159,7 +159,7 @@ static int fy_tag_token_format_internal(const struct fy_token *fyt, void *out, s
  2065. if (out) {
  2066. outsz = *outszp;
  2067. o = out;
  2068. - oe = out + outsz;
  2069. + oe = (char *)out + outsz;
  2070. }
  2071. if (!fyt->tag.fyt_td)
  2072. @@ -246,7 +246,7 @@ static int fy_tag_directive_token_format_internal(const struct fy_token *fyt,
  2073. if (out) {
  2074. outsz = *outszp;
  2075. o = out;
  2076. - oe = out + outsz;
  2077. + oe = (char *)out + outsz;
  2078. }
  2079. #define O_CPY(_src, _len) \
  2080. diff --git a/src/lib/fy-types.c b/src/lib/fy-types.c
  2081. index fd34fab..5e0da30 100644
  2082. --- a/src/lib/fy-types.c
  2083. +++ b/src/lib/fy-types.c
  2084. @@ -11,11 +11,13 @@
  2085. #include <stdio.h>
  2086. #include <string.h>
  2087. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2088. #include <sys/mman.h>
  2089. #include <sys/types.h>
  2090. #include <sys/stat.h>
  2091. #include <fcntl.h>
  2092. #include <unistd.h>
  2093. +#endif
  2094. #include <assert.h>
  2095. #include <stdlib.h>
  2096. #include <errno.h>
  2097. diff --git a/src/lib/fy-utf8.c b/src/lib/fy-utf8.c
  2098. index e5103ac..8105f71 100644
  2099. --- a/src/lib/fy-utf8.c
  2100. +++ b/src/lib/fy-utf8.c
  2101. @@ -253,11 +253,11 @@ const void *fy_utf8_memchr_generic(const void *s, int c, size_t n)
  2102. int cc, w;
  2103. const void *e;
  2104. - e = s + n;
  2105. - while (s < e && (cc = fy_utf8_get(s, e - s, &w)) >= 0) {
  2106. + e = (char*)s + n;
  2107. + while (s < e && (cc = fy_utf8_get(s, (char*)e - (char*)s, &w)) >= 0) {
  2108. if (c == cc)
  2109. return s;
  2110. - s += w;
  2111. + s = (char*)s + w;
  2112. }
  2113. return NULL;
  2114. diff --git a/src/lib/fy-utf8.h b/src/lib/fy-utf8.h
  2115. index 9dc0825..fa4faa1 100644
  2116. --- a/src/lib/fy-utf8.h
  2117. +++ b/src/lib/fy-utf8.h
  2118. @@ -87,7 +87,7 @@ int fy_utf8_get_right_generic(const void *ptr, int left, int *widthp);
  2119. static inline int fy_utf8_get_right(const void *ptr, int left, int *widthp)
  2120. {
  2121. - const uint8_t *p = ptr + left;
  2122. + const uint8_t *p = (const uint8_t*)ptr + left;
  2123. /* single byte (hot path) */
  2124. if (left > 0 && !(p[-1] & 0x80)) {
  2125. @@ -194,7 +194,7 @@ static inline const void *fy_utf8_strchr(const void *s, int c)
  2126. static inline int fy_utf8_count(const void *ptr, size_t len)
  2127. {
  2128. - const uint8_t *s = ptr, *e = ptr + len;
  2129. + const uint8_t *s = ptr, *e = (const uint8_t *)ptr + len;
  2130. int w, count;
  2131. count = 0;
  2132. diff --git a/src/lib/fy-utils.c b/src/lib/fy-utils.c
  2133. index 8b55ccb..8f87ae7 100644
  2134. --- a/src/lib/fy-utils.c
  2135. +++ b/src/lib/fy-utils.c
  2136. @@ -15,16 +15,101 @@
  2137. #include <stdlib.h>
  2138. #include <string.h>
  2139. #include <errno.h>
  2140. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2141. #include <termios.h>
  2142. #include <unistd.h>
  2143. #include <sys/select.h>
  2144. #include <sys/time.h>
  2145. #include <sys/types.h>
  2146. +#elif defined(_MSC_VER)
  2147. +#include <windows.h>
  2148. +#endif
  2149. #include "fy-utf8.h"
  2150. #include "fy-ctype.h"
  2151. #include "fy-utils.h"
  2152. +int fy_get_pagesize() {
  2153. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2154. + return sysconf(_SC_PAGESIZE);
  2155. +#elif defined (_MSC_VER)
  2156. + SYSTEM_INFO si;
  2157. + GetSystemInfo(&si);
  2158. + return si.dwPageSize;
  2159. +#endif
  2160. +}
  2161. +
  2162. +#if defined(_MSC_VER)
  2163. +#ifndef VA_COPY
  2164. +# ifdef HAVE_VA_COPY
  2165. +# define VA_COPY(dest, src) va_copy(dest, src)
  2166. +# else
  2167. +# ifdef HAVE___VA_COPY
  2168. +# define VA_COPY(dest, src) __va_copy(dest, src)
  2169. +# else
  2170. +# define VA_COPY(dest, src) (dest) = (src)
  2171. +# endif
  2172. +# endif
  2173. +#endif
  2174. +
  2175. +#define INIT_SZ 128
  2176. +
  2177. +int
  2178. +vasprintf(char **str, const char *fmt, va_list ap)
  2179. +{
  2180. + int ret;
  2181. + va_list ap2;
  2182. + char *string, *newstr;
  2183. + size_t len;
  2184. +
  2185. + if ((string = malloc(INIT_SZ)) == NULL)
  2186. + goto fail;
  2187. +
  2188. + VA_COPY(ap2, ap);
  2189. + ret = vsnprintf(string, INIT_SZ, fmt, ap2);
  2190. + va_end(ap2);
  2191. + if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */
  2192. + *str = string;
  2193. + } else if (ret == INT_MAX || ret < 0) { /* Bad length */
  2194. + free(string);
  2195. + goto fail;
  2196. + } else { /* bigger than initial, realloc allowing for nul */
  2197. + len = (size_t)ret + 1;
  2198. + if ((newstr = realloc(string, len)) == NULL) {
  2199. + free(string);
  2200. + goto fail;
  2201. + }
  2202. + VA_COPY(ap2, ap);
  2203. + ret = vsnprintf(newstr, len, fmt, ap2);
  2204. + va_end(ap2);
  2205. + if (ret < 0 || (size_t)ret >= len) { /* failed with realloc'ed string */
  2206. + free(newstr);
  2207. + goto fail;
  2208. + }
  2209. + *str = newstr;
  2210. + }
  2211. + return (ret);
  2212. +
  2213. +fail:
  2214. + *str = NULL;
  2215. + errno = ENOMEM;
  2216. + return (-1);
  2217. +}
  2218. +
  2219. +int asprintf(char **str, const char *fmt, ...)
  2220. +{
  2221. + va_list ap;
  2222. + int ret;
  2223. +
  2224. + *str = NULL;
  2225. + va_start(ap, fmt);
  2226. + ret = vasprintf(str, fmt, ap);
  2227. + va_end(ap);
  2228. +
  2229. + return ret;
  2230. +}
  2231. +#endif
  2232. +
  2233. #if defined(__APPLE__) && (_POSIX_C_SOURCE < 200809L)
  2234. /*
  2235. @@ -397,6 +482,7 @@ int fy_tag_scan(const char *data, size_t len, struct fy_tag_scan_info *info)
  2236. return 0;
  2237. }
  2238. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2239. /* simple terminal methods; mainly for getting size of terminal */
  2240. int fy_term_set_raw(int fd, struct termios *oldt)
  2241. {
  2242. @@ -632,3 +718,4 @@ int fy_term_query_size(int fd, int *rows, int *cols)
  2243. return ret;
  2244. }
  2245. +#endif
  2246. diff --git a/src/lib/fy-utils.h b/src/lib/fy-utils.h
  2247. index cf3e3c5..dd99125 100644
  2248. --- a/src/lib/fy-utils.h
  2249. +++ b/src/lib/fy-utils.h
  2250. @@ -15,13 +15,22 @@
  2251. #include <stdio.h>
  2252. #include <stdbool.h>
  2253. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2254. #include <unistd.h>
  2255. #include <termios.h>
  2256. +#endif
  2257. #if defined(__APPLE__) && (_POSIX_C_SOURCE < 200809L)
  2258. FILE *open_memstream(char **ptr, size_t *sizeloc);
  2259. #endif
  2260. +int fy_get_pagesize();
  2261. +
  2262. +#if defined(_MSC_VER)
  2263. +int vasprintf(char **strp, const char *fmt, va_list ap);
  2264. +int asprintf(char **strp, const char *fmt, ...);
  2265. +#endif
  2266. +
  2267. int fy_tag_handle_length(const char *data, size_t len);
  2268. bool fy_tag_uri_is_valid(const char *data, size_t len);
  2269. int fy_tag_uri_length(const char *data, size_t len);
  2270. diff --git a/src/lib/fy-walk.c b/src/lib/fy-walk.c
  2271. index 5e7cda3..a2138d2 100644
  2272. --- a/src/lib/fy-walk.c
  2273. +++ b/src/lib/fy-walk.c
  2274. @@ -15,7 +15,9 @@
  2275. #include <stdlib.h>
  2276. #include <ctype.h>
  2277. #include <errno.h>
  2278. +#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  2279. #include <unistd.h>
  2280. +#endif
  2281. #include <math.h>
  2282. #include <limits.h>
  2283. From 16fcfcfa8c2ceb9628b4fb62caf2c91d1d05459b Mon Sep 17 00:00:00 2001
  2284. From: Innokentii Mokin <innokentii@yandex-team.ru>
  2285. Date: Sun, 29 Jan 2023 00:42:52 +0300
  2286. Subject: [PATCH 4/7] small fixes
  2287. ---
  2288. src/lib/fy-diag.c | 9 +++++++--
  2289. 1 file changed, 7 insertions(+), 2 deletions(-)
  2290. diff --git a/src/lib/fy-diag.c b/src/lib/fy-diag.c
  2291. index ee6a77c..ca324fa 100644
  2292. --- a/src/lib/fy-diag.c
  2293. +++ b/src/lib/fy-diag.c
  2294. @@ -36,6 +36,8 @@ static const char *error_type_txt[] = {
  2295. int fy_diag_diag(struct fy_diag *diag, enum fy_error_type level, const char* fmt, ...)
  2296. {
  2297. + int ret;
  2298. +
  2299. va_list args;
  2300. struct fy_diag_ctx ctx = {
  2301. .level = level,
  2302. @@ -49,8 +51,10 @@ int fy_diag_diag(struct fy_diag *diag, enum fy_error_type level, const char* fmt
  2303. };
  2304. va_start(args, fmt);
  2305. - fy_diagf(diag, &ctx, fmt, args);
  2306. + ret = fy_diagf(diag, &ctx, fmt, args);
  2307. va_end(args);
  2308. +
  2309. + return ret;
  2310. }
  2311. const char *fy_error_type_to_string(enum fy_error_type type)
  2312. @@ -865,11 +869,12 @@ void fy_diag_vreport(struct fy_diag *diag,
  2313. /* get the colors */
  2314. fy_diag_get_error_colors(diag, fydrc->type, &color_start, &color_end, &white);
  2315. - if (name || (line > 0 && column > 0))
  2316. + if (name || (line > 0 && column > 0)) {
  2317. if (line > 0 && column > 0)
  2318. alloca_sprintf(&name_str, "%s%s:%d:%d: ", white, name, line, column);
  2319. else
  2320. alloca_sprintf(&name_str, "%s%s: ", white, name);
  2321. + }
  2322. if (!diag->collect_errors) {
  2323. fy_diag_printf(diag, "%s" "%s%s: %s" "%s\n",
  2324. From 308d127b2d5772b602582829339532fa312e66aa Mon Sep 17 00:00:00 2001
  2325. From: Innokentii Mokin <innokentii@yandex-team.ru>
  2326. Date: Sun, 29 Jan 2023 01:03:34 +0300
  2327. Subject: [PATCH 5/7] fix __attribute__ in diag
  2328. ---
  2329. src/lib/fy-diag.h | 24 ++++++++++++------------
  2330. 1 file changed, 12 insertions(+), 12 deletions(-)
  2331. diff --git a/src/lib/fy-diag.h b/src/lib/fy-diag.h
  2332. index bcf6568..9f75af7 100644
  2333. --- a/src/lib/fy-diag.h
  2334. +++ b/src/lib/fy-diag.h
  2335. @@ -98,12 +98,12 @@ void fy_diag_vreport(struct fy_diag *diag,
  2336. void fy_diag_report(struct fy_diag *diag,
  2337. const struct fy_diag_report_ctx *fydrc,
  2338. const char *fmt, ...)
  2339. - __attribute__((format(printf, 3, 4)));
  2340. + FY_ATTRIBUTE(format(printf, 3, 4));
  2341. #ifdef FY_DEVMODE
  2342. #define __FY_DEBUG_UNUSED__ /* nothing */
  2343. #else
  2344. -#define __FY_DEBUG_UNUSED__ __attribute__((__unused__))
  2345. +#define __FY_DEBUG_UNUSED__ FY_ATTRIBUTE(__unused__)
  2346. #endif
  2347. /* parser diagnostics */
  2348. @@ -119,7 +119,7 @@ int fy_parser_vdiag(struct fy_parser *fyp, unsigned int flags,
  2349. int fy_parser_diag(struct fy_parser *fyp, unsigned int flags,
  2350. const char *file, int line, const char *func,
  2351. const char *fmt, ...)
  2352. - __attribute__((format(printf, 6, 7)));
  2353. + FY_ATTRIBUTE(format(printf, 6, 7));
  2354. void fy_diag_error_atom_display(struct fy_diag *diag, enum fy_error_type type,
  2355. struct fy_atom *atom);
  2356. @@ -132,7 +132,7 @@ void fy_parser_diag_vreport(struct fy_parser *fyp,
  2357. void fy_parser_diag_report(struct fy_parser *fyp,
  2358. const struct fy_diag_report_ctx *fydrc,
  2359. const char *fmt, ...)
  2360. - __attribute__((format(printf, 3, 4)));
  2361. + FY_ATTRIBUTE(format(printf, 3, 4));
  2362. #ifdef FY_DEVMODE
  2363. @@ -272,7 +272,7 @@ int fy_reader_vdiag(struct fy_reader *fyr, unsigned int flags,
  2364. int fy_reader_diag(struct fy_reader *fyr, unsigned int flags,
  2365. const char *file, int line, const char *func,
  2366. const char *fmt, ...)
  2367. - __attribute__((format(printf, 6, 7)));
  2368. + FY_ATTRIBUTE(format(printf, 6, 7));
  2369. void fy_reader_diag_vreport(struct fy_reader *fyr,
  2370. const struct fy_diag_report_ctx *fydrc,
  2371. @@ -280,7 +280,7 @@ void fy_reader_diag_vreport(struct fy_reader *fyr,
  2372. void fy_reader_diag_report(struct fy_reader *fyr,
  2373. const struct fy_diag_report_ctx *fydrc,
  2374. const char *fmt, ...)
  2375. - __attribute__((format(printf, 3, 4)));
  2376. + FY_ATTRIBUTE(format(printf, 3, 4));
  2377. #ifdef FY_DEVMODE
  2378. @@ -412,7 +412,7 @@ int fy_document_vdiag(struct fy_document *fyd, unsigned int flags,
  2379. int fy_document_diag(struct fy_document *fyd, unsigned int flags,
  2380. const char *file, int line, const char *func,
  2381. const char *fmt, ...)
  2382. - __attribute__((format(printf, 6, 7)));
  2383. + FY_ATTRIBUTE(format(printf, 6, 7));
  2384. void fy_document_diag_vreport(struct fy_document *fyd,
  2385. const struct fy_diag_report_ctx *fydrc,
  2386. @@ -420,7 +420,7 @@ void fy_document_diag_vreport(struct fy_document *fyd,
  2387. void fy_document_diag_report(struct fy_document *fyd,
  2388. const struct fy_diag_report_ctx *fydrc,
  2389. const char *fmt, ...)
  2390. - __attribute__((format(printf, 3, 4)));
  2391. + FY_ATTRIBUTE(format(printf, 3, 4));
  2392. #ifdef FY_DEVMODE
  2393. @@ -514,7 +514,7 @@ int fy_composer_vdiag(struct fy_composer *fyc, unsigned int flags,
  2394. int fy_composer_diag(struct fy_composer *fyc, unsigned int flags,
  2395. const char *file, int line, const char *func,
  2396. const char *fmt, ...)
  2397. - __attribute__((format(printf, 6, 7)));
  2398. + FY_ATTRIBUTE(format(printf, 6, 7));
  2399. void fy_composer_diag_vreport(struct fy_composer *fyc,
  2400. const struct fy_diag_report_ctx *fydrc,
  2401. @@ -522,7 +522,7 @@ void fy_composer_diag_vreport(struct fy_composer *fyc,
  2402. void fy_composer_diag_report(struct fy_composer *fyc,
  2403. const struct fy_diag_report_ctx *fydrc,
  2404. const char *fmt, ...)
  2405. - __attribute__((format(printf, 3, 4)));
  2406. + FY_ATTRIBUTE(format(printf, 3, 4));
  2407. #ifdef FY_DEVMODE
  2408. @@ -599,7 +599,7 @@ int fy_document_builder_vdiag(struct fy_document_builder *fydb, unsigned int fla
  2409. int fy_document_builder_diag(struct fy_document_builder *fydb, unsigned int flags,
  2410. const char *file, int line, const char *func,
  2411. const char *fmt, ...)
  2412. - __attribute__((format(printf, 6, 7)));
  2413. + FY_ATTRIBUTE(format(printf, 6, 7));
  2414. void fy_document_builder_diag_vreport(struct fy_document_builder *fydb,
  2415. const struct fy_diag_report_ctx *fydrc,
  2416. @@ -607,7 +607,7 @@ void fy_document_builder_diag_vreport(struct fy_document_builder *fydb,
  2417. void fy_document_builder_diag_report(struct fy_document_builder *fydb,
  2418. const struct fy_diag_report_ctx *fydrc,
  2419. const char *fmt, ...)
  2420. - __attribute__((format(printf, 3, 4)));
  2421. + FY_ATTRIBUTE(format(printf, 3, 4));
  2422. #ifdef FY_DEVMODE
  2423. From cc6fb5de268eb22e46fd2ac603cda5cbad56f8d5 Mon Sep 17 00:00:00 2001
  2424. From: Innokentii Mokin <innokentii@yandex-team.ru>
  2425. Date: Sun, 29 Jan 2023 01:08:33 +0300
  2426. Subject: [PATCH 6/7] fix __attribute__
  2427. ---
  2428. src/lib/fy-atom.c | 2 +-
  2429. src/lib/fy-emit-accum.h | 2 +-
  2430. src/lib/fy-emit.c | 2 +-
  2431. 3 files changed, 3 insertions(+), 3 deletions(-)
  2432. diff --git a/src/lib/fy-atom.c b/src/lib/fy-atom.c
  2433. index efeabbe..a38e6fb 100644
  2434. --- a/src/lib/fy-atom.c
  2435. +++ b/src/lib/fy-atom.c
  2436. @@ -223,7 +223,7 @@ _fy_atom_iter_add_chunk_copy(struct fy_atom_iter *iter, const char *str, size_t
  2437. /* keep it around without a warning even though it's unused */
  2438. static int
  2439. _fy_atom_iter_add_utf8(struct fy_atom_iter *iter, int c)
  2440. - __attribute__((__unused__));
  2441. + FY_ATTRIBUTE(__unused__);
  2442. static int
  2443. _fy_atom_iter_add_utf8(struct fy_atom_iter *iter, int c)
  2444. diff --git a/src/lib/fy-emit-accum.h b/src/lib/fy-emit-accum.h
  2445. index fd9bb67..acc8ae7 100644
  2446. --- a/src/lib/fy-emit-accum.h
  2447. +++ b/src/lib/fy-emit-accum.h
  2448. @@ -212,7 +212,7 @@ fy_emit_accum_utf8_write(struct fy_emit_accum *ea, const void *data, size_t len)
  2449. static inline int
  2450. fy_emit_accum_utf8_printf_raw(struct fy_emit_accum *ea, const char *fmt, ...)
  2451. - __attribute__((format(printf, 2, 3)));
  2452. + FY_ATTRIBUTE(format(printf, 2, 3));
  2453. static inline int
  2454. fy_emit_accum_utf8_printf_raw(struct fy_emit_accum *ea, const char *fmt, ...)
  2455. diff --git a/src/lib/fy-emit.c b/src/lib/fy-emit.c
  2456. index 8da29ce..0edc9d9 100644
  2457. --- a/src/lib/fy-emit.c
  2458. +++ b/src/lib/fy-emit.c
  2459. @@ -30,7 +30,7 @@
  2460. /* fwd decl */
  2461. void fy_emit_write(struct fy_emitter *emit, enum fy_emitter_write_type type, const char *str, int len);
  2462. void fy_emit_printf(struct fy_emitter *emit, enum fy_emitter_write_type type, const char *fmt, ...)
  2463. - __attribute__((format(printf, 3, 4)));
  2464. + FY_ATTRIBUTE(format(printf, 3, 4));
  2465. static inline bool fy_emit_is_json_mode(const struct fy_emitter *emit)
  2466. {
  2467. From bf81e2b8db324bce5ef7f9e44cff68faddf58233 Mon Sep 17 00:00:00 2001
  2468. From: Innokentii Mokin <innokentii@yandex-team.ru>
  2469. Date: Sun, 29 Jan 2023 01:16:11 +0300
  2470. Subject: [PATCH 7/7] fix ptr arithmetics
  2471. ---
  2472. src/lib/fy-doc.c | 4 ++--
  2473. 1 file changed, 2 insertions(+), 2 deletions(-)
  2474. diff --git a/src/lib/fy-doc.c b/src/lib/fy-doc.c
  2475. index 22e0c51..a18c629 100644
  2476. --- a/src/lib/fy-doc.c
  2477. +++ b/src/lib/fy-doc.c
  2478. @@ -942,8 +942,8 @@ struct fy_token *fy_node_non_synthesized_token(struct fy_node *fyn)
  2479. if (!fyt_start || !fyt_end)
  2480. return NULL;
  2481. - s = fy_input_start(fyi) + fyt_start->handle.start_mark.input_pos;
  2482. - e = fy_input_start(fyi) + fyt_end->handle.end_mark.input_pos;
  2483. + s = (char *)fy_input_start(fyi) + fyt_start->handle.start_mark.input_pos;
  2484. + e = (char *)fy_input_start(fyi) + fyt_end->handle.end_mark.input_pos;
  2485. size = (size_t)(e - s);
  2486. if (size > 0)