Skip to content

Commit

Permalink
pcre2: fix various ccall signatures (follow-on to #11447)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Jun 1, 2015
1 parent acf8a9a commit 234f1a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,25 @@ end

function get_ovec(match_data)
ptr = ccall((:pcre2_get_ovector_pointer_8, PCRE_LIB), Ptr{Csize_t},
(Ptr{Void},), match_data)
(Ptr{Void},), match_data)
n = ccall((:pcre2_get_ovector_count_8, PCRE_LIB), UInt32,
(Ptr{Void},), match_data)
pointer_to_array(ptr, 2n, false)
end

function compile(pattern::AbstractString, options::Integer)
errno = Ref{Int32}(0)
erroff = Ref{UInt32}(0)
errno = Ref{Cint}(0)
erroff = Ref{Csize_t}(0)
re_ptr = ccall((:pcre2_compile_8, PCRE_LIB), Ptr{Void},
(Cstring, UInt32, UInt32, Ref{Int32}, Ref{UInt32}, Ptr{Void}),
pattern, sizeof(pattern), options, errno, erroff, C_NULL)
(Ptr{UInt8}, Csize_t, UInt32, Ref{Cint}, Ref{Csize_t}, Ptr{Void}),
pattern, sizeof(pattern), options, errno, erroff, C_NULL)
re_ptr == C_NULL && error("PCRE compilation error: $(err_message(errno[])) at offset $(erroff[])")
re_ptr
end

function jit_compile(regex::Ptr{Void})
errno = ccall((:pcre2_jit_compile_8, PCRE_LIB), UInt32,
(Ptr{Void}, Int32),
regex, JIT_COMPLETE)
errno = ccall((:pcre2_jit_compile_8, PCRE_LIB), Cint,
(Ptr{Void}, UInt32), regex, JIT_COMPLETE)
errno == 0 || error("PCRE JIT error: $(err_message(errno))")
end

Expand All @@ -118,13 +117,13 @@ free_match_context(context) =
function err_message(errno)
buffer = Array(UInt8, 256)
ccall((:pcre2_get_error_message_8, PCRE_LIB), Void,
(Int32, Ptr{UInt8}, UInt32), errno, buffer, sizeof(buffer))
(Int32, Ptr{UInt8}, Csize_t), errno, buffer, sizeof(buffer))
bytestring(pointer(buffer))
end

function exec(re,subject,offset,options,match_data)
rc = ccall((:pcre2_match_8, PCRE_LIB), Cint,
(Ptr{Void}, Cstring, Csize_t, Csize_t, Cuint, Ptr{Void}, Ptr{Void}),
(Ptr{Void}, Ptr{UInt8}, Csize_t, Csize_t, Cuint, Ptr{Void}, Ptr{Void}),
re, subject, sizeof(subject), offset, options, match_data, MATCH_CONTEXT)
# rc == -1 means no match, -2 means partial match.
rc < -2 && error("PCRE.exec error: $(err_message(rc))")
Expand All @@ -141,5 +140,4 @@ function substring_number_from_name(re, name)
(Ptr{Void}, Cstring), re, name)
end


end # module
4 changes: 2 additions & 2 deletions test/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ buf = PipeBuffer()
show(buf, r"")
@test readall(buf) == "r\"\""

# issue #10994: PCRE does not allow NUL chars in the pattern
@test_throws ArgumentError Regex("a\0b")
# see #10994, #11447: PCRE2 allows NUL chars in the pattern
@test ismatch(Regex("^a\0b\$"), "a\0b")

# regex match / search string must be a ByteString
@test_throws ArgumentError match(r"test", utf32("this is a test"))
Expand Down

0 comments on commit 234f1a8

Please sign in to comment.