Skip to content

Commit a064b97

Browse files
Fix build failures related to UTF-32
1 parent 299f194 commit a064b97

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/ffi.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub trait CodeUnitWidth: std::fmt::Debug + 'static {
9191
type PCRE2_CHAR: Default + Copy + TryInto<Self::SubjectChar>;
9292
type PCRE2_SPTR;
9393
type name_table_entry: NameTableEntry;
94-
type SubjectChar: Copy;
94+
type SubjectChar: Copy + Default;
9595
type Pattern: Clone + std::fmt::Debug;
9696

9797
fn escape_subject(subject: &[Self::SubjectChar]) -> String;
@@ -973,7 +973,7 @@ impl<W: CodeUnitWidth> MatchData<W> {
973973
pub(crate) unsafe fn find(
974974
&mut self,
975975
code: &Code<W>,
976-
mut subject: &[W::SubjectChar],
976+
subject: &[W::SubjectChar],
977977
start: usize,
978978
options: u32,
979979
) -> Result<bool, Error> {
@@ -996,17 +996,18 @@ impl<W: CodeUnitWidth> MatchData<W> {
996996
// explode if you try to dereference it.
997997
//
998998
// [1]: https://github.com/BurntSushi/rust-pcre2/issues/42
999-
static SINGLETON: &[u8] = &[0];
1000-
let len = subject.len();
1001-
if subject.is_empty() {
1002-
subject = SINGLETON;
1003-
}
1004-
let (subj_ptr, subj_len) = W::subject_to_sptr_len(subject);
999+
let singleton: W::SubjectChar = Default::default();
1000+
let (subj_ptr, subj_len) = if subject.is_empty() {
1001+
let ptr = W::subject_to_sptr_len(slice::from_ref(&singleton)).0;
1002+
(ptr, 0)
1003+
} else {
1004+
W::subject_to_sptr_len(subject)
1005+
};
10051006

10061007
let rc = W::pcre2_match(
10071008
code.as_ptr(),
1008-
subject.as_ptr(),
1009-
len,
1009+
subj_ptr,
1010+
subj_len,
10101011
start,
10111012
options,
10121013
self.match_data,

0 commit comments

Comments
 (0)