Skip to content

Commit

Permalink
Use per-thread libxml2 global state on all platforms (#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).
  • Loading branch information
HertzDevil authored Oct 25, 2024
1 parent 24fc1a9 commit 4016f39
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/xml/libxml2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down

0 comments on commit 4016f39

Please sign in to comment.