[gcc r14-7506] gccrs: libproc_macro: Add drop function on Ident struct

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:39:49 GMT 2024


https://gcc.gnu.org/g:c9534eb5d93dcb8bb567def37d42b8dcabcea426

commit r14-7506-gc9534eb5d93dcb8bb567def37d42b8dcabcea426
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Wed Apr 12 17:47:43 2023 +0200

    gccrs: libproc_macro: Add drop function on Ident struct
    
    Add a drop function that cleans internal fields of a given Ident struct.
    
    libgrust/ChangeLog:
    
            * libproc_macro/ident.cc (Ident__drop): Replace by call
            to Ident::drop.
            (Ident::drop): Add drop function.
            * libproc_macro/ident.h: Add drop prototype.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 libgrust/libproc_macro/ident.cc | 9 ++++++++-
 libgrust/libproc_macro/ident.h  | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/libgrust/libproc_macro/ident.cc b/libgrust/libproc_macro/ident.cc
index d7d588975d7..0bed2a8e7d4 100644
--- a/libgrust/libproc_macro/ident.cc
+++ b/libgrust/libproc_macro/ident.cc
@@ -42,7 +42,7 @@ Ident__new_raw (unsigned char *str, std::uint64_t len)
 void
 Ident__drop (Ident *ident)
 {
-  delete[] ident->val;
+  Ident::drop (ident);
 }
 
 Ident
@@ -76,4 +76,11 @@ Ident::make_ident (const unsigned char *str, std::uint64_t len, bool raw)
   return {raw, val, len};
 }
 
+void
+Ident::drop (Ident *ident)
+{
+  delete[] ident->val;
+  ident->len = 0;
+}
+
 } // namespace Ident
diff --git a/libgrust/libproc_macro/ident.h b/libgrust/libproc_macro/ident.h
index 5a2a46a8c1f..0e21275863e 100644
--- a/libgrust/libproc_macro/ident.h
+++ b/libgrust/libproc_macro/ident.h
@@ -41,6 +41,8 @@ public:
   static Ident make_ident (std::string str, bool raw = false);
   static Ident make_ident (const unsigned char *str, std::uint64_t len,
 			   bool raw = false);
+
+  static void drop (Ident *ident);
 };
 
 extern "C" {


More information about the Gcc-cvs mailing list