public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] libproc_macro: Make internal Punct type ffi safe
@ 2023-04-06 21:30 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f

commit 6a12e6ea0e6a8575e9c21a4e68d9b636ed157a2f
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Thu Feb 16 13:25:45 2023 +0100

    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>

Diff:
---
 librust/proc_macro/rust/bridge/punct.rs | 11 +++++++++--
 librust/proc_macro/rust/punct.rs        |  6 +++---
 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 57487eac930..f1bb9141ed0 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 cbd64fc55a5..7320a1e6514 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()
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-06 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:30 [gcc/devel/rust/master] libproc_macro: Make internal Punct type ffi safe Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).