Support raw pointers in cxx::bridge.
This allows raw pointers to types to be passed into and out of
cxx::bridge extern "C++" APIs. As normal with raw pointers in Rust,
there are no safety or lifetime guarantees.
Passing a raw pointer into such an API requires that the
function be marked "unsafe".
diff --git a/syntax/check.rs b/syntax/check.rs
index 2098a1b..e4933d3 100644
--- a/syntax/check.rs
+++ b/syntax/check.rs
@@ -8,6 +8,8 @@
use quote::{quote, ToTokens};
use std::fmt::Display;
+use super::Ptr;
+
pub(crate) struct Check<'a> {
apis: &'a [Api],
types: &'a Types<'a>,
@@ -35,6 +37,7 @@
Type::WeakPtr(ptr) => check_type_weak_ptr(cx, ptr),
Type::CxxVector(ptr) => check_type_cxx_vector(cx, ptr),
Type::Ref(ty) => check_type_ref(cx, ty),
+ Type::Ptr(ty) => check_type_ptr(cx, ty),
Type::Array(array) => check_type_array(cx, array),
Type::Fn(ty) => check_type_fn(cx, ty),
Type::SliceRef(ty) => check_type_slice_ref(cx, ty),
@@ -221,7 +224,7 @@
}
match ty.inner {
- Type::Fn(_) | Type::Void(_) => {}
+ Type::Fn(_) | Type::Void(_) | Type::Ptr(_) => {}
Type::Ref(_) => {
cx.error(ty, "C++ does not allow references to references");
return;
@@ -232,6 +235,12 @@
cx.error(ty, "unsupported reference type");
}
+fn check_type_ptr(cx: &mut Check, ty: &Ptr) {
+ if let Type::Ident(_) = ty.inner { return }
+
+ cx.error(ty, "unsupported pointer type");
+}
+
fn check_type_slice_ref(cx: &mut Check, ty: &SliceRef) {
let supported = !is_unsized(cx, &ty.inner)
|| match &ty.inner {
@@ -555,6 +564,7 @@
| Type::SharedPtr(_)
| Type::WeakPtr(_)
| Type::Ref(_)
+ | Type::Ptr(_)
| Type::Str(_)
| Type::SliceRef(_) => false,
}
@@ -628,6 +638,7 @@
Type::SharedPtr(_) => "shared_ptr".to_owned(),
Type::WeakPtr(_) => "weak_ptr".to_owned(),
Type::Ref(_) => "reference".to_owned(),
+ Type::Ptr(_) => "raw pointer".to_owned(),
Type::Str(_) => "&str".to_owned(),
Type::CxxVector(_) => "C++ vector".to_owned(),
Type::SliceRef(_) => "slice".to_owned(),