Skip to content

Commit

Permalink
Merge pull request #78 from ScottPJones/spj/v7update
Browse files Browse the repository at this point in the history
Updates for v0.6/v0.7 compatibility
  • Loading branch information
SimonDanisch authored Feb 15, 2018
2 parents 6dc2a52 + 7c87b6f commit 4502cd9
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 129 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- 0.6
- nightly
notifications:
email: false
git:
depth: 99999999

matrix:
allow_failures:
- julia: nightly

after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("LightXML")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("LightXML")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.4
Compat 0.17.0
julia 0.6
Compat 0.45.0
@windows WinRPM
11 changes: 7 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
3 changes: 2 additions & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Compat
if is_windows()

@static if Compat.Sys.iswindows()
using WinRPM
WinRPM.install("libxml2-2", yes=true)
end
27 changes: 9 additions & 18 deletions src/LightXML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ __precompile__()

module LightXML

using Compat; import Compat.String

# iteratorsize is new in 0.5, declare it here for older versions. However,
# we do not actually support calling these, since the traits are not defined
if VERSION < v"0.5.0-dev+3305"
function iteratorsize(v)
error("Do not call this on older versions")
using Compat

const libxml2 =
if Compat.Sys.iswindows()
Pkg.dir("WinRPM", "deps", "usr", "$(Sys.ARCH)-w64-mingw32", "sys-root", "mingw",
"bin", "libxml2-2")
else
"libxml2"
end
else
import Base: iteratorsize, SizeUnknown, IsInfinite, HasLength
end


if is_windows()
const libxml2 = Pkg.dir("WinRPM","deps","usr","$(Sys.ARCH)-w64-mingw32","sys-root","mingw","bin","libxml2-2")
else
const libxml2 = "libxml2"
end

export

Expand All @@ -45,7 +36,7 @@ const Xchar = UInt8
const Xstr = Ptr{Xchar}

# opaque pointer type (do not dereference!) corresponding to xmlBufferPtr in C
immutable xmlBuffer end
struct xmlBuffer end
const Xptr = Ptr{xmlBuffer}

# pre-condition: p is not null
Expand Down
11 changes: 7 additions & 4 deletions src/cdata.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function new_cdatanode(xdoc::XMLDocument, txt::String)
p = ccall((:xmlNewCDataBlock,libxml2), Xptr, (Xptr, Xstr, Cint), xdoc.ptr, txt, length(txt)+1)
XMLNode(p)
function new_cdatanode(xdoc::XMLDocument, txt::AbstractString)
p = ccall((:xmlNewCDataBlock,libxml2), Xptr,
(Xptr, Xstr, Cint),
xdoc.ptr, txt, length(txt) + 1)
XMLNode(p)
end

add_cdata(xdoc::XMLDocument, x::XMLElement, txt::String) = add_child(x, new_cdatanode(xdoc,txt))
add_cdata(xdoc::XMLDocument, x::XMLElement, txt::AbstractString) =
add_child(x, new_cdatanode(xdoc, txt))
60 changes: 28 additions & 32 deletions src/document.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#### Document type

immutable _XMLDocStruct # use the same layout as C
struct _XMLDocStruct # use the same layout as C
# common part
_private::Ptr{Void}
_private::Ptr{Cvoid}
nodetype::Cint
name::Xstr
children::Xptr
Expand All @@ -22,17 +22,17 @@ immutable _XMLDocStruct # use the same layout as C
version::Xstr
encoding::Xstr

ids::Ptr{Void}
refs::Ptr{Void}
ids::Ptr{Cvoid}
refs::Ptr{Cvoid}
url::Xstr
charset::Cint
dict::Xstr
psvi::Ptr{Void}
psvi::Ptr{Cvoid}
parseflags::Cint
properties::Cint
end

type XMLDocument
mutable struct XMLDocument
ptr::Xptr
_struct::_XMLDocStruct

Expand All @@ -55,8 +55,8 @@ end

version(xdoc::XMLDocument) = unsafe_string(xdoc._struct.version)
encoding(xdoc::XMLDocument) = unsafe_string(xdoc._struct.encoding)
compression(xdoc::XMLDocument) = @compat Int(xdoc._struct.compression)
standalone(xdoc::XMLDocument) = @compat Int(xdoc._struct.standalone)
compression(xdoc::XMLDocument) = Int(xdoc._struct.compression)
standalone(xdoc::XMLDocument) = Int(xdoc._struct.standalone)

function root(xdoc::XMLDocument)
pr = ccall((:xmlDocGetRootElement,libxml2), Xptr, (Xptr,), xdoc.ptr)
Expand All @@ -68,7 +68,7 @@ end
#### construction & free

function free(xdoc::XMLDocument)
ccall((:xmlFreeDoc,libxml2), Void, (Xptr,), xdoc.ptr)
ccall((:xmlFreeDoc,libxml2), Cvoid, (Xptr,), xdoc.ptr)
xdoc.ptr = C_NULL
end

Expand All @@ -84,42 +84,38 @@ end

#### parse and free

function parse_file(filename::AbstractString)
p = ccall((:xmlParseFile,libxml2), Xptr, (Cstring,), filename)
function _check_result(p)
p != C_NULL || throw(XMLParseError("Failure in parsing an XML file."))
XMLDocument(p)
end

function parse_file(filename::AbstractString, encoding, options::Integer)
p = ccall((:xmlReadFile,libxml2), Xptr, (Cstring, Ptr{Cchar}, Cint),
filename, encoding, options)
p != C_NULL || throw(XMLParseError("Failure in parsing an XML file."))
XMLDocument(p)
end
parse_file(filename::AbstractString) =
_check_result(ccall((:xmlParseFile,libxml2), Xptr, (Cstring,), filename))

function parse_string(s::AbstractString)
p = ccall((:xmlParseMemory,libxml2), Xptr, (Xstr, Cint), s, sizeof(s) + 1)
p != C_NULL || throw(XMLParseError("Failure in parsing an XML string."))
XMLDocument(p)
end
parse_file(filename::AbstractString, encoding, options::Integer) =
_check_result(ccall((:xmlReadFile,libxml2), Xptr, (Cstring, Ptr{Cchar}, Cint),
filename, encoding, options))

parse_string(s::AbstractString) =
_check_result(ccall((:xmlParseMemory,libxml2), Xptr, (Xstr, Cint), s, sizeof(s) + 1))


#### output

function save_file(xdoc::XMLDocument, filename::AbstractString; encoding::AbstractString="utf-8")
ret = ccall((:xmlSaveFormatFileEnc,libxml2), Cint, (Cstring, Xptr, Cstring, Cint),
filename, xdoc.ptr, encoding, 1)
if ret < 0
throw(XMLWriteError("Failed to save XML to file $filename"))
end
return @compat Int(ret) # number of bytes written
ret = ccall((:xmlSaveFormatFileEnc,libxml2), Cint,
(Cstring, Xptr, Cstring, Cint),
filename, xdoc.ptr, encoding, 1)
ret < 0 && throw(XMLWriteError("Failed to save XML to file $filename"))
Int(ret) # number of bytes written
end

function Base.string(xdoc::XMLDocument; encoding::AbstractString="utf-8")
buf_out = Vector{Xstr}(1)
len_out = Vector{Cint}(1)
ccall((:xmlDocDumpFormatMemoryEnc,libxml2), Void, (Xptr, Ptr{Xstr}, Ptr{Cint}, Cstring, Cint),
xdoc.ptr, buf_out, len_out, encoding, 1)
buf_out = Vector{Xstr}(uninitialized, 1)
len_out = Vector{Cint}(uninitialized, 1)
ccall((:xmlDocDumpFormatMemoryEnc,libxml2), Cvoid,
(Xptr, Ptr{Xstr}, Ptr{Cint}, Cstring, Cint),
xdoc.ptr, buf_out, len_out, encoding, 1)
_xcopystr(buf_out[1])
end

Expand Down
17 changes: 7 additions & 10 deletions src/errors.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
abstract type XMLError <: Exception end

@compat abstract type XMLError <: Exception end
struct XMLNoRootError <: XMLError ; end

immutable XMLParseError{T<:AbstractString} <: XMLError
msg::T
end
struct XMLAttributeNotFound <: XMLError ; end

immutable XMLNoRootError <: XMLError
end

immutable XMLAttributeNotFound <: XMLError
struct XMLParseError{T<:AbstractString} <: XMLError
msg::T
end

immutable XMLWriteError{T<:AbstractString} <: XMLError
struct XMLWriteError{T<:AbstractString} <: XMLError
msg::T
end

immutable XMLTreeError{T<:AbstractString} <: XMLError
struct XMLTreeError{T<:AbstractString} <: XMLError
msg::T
end
Loading

0 comments on commit 4502cd9

Please sign in to comment.