Skip to content

Commit 3227651

Browse files
committed
fix buffer interfaces
1 parent 3a7ea72 commit 3227651

File tree

4 files changed

+29
-50
lines changed

4 files changed

+29
-50
lines changed

src/EzXML.jl

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ end
114114
include("error.jl")
115115
include("node.jl")
116116
include("document.jl")
117-
include("buffer.jl")
118117
include("xpath.jl")
119118
include("streamreader.jl")
120119

src/buffer.jl

-36
This file was deleted.

src/node.jl

+27-11
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,37 @@ function prettyprint(io::IO, node::Node)
275275
dump_node(io, node, true)
276276
end
277277

278-
# Dump `node` to `io`.
279-
function dump_node(io, node, format)
278+
function dump_node(io::IO, node::Node, format::Bool)
280279
if hasdocument(node)
281280
doc_ptr = document(node).node.ptr
282281
else
283-
doc_ptr = C_NULL
282+
doc_ptr = convert(Ptr{_Node}, C_NULL)
283+
end
284+
buf_ptr = @check ccall(
285+
(:xmlBufCreate, libxml2),
286+
Ptr{Cvoid},
287+
()) != C_NULL
288+
try
289+
level = 0
290+
size = ccall(
291+
(:xmlBufNodeDump, libxml2),
292+
Csize_t,
293+
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
294+
buf_ptr, doc_ptr, node.ptr, level, format)
295+
content_ptr = @check ccall(
296+
(:xmlBufContent, libxml2),
297+
Ptr{UInt8},
298+
(Ptr{Cvoid},),
299+
buf_ptr) != C_NULL
300+
unsafe_write(io, content_ptr, size)
301+
return nothing
302+
finally
303+
ccall(
304+
(:xmlBufFree, libxml2),
305+
Cvoid,
306+
(Ptr{Cvoid},),
307+
buf_ptr)
284308
end
285-
buf = Buffer()
286-
level = 0
287-
len = @check ccall(
288-
(:xmlNodeDump, libxml2),
289-
Cint,
290-
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Cint, Cint),
291-
buf.ptr, doc_ptr, node.ptr, level, format) != -1
292-
print(io, unsafe_string(unsafe_load(buf.ptr).content))
293309
end
294310

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

test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1158,15 +1158,15 @@ end
11581158

11591159
doc = parsexml("<e1><e2/></e1>")
11601160
buf = IOBuffer()
1161-
print(buf, doc)
1161+
@test print(buf, doc) === nothing
11621162
@test take!(buf) == b"""
11631163
<?xml version="1.0" encoding="UTF-8"?>
11641164
<e1><e2/></e1>
11651165
"""
11661166

11671167
doc = parsexml("<e1><e2/></e1>")
11681168
buf = IOBuffer()
1169-
prettyprint(buf, doc)
1169+
@test prettyprint(buf, doc) === nothing
11701170
@test take!(buf) == b"""
11711171
<?xml version="1.0" encoding="UTF-8"?>
11721172
<e1>

0 commit comments

Comments
 (0)