Browse Source

Bump posix-regex version

jD91mZM2 6 years ago
parent
commit
0684fb6e4c
3 changed files with 5 additions and 31 deletions
  1. 1 1
      posix-regex
  2. 1 5
      src/header/fnmatch/mod.rs
  3. 3 25
      src/header/regex/mod.rs

+ 1 - 1
posix-regex

@@ -1 +1 @@
-Subproject commit bf7d93bb7aba406dc135a7a9eb031371e7739fe6
+Subproject commit 0d996efe5cfe7ce181af35d8817ac4deae644d4a

+ 1 - 5
src/header/fnmatch/mod.rs

@@ -118,11 +118,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)>
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn fnmatch(
-    mut pattern: *const c_char,
-    mut input: *const c_char,
-    flags: c_int,
-) -> c_int {
+pub unsafe extern "C" fn fnmatch(pattern: *const c_char, input: *const c_char, flags: c_int) -> c_int {
     let mut len = 0;
     while *input.offset(len) != 0 {
         len += 1;

+ 3 - 25
src/header/regex/mod.rs

@@ -49,18 +49,6 @@ pub const REG_ERANGE:   c_int = 12;
 pub const REG_ESPACE:   c_int = 13;
 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]
 pub extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int {
     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)
 
     match res {
         Ok(mut branches) => unsafe {
-            let re_nsub = count_groups(&branches);
+            let re_nsub = PosixRegex::new(Cow::Borrowed(&branches)).count_groups();
             *out = regex_t {
                 ptr: branches.as_mut_ptr() as *mut c_void,
                 length: branches.len(),
@@ -118,7 +106,6 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char,
     let flags = regex.cflags | eflags;
 
     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 matches = PosixRegex::new(Cow::Borrowed(&branches))
@@ -134,9 +121,8 @@ pub extern "C" fn regexec(regex: *const regex_t, input: *const c_char,
             && nmatch > 0 {
         let first = &matches[0];
 
-        let len = first.len().min(nmatch as usize);
-        for i in 0..len {
-            let (start, end) = first[i];
+        for i in 0..nmatch as usize {
+            let (start, end) = first.get(i).and_then(|&range| range).unwrap_or((!0, !0));
             unsafe {
                 *pmatch.offset(i as isize) = regmatch_t {
                     rm_so: start,
@@ -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 }