Skip to content

Commit 80888c4

Browse files
committed
fix buffer interfaces
1 parent 96c6fb7 commit 80888c4

File tree

4 files changed

+29
-46
lines changed

4 files changed

+29
-46
lines changed

src/EzXML.jl

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ using XML2_jll: libxml2
108108
include("error.jl")
109109
include("node.jl")
110110
include("document.jl")
111-
include("buffer.jl")
112111
include("xpath.jl")
113112
include("streamreader.jl")
114113

src/buffer.jl

-32
This file was deleted.

src/node.jl

+27-11
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,37 @@ function prettyprint(io::IO, node::Node)
323323
dump_node(io, node, true)
324324
end
325325

326-
# Dump `node` to `io`.
327-
function dump_node(io, node, format)
326+
function dump_node(io::IO, node::Node, format::Bool)
328327
if hasdocument(node)
329328
doc_ptr = document(node).node.ptr
330329
else
331-
doc_ptr = C_NULL
330+
doc_ptr = convert(Ptr{_Node}, C_NULL)
331+
end
332+
buf_ptr = @check ccall(
333+
(:xmlBufCreate, libxml2),
334+
Ptr{Cvoid},
335+
()) != C_NULL
336+
try
337+
level = 0
338+
size = ccall(
339+
(:xmlBufNodeDump, libxml2),
340+
Csize_t,
341+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
342+
buf_ptr, doc_ptr, node.ptr, level, format)
343+
content_ptr = @check ccall(
344+
(:xmlBufContent, libxml2),
345+
Ptr{UInt8},
346+
(Ptr{Cvoid},),
347+
buf_ptr) != C_NULL
348+
unsafe_write(io, content_ptr, size)
349+
return nothing
350+
finally
351+
ccall(
352+
(:xmlBufFree, libxml2),
353+
Cvoid,
354+
(Ptr{Cvoid},),
355+
buf_ptr)
332356
end
333-
buf = Buffer()
334-
level = 0
335-
len = @check ccall(
336-
(:xmlNodeDump, libxml2),
337-
Cint,
338-
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
339-
buf.ptr, doc_ptr, node.ptr, level, format) != -1
340-
print(io, unsafe_string(unsafe_load(buf.ptr).content))
341357
end
342358

343359
function Base.:(==)(n1::Node, n2::Node)

test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,15 @@ end
13271327

13281328
doc = parsexml("<e1><e2/></e1>")
13291329
buf = IOBuffer()
1330-
print(buf, doc)
1330+
@test print(buf, doc) === nothing
13311331
@test take!(buf) == b"""
13321332
<?xml version="1.0" encoding="UTF-8"?>
13331333
<e1><e2/></e1>
13341334
"""
13351335

13361336
doc = parsexml("<e1><e2/></e1>")
13371337
buf = IOBuffer()
1338-
prettyprint(buf, doc)
1338+
@test prettyprint(buf, doc) === nothing
13391339
@test take!(buf) == b"""
13401340
<?xml version="1.0" encoding="UTF-8"?>
13411341
<e1>

0 commit comments

Comments
 (0)