Skip to content

Commit 73eeef3

Browse files
committed
Add CxxExceptionPtr atom
This represents C++ `std::exception_ptr` on the Rust side via `CxxException` object, which can be mentioned as a return type for functions creating custom exceptions or evaluating exceptions caught from C++ (added in further commits).
1 parent ffd3e4c commit 73eeef3

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

gen/src/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) {
211211
Some(Isize) => out.builtin.rust_isize = true,
212212
Some(CxxString) => out.include.string = true,
213213
Some(RustString) => out.builtin.rust_string = true,
214-
Some(Bool) | Some(Char) | Some(F32) | Some(F64) | None => {}
214+
Some(Bool) | Some(Char) | Some(F32) | Some(F64) | Some(CxxExceptionPtr) | None => {}
215215
},
216216
Type::RustBox(_) => out.builtin.rust_box = true,
217217
Type::RustVec(_) => out.builtin.rust_vec = true,
@@ -1323,6 +1323,7 @@ fn write_atom(out: &mut OutFile, atom: Atom) {
13231323
F64 => write!(out, "double"),
13241324
CxxString => write!(out, "::std::string"),
13251325
RustString => write!(out, "::rust::String"),
1326+
CxxExceptionPtr => write!(out, "::std::exception_ptr"),
13261327
}
13271328
}
13281329

macro/src/expand.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,10 @@ fn expand_extern_type(ty: &Type, types: &Types, proper: bool) -> TokenStream {
17511751
let span = ident.rust.span();
17521752
quote_spanned!(span=> ::cxx::private::RustString)
17531753
}
1754+
Type::Ident(ident) if ident.rust == CxxExceptionPtr => {
1755+
let span = ident.rust.span();
1756+
quote_spanned!(span=> ::cxx::CxxException)
1757+
}
17541758
Type::RustBox(ty) | Type::UniquePtr(ty) => {
17551759
let span = ty.name.span();
17561760
if proper && types.is_considered_improper_ctype(&ty.inner) {

syntax/atom.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum Atom {
2020
F64,
2121
CxxString,
2222
RustString,
23+
CxxExceptionPtr,
2324
}
2425

2526
impl Atom {
@@ -46,6 +47,7 @@ impl Atom {
4647
"f64" => Some(F64),
4748
"CxxString" => Some(CxxString),
4849
"String" => Some(RustString),
50+
"CxxException" => Some(CxxExceptionPtr),
4951
_ => None,
5052
}
5153
}
@@ -77,6 +79,7 @@ impl AsRef<str> for Atom {
7779
F64 => "f64",
7880
CxxString => "CxxString",
7981
RustString => "String",
82+
CxxExceptionPtr => "CxxException",
8083
}
8184
}
8285
}

syntax/check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) {
126126
None | Some(Bool) | Some(Char) | Some(U8) | Some(U16) | Some(U32) | Some(U64)
127127
| Some(Usize) | Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize)
128128
| Some(F32) | Some(F64) | Some(RustString) => return,
129-
Some(CxxString) => {}
129+
Some(CxxString) | Some(CxxExceptionPtr) => {}
130130
}
131131
}
132132
Type::Str(_) => return,
@@ -165,7 +165,7 @@ fn check_type_shared_ptr(cx: &mut Check, ptr: &Ty1) {
165165
None | Some(Bool) | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize)
166166
| Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32)
167167
| Some(F64) | Some(CxxString) => return,
168-
Some(Char) | Some(RustString) => {}
168+
Some(Char) | Some(RustString) | Some(CxxExceptionPtr) => {}
169169
}
170170
} else if let Type::CxxVector(_) = &ptr.inner {
171171
cx.error(ptr, "std::shared_ptr<std::vector> is not supported yet");
@@ -186,7 +186,7 @@ fn check_type_weak_ptr(cx: &mut Check, ptr: &Ty1) {
186186
None | Some(Bool) | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize)
187187
| Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32)
188188
| Some(F64) | Some(CxxString) => return,
189-
Some(Char) | Some(RustString) => {}
189+
Some(Char) | Some(RustString) | Some(CxxExceptionPtr) => {}
190190
}
191191
} else if let Type::CxxVector(_) = &ptr.inner {
192192
cx.error(ptr, "std::weak_ptr<std::vector> is not supported yet");
@@ -211,7 +211,7 @@ fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) {
211211
| Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64)
212212
| Some(CxxString) => return,
213213
Some(Char) => { /* todo */ }
214-
Some(Bool) | Some(RustString) => {}
214+
Some(Bool) | Some(RustString) | Some(CxxExceptionPtr) => {}
215215
}
216216
}
217217

syntax/pod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl<'a> Types<'a> {
1010
match atom {
1111
Bool | Char | U8 | U16 | U32 | U64 | Usize | I8 | I16 | I32 | I64
1212
| Isize | F32 | F64 => true,
13-
CxxString | RustString => false,
13+
CxxString | RustString | CxxExceptionPtr => false,
1414
}
1515
} else if let Some(strct) = self.structs.get(ident) {
1616
derive::contains(&strct.derives, Trait::Copy)

syntax/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl ToTokens for Type {
1414
if ident.rust == Char {
1515
let span = ident.rust.span();
1616
tokens.extend(quote_spanned!(span=> ::cxx::private::));
17-
} else if ident.rust == CxxString {
17+
} else if ident.rust == CxxString || ident.rust == CxxExceptionPtr {
1818
let span = ident.rust.span();
1919
tokens.extend(quote_spanned!(span=> ::cxx::));
2020
} else if ident.rust == RustString {

0 commit comments

Comments
 (0)