mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 15:05:27 +08:00
Stop generating autoccx ffi wrappers for pcre2 regex
We have "native" FFI wrappers for these now via the pcre2 crate.
This commit is contained in:
parent
6ff971e4c2
commit
169f90448a
@ -1,8 +1,6 @@
|
||||
use crate::wchar;
|
||||
use crate::wchar_ffi::WCharToFFI;
|
||||
#[rustfmt::skip]
|
||||
use ::std::fmt::{self, Debug, Formatter};
|
||||
#[rustfmt::skip]
|
||||
use ::std::pin::Pin;
|
||||
#[rustfmt::skip]
|
||||
use ::std::slice;
|
||||
@ -32,7 +30,6 @@ include_cpp! {
|
||||
#include "parser.h"
|
||||
#include "parse_util.h"
|
||||
#include "proc.h"
|
||||
#include "re.h"
|
||||
#include "tokenizer.h"
|
||||
#include "wildcard.h"
|
||||
#include "wutil.h"
|
||||
@ -93,12 +90,6 @@ include_cpp! {
|
||||
|
||||
generate!("fd_event_signaller_t")
|
||||
|
||||
generate_pod!("re::flags_t")
|
||||
generate_pod!("re::re_error_t")
|
||||
generate!("re::regex_t")
|
||||
generate!("re::regex_result_ffi")
|
||||
generate!("re::try_compile_ffi")
|
||||
|
||||
generate!("signal_handle")
|
||||
generate!("signal_check_cancel")
|
||||
|
||||
@ -209,10 +200,6 @@ impl env_stack_t {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_compile(anchored: &wstr, flags: &re::flags_t) -> Pin<Box<re::regex_result_ffi>> {
|
||||
re::try_compile_ffi(&anchored.to_ffi(), flags).within_box()
|
||||
}
|
||||
|
||||
impl job_t {
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub fn get_procs(&self) -> &mut [UniquePtr<process_t>] {
|
||||
@ -263,12 +250,6 @@ impl From<wcharz_t> for wchar::WString {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for re::regex_t {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("regex_t")
|
||||
}
|
||||
}
|
||||
|
||||
/// A bogus trait for turning &mut Foo into Pin<&mut Foo>.
|
||||
/// autocxx enforces that non-const methods must be called through Pin,
|
||||
/// but this means we can't pass around mutable references to types like parser_t.
|
||||
@ -294,9 +275,6 @@ impl Repin for job_t {}
|
||||
impl Repin for output_stream_t {}
|
||||
impl Repin for parser_t {}
|
||||
impl Repin for process_t {}
|
||||
impl Repin for re::regex_result_ffi {}
|
||||
|
||||
unsafe impl Send for re::regex_t {}
|
||||
|
||||
pub use autocxx::c_int;
|
||||
pub use ffi::*;
|
||||
|
@ -20,33 +20,32 @@ pub fn to_boxed_chars(s: &wstr) -> Box<[char]> {
|
||||
chars.into()
|
||||
}
|
||||
|
||||
use crate::ffi_tests::add_test;
|
||||
add_test!("test_regex_make_anchored", || {
|
||||
use crate::ffi;
|
||||
use crate::wchar::L;
|
||||
use crate::wchar_ffi::WCharToFFI;
|
||||
#[test]
|
||||
fn test_regex_make_anchored() {
|
||||
use pcre2::utf32::{Regex, RegexBuilder};
|
||||
|
||||
let flags = ffi::re::flags_t { icase: false };
|
||||
let mut result = ffi::try_compile(®ex_make_anchored(L!("ab(.+?)")), &flags);
|
||||
assert!(!result.has_error());
|
||||
fn test_match(re: &Regex, subject: &wstr) -> bool {
|
||||
re.is_match(&to_boxed_chars(subject)).unwrap()
|
||||
}
|
||||
|
||||
let re = result.as_mut().get_regex();
|
||||
let builder = RegexBuilder::new();
|
||||
let result = builder.build(to_boxed_chars(®ex_make_anchored(L!("ab(.+?)"))));
|
||||
assert!(result.is_ok());
|
||||
let re = &result.unwrap();
|
||||
|
||||
assert!(!re.is_null());
|
||||
assert!(!re.matches_ffi(&L!("").to_ffi()));
|
||||
assert!(!re.matches_ffi(&L!("ab").to_ffi()));
|
||||
assert!(re.matches_ffi(&L!("abcd").to_ffi()));
|
||||
assert!(!re.matches_ffi(&L!("xabcd").to_ffi()));
|
||||
assert!(re.matches_ffi(&L!("abcdefghij").to_ffi()));
|
||||
assert!(!test_match(re, L!("")));
|
||||
assert!(!test_match(re, L!("ab")));
|
||||
assert!(test_match(re, L!("abcd")));
|
||||
assert!(!test_match(re, L!("xabcd")));
|
||||
assert!(test_match(re, L!("abcdefghij")));
|
||||
|
||||
let mut result = ffi::try_compile(®ex_make_anchored(L!("(a+)|(b+)")), &flags);
|
||||
assert!(!result.has_error());
|
||||
let result = builder.build(to_boxed_chars(®ex_make_anchored(L!("(a+)|(b+)"))));
|
||||
assert!(result.is_ok());
|
||||
|
||||
let re = result.as_mut().get_regex();
|
||||
assert!(!re.is_null());
|
||||
assert!(!re.matches_ffi(&L!("").to_ffi()));
|
||||
assert!(!re.matches_ffi(&L!("aabb").to_ffi()));
|
||||
assert!(re.matches_ffi(&L!("aaaa").to_ffi()));
|
||||
assert!(re.matches_ffi(&L!("bbbb").to_ffi()));
|
||||
assert!(!re.matches_ffi(&L!("aaaax").to_ffi()));
|
||||
});
|
||||
let re = &result.unwrap();
|
||||
assert!(!test_match(re, L!("")));
|
||||
assert!(!test_match(re, L!("aabb")));
|
||||
assert!(test_match(re, L!("aaaa")));
|
||||
assert!(test_match(re, L!("bbbb")));
|
||||
assert!(!test_match(re, L!("aaaax")));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user