Merge branch 'update_posix_regex_to_master' into 'master'
Update posix-regex to master branch See merge request redox-os/relibc!634
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
[submodule "posix-regex"]
|
||||
path = posix-regex
|
||||
url = https://gitlab.redox-os.org/redox-os/posix-regex.git
|
||||
branch = master
|
||||
[submodule "compiler-builtins"]
|
||||
path = compiler-builtins
|
||||
url = https://gitlab.redox-os.org/redox-os/compiler-builtins.git
|
||||
|
||||
Generated
+79
-2
@@ -172,7 +172,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dlmalloc"
|
||||
version = "0.2.4"
|
||||
version = "0.2.8"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
@@ -369,7 +373,7 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
|
||||
|
||||
[[package]]
|
||||
name = "posix-regex"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
@@ -682,3 +686,76 @@ name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
+1
-1
Submodule openlibm updated: 5992e5a177...3cfad14805
+1
-1
Submodule posix-regex updated: 0d996efe5c...f42f21519d
@@ -8,6 +8,7 @@ use core::slice;
|
||||
use crate::platform::types::*;
|
||||
use posix_regex::{
|
||||
compile::{Collation, Range, Token},
|
||||
tree::{Tree, TreeBuilder},
|
||||
PosixRegex,
|
||||
};
|
||||
|
||||
@@ -21,7 +22,7 @@ pub const FNM_PERIOD: c_int = 4;
|
||||
pub const FNM_CASEFOLD: c_int = 8;
|
||||
// TODO: FNM_EXTMATCH
|
||||
|
||||
unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)> {
|
||||
unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Tree {
|
||||
fn any(leading: bool, flags: c_int) -> Token {
|
||||
let mut list = Vec::new();
|
||||
if flags & FNM_PATHNAME == FNM_PATHNAME {
|
||||
@@ -40,9 +41,12 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)>
|
||||
c == b'/' && flags & FNM_PATHNAME == FNM_PATHNAME
|
||||
}
|
||||
|
||||
let mut tokens = Vec::new();
|
||||
let mut leading = true;
|
||||
|
||||
let mut builder = TreeBuilder::default();
|
||||
builder.start_internal(Token::Root, Range(1, Some(1)));
|
||||
builder.start_internal(Token::Alternative, Range(1, Some(1)));
|
||||
|
||||
while unsafe { *pattern != 0 } {
|
||||
let was_leading = leading;
|
||||
leading = false;
|
||||
@@ -50,7 +54,7 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)>
|
||||
let c = unsafe { *pattern };
|
||||
pattern = unsafe { pattern.offset(1) };
|
||||
|
||||
tokens.push(match c {
|
||||
let (token, range) = match c {
|
||||
b'\\' if flags & FNM_NOESCAPE == FNM_NOESCAPE => {
|
||||
let c = unsafe { *pattern };
|
||||
if c == 0 {
|
||||
@@ -110,9 +114,13 @@ unsafe fn tokenize(mut pattern: *const u8, flags: c_int) -> Vec<(Token, Range)>
|
||||
leading = is_leading(flags, c);
|
||||
(Token::Char(c), ONCE)
|
||||
}
|
||||
})
|
||||
};
|
||||
builder.leaf(token, range);
|
||||
}
|
||||
tokens
|
||||
builder.leaf(Token::End, ONCE);
|
||||
builder.finish_internal();
|
||||
builder.finish_internal();
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -128,10 +136,9 @@ pub unsafe extern "C" fn fnmatch(
|
||||
}
|
||||
let input = unsafe { slice::from_raw_parts(input as *const u8, len as usize) };
|
||||
|
||||
let mut tokens = unsafe { tokenize(pattern as *const u8, flags) };
|
||||
tokens.push((Token::End, ONCE));
|
||||
let tokens = unsafe { tokenize(pattern as *const u8, flags) };
|
||||
|
||||
if PosixRegex::new(Cow::Owned(vec![tokens]))
|
||||
if PosixRegex::new(Cow::Owned(tokens))
|
||||
.case_insensitive(flags & FNM_CASEFOLD == FNM_CASEFOLD)
|
||||
.matches_exact(input)
|
||||
.is_some()
|
||||
|
||||
+8
-21
@@ -1,26 +1,20 @@
|
||||
//! regex.h implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/regex.h.html
|
||||
|
||||
use crate::{header::string::strlen, platform::types::*};
|
||||
use alloc::{borrow::Cow, vec::Vec};
|
||||
use alloc::{borrow::Cow, boxed::Box};
|
||||
use core::{mem, ptr, slice};
|
||||
use posix_regex::{
|
||||
compile::{Error as CompileError, Range, Token},
|
||||
PosixRegex, PosixRegexBuilder,
|
||||
};
|
||||
use posix_regex::{compile::Error as CompileError, tree::Tree, PosixRegex, PosixRegexBuilder};
|
||||
|
||||
pub type regoff_t = size_t;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct regex_t {
|
||||
// Can't be a normal Vec<T> because then the struct size won't be known
|
||||
// from C.
|
||||
// Points to a posix_regex::Tree
|
||||
ptr: *mut c_void,
|
||||
length: size_t,
|
||||
capacity: size_t,
|
||||
|
||||
cflags: c_int,
|
||||
re_nsub: size_t,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct regmatch_t {
|
||||
rm_so: regoff_t,
|
||||
@@ -65,14 +59,11 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags:
|
||||
Ok(mut 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(),
|
||||
capacity: branches.capacity(),
|
||||
ptr: Box::into_raw(Box::new(branches)) as *mut c_void,
|
||||
|
||||
cflags,
|
||||
re_nsub,
|
||||
};
|
||||
mem::forget(branches);
|
||||
0
|
||||
}
|
||||
Err(CompileError::EmptyRepetition)
|
||||
@@ -89,11 +80,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags:
|
||||
#[no_mangle]
|
||||
#[linkage = "weak"] // redefined in GIT
|
||||
pub unsafe extern "C" fn regfree(regex: *mut regex_t) {
|
||||
Vec::from_raw_parts(
|
||||
(*regex).ptr as *mut Vec<(Token, Range)>,
|
||||
(*regex).length,
|
||||
(*regex).capacity,
|
||||
);
|
||||
Box::from_raw((*regex).ptr);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -111,12 +98,12 @@ pub unsafe extern "C" fn regexec(
|
||||
|
||||
let regex = &*regex;
|
||||
|
||||
// Allow specifying a compiler argument to the executor and vise versa
|
||||
// Allow specifying a compiler argument to the executor and viceversa
|
||||
// because why not?
|
||||
let flags = regex.cflags | eflags;
|
||||
|
||||
let input = slice::from_raw_parts(input as *const u8, strlen(input));
|
||||
let branches = slice::from_raw_parts(regex.ptr as *const Vec<(Token, Range)>, regex.length);
|
||||
let branches = &*(regex.ptr as *mut Tree);
|
||||
|
||||
let matches = PosixRegex::new(Cow::Borrowed(&branches))
|
||||
.case_insensitive(flags & REG_ICASE == REG_ICASE)
|
||||
|
||||
Reference in New Issue
Block a user