Skip to content

Commit

Permalink
Use per-thread libxml2 global state on all platforms (crystal-lang#15121
Browse files Browse the repository at this point in the history
)

libxml2's build files enable threads by default, so I'd be surprised if any platform still disables them (embedded systems don't count yet).
HertzDevil authored Oct 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 24fc1a9 commit 4016f39
Showing 2 changed files with 4 additions and 20 deletions.
14 changes: 2 additions & 12 deletions src/xml.cr
Original file line number Diff line number Diff line change
@@ -107,12 +107,7 @@ module XML
end

protected def self.with_indent_tree_output(indent : Bool, &)
ptr = {% if flag?(:win32) %}
LibXML.__xmlIndentTreeOutput
{% else %}
pointerof(LibXML.xmlIndentTreeOutput)
{% end %}

ptr = LibXML.__xmlIndentTreeOutput
old, ptr.value = ptr.value, indent ? 1 : 0
begin
yield
@@ -122,12 +117,7 @@ module XML
end

protected def self.with_tree_indent_string(string : String, &)
ptr = {% if flag?(:win32) %}
LibXML.__xmlTreeIndentString
{% else %}
pointerof(LibXML.xmlTreeIndentString)
{% end %}

ptr = LibXML.__xmlTreeIndentString
old, ptr.value = ptr.value, string.to_unsafe
begin
yield
10 changes: 2 additions & 8 deletions src/xml/libxml2.cr
Original file line number Diff line number Diff line change
@@ -13,14 +13,8 @@ lib LibXML

fun xmlInitParser

# TODO: check if other platforms also support per-thread globals
{% if flag?(:win32) %}
fun __xmlIndentTreeOutput : Int*
fun __xmlTreeIndentString : UInt8**
{% else %}
$xmlIndentTreeOutput : Int
$xmlTreeIndentString : UInt8*
{% end %}
fun __xmlIndentTreeOutput : Int*
fun __xmlTreeIndentString : UInt8**

alias Dtd = Void*
alias Dict = Void*

0 comments on commit 4016f39

Please sign in to comment.