public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7804] gccrs: libproc_macro: Change rust Ident definition
@ 2024-01-16 17:59 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:43208b6cbabe9189a48de64e4a42087af14cd671

commit r14-7804-g43208b6cbabe9189a48de64e4a42087af14cd671
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Jul 19 13:18:14 2023 +0200

    gccrs: libproc_macro: Change rust Ident definition
    
    Change rust interface Ident definition to match C++ struct definition.
    This structure now uses an FFIString instead of raw pointers.
    
    libgrust/ChangeLog:
    
            * libproc_macro/rust/bridge/ident.rs: Change raw
            pointer string with an FFIString.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 libgrust/libproc_macro/rust/bridge/ident.rs | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/libgrust/libproc_macro/rust/bridge/ident.rs b/libgrust/libproc_macro/rust/bridge/ident.rs
index 4218921724a..d58896dbd3e 100644
--- a/libgrust/libproc_macro/rust/bridge/ident.rs
+++ b/libgrust/libproc_macro/rust/bridge/ident.rs
@@ -1,11 +1,10 @@
+use bridge::ffistring::FFIString;
 use bridge::span::Span;
-use std::convert::TryInto;
-use std::ffi::c_uchar;
 use std::fmt;
 
 extern "C" {
-    fn Ident__new(string: *const c_uchar, len: u64, span: Span) -> Ident;
-    fn Ident__new_raw(string: *const c_uchar, len: u64, span: Span) -> Ident;
+    fn Ident__new(str: FFIString, span: Span) -> Ident;
+    fn Ident__new_raw(str: FFIString, span: Span) -> Ident;
     fn Ident__drop(ident: *mut Ident);
     fn Ident__clone(ident: *const Ident) -> Ident;
 }
@@ -14,18 +13,17 @@ extern "C" {
 #[derive(Debug)]
 pub struct Ident {
     pub(crate) is_raw: bool,
-    pub(crate) val: *const c_uchar,
-    len: u64,
+    value: FFIString,
     span: Span,
 }
 
 impl Ident {
     pub fn new(string: &str, span: Span) -> Self {
-        unsafe { Ident__new(string.as_ptr(), string.len().try_into().unwrap(), span) }
+        unsafe { Ident__new(string.into(), span) }
     }
 
     pub fn new_raw(string: &str, span: Span) -> Self {
-        unsafe { Ident__new_raw(string.as_ptr(), string.len().try_into().unwrap(), span) }
+        unsafe { Ident__new_raw(string.into(), span) }
     }
 
     pub fn span(&self) -> Span {
@@ -49,16 +47,7 @@ impl fmt::Display for Ident {
         if self.is_raw {
             f.write_str("r#")?;
         }
-        fmt::Display::fmt(
-            unsafe {
-                std::str::from_utf8(std::slice::from_raw_parts(
-                    self.val,
-                    self.len.try_into().unwrap(),
-                ))
-                .unwrap()
-            },
-            f,
-        )
+        self.value.fmt(f)
     }
 }

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

only message in thread, other threads:[~2024-01-16 17:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:59 [gcc r14-7804] gccrs: libproc_macro: Change rust Ident definition Arthur Cohen

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).