nokolexbor 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (486) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nokolexbor/config.h +186 -0
  3. data/ext/nokolexbor/extconf.rb +131 -0
  4. data/ext/nokolexbor/libxml/HTMLparser.h +320 -0
  5. data/ext/nokolexbor/libxml/SAX2.h +173 -0
  6. data/ext/nokolexbor/libxml/chvalid.h +230 -0
  7. data/ext/nokolexbor/libxml/debugXML.h +217 -0
  8. data/ext/nokolexbor/libxml/dict.h +81 -0
  9. data/ext/nokolexbor/libxml/encoding.h +232 -0
  10. data/ext/nokolexbor/libxml/entities.h +153 -0
  11. data/ext/nokolexbor/libxml/globals.h +529 -0
  12. data/ext/nokolexbor/libxml/hash.h +236 -0
  13. data/ext/nokolexbor/libxml/list.h +137 -0
  14. data/ext/nokolexbor/libxml/parser.h +1264 -0
  15. data/ext/nokolexbor/libxml/parserInternals.h +641 -0
  16. data/ext/nokolexbor/libxml/pattern.h +100 -0
  17. data/ext/nokolexbor/libxml/threads.h +94 -0
  18. data/ext/nokolexbor/libxml/tree.h +1315 -0
  19. data/ext/nokolexbor/libxml/uri.h +94 -0
  20. data/ext/nokolexbor/libxml/valid.h +448 -0
  21. data/ext/nokolexbor/libxml/xmlIO.h +369 -0
  22. data/ext/nokolexbor/libxml/xmlautomata.h +146 -0
  23. data/ext/nokolexbor/libxml/xmlerror.h +919 -0
  24. data/ext/nokolexbor/libxml/xmlexports.h +79 -0
  25. data/ext/nokolexbor/libxml/xmlmemory.h +226 -0
  26. data/ext/nokolexbor/libxml/xmlregexp.h +222 -0
  27. data/ext/nokolexbor/libxml/xmlstring.h +140 -0
  28. data/ext/nokolexbor/libxml/xmlversion.h +526 -0
  29. data/ext/nokolexbor/libxml/xpath.h +575 -0
  30. data/ext/nokolexbor/libxml/xpathInternals.h +632 -0
  31. data/ext/nokolexbor/libxml/xpointer.h +137 -0
  32. data/ext/nokolexbor/libxml.h +76 -0
  33. data/ext/nokolexbor/memory.c +39 -0
  34. data/ext/nokolexbor/nl_document.c +51 -0
  35. data/ext/nokolexbor/nl_node.c +790 -0
  36. data/ext/nokolexbor/nl_node_set.c +368 -0
  37. data/ext/nokolexbor/nl_xpath_context.c +200 -0
  38. data/ext/nokolexbor/nokolexbor.c +63 -0
  39. data/ext/nokolexbor/nokolexbor.h +37 -0
  40. data/ext/nokolexbor/private/buf.h +70 -0
  41. data/ext/nokolexbor/private/dict.h +11 -0
  42. data/ext/nokolexbor/private/enc.h +17 -0
  43. data/ext/nokolexbor/private/error.h +21 -0
  44. data/ext/nokolexbor/private/globals.h +9 -0
  45. data/ext/nokolexbor/private/memory.h +9 -0
  46. data/ext/nokolexbor/private/parser.h +27 -0
  47. data/ext/nokolexbor/private/string.h +9 -0
  48. data/ext/nokolexbor/private/threads.h +50 -0
  49. data/ext/nokolexbor/private/tree.h +18 -0
  50. data/ext/nokolexbor/private/xpath.h +7 -0
  51. data/ext/nokolexbor/timsort.h +601 -0
  52. data/ext/nokolexbor/xml_SAX2.c +80 -0
  53. data/ext/nokolexbor/xml_buf.c +363 -0
  54. data/ext/nokolexbor/xml_chvalid.c +334 -0
  55. data/ext/nokolexbor/xml_dict.c +1264 -0
  56. data/ext/nokolexbor/xml_encoding.c +124 -0
  57. data/ext/nokolexbor/xml_error.c +134 -0
  58. data/ext/nokolexbor/xml_globals.c +1085 -0
  59. data/ext/nokolexbor/xml_hash.c +1141 -0
  60. data/ext/nokolexbor/xml_memory.c +203 -0
  61. data/ext/nokolexbor/xml_parser.c +127 -0
  62. data/ext/nokolexbor/xml_parserInternals.c +338 -0
  63. data/ext/nokolexbor/xml_pattern.c +2375 -0
  64. data/ext/nokolexbor/xml_string.c +1051 -0
  65. data/ext/nokolexbor/xml_threads.c +881 -0
  66. data/ext/nokolexbor/xml_tree.c +148 -0
  67. data/ext/nokolexbor/xml_xpath.c +14743 -0
  68. data/lib/nokolexbor/attribute.rb +18 -0
  69. data/lib/nokolexbor/document.rb +6 -0
  70. data/lib/nokolexbor/node.rb +264 -0
  71. data/lib/nokolexbor/node_set.rb +124 -0
  72. data/lib/nokolexbor/version.rb +5 -0
  73. data/lib/nokolexbor/xpath_context.rb +14 -0
  74. data/lib/nokolexbor.rb +17 -0
  75. data/patches/0001-lexbor-support-text-pseudo-element.patch +137 -0
  76. data/patches/0002-lexbor-match-id-class-case-sensitive.patch +22 -0
  77. data/patches/0003-lexbor-attach-template-content-to-self.patch +13 -0
  78. data/vendor/lexbor/CMakeLists.txt +331 -0
  79. data/vendor/lexbor/config.cmake +890 -0
  80. data/vendor/lexbor/feature.cmake +134 -0
  81. data/vendor/lexbor/source/lexbor/core/array.c +208 -0
  82. data/vendor/lexbor/source/lexbor/core/array.h +100 -0
  83. data/vendor/lexbor/source/lexbor/core/array_obj.c +216 -0
  84. data/vendor/lexbor/source/lexbor/core/array_obj.h +134 -0
  85. data/vendor/lexbor/source/lexbor/core/avl.c +442 -0
  86. data/vendor/lexbor/source/lexbor/core/avl.h +82 -0
  87. data/vendor/lexbor/source/lexbor/core/base.h +86 -0
  88. data/vendor/lexbor/source/lexbor/core/bst.c +468 -0
  89. data/vendor/lexbor/source/lexbor/core/bst.h +108 -0
  90. data/vendor/lexbor/source/lexbor/core/bst_map.c +238 -0
  91. data/vendor/lexbor/source/lexbor/core/bst_map.h +87 -0
  92. data/vendor/lexbor/source/lexbor/core/config.cmake +12 -0
  93. data/vendor/lexbor/source/lexbor/core/conv.c +203 -0
  94. data/vendor/lexbor/source/lexbor/core/conv.h +53 -0
  95. data/vendor/lexbor/source/lexbor/core/core.h +35 -0
  96. data/vendor/lexbor/source/lexbor/core/def.h +57 -0
  97. data/vendor/lexbor/source/lexbor/core/diyfp.c +153 -0
  98. data/vendor/lexbor/source/lexbor/core/diyfp.h +258 -0
  99. data/vendor/lexbor/source/lexbor/core/dobject.c +187 -0
  100. data/vendor/lexbor/source/lexbor/core/dobject.h +92 -0
  101. data/vendor/lexbor/source/lexbor/core/dtoa.c +404 -0
  102. data/vendor/lexbor/source/lexbor/core/dtoa.h +28 -0
  103. data/vendor/lexbor/source/lexbor/core/fs.h +60 -0
  104. data/vendor/lexbor/source/lexbor/core/hash.c +476 -0
  105. data/vendor/lexbor/source/lexbor/core/hash.h +218 -0
  106. data/vendor/lexbor/source/lexbor/core/in.c +267 -0
  107. data/vendor/lexbor/source/lexbor/core/in.h +172 -0
  108. data/vendor/lexbor/source/lexbor/core/lexbor.h +35 -0
  109. data/vendor/lexbor/source/lexbor/core/mem.c +228 -0
  110. data/vendor/lexbor/source/lexbor/core/mem.h +141 -0
  111. data/vendor/lexbor/source/lexbor/core/mraw.c +428 -0
  112. data/vendor/lexbor/source/lexbor/core/mraw.h +114 -0
  113. data/vendor/lexbor/source/lexbor/core/perf.h +45 -0
  114. data/vendor/lexbor/source/lexbor/core/plog.c +73 -0
  115. data/vendor/lexbor/source/lexbor/core/plog.h +102 -0
  116. data/vendor/lexbor/source/lexbor/core/print.c +168 -0
  117. data/vendor/lexbor/source/lexbor/core/print.h +39 -0
  118. data/vendor/lexbor/source/lexbor/core/sbst.h +59 -0
  119. data/vendor/lexbor/source/lexbor/core/serialize.c +27 -0
  120. data/vendor/lexbor/source/lexbor/core/serialize.h +32 -0
  121. data/vendor/lexbor/source/lexbor/core/shs.c +118 -0
  122. data/vendor/lexbor/source/lexbor/core/shs.h +82 -0
  123. data/vendor/lexbor/source/lexbor/core/str.c +617 -0
  124. data/vendor/lexbor/source/lexbor/core/str.h +247 -0
  125. data/vendor/lexbor/source/lexbor/core/str_res.h +369 -0
  126. data/vendor/lexbor/source/lexbor/core/strtod.c +326 -0
  127. data/vendor/lexbor/source/lexbor/core/strtod.h +28 -0
  128. data/vendor/lexbor/source/lexbor/core/types.h +39 -0
  129. data/vendor/lexbor/source/lexbor/core/utils.c +43 -0
  130. data/vendor/lexbor/source/lexbor/core/utils.h +36 -0
  131. data/vendor/lexbor/source/lexbor/css/base.h +44 -0
  132. data/vendor/lexbor/source/lexbor/css/config.cmake +2 -0
  133. data/vendor/lexbor/source/lexbor/css/css.h +25 -0
  134. data/vendor/lexbor/source/lexbor/css/log.c +336 -0
  135. data/vendor/lexbor/source/lexbor/css/log.h +103 -0
  136. data/vendor/lexbor/source/lexbor/css/node.h +29 -0
  137. data/vendor/lexbor/source/lexbor/css/parser.c +473 -0
  138. data/vendor/lexbor/source/lexbor/css/parser.h +368 -0
  139. data/vendor/lexbor/source/lexbor/css/selectors/base.h +48 -0
  140. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.c +91 -0
  141. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.h +66 -0
  142. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_const.h +109 -0
  143. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_res.h +302 -0
  144. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.c +279 -0
  145. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.h +85 -0
  146. data/vendor/lexbor/source/lexbor/css/selectors/selector.c +927 -0
  147. data/vendor/lexbor/source/lexbor/css/selectors/selector.h +200 -0
  148. data/vendor/lexbor/source/lexbor/css/selectors/selectors.c +340 -0
  149. data/vendor/lexbor/source/lexbor/css/selectors/selectors.h +137 -0
  150. data/vendor/lexbor/source/lexbor/css/selectors/state.c +1718 -0
  151. data/vendor/lexbor/source/lexbor/css/selectors/state.h +79 -0
  152. data/vendor/lexbor/source/lexbor/css/stylesheet.h +37 -0
  153. data/vendor/lexbor/source/lexbor/css/syntax/anb.c +443 -0
  154. data/vendor/lexbor/source/lexbor/css/syntax/anb.h +45 -0
  155. data/vendor/lexbor/source/lexbor/css/syntax/base.h +33 -0
  156. data/vendor/lexbor/source/lexbor/css/syntax/parser.c +9 -0
  157. data/vendor/lexbor/source/lexbor/css/syntax/parser.h +25 -0
  158. data/vendor/lexbor/source/lexbor/css/syntax/res.h +48 -0
  159. data/vendor/lexbor/source/lexbor/css/syntax/state.c +2603 -0
  160. data/vendor/lexbor/source/lexbor/css/syntax/state.h +140 -0
  161. data/vendor/lexbor/source/lexbor/css/syntax/state_res.h +273 -0
  162. data/vendor/lexbor/source/lexbor/css/syntax/syntax.c +67 -0
  163. data/vendor/lexbor/source/lexbor/css/syntax/token.c +618 -0
  164. data/vendor/lexbor/source/lexbor/css/syntax/token.h +298 -0
  165. data/vendor/lexbor/source/lexbor/css/syntax/token_res.h +68 -0
  166. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.c +30 -0
  167. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.h +58 -0
  168. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.c +278 -0
  169. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.h +121 -0
  170. data/vendor/lexbor/source/lexbor/dom/base.h +32 -0
  171. data/vendor/lexbor/source/lexbor/dom/collection.c +97 -0
  172. data/vendor/lexbor/source/lexbor/dom/collection.h +112 -0
  173. data/vendor/lexbor/source/lexbor/dom/config.cmake +3 -0
  174. data/vendor/lexbor/source/lexbor/dom/dom.h +29 -0
  175. data/vendor/lexbor/source/lexbor/dom/exception.c +18 -0
  176. data/vendor/lexbor/source/lexbor/dom/exception.h +73 -0
  177. data/vendor/lexbor/source/lexbor/dom/interface.c +110 -0
  178. data/vendor/lexbor/source/lexbor/dom/interface.h +88 -0
  179. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.c +445 -0
  180. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.h +152 -0
  181. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_const.h +62 -0
  182. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_res.h +143 -0
  183. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.c +55 -0
  184. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.h +38 -0
  185. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.c +110 -0
  186. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.h +51 -0
  187. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.c +64 -0
  188. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.h +42 -0
  189. data/vendor/lexbor/source/lexbor/dom/interfaces/document.c +536 -0
  190. data/vendor/lexbor/source/lexbor/dom/interfaces/document.h +243 -0
  191. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.c +36 -0
  192. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.h +36 -0
  193. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.c +125 -0
  194. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.h +108 -0
  195. data/vendor/lexbor/source/lexbor/dom/interfaces/element.c +1411 -0
  196. data/vendor/lexbor/source/lexbor/dom/interfaces/element.h +319 -0
  197. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.c +32 -0
  198. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.h +34 -0
  199. data/vendor/lexbor/source/lexbor/dom/interfaces/node.c +661 -0
  200. data/vendor/lexbor/source/lexbor/dom/interfaces/node.h +192 -0
  201. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.c +87 -0
  202. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.h +66 -0
  203. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.c +36 -0
  204. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.h +44 -0
  205. data/vendor/lexbor/source/lexbor/dom/interfaces/text.c +63 -0
  206. data/vendor/lexbor/source/lexbor/dom/interfaces/text.h +42 -0
  207. data/vendor/lexbor/source/lexbor/encoding/base.h +218 -0
  208. data/vendor/lexbor/source/lexbor/encoding/big5.c +42839 -0
  209. data/vendor/lexbor/source/lexbor/encoding/config.cmake +12 -0
  210. data/vendor/lexbor/source/lexbor/encoding/const.h +65 -0
  211. data/vendor/lexbor/source/lexbor/encoding/decode.c +3193 -0
  212. data/vendor/lexbor/source/lexbor/encoding/decode.h +370 -0
  213. data/vendor/lexbor/source/lexbor/encoding/encode.c +1931 -0
  214. data/vendor/lexbor/source/lexbor/encoding/encode.h +377 -0
  215. data/vendor/lexbor/source/lexbor/encoding/encoding.c +252 -0
  216. data/vendor/lexbor/source/lexbor/encoding/encoding.h +475 -0
  217. data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +53883 -0
  218. data/vendor/lexbor/source/lexbor/encoding/gb18030.c +47905 -0
  219. data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +159 -0
  220. data/vendor/lexbor/source/lexbor/encoding/jis0208.c +22477 -0
  221. data/vendor/lexbor/source/lexbor/encoding/jis0212.c +15787 -0
  222. data/vendor/lexbor/source/lexbor/encoding/multi.h +53 -0
  223. data/vendor/lexbor/source/lexbor/encoding/range.c +71 -0
  224. data/vendor/lexbor/source/lexbor/encoding/range.h +34 -0
  225. data/vendor/lexbor/source/lexbor/encoding/res.c +222 -0
  226. data/vendor/lexbor/source/lexbor/encoding/res.h +34 -0
  227. data/vendor/lexbor/source/lexbor/encoding/single.c +13748 -0
  228. data/vendor/lexbor/source/lexbor/encoding/single.h +116 -0
  229. data/vendor/lexbor/source/lexbor/html/base.h +44 -0
  230. data/vendor/lexbor/source/lexbor/html/config.cmake +3 -0
  231. data/vendor/lexbor/source/lexbor/html/encoding.c +574 -0
  232. data/vendor/lexbor/source/lexbor/html/encoding.h +106 -0
  233. data/vendor/lexbor/source/lexbor/html/html.h +107 -0
  234. data/vendor/lexbor/source/lexbor/html/interface.c +165 -0
  235. data/vendor/lexbor/source/lexbor/html/interface.h +186 -0
  236. data/vendor/lexbor/source/lexbor/html/interface_res.h +4449 -0
  237. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.c +36 -0
  238. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.h +34 -0
  239. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.c +36 -0
  240. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.h +34 -0
  241. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.c +36 -0
  242. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.h +34 -0
  243. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.c +36 -0
  244. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.h +34 -0
  245. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.c +36 -0
  246. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.h +34 -0
  247. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.c +36 -0
  248. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.h +34 -0
  249. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.c +36 -0
  250. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.h +34 -0
  251. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.c +36 -0
  252. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.h +34 -0
  253. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.c +36 -0
  254. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.h +34 -0
  255. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.c +36 -0
  256. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.h +34 -0
  257. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.c +36 -0
  258. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.h +34 -0
  259. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.c +36 -0
  260. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.h +34 -0
  261. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.c +36 -0
  262. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.h +34 -0
  263. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.c +36 -0
  264. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.h +34 -0
  265. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.c +36 -0
  266. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.h +34 -0
  267. data/vendor/lexbor/source/lexbor/html/interfaces/document.c +444 -0
  268. data/vendor/lexbor/source/lexbor/html/interfaces/document.h +256 -0
  269. data/vendor/lexbor/source/lexbor/html/interfaces/element.c +64 -0
  270. data/vendor/lexbor/source/lexbor/html/interfaces/element.h +54 -0
  271. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.c +36 -0
  272. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.h +34 -0
  273. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.c +36 -0
  274. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.h +34 -0
  275. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.c +36 -0
  276. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.h +34 -0
  277. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.c +36 -0
  278. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.h +34 -0
  279. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.c +36 -0
  280. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.h +34 -0
  281. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.c +36 -0
  282. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.h +34 -0
  283. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.c +36 -0
  284. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.h +34 -0
  285. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.c +36 -0
  286. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.h +34 -0
  287. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.c +36 -0
  288. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.h +34 -0
  289. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.c +36 -0
  290. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.h +34 -0
  291. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.c +36 -0
  292. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.h +34 -0
  293. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.c +36 -0
  294. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.h +34 -0
  295. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.c +36 -0
  296. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.h +34 -0
  297. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.c +36 -0
  298. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.h +34 -0
  299. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.c +36 -0
  300. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.h +34 -0
  301. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.c +36 -0
  302. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.h +34 -0
  303. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.c +36 -0
  304. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.h +34 -0
  305. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.c +36 -0
  306. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.h +34 -0
  307. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.c +36 -0
  308. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.h +34 -0
  309. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.c +36 -0
  310. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.h +34 -0
  311. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.c +36 -0
  312. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.h +34 -0
  313. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.c +36 -0
  314. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.h +34 -0
  315. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.c +36 -0
  316. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.h +34 -0
  317. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.c +36 -0
  318. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.h +34 -0
  319. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.c +36 -0
  320. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.h +34 -0
  321. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.c +36 -0
  322. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.h +34 -0
  323. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.c +36 -0
  324. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.h +34 -0
  325. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.c +36 -0
  326. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.h +34 -0
  327. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.c +36 -0
  328. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.h +34 -0
  329. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.c +36 -0
  330. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.h +34 -0
  331. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.c +36 -0
  332. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.h +34 -0
  333. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.c +36 -0
  334. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.h +34 -0
  335. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.c +36 -0
  336. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.h +34 -0
  337. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.c +36 -0
  338. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.h +34 -0
  339. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.c +36 -0
  340. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.h +34 -0
  341. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.c +36 -0
  342. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.h +34 -0
  343. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.c +36 -0
  344. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.h +34 -0
  345. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.c +36 -0
  346. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.h +34 -0
  347. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.c +36 -0
  348. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.h +34 -0
  349. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.c +36 -0
  350. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.h +34 -0
  351. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.c +36 -0
  352. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.h +34 -0
  353. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.c +36 -0
  354. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.h +34 -0
  355. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.c +36 -0
  356. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.h +34 -0
  357. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.c +36 -0
  358. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.h +34 -0
  359. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.c +36 -0
  360. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.h +34 -0
  361. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.c +36 -0
  362. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.h +34 -0
  363. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.c +36 -0
  364. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.h +34 -0
  365. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.c +46 -0
  366. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.h +38 -0
  367. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.c +36 -0
  368. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.h +34 -0
  369. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.c +36 -0
  370. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.h +34 -0
  371. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.c +133 -0
  372. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.h +42 -0
  373. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.c +36 -0
  374. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.h +34 -0
  375. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.c +36 -0
  376. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.h +34 -0
  377. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.c +36 -0
  378. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.h +34 -0
  379. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.c +36 -0
  380. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.h +34 -0
  381. data/vendor/lexbor/source/lexbor/html/interfaces/window.c +36 -0
  382. data/vendor/lexbor/source/lexbor/html/interfaces/window.h +34 -0
  383. data/vendor/lexbor/source/lexbor/html/node.c +14 -0
  384. data/vendor/lexbor/source/lexbor/html/node.h +67 -0
  385. data/vendor/lexbor/source/lexbor/html/parser.c +469 -0
  386. data/vendor/lexbor/source/lexbor/html/parser.h +170 -0
  387. data/vendor/lexbor/source/lexbor/html/serialize.c +1510 -0
  388. data/vendor/lexbor/source/lexbor/html/serialize.h +93 -0
  389. data/vendor/lexbor/source/lexbor/html/tag.h +103 -0
  390. data/vendor/lexbor/source/lexbor/html/tag_res.h +2262 -0
  391. data/vendor/lexbor/source/lexbor/html/token.c +386 -0
  392. data/vendor/lexbor/source/lexbor/html/token.h +130 -0
  393. data/vendor/lexbor/source/lexbor/html/token_attr.c +44 -0
  394. data/vendor/lexbor/source/lexbor/html/token_attr.h +67 -0
  395. data/vendor/lexbor/source/lexbor/html/tokenizer/error.c +28 -0
  396. data/vendor/lexbor/source/lexbor/html/tokenizer/error.h +141 -0
  397. data/vendor/lexbor/source/lexbor/html/tokenizer/res.h +4956 -0
  398. data/vendor/lexbor/source/lexbor/html/tokenizer/state.c +2171 -0
  399. data/vendor/lexbor/source/lexbor/html/tokenizer/state.h +225 -0
  400. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.c +489 -0
  401. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.h +27 -0
  402. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.c +1654 -0
  403. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.h +27 -0
  404. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.c +303 -0
  405. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.h +32 -0
  406. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.c +311 -0
  407. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.h +32 -0
  408. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.c +1209 -0
  409. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.h +32 -0
  410. data/vendor/lexbor/source/lexbor/html/tokenizer.c +499 -0
  411. data/vendor/lexbor/source/lexbor/html/tokenizer.h +343 -0
  412. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.c +241 -0
  413. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.h +117 -0
  414. data/vendor/lexbor/source/lexbor/html/tree/error.c +26 -0
  415. data/vendor/lexbor/source/lexbor/html/tree/error.h +114 -0
  416. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_body.c +62 -0
  417. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_frameset.c +63 -0
  418. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_body.c +82 -0
  419. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_frameset.c +88 -0
  420. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_head.c +222 -0
  421. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_head.c +144 -0
  422. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_html.c +166 -0
  423. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/foreign_content.c +358 -0
  424. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_body.c +1974 -0
  425. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_caption.c +158 -0
  426. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_cell.c +187 -0
  427. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_column_group.c +194 -0
  428. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_frameset.c +149 -0
  429. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head.c +374 -0
  430. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head_noscript.c +121 -0
  431. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_row.c +211 -0
  432. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select.c +341 -0
  433. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select_in_table.c +115 -0
  434. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table.c +451 -0
  435. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_body.c +208 -0
  436. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_text.c +127 -0
  437. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_template.c +189 -0
  438. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/initial.c +411 -0
  439. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/text.c +61 -0
  440. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode.h +135 -0
  441. data/vendor/lexbor/source/lexbor/html/tree/open_elements.c +251 -0
  442. data/vendor/lexbor/source/lexbor/html/tree/open_elements.h +105 -0
  443. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.c +10 -0
  444. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.h +100 -0
  445. data/vendor/lexbor/source/lexbor/html/tree.c +1726 -0
  446. data/vendor/lexbor/source/lexbor/html/tree.h +431 -0
  447. data/vendor/lexbor/source/lexbor/html/tree_res.h +111 -0
  448. data/vendor/lexbor/source/lexbor/ns/base.h +32 -0
  449. data/vendor/lexbor/source/lexbor/ns/config.cmake +2 -0
  450. data/vendor/lexbor/source/lexbor/ns/const.h +37 -0
  451. data/vendor/lexbor/source/lexbor/ns/ns.c +154 -0
  452. data/vendor/lexbor/source/lexbor/ns/ns.h +66 -0
  453. data/vendor/lexbor/source/lexbor/ns/res.h +97 -0
  454. data/vendor/lexbor/source/lexbor/ports/posix/config.cmake +11 -0
  455. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/fs.c +236 -0
  456. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/memory.c +33 -0
  457. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/perf.c +158 -0
  458. data/vendor/lexbor/source/lexbor/ports/windows_nt/config.cmake +18 -0
  459. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/fs.c +239 -0
  460. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/memory.c +33 -0
  461. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/perf.c +81 -0
  462. data/vendor/lexbor/source/lexbor/selectors/base.h +30 -0
  463. data/vendor/lexbor/source/lexbor/selectors/config.cmake +2 -0
  464. data/vendor/lexbor/source/lexbor/selectors/selectors.c +1591 -0
  465. data/vendor/lexbor/source/lexbor/selectors/selectors.h +71 -0
  466. data/vendor/lexbor/source/lexbor/tag/base.h +32 -0
  467. data/vendor/lexbor/source/lexbor/tag/config.cmake +2 -0
  468. data/vendor/lexbor/source/lexbor/tag/const.h +225 -0
  469. data/vendor/lexbor/source/lexbor/tag/res.h +562 -0
  470. data/vendor/lexbor/source/lexbor/tag/tag.c +144 -0
  471. data/vendor/lexbor/source/lexbor/tag/tag.h +123 -0
  472. data/vendor/lexbor/source/lexbor/utils/base.h +32 -0
  473. data/vendor/lexbor/source/lexbor/utils/config.cmake +2 -0
  474. data/vendor/lexbor/source/lexbor/utils/http.c +534 -0
  475. data/vendor/lexbor/source/lexbor/utils/http.h +90 -0
  476. data/vendor/lexbor/source/lexbor/utils/utils.h +15 -0
  477. data/vendor/lexbor/source/lexbor/utils/warc.c +817 -0
  478. data/vendor/lexbor/source/lexbor/utils/warc.h +126 -0
  479. data/vendor/lexbor/utils/lexbor/css/selectors/pseudo.py +231 -0
  480. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/const.h +21 -0
  481. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/res.h +26 -0
  482. data/vendor/lexbor/utils/lexbor/css/syntax/definitions.py +49 -0
  483. data/vendor/lexbor/utils/lexbor/css/syntax/token_res.py +54 -0
  484. data/vendor/lexbor/utils/lexbor/css/syntax/tokenizer_code_map.py +36 -0
  485. data/vendor/lexbor/version +1 -0
  486. metadata +542 -0
@@ -0,0 +1,881 @@
1
+ /**
2
+ * threads.c: set of generic threading related routines
3
+ *
4
+ * See Copyright for the status of this software.
5
+ *
6
+ * Gary Pennington <Gary.Pennington@uk.sun.com>
7
+ * daniel@veillard.com
8
+ */
9
+
10
+ #define IN_LIBXML
11
+ #include "libxml.h"
12
+
13
+ #include <string.h>
14
+ #include <stdlib.h>
15
+
16
+ #include "libxml/threads.h"
17
+ #include "libxml/globals.h"
18
+
19
+ #if defined(SOLARIS)
20
+ #include <note.h>
21
+ #endif
22
+
23
+ #include "private/dict.h"
24
+ #include "private/threads.h"
25
+
26
+ /* #define DEBUG_THREADS */
27
+
28
+ #if defined(HAVE_POSIX_THREADS) && \
29
+ defined(__GLIBC__) && \
30
+ __GLIBC__ * 100 + __GLIBC_MINOR__ >= 234
31
+
32
+ /*
33
+ * The modern way available since glibc 2.32.
34
+ *
35
+ * The check above is for glibc 2.34 which merged the pthread symbols into
36
+ * libc. Since we still allow linking without pthread symbols (see below),
37
+ * this only works if pthread symbols are guaranteed to be available.
38
+ */
39
+
40
+ #include <sys/single_threaded.h>
41
+
42
+ #define XML_IS_THREADED() (!__libc_single_threaded)
43
+
44
+ #elif defined(HAVE_POSIX_THREADS) && \
45
+ defined(__GLIBC__) && \
46
+ defined(__GNUC__)
47
+
48
+ /*
49
+ * The traditional way to check for single-threaded applications with
50
+ * glibc was to check whether the separate libpthread library is
51
+ * linked in. This works by not linking libxml2 with libpthread (see
52
+ * BASE_THREAD_LIBS in configure.ac and Makefile.am) and declaring
53
+ * pthread functions as weak symbols.
54
+ *
55
+ * In glibc 2.34, the pthread symbols were moved from libpthread to libc,
56
+ * so this doesn't work anymore.
57
+ *
58
+ * At some point, this legacy code and the BASE_THREAD_LIBS hack in
59
+ * configure.ac can probably be removed.
60
+ */
61
+
62
+ #pragma weak pthread_getspecific
63
+ #pragma weak pthread_setspecific
64
+ #pragma weak pthread_key_create
65
+ #pragma weak pthread_key_delete
66
+ #pragma weak pthread_mutex_init
67
+ #pragma weak pthread_mutex_destroy
68
+ #pragma weak pthread_mutex_lock
69
+ #pragma weak pthread_mutex_unlock
70
+ #pragma weak pthread_cond_init
71
+ #pragma weak pthread_cond_destroy
72
+ #pragma weak pthread_cond_wait
73
+ #pragma weak pthread_equal
74
+ #pragma weak pthread_self
75
+ #pragma weak pthread_key_create
76
+ #pragma weak pthread_key_delete
77
+ #pragma weak pthread_cond_signal
78
+
79
+ #define XML_PTHREAD_WEAK
80
+ #define XML_IS_THREADED() libxml_is_threaded
81
+
82
+ static int libxml_is_threaded = -1;
83
+
84
+ #else /* other POSIX platforms */
85
+
86
+ #define XML_IS_THREADED() 1
87
+
88
+ #endif
89
+
90
+ /*
91
+ * TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
92
+ * to avoid some craziness since xmlMalloc/xmlFree may actually
93
+ * be hosted on allocated blocks needing them for the allocation ...
94
+ */
95
+
96
+ /*
97
+ * xmlRMutex are reentrant mutual exception locks
98
+ */
99
+ struct _xmlRMutex {
100
+ #ifdef HAVE_POSIX_THREADS
101
+ pthread_mutex_t lock;
102
+ unsigned int held;
103
+ unsigned int waiters;
104
+ pthread_t tid;
105
+ pthread_cond_t cv;
106
+ #elif defined HAVE_WIN32_THREADS
107
+ CRITICAL_SECTION cs;
108
+ #else
109
+ int empty;
110
+ #endif
111
+ };
112
+
113
+ /*
114
+ * This module still has some internal static data.
115
+ * - xmlLibraryLock a global lock
116
+ * - globalkey used for per-thread data
117
+ */
118
+
119
+ #ifdef HAVE_POSIX_THREADS
120
+ static pthread_key_t globalkey;
121
+ static pthread_t mainthread;
122
+ static pthread_mutex_t global_init_lock = PTHREAD_MUTEX_INITIALIZER;
123
+ #elif defined HAVE_WIN32_THREADS
124
+ #if defined(HAVE_COMPILER_TLS)
125
+ static __declspec(thread) xmlGlobalState tlstate;
126
+ static __declspec(thread) int tlstate_inited = 0;
127
+ #else /* HAVE_COMPILER_TLS */
128
+ static DWORD globalkey = TLS_OUT_OF_INDEXES;
129
+ #endif /* HAVE_COMPILER_TLS */
130
+ static DWORD mainthread;
131
+ static volatile LPCRITICAL_SECTION global_init_lock = NULL;
132
+ #endif
133
+
134
+ static xmlRMutexPtr xmlLibraryLock = NULL;
135
+
136
+ /**
137
+ * xmlInitMutex:
138
+ * @mutex: the mutex
139
+ *
140
+ * Initialize a mutex.
141
+ */
142
+ void
143
+ xmlInitMutex(xmlMutexPtr mutex)
144
+ {
145
+ #ifdef HAVE_POSIX_THREADS
146
+ pthread_mutex_init(&mutex->lock, NULL);
147
+ #elif defined HAVE_WIN32_THREADS
148
+ InitializeCriticalSection(&mutex->cs);
149
+ #else
150
+ (void) mutex;
151
+ #endif
152
+ }
153
+
154
+ /**
155
+ * xmlNewMutex:
156
+ *
157
+ * xmlNewMutex() is used to allocate a libxml2 token struct for use in
158
+ * synchronizing access to data.
159
+ *
160
+ * Returns a new simple mutex pointer or NULL in case of error
161
+ */
162
+ xmlMutexPtr
163
+ xmlNewMutex(void)
164
+ {
165
+ xmlMutexPtr tok;
166
+
167
+ if ((tok = malloc(sizeof(xmlMutex))) == NULL)
168
+ return (NULL);
169
+ xmlInitMutex(tok);
170
+ return (tok);
171
+ }
172
+
173
+ /**
174
+ * xmlCleanupMutex:
175
+ * @mutex: the simple mutex
176
+ *
177
+ * Reclaim resources associated with a mutex.
178
+ */
179
+ void
180
+ xmlCleanupMutex(xmlMutexPtr mutex)
181
+ {
182
+ #ifdef HAVE_POSIX_THREADS
183
+ pthread_mutex_destroy(&mutex->lock);
184
+ #elif defined HAVE_WIN32_THREADS
185
+ DeleteCriticalSection(&mutex->cs);
186
+ #else
187
+ (void) mutex;
188
+ #endif
189
+ }
190
+
191
+ /**
192
+ * xmlFreeMutex:
193
+ * @tok: the simple mutex
194
+ *
195
+ * Free a mutex.
196
+ */
197
+ void
198
+ xmlFreeMutex(xmlMutexPtr tok)
199
+ {
200
+ if (tok == NULL)
201
+ return;
202
+
203
+ xmlCleanupMutex(tok);
204
+ free(tok);
205
+ }
206
+
207
+ /**
208
+ * xmlMutexLock:
209
+ * @tok: the simple mutex
210
+ *
211
+ * xmlMutexLock() is used to lock a libxml2 token.
212
+ */
213
+ void
214
+ xmlMutexLock(xmlMutexPtr tok)
215
+ {
216
+ if (tok == NULL)
217
+ return;
218
+ #ifdef HAVE_POSIX_THREADS
219
+ /*
220
+ * This assumes that __libc_single_threaded won't change while the
221
+ * lock is held.
222
+ */
223
+ if (XML_IS_THREADED() != 0)
224
+ pthread_mutex_lock(&tok->lock);
225
+ #elif defined HAVE_WIN32_THREADS
226
+ EnterCriticalSection(&tok->cs);
227
+ #endif
228
+
229
+ }
230
+
231
+ /**
232
+ * xmlMutexUnlock:
233
+ * @tok: the simple mutex
234
+ *
235
+ * xmlMutexUnlock() is used to unlock a libxml2 token.
236
+ */
237
+ void
238
+ xmlMutexUnlock(xmlMutexPtr tok)
239
+ {
240
+ if (tok == NULL)
241
+ return;
242
+ #ifdef HAVE_POSIX_THREADS
243
+ if (XML_IS_THREADED() != 0)
244
+ pthread_mutex_unlock(&tok->lock);
245
+ #elif defined HAVE_WIN32_THREADS
246
+ LeaveCriticalSection(&tok->cs);
247
+ #endif
248
+ }
249
+
250
+ /**
251
+ * xmlNewRMutex:
252
+ *
253
+ * xmlRNewMutex() is used to allocate a reentrant mutex for use in
254
+ * synchronizing access to data. token_r is a re-entrant lock and thus useful
255
+ * for synchronizing access to data structures that may be manipulated in a
256
+ * recursive fashion.
257
+ *
258
+ * Returns the new reentrant mutex pointer or NULL in case of error
259
+ */
260
+ xmlRMutexPtr
261
+ xmlNewRMutex(void)
262
+ {
263
+ xmlRMutexPtr tok;
264
+
265
+ if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
266
+ return (NULL);
267
+ #ifdef HAVE_POSIX_THREADS
268
+ pthread_mutex_init(&tok->lock, NULL);
269
+ tok->held = 0;
270
+ tok->waiters = 0;
271
+ pthread_cond_init(&tok->cv, NULL);
272
+ #elif defined HAVE_WIN32_THREADS
273
+ InitializeCriticalSection(&tok->cs);
274
+ #endif
275
+ return (tok);
276
+ }
277
+
278
+ /**
279
+ * xmlFreeRMutex:
280
+ * @tok: the reentrant mutex
281
+ *
282
+ * xmlRFreeMutex() is used to reclaim resources associated with a
283
+ * reentrant mutex.
284
+ */
285
+ void
286
+ xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
287
+ {
288
+ if (tok == NULL)
289
+ return;
290
+ #ifdef HAVE_POSIX_THREADS
291
+ pthread_mutex_destroy(&tok->lock);
292
+ pthread_cond_destroy(&tok->cv);
293
+ #elif defined HAVE_WIN32_THREADS
294
+ DeleteCriticalSection(&tok->cs);
295
+ #endif
296
+ free(tok);
297
+ }
298
+
299
+ /**
300
+ * xmlRMutexLock:
301
+ * @tok: the reentrant mutex
302
+ *
303
+ * xmlRMutexLock() is used to lock a libxml2 token_r.
304
+ */
305
+ void
306
+ xmlRMutexLock(xmlRMutexPtr tok)
307
+ {
308
+ if (tok == NULL)
309
+ return;
310
+ #ifdef HAVE_POSIX_THREADS
311
+ if (XML_IS_THREADED() == 0)
312
+ return;
313
+
314
+ pthread_mutex_lock(&tok->lock);
315
+ if (tok->held) {
316
+ if (pthread_equal(tok->tid, pthread_self())) {
317
+ tok->held++;
318
+ pthread_mutex_unlock(&tok->lock);
319
+ return;
320
+ } else {
321
+ tok->waiters++;
322
+ while (tok->held)
323
+ pthread_cond_wait(&tok->cv, &tok->lock);
324
+ tok->waiters--;
325
+ }
326
+ }
327
+ tok->tid = pthread_self();
328
+ tok->held = 1;
329
+ pthread_mutex_unlock(&tok->lock);
330
+ #elif defined HAVE_WIN32_THREADS
331
+ EnterCriticalSection(&tok->cs);
332
+ #endif
333
+ }
334
+
335
+ /**
336
+ * xmlRMutexUnlock:
337
+ * @tok: the reentrant mutex
338
+ *
339
+ * xmlRMutexUnlock() is used to unlock a libxml2 token_r.
340
+ */
341
+ void
342
+ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
343
+ {
344
+ if (tok == NULL)
345
+ return;
346
+ #ifdef HAVE_POSIX_THREADS
347
+ if (XML_IS_THREADED() == 0)
348
+ return;
349
+
350
+ pthread_mutex_lock(&tok->lock);
351
+ tok->held--;
352
+ if (tok->held == 0) {
353
+ if (tok->waiters)
354
+ pthread_cond_signal(&tok->cv);
355
+ memset(&tok->tid, 0, sizeof(tok->tid));
356
+ }
357
+ pthread_mutex_unlock(&tok->lock);
358
+ #elif defined HAVE_WIN32_THREADS
359
+ LeaveCriticalSection(&tok->cs);
360
+ #endif
361
+ }
362
+
363
+ /**
364
+ * xmlGlobalInitMutexLock
365
+ *
366
+ * Makes sure that the global initialization mutex is initialized and
367
+ * locks it.
368
+ */
369
+ void
370
+ __xmlGlobalInitMutexLock(void)
371
+ {
372
+ /* Make sure the global init lock is initialized and then lock it. */
373
+ #ifdef HAVE_POSIX_THREADS
374
+ #ifdef XML_PTHREAD_WEAK
375
+ if (pthread_mutex_lock == NULL)
376
+ return;
377
+ #else
378
+ if (XML_IS_THREADED() == 0)
379
+ return;
380
+ #endif
381
+ /* The mutex is statically initialized, so we just lock it. */
382
+ pthread_mutex_lock(&global_init_lock);
383
+ #elif defined HAVE_WIN32_THREADS
384
+ LPCRITICAL_SECTION cs;
385
+
386
+ /* Create a new critical section */
387
+ if (global_init_lock == NULL) {
388
+ cs = malloc(sizeof(CRITICAL_SECTION));
389
+ if (cs == NULL) {
390
+ xmlGenericError(xmlGenericErrorContext,
391
+ "xmlGlobalInitMutexLock: out of memory\n");
392
+ return;
393
+ }
394
+ InitializeCriticalSection(cs);
395
+
396
+ /* Swap it into the global_init_lock */
397
+ #ifdef InterlockedCompareExchangePointer
398
+ InterlockedCompareExchangePointer((void **) &global_init_lock,
399
+ cs, NULL);
400
+ #else /* Use older void* version */
401
+ InterlockedCompareExchange((void **) &global_init_lock,
402
+ (void *) cs, NULL);
403
+ #endif /* InterlockedCompareExchangePointer */
404
+
405
+ /* If another thread successfully recorded its critical
406
+ * section in the global_init_lock then discard the one
407
+ * allocated by this thread. */
408
+ if (global_init_lock != cs) {
409
+ DeleteCriticalSection(cs);
410
+ free(cs);
411
+ }
412
+ }
413
+
414
+ /* Lock the chosen critical section */
415
+ EnterCriticalSection(global_init_lock);
416
+ #endif
417
+ }
418
+
419
+ void
420
+ __xmlGlobalInitMutexUnlock(void)
421
+ {
422
+ #ifdef HAVE_POSIX_THREADS
423
+ #ifdef XML_PTHREAD_WEAK
424
+ if (pthread_mutex_lock == NULL)
425
+ return;
426
+ #else
427
+ if (XML_IS_THREADED() == 0)
428
+ return;
429
+ #endif
430
+ pthread_mutex_unlock(&global_init_lock);
431
+ #elif defined HAVE_WIN32_THREADS
432
+ if (global_init_lock != NULL) {
433
+ LeaveCriticalSection(global_init_lock);
434
+ }
435
+ #endif
436
+ }
437
+
438
+ /**
439
+ * xmlGlobalInitMutexDestroy
440
+ *
441
+ * Makes sure that the global initialization mutex is destroyed before
442
+ * application termination.
443
+ */
444
+ void
445
+ __xmlGlobalInitMutexDestroy(void)
446
+ {
447
+ #ifdef HAVE_POSIX_THREADS
448
+ #elif defined HAVE_WIN32_THREADS
449
+ if (global_init_lock != NULL) {
450
+ DeleteCriticalSection(global_init_lock);
451
+ free(global_init_lock);
452
+ global_init_lock = NULL;
453
+ }
454
+ #endif
455
+ }
456
+
457
+ /************************************************************************
458
+ * *
459
+ * Per thread global state handling *
460
+ * *
461
+ ************************************************************************/
462
+
463
+ #ifdef LIBXML_THREAD_ENABLED
464
+ #ifdef xmlLastError
465
+ #undef xmlLastError
466
+ #endif
467
+
468
+ /**
469
+ * xmlFreeGlobalState:
470
+ * @state: a thread global state
471
+ *
472
+ * xmlFreeGlobalState() is called when a thread terminates with a non-NULL
473
+ * global state. It is is used here to reclaim memory resources.
474
+ */
475
+ static void
476
+ xmlFreeGlobalState(void *state)
477
+ {
478
+ xmlGlobalState *gs = (xmlGlobalState *) state;
479
+
480
+ /* free any memory allocated in the thread's xmlLastError */
481
+ xmlResetError(&(gs->xmlLastError));
482
+ free(state);
483
+ }
484
+
485
+ /**
486
+ * xmlNewGlobalState:
487
+ *
488
+ * xmlNewGlobalState() allocates a global state. This structure is used to
489
+ * hold all data for use by a thread when supporting backwards compatibility
490
+ * of libxml2 to pre-thread-safe behaviour.
491
+ *
492
+ * Returns the newly allocated xmlGlobalStatePtr or NULL in case of error
493
+ */
494
+ static xmlGlobalStatePtr
495
+ xmlNewGlobalState(void)
496
+ {
497
+ xmlGlobalState *gs;
498
+
499
+ gs = malloc(sizeof(xmlGlobalState));
500
+ if (gs == NULL) {
501
+ xmlGenericError(xmlGenericErrorContext,
502
+ "xmlGetGlobalState: out of memory\n");
503
+ return (NULL);
504
+ }
505
+
506
+ memset(gs, 0, sizeof(xmlGlobalState));
507
+ xmlInitializeGlobalState(gs);
508
+ return (gs);
509
+ }
510
+ #endif /* LIBXML_THREAD_ENABLED */
511
+
512
+ #ifdef HAVE_POSIX_THREADS
513
+ #elif defined HAVE_WIN32_THREADS
514
+ #if !defined(HAVE_COMPILER_TLS)
515
+ #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
516
+ typedef struct _xmlGlobalStateCleanupHelperParams {
517
+ HANDLE thread;
518
+ void *memory;
519
+ } xmlGlobalStateCleanupHelperParams;
520
+
521
+ static void XMLCDECL
522
+ xmlGlobalStateCleanupHelper(void *p)
523
+ {
524
+ xmlGlobalStateCleanupHelperParams *params =
525
+ (xmlGlobalStateCleanupHelperParams *) p;
526
+ WaitForSingleObject(params->thread, INFINITE);
527
+ CloseHandle(params->thread);
528
+ xmlFreeGlobalState(params->memory);
529
+ free(params);
530
+ _endthread();
531
+ }
532
+ #else /* LIBXML_STATIC && !LIBXML_STATIC_FOR_DLL */
533
+
534
+ typedef struct _xmlGlobalStateCleanupHelperParams {
535
+ void *memory;
536
+ struct _xmlGlobalStateCleanupHelperParams *prev;
537
+ struct _xmlGlobalStateCleanupHelperParams *next;
538
+ } xmlGlobalStateCleanupHelperParams;
539
+
540
+ static xmlGlobalStateCleanupHelperParams *cleanup_helpers_head = NULL;
541
+ static CRITICAL_SECTION cleanup_helpers_cs;
542
+
543
+ #endif /* LIBXMLSTATIC && !LIBXML_STATIC_FOR_DLL */
544
+ #endif /* HAVE_COMPILER_TLS */
545
+ #endif /* HAVE_WIN32_THREADS */
546
+
547
+ /**
548
+ * xmlGetGlobalState:
549
+ *
550
+ * DEPRECATED: Internal function, do not use.
551
+ *
552
+ * xmlGetGlobalState() is called to retrieve the global state for a thread.
553
+ *
554
+ * Returns the thread global state or NULL in case of error
555
+ */
556
+ xmlGlobalStatePtr
557
+ xmlGetGlobalState(void)
558
+ {
559
+ #ifdef HAVE_POSIX_THREADS
560
+ xmlGlobalState *globalval;
561
+
562
+ if (XML_IS_THREADED() == 0)
563
+ return (NULL);
564
+
565
+ if ((globalval = (xmlGlobalState *)
566
+ pthread_getspecific(globalkey)) == NULL) {
567
+ xmlGlobalState *tsd = xmlNewGlobalState();
568
+ if (tsd == NULL)
569
+ return(NULL);
570
+
571
+ pthread_setspecific(globalkey, tsd);
572
+ return (tsd);
573
+ }
574
+ return (globalval);
575
+ #elif defined HAVE_WIN32_THREADS
576
+ #if defined(HAVE_COMPILER_TLS)
577
+ if (!tlstate_inited) {
578
+ tlstate_inited = 1;
579
+ xmlInitializeGlobalState(&tlstate);
580
+ }
581
+ return &tlstate;
582
+ #else /* HAVE_COMPILER_TLS */
583
+ xmlGlobalState *globalval;
584
+ xmlGlobalStateCleanupHelperParams *p;
585
+ #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
586
+ globalval = (xmlGlobalState *) TlsGetValue(globalkey);
587
+ #else
588
+ p = (xmlGlobalStateCleanupHelperParams *) TlsGetValue(globalkey);
589
+ globalval = (xmlGlobalState *) (p ? p->memory : NULL);
590
+ #endif
591
+ if (globalval == NULL) {
592
+ xmlGlobalState *tsd = xmlNewGlobalState();
593
+
594
+ if (tsd == NULL)
595
+ return(NULL);
596
+ p = (xmlGlobalStateCleanupHelperParams *)
597
+ malloc(sizeof(xmlGlobalStateCleanupHelperParams));
598
+ if (p == NULL) {
599
+ xmlGenericError(xmlGenericErrorContext,
600
+ "xmlGetGlobalState: out of memory\n");
601
+ xmlFreeGlobalState(tsd);
602
+ return(NULL);
603
+ }
604
+ p->memory = tsd;
605
+ #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
606
+ DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
607
+ GetCurrentProcess(), &p->thread, 0, TRUE,
608
+ DUPLICATE_SAME_ACCESS);
609
+ TlsSetValue(globalkey, tsd);
610
+ _beginthread(xmlGlobalStateCleanupHelper, 0, p);
611
+ #else
612
+ EnterCriticalSection(&cleanup_helpers_cs);
613
+ if (cleanup_helpers_head != NULL) {
614
+ cleanup_helpers_head->prev = p;
615
+ }
616
+ p->next = cleanup_helpers_head;
617
+ p->prev = NULL;
618
+ cleanup_helpers_head = p;
619
+ TlsSetValue(globalkey, p);
620
+ LeaveCriticalSection(&cleanup_helpers_cs);
621
+ #endif
622
+
623
+ return (tsd);
624
+ }
625
+ return (globalval);
626
+ #endif /* HAVE_COMPILER_TLS */
627
+ #else
628
+ return (NULL);
629
+ #endif
630
+ }
631
+
632
+ /************************************************************************
633
+ * *
634
+ * Library wide thread interfaces *
635
+ * *
636
+ ************************************************************************/
637
+
638
+ /**
639
+ * xmlGetThreadId:
640
+ *
641
+ * DEPRECATED: Internal function, do not use.
642
+ *
643
+ * xmlGetThreadId() find the current thread ID number
644
+ * Note that this is likely to be broken on some platforms using pthreads
645
+ * as the specification doesn't mandate pthread_t to be an integer type
646
+ *
647
+ * Returns the current thread ID number
648
+ */
649
+ int
650
+ xmlGetThreadId(void)
651
+ {
652
+ #ifdef HAVE_POSIX_THREADS
653
+ pthread_t id;
654
+ int ret;
655
+
656
+ if (XML_IS_THREADED() == 0)
657
+ return (0);
658
+ id = pthread_self();
659
+ /* horrible but preserves compat, see warning above */
660
+ memcpy(&ret, &id, sizeof(ret));
661
+ return (ret);
662
+ #elif defined HAVE_WIN32_THREADS
663
+ return GetCurrentThreadId();
664
+ #else
665
+ return ((int) 0);
666
+ #endif
667
+ }
668
+
669
+ /**
670
+ * xmlIsMainThread:
671
+ *
672
+ * DEPRECATED: Internal function, do not use.
673
+ *
674
+ * xmlIsMainThread() check whether the current thread is the main thread.
675
+ *
676
+ * Returns 1 if the current thread is the main thread, 0 otherwise
677
+ */
678
+ int
679
+ xmlIsMainThread(void)
680
+ {
681
+ xmlInitParser();
682
+
683
+ #ifdef DEBUG_THREADS
684
+ xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
685
+ #endif
686
+ #ifdef HAVE_POSIX_THREADS
687
+ if (XML_IS_THREADED() == 0)
688
+ return (1);
689
+ return (pthread_equal(mainthread,pthread_self()));
690
+ #elif defined HAVE_WIN32_THREADS
691
+ return (mainthread == GetCurrentThreadId());
692
+ #else
693
+ return (1);
694
+ #endif
695
+ }
696
+
697
+ /**
698
+ * xmlLockLibrary:
699
+ *
700
+ * xmlLockLibrary() is used to take out a re-entrant lock on the libxml2
701
+ * library.
702
+ */
703
+ void
704
+ xmlLockLibrary(void)
705
+ {
706
+ #ifdef DEBUG_THREADS
707
+ xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
708
+ #endif
709
+ xmlRMutexLock(xmlLibraryLock);
710
+ }
711
+
712
+ /**
713
+ * xmlUnlockLibrary:
714
+ *
715
+ * xmlUnlockLibrary() is used to release a re-entrant lock on the libxml2
716
+ * library.
717
+ */
718
+ void
719
+ xmlUnlockLibrary(void)
720
+ {
721
+ #ifdef DEBUG_THREADS
722
+ xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
723
+ #endif
724
+ xmlRMutexUnlock(xmlLibraryLock);
725
+ }
726
+
727
+ /**
728
+ * xmlInitThreads:
729
+ *
730
+ * DEPRECATED: Alias for xmlInitParser.
731
+ */
732
+ void
733
+ xmlInitThreads(void)
734
+ {
735
+ xmlInitParser();
736
+ }
737
+
738
+ /**
739
+ * xmlInitThreadsInternal:
740
+ *
741
+ * Used to to initialize all the thread related data.
742
+ */
743
+ void
744
+ xmlInitThreadsInternal(void)
745
+ {
746
+ #ifdef HAVE_POSIX_THREADS
747
+ #ifdef XML_PTHREAD_WEAK
748
+ /*
749
+ * This is somewhat unreliable since libpthread could be loaded
750
+ * later with dlopen() and threads could be created. But it's
751
+ * long-standing behavior and hard to work around.
752
+ */
753
+ if (libxml_is_threaded == -1)
754
+ libxml_is_threaded = (pthread_mutex_lock != NULL);
755
+ #endif /* XML_PTHREAD_WEAK */
756
+ pthread_key_create(&globalkey, xmlFreeGlobalState);
757
+ mainthread = pthread_self();
758
+ #elif defined(HAVE_WIN32_THREADS)
759
+ #if !defined(HAVE_COMPILER_TLS)
760
+ #if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
761
+ InitializeCriticalSection(&cleanup_helpers_cs);
762
+ #endif
763
+ globalkey = TlsAlloc();
764
+ #endif
765
+ mainthread = GetCurrentThreadId();
766
+ #endif
767
+ }
768
+
769
+ /**
770
+ * xmlCleanupThreads:
771
+ *
772
+ * DEPRECATED: This function is a no-op. Call xmlCleanupParser
773
+ * to free global state but see the warnings there. xmlCleanupParser
774
+ * should be only called once at program exit. In most cases, you don't
775
+ * have call cleanup functions at all.
776
+ */
777
+ void
778
+ xmlCleanupThreads(void)
779
+ {
780
+ }
781
+
782
+ /**
783
+ * xmlCleanupThreadsInternal:
784
+ *
785
+ * Used to to cleanup all the thread related data.
786
+ */
787
+ void
788
+ xmlCleanupThreadsInternal(void)
789
+ {
790
+ #ifdef HAVE_POSIX_THREADS
791
+ pthread_key_delete(globalkey);
792
+ #elif defined(HAVE_WIN32_THREADS)
793
+ #if !defined(HAVE_COMPILER_TLS)
794
+ if (globalkey != TLS_OUT_OF_INDEXES) {
795
+ #if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
796
+ xmlGlobalStateCleanupHelperParams *p;
797
+
798
+ EnterCriticalSection(&cleanup_helpers_cs);
799
+ p = cleanup_helpers_head;
800
+ while (p != NULL) {
801
+ xmlGlobalStateCleanupHelperParams *temp = p;
802
+
803
+ p = p->next;
804
+ xmlFreeGlobalState(temp->memory);
805
+ free(temp);
806
+ }
807
+ cleanup_helpers_head = 0;
808
+ LeaveCriticalSection(&cleanup_helpers_cs);
809
+ #endif
810
+ TlsFree(globalkey);
811
+ globalkey = TLS_OUT_OF_INDEXES;
812
+ }
813
+ #if !defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)
814
+ DeleteCriticalSection(&cleanup_helpers_cs);
815
+ #endif
816
+ #endif
817
+ #endif
818
+ }
819
+
820
+ /**
821
+ * DllMain:
822
+ * @hinstDLL: handle to DLL instance
823
+ * @fdwReason: Reason code for entry
824
+ * @lpvReserved: generic pointer (depends upon reason code)
825
+ *
826
+ * Entry point for Windows library. It is being used to free thread-specific
827
+ * storage.
828
+ *
829
+ * Returns TRUE always
830
+ */
831
+ #ifdef HAVE_POSIX_THREADS
832
+ #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
833
+ #if defined(LIBXML_STATIC_FOR_DLL)
834
+ int XMLCALL
835
+ xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason,
836
+ ATTRIBUTE_UNUSED void *lpvReserved)
837
+ #else
838
+ /* declare to avoid "no previous prototype for 'DllMain'" warning */
839
+ /* Note that we do NOT want to include this function declaration in
840
+ a public header because it's meant to be called by Windows itself,
841
+ not a program that uses this library. This also has to be exported. */
842
+
843
+ XMLPUBFUN BOOL WINAPI
844
+ DllMain (HINSTANCE hinstDLL,
845
+ DWORD fdwReason,
846
+ LPVOID lpvReserved);
847
+
848
+ BOOL WINAPI
849
+ DllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason,
850
+ ATTRIBUTE_UNUSED LPVOID lpvReserved)
851
+ #endif
852
+ {
853
+ switch (fdwReason) {
854
+ case DLL_THREAD_DETACH:
855
+ if (globalkey != TLS_OUT_OF_INDEXES) {
856
+ xmlGlobalState *globalval = NULL;
857
+ xmlGlobalStateCleanupHelperParams *p =
858
+ (xmlGlobalStateCleanupHelperParams *)
859
+ TlsGetValue(globalkey);
860
+ globalval = (xmlGlobalState *) (p ? p->memory : NULL);
861
+ if (globalval) {
862
+ xmlFreeGlobalState(globalval);
863
+ TlsSetValue(globalkey, NULL);
864
+ }
865
+ if (p) {
866
+ EnterCriticalSection(&cleanup_helpers_cs);
867
+ if (p == cleanup_helpers_head)
868
+ cleanup_helpers_head = p->next;
869
+ else
870
+ p->prev->next = p->next;
871
+ if (p->next != NULL)
872
+ p->next->prev = p->prev;
873
+ LeaveCriticalSection(&cleanup_helpers_cs);
874
+ free(p);
875
+ }
876
+ }
877
+ break;
878
+ }
879
+ return TRUE;
880
+ }
881
+ #endif