Skip to content

Commit aec3f24

Browse files
authored
Merge pull request #644 from dtolnay/result
Decouple C++ exception representation from Rust str
2 parents cf7bb9b + 8ce57ec commit aec3f24

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/result.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
use crate::exception::Exception;
2-
use crate::rust_str::RustStr;
32
use alloc::boxed::Box;
43
use alloc::string::{String, ToString};
54
use core::fmt::Display;
6-
use core::ptr;
5+
use core::ptr::{self, NonNull};
76
use core::result::Result as StdResult;
87
use core::slice;
98
use core::str;
109

10+
#[repr(C)]
11+
#[derive(Copy, Clone)]
12+
struct PtrLen {
13+
ptr: NonNull<u8>,
14+
len: usize,
15+
}
16+
1117
#[repr(C)]
1218
pub union Result {
13-
err: RustStr,
19+
err: PtrLen,
1420
ok: *const u8, // null
1521
}
1622

@@ -41,7 +47,10 @@ unsafe fn to_c_error(msg: String) -> Result {
4147
let copy = error(ptr, len);
4248
let slice = slice::from_raw_parts(copy, len);
4349
let string = str::from_utf8_unchecked(slice);
44-
let err = RustStr::from(string);
50+
let err = PtrLen {
51+
ptr: NonNull::from(string).cast::<u8>(),
52+
len: string.len(),
53+
};
4554
Result { err }
4655
}
4756

0 commit comments

Comments
 (0)