Skip to content
Snippets Groups Projects
Verified Commit 0684fb6e authored by jD91mZM2's avatar jD91mZM2
Browse files

Bump posix-regex version

parent d2528384
No related branches found
No related tags found
No related merge requests found
Subproject commit bf7d93bb7aba406dc135a7a9eb031371e7739fe6 Subproject commit 0d996efe5cfe7ce181af35d8817ac4deae644d4a
...@@ -118,11 +118,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)> ...@@ -118,11 +118,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)>
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fnmatch( pub unsafe extern "C" fn fnmatch(pattern: *const c_char, input: *const c_char, flags: c_int) -> c_int {
mut pattern: *const c_char,
mut input: *const c_char,
flags: c_int,
) -> c_int {
let mut len = 0; let mut len = 0;
while *input.offset(len) != 0 { while *input.offset(len) != 0 {
len += 1; len += 1;
......
...@@ -49,18 +49,6 @@ pub const REG_ERANGE: c_int = 12; ...@@ -49,18 +49,6 @@ pub const REG_ERANGE: c_int = 12;
pub const REG_ESPACE: c_int = 13; pub const REG_ESPACE: c_int = 13;
pub const REG_BADRPT: c_int = 14; pub const REG_BADRPT: c_int = 14;
fn count_groups(branches: &[Vec<(Token, Range)>]) -> usize {
let mut count = 0;
for branch in branches {
for (token, _) in branch {
if let Token::Group(ref inner) = token {
count += 1 + count_groups(inner);
}
}
}
count
}
#[no_mangle] #[no_mangle]
pub extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int { pub extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int {
if cflags & REG_EXTENDED == REG_EXTENDED { if cflags & REG_EXTENDED == REG_EXTENDED {
...@@ -74,7 +62,7 @@ pub extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) ...@@ -74,7 +62,7 @@ pub extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int)
match res { match res {
Ok(mut branches) => unsafe { Ok(mut branches) => unsafe {
let re_nsub = count_groups(&branches); let re_nsub = PosixRegex::new(Cow::Borrowed(&branches)).count_groups();
*out = regex_t { *out = regex_t {
ptr: branches.as_mut_ptr() as *mut c_void, ptr: branches.as_mut_ptr() as *mut c_void,
length: branches.len(), length: branches.len(),
...@@ -118,7 +106,6 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char, ...@@ -118,7 +106,6 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char,
let flags = regex.cflags | eflags; let flags = regex.cflags | eflags;
let input = unsafe { slice::from_raw_parts(input as *const u8, strlen(input)) }; let input = unsafe { slice::from_raw_parts(input as *const u8, strlen(input)) };
let branches = unsafe { slice::from_raw_parts(regex.ptr as *const Vec<(Token, Range)>, regex.length) }; let branches = unsafe { slice::from_raw_parts(regex.ptr as *const Vec<(Token, Range)>, regex.length) };
let matches = PosixRegex::new(Cow::Borrowed(&branches)) let matches = PosixRegex::new(Cow::Borrowed(&branches))
...@@ -134,9 +121,8 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char, ...@@ -134,9 +121,8 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char,
&& nmatch > 0 { && nmatch > 0 {
let first = &matches[0]; let first = &matches[0];
let len = first.len().min(nmatch as usize); for i in 0..nmatch as usize {
for i in 0..len { let (start, end) = first.get(i).and_then(|&range| range).unwrap_or((!0, !0));
let (start, end) = first[i];
unsafe { unsafe {
*pmatch.offset(i as isize) = regmatch_t { *pmatch.offset(i as isize) = regmatch_t {
rm_so: start, rm_so: start,
...@@ -144,14 +130,6 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char, ...@@ -144,14 +130,6 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char,
}; };
} }
} }
for i in len as isize..nmatch as isize {
unsafe {
*pmatch.offset(i) = regmatch_t {
rm_so: !0,
rm_eo: !0
};
}
}
} }
if matches.is_empty() { REG_NOMATCH } else { 0 } if matches.is_empty() { REG_NOMATCH } else { 0 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment