Skip to content

Commit afa1404

Browse files
committed
Upgrade to PCRE2 10.10
1 parent 556bbe3 commit afa1404

File tree

13 files changed

+167
-173
lines changed

13 files changed

+167
-173
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ notifications:
2323
before_install:
2424
- if [ `uname` = "Linux" ]; then
2525
BUILDOPTS="USEGCC=1 LLVM_CONFIG=llvm-config-3.3 LLVM_LLC=llc-3.3 VERBOSE=1 USE_BLAS64=0";
26-
for lib in LLVM ZLIB SUITESPARSE ARPACK BLAS FFTW LAPACK GMP MPFR PCRE LIBUNWIND OPENLIBM RMATH; do
26+
for lib in LLVM ZLIB SUITESPARSE ARPACK BLAS FFTW LAPACK GMP MPFR LIBUNWIND OPENLIBM RMATH; do
2727
export BUILDOPTS="$BUILDOPTS USE_SYSTEM_$lib=1";
2828
done;
2929
sudo add-apt-repository ppa:staticfloat/julia-deps -y;
@@ -42,7 +42,7 @@ before_install:
4242
brew install -v --only-dependencies --HEAD julia;
4343
BUILDOPTS="USECLANG=1 LLVM_CONFIG=$(brew --prefix llvm33-julia)/bin/llvm-config-3.3 VERBOSE=1 USE_BLAS64=0 SUITESPARSE_INC=-I$(brew --prefix suite-sparse-julia)/include";
4444
BUILDOPTS="$BUILDOPTS LIBBLAS=-lopenblas LIBBLASNAME=libopenblas LIBLAPACK=-lopenblas LIBLAPACKNAME=libopenblas";
45-
for lib in LLVM ZLIB SUITESPARSE ARPACK BLAS FFTW LAPACK GMP MPFR PCRE LIBUNWIND LIBGIT2; do
45+
for lib in LLVM ZLIB SUITESPARSE ARPACK BLAS FFTW LAPACK GMP MPFR LIBUNWIND LIBGIT2; do
4646
export BUILDOPTS="$BUILDOPTS USE_SYSTEM_$lib=1";
4747
done;
4848
export LDFLAGS="-L$(brew --prefix openblas-julia)/lib -L$(brew --prefix suite-sparse-julia)/lib";

Make.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ LLVM_LLC=$(build_bindir)/llc$(EXE)
557557
endif
558558

559559
ifeq ($(USE_SYSTEM_PCRE), 1)
560-
PCRE_CONFIG = pcre-config
560+
PCRE_CONFIG = pcre2-config
561561
else
562-
PCRE_CONFIG = $(build_bindir)/pcre-config
562+
PCRE_CONFIG = $(build_bindir)/pcre2-config
563563
endif
564564

565565
# Use 64-bit libraries by default on 64-bit architectures

base/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ JULIAHOME = ..
22
include ../deps/Versions.make
33
include ../Make.inc
44

5-
PCRE_CONST = 0x[0-9a-fA-F]+|[-+]?\s*[0-9]+
6-
75
TAGGED_RELEASE_BANNER = ""
86

97
ifneq ($(USEMSVC), 1)
@@ -14,13 +12,16 @@ endif
1412

1513
all: pcre_h.jl errno_h.jl build_h.jl.phony fenv_constants.jl file_constants.jl uv_constants.jl version_git.jl.phony
1614

17-
pcre_h.jl:
15+
PCRE_CONST = 0x[0-9a-fA-F]+|[0-9]+
1816
ifeq ($(USE_SYSTEM_PCRE), 1)
19-
@$(call PRINT_PERL, $(CPP) -dM $(shell $(PCRE_CONFIG) --prefix)/include/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
17+
PCRE_INCL_PATH = $(shell $(PCRE_CONFIG) --prefix)/include/pcre2.h
2018
else
21-
@$(call PRINT_PERL, $(CPP) -dM $(build_includedir)/pcre.h | perl -nle '/^\s*#define\s+PCRE_(\w*)\s*\(?($(PCRE_CONST))\)?\s*$$/ and print "const $$1 = Int32($$2)"' | sort > $@)
19+
PCRE_INCL_PATH = $(build_includedir)/pcre2.h
2220
endif
2321

22+
pcre_h.jl:
23+
@$(call PRINT_PERL, $(CPP) -D PCRE2_CODE_UNIT_WIDTH=8 -dM $(PCRE_INCL_PATH) | perl -nle '/^\s*#define\s+PCRE2_(\w*)\s*\(?($(PCRE_CONST))\)?u?\s*$$/ and print "const $$1 = UInt32($$2)"' | sort > $@)
24+
2425
errno_h.jl:
2526
@$(call PRINT_PERL, echo '#include "errno.h"' | $(CPP) -dM - | perl -nle 'print "const $$1 = Int32($$2)" if /^#define\s+(E\w+)\s+(\d+)\s*$$/' | sort > $@)
2627

base/pcre.jl

Lines changed: 69 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
## low-level pcre interface ##
3+
## low-level pcre2 interface ##
44

55
module PCRE
66

77
include("pcre_h.jl")
88

9-
const VERSION = bytestring(ccall((:pcre_version, :libpcre), Ptr{UInt8}, ()))
9+
const PCRE_LIB = "libpcre2-8"
1010

1111
global JIT_STACK = C_NULL
12+
global MATCH_CONTEXT = C_NULL
13+
1214
function __init__()
1315
JIT_STACK_START_SIZE = 32768
1416
JIT_STACK_MAX_SIZE = 1048576
15-
global JIT_STACK = ccall((:pcre_jit_stack_alloc, :libpcre), Ptr{Void},
16-
(Cint, Cint), JIT_STACK_START_SIZE, JIT_STACK_MAX_SIZE)
17+
global JIT_STACK = ccall((:pcre2_jit_stack_create_8, PCRE_LIB), Ptr{Void},
18+
(Cint, Cint, Ptr{Void}),
19+
JIT_STACK_START_SIZE, JIT_STACK_MAX_SIZE, C_NULL)
20+
global MATCH_CONTEXT = ccall((:pcre2_match_context_create_8, PCRE_LIB),
21+
Ptr{Void}, (Ptr{Void},), C_NULL)
22+
ccall((:pcre2_jit_stack_assign_8, PCRE_LIB), Void,
23+
(Ptr{Void}, Ptr{Void}, Ptr{Void}), MATCH_CONTEXT, C_NULL, JIT_STACK)
1724
end
1825

1926
# supported options for different use cases
@@ -25,7 +32,6 @@ const COMPILE_MASK =
2532
DOTALL |
2633
EXTENDED |
2734
FIRSTLINE |
28-
JAVASCRIPT_COMPAT |
2935
MULTILINE |
3036
NEWLINE_ANY |
3137
NEWLINE_ANYCRLF |
@@ -34,9 +40,9 @@ const COMPILE_MASK =
3440
NEWLINE_LF |
3541
NO_AUTO_CAPTURE |
3642
NO_START_OPTIMIZE |
37-
NO_UTF8_CHECK |
43+
NO_UTF_CHECK |
3844
UNGREEDY |
39-
UTF8
45+
UTF
4046

4147
const EXECUTE_MASK =
4248
NEWLINE_ANY |
@@ -49,20 +55,20 @@ const EXECUTE_MASK =
4955
NOTEMPTY_ATSTART |
5056
NOTEOL |
5157
NO_START_OPTIMIZE |
52-
NO_UTF8_CHECK |
58+
NO_UTF_CHECK |
5359
PARTIAL_HARD |
5460
PARTIAL_SOFT
5561

62+
5663
const OPTIONS_MASK = COMPILE_MASK | EXECUTE_MASK
5764

58-
function info{T}(
59-
regex::Ptr{Void},
60-
extra::Ptr{Void}, what::Integer, ::Type{T}
61-
)
65+
const UNSET = ~Csize_t(0) # Indicates that an output vector element is unset
66+
67+
function info(regex::Ptr{Void}, what::Integer, T)
6268
buf = zeros(UInt8,sizeof(T))
63-
ret = ccall((:pcre_fullinfo, :libpcre), Int32,
64-
(Ptr{Void}, Ptr{Void}, Int32, Ptr{UInt8}),
65-
regex, extra, what, buf)
69+
ret = ccall((:pcre2_pattern_info_8, PCRE_LIB), Int32,
70+
(Ptr{Void}, Int32, Ptr{UInt8}),
71+
regex, what, buf)
6672
if ret != 0
6773
error(ret == ERROR_NULL ? "NULL regex object" :
6874
ret == ERROR_BADMAGIC ? "invalid regex object" :
@@ -72,83 +78,68 @@ function info{T}(
7278
reinterpret(T,buf)[1]
7379
end
7480

75-
function config{T}(what::Integer, ::Type{T})
76-
buf = zeros(UInt8, sizeof(T))
77-
ret = ccall((:pcre_config, :libpcre), Int32,
78-
(Int32, Ptr{UInt8}),
79-
what, buf)
80-
81-
if ret != 0
82-
error("PCRE.config error code $n")
83-
end
84-
reinterpret(T,buf)[1]
81+
function get_ovec(match_data)
82+
ptr = ccall((:pcre2_get_ovector_pointer_8, PCRE_LIB), Ptr{Csize_t},
83+
(Ptr{Void},), match_data)
84+
n = ccall((:pcre2_get_ovector_count_8, PCRE_LIB), UInt32,
85+
(Ptr{Void},), match_data)
86+
pointer_to_array(ptr, 2n, false)
8587
end
8688

8789
function compile(pattern::AbstractString, options::Integer)
88-
errstr = Array(Ptr{UInt8},1)
89-
errstr[1] = C_NULL
90-
erroff = zeros(Int32,1)
91-
re_ptr = ccall((:pcre_compile, :libpcre), Ptr{Void},
92-
(Cstring, Int32, Ptr{Ptr{UInt8}}, Ptr{Int32}, Ptr{UInt8}),
93-
pattern, options, errstr, erroff, C_NULL)
94-
if re_ptr == C_NULL
95-
error("$(bytestring(errstr[1]))",
96-
" at position $(erroff[1]+1)",
97-
" in $(repr(pattern))")
98-
end
99-
90+
errno = Ref{Int32}(0)
91+
erroff = Ref{UInt32}(0)
92+
re_ptr = ccall((:pcre2_compile_8, PCRE_LIB), Ptr{Void},
93+
(Cstring, UInt32, UInt32, Ref{Int32}, Ref{UInt32}, Ptr{Void}),
94+
pattern, sizeof(pattern), options, errno, erroff, C_NULL)
95+
re_ptr == C_NULL && error("PCRE compilation error: $(err_message(errno[])) at offset $(erroff[])")
10096
re_ptr
10197
end
10298

103-
function study(regex::Ptr{Void}, options::Integer)
104-
# NOTE: options should always be zero in current PCRE
105-
errstr = Array(Ptr{UInt8},1)
106-
errstr[1] = C_NULL
107-
extra = ccall((:pcre_study, :libpcre), Ptr{Void},
108-
(Ptr{Void}, Int32, Ptr{Ptr{UInt8}}),
109-
regex, options, errstr)
110-
if errstr[1] != C_NULL
111-
error("$(bytestring(errstr[1]))")
112-
end
113-
114-
ccall((:pcre_assign_jit_stack, :libpcre), Void,
115-
(Ptr{Void}, Ptr{Void}, Ptr{Void}),
116-
extra, C_NULL, JIT_STACK)
117-
extra
99+
function jit_compile(regex::Ptr{Void})
100+
errno = ccall((:pcre2_jit_compile_8, PCRE_LIB), UInt32,
101+
(Ptr{Void}, Int32),
102+
regex, JIT_COMPLETE)
103+
errno == 0 || error("PCRE JIT error: $(err_message(errno))")
118104
end
119105

120-
study(re::Ptr{Void}) = study(re, Int32(0))
106+
free_match_data(match_data) =
107+
ccall((:pcre2_match_data_free_8, PCRE_LIB), Void, (Ptr{Void},), match_data)
108+
109+
free_re(re) =
110+
ccall((:pcre2_code_free_8, PCRE_LIB), Void, (Ptr{Void},), re)
111+
112+
free_jit_stack(stack) =
113+
ccall((:pcre2_jit_stack_free_8, PCRE_LIB), Void, (Ptr{Void},), stack)
121114

122-
free_study(extra::Ptr{Void}) =
123-
ccall((:pcre_free_study, :libpcre), Void, (Ptr{Void},), extra)
124-
free(regex::Ptr{Void}) =
125-
ccall(unsafe_load(cglobal((:pcre_free, :libpcre),Ptr{Void})), Void, (Ptr{Void},), regex)
115+
free_match_context(context) =
116+
ccall((:pcre2_match_context_free_8, PCRE_LIB), Void, (Ptr{Void},), context)
126117

127-
function exec(regex::Ptr{Void}, extra::Ptr{Void}, str::SubString, offset::Integer,
128-
options::Integer, ovec::Vector{Int32})
129-
return exec(regex, extra, str.string, str.offset, offset, sizeof(str),
130-
options, ovec)
118+
function err_message(errno)
119+
buffer = Array(UInt8, 256)
120+
ccall((:pcre2_get_error_message_8, PCRE_LIB), Void,
121+
(Int32, Ptr{UInt8}, UInt32), errno, buffer, sizeof(buffer))
122+
bytestring(pointer(buffer))
131123
end
132124

133-
function exec(regex::Ptr{Void}, extra::Ptr{Void}, str::ByteString, offset::Integer,
134-
options::Integer, ovec::Vector{Int32})
135-
return exec(regex, extra, str, 0, offset, sizeof(str), options, ovec)
125+
function exec(re,subject,offset,options,match_data)
126+
rc = ccall((:pcre2_match_8, PCRE_LIB), Cint,
127+
(Ptr{Void}, Cstring, Csize_t, Csize_t, Cuint, Ptr{Void}, Ptr{Void}),
128+
re, subject, sizeof(subject), offset, options, match_data, MATCH_CONTEXT)
129+
# rc == -1 means no match, -2 means partial match.
130+
rc < -2 && error("PCRE.exec error: $(err_message(rc))")
131+
rc >= 0
136132
end
137133

138-
function exec(regex::Ptr{Void}, extra::Ptr{Void},
139-
str::ByteString, shift::Integer, offset::Integer,
140-
len::Integer, options::Integer,
141-
ovec::Vector{Int32})
142-
if offset < 0 || len < offset || len+shift > sizeof(str)
143-
throw(BoundsError())
144-
end
145-
n = ccall((:pcre_exec, :libpcre), Int32,
146-
(Ptr{Void}, Ptr{Void}, Ptr{UInt8}, Int32,
147-
Int32, Int32, Ptr{Int32}, Int32),
148-
regex, extra, pointer(str.data,shift+1), len,
149-
offset, options, ovec, length(ovec))
150-
n < -1 && error("PCRE.exec error code $n")
151-
return n > -1
134+
function create_match_data(re)
135+
ccall((:pcre2_match_data_create_from_pattern_8, PCRE_LIB),
136+
Ptr{Void}, (Ptr{Void}, Ptr{Void}), re, C_NULL)
137+
end
138+
139+
function substring_number_from_name(re, name)
140+
ccall((:pcre2_substring_number_from_name_8, PCRE_LIB), Cint,
141+
(Ptr{Void}, Cstring), re, name)
152142
end
153143

144+
154145
end # module

0 commit comments

Comments
 (0)