]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: libproc_macro: Change rust Ident definition
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wed, 19 Jul 2023 11:18:14 +0000 (13:18 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:57 +0000 (18:55 +0100)
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>
libgrust/libproc_macro/rust/bridge/ident.rs

index 4218921724ac3debbbb3fb7f87a47d815c9fdaa1..d58896dbd3e572ad292d2dac685a54e0ff429329 100644 (file)
@@ -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)
     }
 }