Skip to content

Commit

Permalink
Update for changes in Base regex support
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Jul 31, 2019
1 parent 6e02811 commit 5bb27da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["Strings", "PCRE", "Regex"]
license = "MIT"
name = "PCRE2"
uuid = "c9310f65-a42c-5928-aca3-d34f64192029"
version = "1.0.1"
version = "1.0.2"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand Down
45 changes: 15 additions & 30 deletions src/PCRE2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ Licensed under MIT License, see LICENSE.md
__precompile__()
module PCRE2

const V6_COMPAT = VERSION < v"0.7.0-DEV"

if VERSION >= v"0.7.0-DEV.3382"
import Libdl
end
import Libdl

# Load in `deps.jl`, complaining if it does not exist
const depsjl_path = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
Expand All @@ -22,36 +18,25 @@ if !isfile(depsjl_path)
end
include(depsjl_path)

PCRE_LOCK = nothing

# Module initialization function
function __init__()
# Always check your dependencies from `deps.jl`
check_deps()
@static if isdefined(Base.PCRE, :PCRE_COMPILE_LOCK)
global PCRE_LOCK = Base.PCRE.PCRE_COMPILE_LOCK
else
global PCRE_LOCK = Threads.SpinLock()
end
end

const CodeUnitTypes = Union{UInt8, UInt16, UInt32}

@static if V6_COMPAT
macro preserve(args...)
syms = args[1:end-1]
for x in syms
isa(x, Symbol) || error("Preserved variable must be a symbol")
end
esc(quote ; $(args[end]) ; end)
end
evr(str, rep, sub) = eval(current_module(), parse(replace(str, rep, sub)))
const Nothing = Void
const Cvoid = Void
_ncodeunits(::Type{UInt8}, s) = sizeof(s)
_ncodeunits(::Type{UInt16}, s) = sizeof(s)>>>1
_ncodeunits(::Type{UInt32}, s) = sizeof(s)>>>2
_ncodeunits(s) = _ncodeunits(codeunit(s), s)
create_vector(T, len) = Vector{T}(len)
else # !V6_COMPAT
import Base.GC: @preserve
evr(str, rep, sub) = Core.eval(@__MODULE__, Meta.parse(replace(str, rep => sub)))
const _ncodeunits = ncodeunits
create_vector(T, len) = Vector{T}(undef, len)
end
import Base.GC: @preserve
evr(str, rep, sub) = Core.eval(@__MODULE__, Meta.parse(replace(str, rep => sub)))
const _ncodeunits = ncodeunits
create_vector(T, len) = Vector{T}(undef, len)

import Base: RefValue

Expand Down Expand Up @@ -88,9 +73,9 @@ jit_error(errno::Integer) = throw(PCRE2_Error("JIT ", errno))
compile_error(errno, erroff) = throw(PCRE2_Error("compilation ", errno, erroff))

function info_error(errno)
errno == ERROR_NULL && pcre_error("NULL regex object")
errno == ERROR_BADMAGIC && pcre_error("Invalid regex object")
errno == ERROR_BADOPTION && pcre_error("Invalid option flags")
errno == Base.PCRE.ERROR_NULL && pcre_error("NULL regex object")
errno == Base.PCRE.ERROR_BADMAGIC && pcre_error("Invalid regex object")
errno == Base.PCRE.ERROR_BADOPTION && pcre_error("Invalid option flags")
pcre_error(errno)
end

Expand Down

2 comments on commit 5bb27da

@ScottPJones
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/2410

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.2 -m "<description of version>" 5bb27daabf7cd6d0c102af532b93ca98e32f58fb
git push origin v1.0.2

Please sign in to comment.