Skip to content

Commit f5d8a5b

Browse files
author
Konovkin Aleksey
committed
small fixes
1 parent ed17485 commit f5d8a5b

2 files changed

Lines changed: 9 additions & 25 deletions

File tree

xmlua/document.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ function Document.lazy_load()
2828
ProcessingInstruction = require("xmlua.processing-instruction")
2929
end
3030

31-
local function print_dbg(...)
32-
-- if ngx then
33-
-- ngx.log(ngx.DEBUG, ...)
34-
-- else
35-
-- print(...)
36-
-- end
37-
end
38-
3931
local methods = {}
4032

4133
local metatable = {}
@@ -202,11 +194,9 @@ function Document.new(raw_document, errors)
202194
ffi.gc(document.raw_document, function(pdocument)
203195
for node in pairs(unlinked) do
204196
if node.parent == ffi.NULL then
205-
print_dbg("Free unlinked: ", node)
206197
libxml2.xmlFreeNode(node)
207198
end
208199
end
209-
print_dbg("xmlFreeDoc: ", pdocument)
210200
libxml2.xmlFreeDoc(pdocument)
211201
end)
212202
setmetatable(document, metatable)

xmlua/libxml2.lua

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ function libxml2.htmlCtxtReadMemory(context, html, options)
124124
if document == ffi.NULL then
125125
return nil
126126
end
127-
print_dbg("htmlCtxtReadMemory: ", document)
128-
return ffi.gc(document, function(p)
129-
print_dbg("xmlFreeDoc: ", p)
130-
xml2.xmlFreeNode(p)
131-
end)
127+
return ffi.gc(document, xml2.xmlFreeDoc)
132128
end
133129
jit.off(libxml2.htmlCtxtReadMemory)
134130

@@ -137,7 +133,7 @@ function libxml2.htmlNewDoc(uri, externa_dtd)
137133
if document == ffi.NULL then
138134
return nil
139135
end
140-
return ffi.gc(document, libxml2.xmlFreeDoc)
136+
return ffi.gc(document, xml2.xmlFreeDoc)
141137
end
142138

143139
function libxml2.xmlNewParserCtxt()
@@ -214,10 +210,7 @@ function libxml2.xmlCtxtReadMemory(context, xml, options)
214210
return nil
215211
end
216212
print_dbg("xmlCtxtReadMemory: ", document, ", ctx=", context)
217-
return ffi.gc(document, function(p)
218-
print_dbg("xmlFreeDoc: ", p, ", ctx=", context)
219-
xml2.xmlFreeDoc(p)
220-
end)
213+
return ffi.gc(document, libxml2.xmlFreeDoc)
221214

222215
end
223216
jit.off(libxml2.xmlCtxtReadMemory)
@@ -230,7 +223,10 @@ function libxml2.xmlParseChunk(context, chunk, is_terminated)
230223
end
231224
end
232225

233-
libxml2.xmlFreeDoc = xml2.xmlFreeDoc
226+
function libxml2.xmlFreeDoc(document)
227+
print_dbg("xmlFreeDoc: ", document)
228+
xml2.xmlFreeDoc(document)
229+
end
234230

235231
function libxml2.xmlDocGetRootElement(document)
236232
local root = xml2.xmlDocGetRootElement(document)
@@ -311,10 +307,7 @@ function libxml2.xmlNewDoc(xml_version)
311307
return nil
312308
end
313309
print_dbg("xmlNewDoc: ", document)
314-
return ffi.gc(document, function(p)
315-
print_dbg("xmlFreeDoc: ", p)
316-
xml2.xmlFreeDoc(p)
317-
end)
310+
return ffi.gc(document, libxml2.xmlFreeDoc)
318311
end
319312

320313
function libxml2.xmlDocSetRootElement(document, root)
@@ -605,6 +598,7 @@ function libxml2.xmlDocCopyNode(node, doc)
605598
end
606599

607600
function libxml2.xmlFreeNode(node)
601+
assert(node.parent == ffi.NULL, "node linked")
608602
print_dbg("xmlFreeNode: ", node, ", doc=", node.doc)
609603
xml2.xmlFreeNode(node)
610604
end

0 commit comments

Comments
 (0)