@@ -9,11 +9,7 @@ Licensed under MIT License, see LICENSE.md
99__precompile__ ()
1010module PCRE2
1111
12- const V6_COMPAT = VERSION < v " 0.7.0-DEV"
13-
14- if VERSION >= v " 0.7.0-DEV.3382"
15- import Libdl
16- end
12+ import Libdl
1713
1814# Load in `deps.jl`, complaining if it does not exist
1915const depsjl_path = joinpath (dirname (@__FILE__ ), " .." , " deps" , " deps.jl" )
@@ -22,36 +18,25 @@ if !isfile(depsjl_path)
2218end
2319include (depsjl_path)
2420
21+ PCRE_LOCK = nothing
22+
2523# Module initialization function
2624function __init__ ()
2725 # Always check your dependencies from `deps.jl`
2826 check_deps ()
27+ @static if isdefined (Base. PCRE, :PCRE_COMPILE_LOCK )
28+ global PCRE_LOCK = Base. PCRE. PCRE_COMPILE_LOCK
29+ else
30+ global PCRE_LOCK = Threads. SpinLock ()
31+ end
2932end
3033
3134const CodeUnitTypes = Union{UInt8, UInt16, UInt32}
3235
33- @static if V6_COMPAT
34- macro preserve (args... )
35- syms = args[1 : end - 1 ]
36- for x in syms
37- isa (x, Symbol) || error (" Preserved variable must be a symbol" )
38- end
39- esc (quote ; $ (args[end ]) ; end )
40- end
41- evr (str, rep, sub) = eval (current_module (), parse (replace (str, rep, sub)))
42- const Nothing = Void
43- const Cvoid = Void
44- _ncodeunits (:: Type{UInt8} , s) = sizeof (s)
45- _ncodeunits (:: Type{UInt16} , s) = sizeof (s)>>> 1
46- _ncodeunits (:: Type{UInt32} , s) = sizeof (s)>>> 2
47- _ncodeunits (s) = _ncodeunits (codeunit (s), s)
48- create_vector (T, len) = Vector {T} (len)
49- else # !V6_COMPAT
50- import Base. GC: @preserve
51- evr (str, rep, sub) = Core. eval (@__MODULE__ , Meta. parse (replace (str, rep => sub)))
52- const _ncodeunits = ncodeunits
53- create_vector (T, len) = Vector {T} (undef, len)
54- end
36+ import Base. GC: @preserve
37+ evr (str, rep, sub) = Core. eval (@__MODULE__ , Meta. parse (replace (str, rep => sub)))
38+ const _ncodeunits = ncodeunits
39+ create_vector (T, len) = Vector {T} (undef, len)
5540
5641import Base: RefValue
5742
@@ -88,9 +73,9 @@ jit_error(errno::Integer) = throw(PCRE2_Error("JIT ", errno))
8873compile_error (errno, erroff) = throw (PCRE2_Error (" compilation " , errno, erroff))
8974
9075function info_error (errno)
91- errno == ERROR_NULL && pcre_error (" NULL regex object" )
92- errno == ERROR_BADMAGIC && pcre_error (" Invalid regex object" )
93- errno == ERROR_BADOPTION && pcre_error (" Invalid option flags" )
76+ errno == Base . PCRE . ERROR_NULL && pcre_error (" NULL regex object" )
77+ errno == Base . PCRE . ERROR_BADMAGIC && pcre_error (" Invalid regex object" )
78+ errno == Base . PCRE . ERROR_BADOPTION && pcre_error (" Invalid option flags" )
9479 pcre_error (errno)
9580end
9681
0 commit comments