aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-16 13:25:45 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:30 +0200
commit6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f (patch)
treec7de7be5d2ffd0d916e7a0d27fadedbc015bbd0b
parente41c961955d9faf8de28aa5096a592573d01ca3b (diff)
downloadgcc-6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f.zip
gcc-6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f.tar.gz
gcc-6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f.tar.bz2
libproc_macro: Make internal Punct type ffi safe
The internal Punct rust type was not entirely ffi safe, thus these changes in order for it to be used by both parts of the libproc_macro. ChangeLog: * librust/proc_macro/rust/bridge/punct.rs: Change internal Punct representation. * librust/proc_macro/rust/punct.rs: Change Punct interface interaction. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/bridge/punct.rs11
-rw-r--r--librust/proc_macro/rust/punct.rs6
2 files changed, 12 insertions, 5 deletions
diff --git a/librust/proc_macro/rust/bridge/punct.rs b/librust/proc_macro/rust/bridge/punct.rs
index 57487ea..f1bb914 100644
--- a/librust/proc_macro/rust/bridge/punct.rs
+++ b/librust/proc_macro/rust/bridge/punct.rs
@@ -1,16 +1,23 @@
use bridge::span::Span;
+use std::convert::TryInto;
+use std::ffi::c_uchar;
use Spacing;
#[repr(C)]
#[derive(Clone, Debug)]
pub struct Punct {
- pub(crate) ch: char,
+ pub(crate) ch: c_uchar,
pub(crate) spacing: Spacing,
}
impl Punct {
pub fn new(ch: char, spacing: Spacing) -> Self {
- Punct { ch, spacing }
+ Punct {
+ ch: ch
+ .try_into()
+ .expect("Failed to convert rust char to c char"),
+ spacing,
+ }
}
pub fn span(&self) -> Span {
diff --git a/librust/proc_macro/rust/punct.rs b/librust/proc_macro/rust/punct.rs
index cbd64fc..7320a1e 100644
--- a/librust/proc_macro/rust/punct.rs
+++ b/librust/proc_macro/rust/punct.rs
@@ -38,7 +38,7 @@ impl Punct {
/// Get the value for this punctuation character as `char`.
pub fn as_char(&self) -> char {
- self.0.ch
+ self.0.ch.into()
}
/// Get the [`Spacing`] of this punctuation character, indicating whether
@@ -77,12 +77,12 @@ impl fmt::Debug for Punct {
impl PartialEq<char> for Punct {
fn eq(&self, rhs: &char) -> bool {
- self.0.ch == *rhs
+ self.as_char() == *rhs
}
}
impl PartialEq<Punct> for char {
fn eq(&self, rhs: &Punct) -> bool {
- *self == rhs.0.ch
+ *self == rhs.as_char()
}
}