diff mbox series

[2/3] ctf-reader: Use smart pointers in create_read_context

Message ID 20211118232330.16310-3-guillermo.e.martinez@oracle.com
State New
Headers show
Series Some improvements in ctf-reader. | expand

Commit Message

Guillermo E. Martinez Nov. 18, 2021, 11:23 p.m. UTC
* include/abg-ctf-reader.h (read_context_sptr): New typedef.
	(create_read_context): Use read_context_sptr as return value.
	* src/abg-ctf-reader.cc (create_read_context): Likewise.
	* tools/abidiff.cc (main): Use read_context_sptr.
	* tools/abilint.cc: Likewise.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
---
 include/abg-ctf-reader.h |  7 +++++--
 src/abg-ctf-reader.cc    |  5 +++--
 tools/abidiff.cc         | 18 ++++++++++--------
 tools/abilint.cc         |  8 ++++----
 4 files changed, 22 insertions(+), 16 deletions(-)

Comments

Dodji Seketeli Nov. 23, 2021, 2:35 p.m. UTC | #1
Hello Guillermo,

"Guillermo E. Martinez via Libabigail" <libabigail@sourceware.org> a écrit:

[...]

> diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
> index 56b2bf91..c527c2ff 100644
> --- a/include/abg-ctf-reader.h
> +++ b/include/abg-ctf-reader.h
> @@ -25,8 +25,11 @@ namespace ctf_reader
>  {
>  
>  class read_context;
> -read_context *create_read_context(const std::string& elf_path,
> -                                  ir::environment *env);
> +typedef shared_ptr<read_context> read_context_sptr;
> +
> +read_context_sptr
> +create_read_context(const std::string& elf_path,
> +                    ir::environment *env);
>  corpus_sptr read_corpus(read_context *ctxt,
>                          elf_reader::status& status);

I appears that  read_corpus that takes a read_context* now needs an
overload function that takes a "const read_context&" too.  That is
needed in abidw, at least, where read_corpus is used in that capacity.

I amended abg-ctf-reader.{h,cc} to declare and define that new overload.
abidw.cc doesn't need any adjustment in that regard.

[...]


> 	* include/abg-ctf-reader.h (read_context_sptr): New typedef.
> 	(create_read_context): Use read_context_sptr as return value.
> 	* src/abg-ctf-reader.cc (create_read_context): Likewise.
> 	* tools/abidiff.cc (main): Use read_context_sptr.
> 	* tools/abilint.cc: Likewise.

I have updated the ChangeLog accordingly.

>
> Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>

I have applied the amended patch to the master branch of the git
repository and am providing it below.

Thanks!

From 7f60fbc96b16507a4097a0c1a86c27279d9cab5d Mon Sep 17 00:00:00 2001
From: "Guillermo E. Martinez via Libabigail" <libabigail@sourceware.org>
Date: Thu, 18 Nov 2021 17:23:29 -0600
Subject: [PATCH] ctf-reader: Make create_read_context return a smart pointer.

	* include/abg-ctf-reader.h (read_context_sptr): New typedef.
	(create_read_context): Use read_context_sptr as return value.
	(read_corpus): New overload that takes a read_context_sptr.
	* src/abg-ctf-reader.cc (create_read_context): Use
	read_context_sptr as return value.
	(read_corpus): New overload that takes a read_context_sptr.
	* tools/abidiff.cc (main): Use read_context_sptr.
	* tools/abidw.cc (load_corpus_and_write_abixml): Adjust call to
	create_read_context.
	* tools/abilint.cc: Likewise.

Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 include/abg-ctf-reader.h | 12 ++++++++----
 src/abg-ctf-reader.cc    | 19 +++++++++++++++++--
 tools/abidiff.cc         | 18 ++++++++++--------
 tools/abidw.cc           |  2 +-
 tools/abilint.cc         |  8 ++++----
 5 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
index 56b2bf91..3343f0d8 100644
--- a/include/abg-ctf-reader.h
+++ b/include/abg-ctf-reader.h
@@ -25,11 +25,15 @@ namespace ctf_reader
 {
 
 class read_context;
-read_context *create_read_context(const std::string& elf_path,
-                                  ir::environment *env);
-corpus_sptr read_corpus(read_context *ctxt,
-                        elf_reader::status& status);
+typedef shared_ptr<read_context> read_context_sptr;
 
+read_context_sptr
+create_read_context(const std::string& elf_path,
+                    ir::environment *env);
+corpus_sptr
+read_corpus(read_context *ctxt, elf_reader::status& status);
+corpus_sptr
+read_corpus(const read_context_sptr &ctxt, elf_reader::status &status);
 } // end namespace ctf_reader
 } // end namespace abigail
 
diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index fd53f8a1..6829e4c0 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -1058,11 +1058,12 @@ slurp_elf_info(read_context *ctxt, corpus_sptr corp)
 /// @param elf_path the patch of some ELF file.
 /// @param env a libabigail IR environment.
 
-read_context *
+read_context_sptr
 create_read_context(const std::string& elf_path,
                     ir::environment *env)
 {
-  return new read_context(elf_path, env);
+  read_context_sptr result(new read_context(elf_path, env));
+  return result;
 }
 
 /// Read the CTF information from some source described by a given
@@ -1116,5 +1117,19 @@ read_corpus(read_context *ctxt, elf_reader::status &status)
   return corp;
 }
 
+/// Read the CTF information from some source described by a given
+/// read context and process it to create a libabigail IR corpus.
+/// Store the corpus in the same read context.
+///
+/// @param ctxt the read context to use.
+///
+/// @param status the resulting status of the corpus read.
+///
+/// @return a shared pointer to the read corpus.
+
+corpus_sptr
+read_corpus(const read_context_sptr &ctxt, elf_reader::status &status)
+{return read_corpus(ctxt.get(), status);}
+
 } // End of namespace ctf_reader
 } // End of namespace abigail
diff --git a/tools/abidiff.cc b/tools/abidiff.cc
index f145f4f1..30959616 100644
--- a/tools/abidiff.cc
+++ b/tools/abidiff.cc
@@ -1169,12 +1169,13 @@ main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file1,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file1,
+                                                             env.get());
 
                 assert (ctxt);
-                c1 = abigail::ctf_reader::read_corpus (ctxt, c1_status);
+                c1 = abigail::ctf_reader::read_corpus(ctxt.get(),
+                                                      c1_status);
               }
             else
 #endif
@@ -1252,12 +1253,13 @@ main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file2,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file2,
+                                                             env.get());
 
                 assert (ctxt);
-                c2 = abigail::ctf_reader::read_corpus (ctxt, c2_status);
+                c2 = abigail::ctf_reader::read_corpus (ctxt.get(),
+                                                       c2_status);
               }
             else
 #endif
diff --git a/tools/abidw.cc b/tools/abidw.cc
index d2bc029b..f7a8937d 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -539,7 +539,7 @@ load_corpus_and_write_abixml(char* argv[],
 #ifdef WITH_CTF
   if (opts.use_ctf)
     {
-      abigail::ctf_reader::read_context *ctxt
+      abigail::ctf_reader::read_context_sptr ctxt
         = abigail::ctf_reader::create_read_context (opts.in_file_path,
                                                     env.get());
 
diff --git a/tools/abilint.cc b/tools/abilint.cc
index 49643b66..2e9bae49 100644
--- a/tools/abilint.cc
+++ b/tools/abilint.cc
@@ -370,12 +370,12 @@ main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file_path,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file_path,
+                                                             env.get());
 
                 assert (ctxt);
-                corp = abigail::ctf_reader::read_corpus (ctxt, s);
+                corp = abigail::ctf_reader::read_corpus (ctxt.get(), s);
               }
             else
 #endif
Guillermo E. Martinez Nov. 23, 2021, 3:42 p.m. UTC | #2
On Tuesday, November 23, 2021 8:35:55 AM CST Dodji Seketeli wrote:
> Hello Guillermo,
Hello Dodji

> "Guillermo E. Martinez via Libabigail" <libabigail@sourceware.org> a écrit:
> 
> [...]
> 
> > diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
> > index 56b2bf91..c527c2ff 100644
> > --- a/include/abg-ctf-reader.h
> > +++ b/include/abg-ctf-reader.h
> > @@ -25,8 +25,11 @@ namespace ctf_reader
> >  {
> >  
> >  class read_context;
> > -read_context *create_read_context(const std::string& elf_path,
> > -                                  ir::environment *env);
> > +typedef shared_ptr<read_context> read_context_sptr;
> > +
> > +read_context_sptr
> > +create_read_context(const std::string& elf_path,
> > +                    ir::environment *env);
> >  corpus_sptr read_corpus(read_context *ctxt,
> >                          elf_reader::status& status);
> 
> I appears that  read_corpus that takes a read_context* now needs an
> overload function that takes a "const read_context&" too.  That is
> needed in abidw, at least, where read_corpus is used in that capacity.
Ok, I see, thanks for add it.

> I amended abg-ctf-reader.{h,cc} to declare and define that new overload.
> abidw.cc doesn't need any adjustment in that regard.
> 
> [...]
> 
> 
> > 	* include/abg-ctf-reader.h (read_context_sptr): New typedef.
> > 	(create_read_context): Use read_context_sptr as return value.
> > 	* src/abg-ctf-reader.cc (create_read_context): Likewise.
> > 	* tools/abidiff.cc (main): Use read_context_sptr.
> > 	* tools/abilint.cc: Likewise.
> 
> I have updated the ChangeLog accordingly.
Thanks,

> >
> > Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
> 
> I have applied the amended patch to the master branch of the git
> repository and am providing it below.
> 
> Thanks!
Great, thanks!

> From 7f60fbc96b16507a4097a0c1a86c27279d9cab5d Mon Sep 17 00:00:00 2001
> From: "Guillermo E. Martinez via Libabigail" <libabigail@sourceware.org>
> Date: Thu, 18 Nov 2021 17:23:29 -0600
> Subject: [PATCH] ctf-reader: Make create_read_context return a smart pointer.
> 
> 	* include/abg-ctf-reader.h (read_context_sptr): New typedef.
> 	(create_read_context): Use read_context_sptr as return value.
> 	(read_corpus): New overload that takes a read_context_sptr.
> 	* src/abg-ctf-reader.cc (create_read_context): Use
> 	read_context_sptr as return value.
> 	(read_corpus): New overload that takes a read_context_sptr.
> 	* tools/abidiff.cc (main): Use read_context_sptr.
> 	* tools/abidw.cc (load_corpus_and_write_abixml): Adjust call to
> 	create_read_context.
> 	* tools/abilint.cc: Likewise.
> 
> Signed-off-by: Guillermo E. Martinez <guillermo.e.martinez@oracle.com>
> Signed-off-by: Dodji Seketeli <dodji@redhat.com>
> ---
>  include/abg-ctf-reader.h | 12 ++++++++----
>  src/abg-ctf-reader.cc    | 19 +++++++++++++++++--
>  tools/abidiff.cc         | 18 ++++++++++--------
>  tools/abidw.cc           |  2 +-
>  tools/abilint.cc         |  8 ++++----
>  5 files changed, 40 insertions(+), 19 deletions(-)
> 
> diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
> index 56b2bf91..3343f0d8 100644
> --- a/include/abg-ctf-reader.h
> +++ b/include/abg-ctf-reader.h
> @@ -25,11 +25,15 @@ namespace ctf_reader
>  {
>  
>  class read_context;
> -read_context *create_read_context(const std::string& elf_path,
> -                                  ir::environment *env);
> -corpus_sptr read_corpus(read_context *ctxt,
> -                        elf_reader::status& status);
> +typedef shared_ptr<read_context> read_context_sptr;
>  
> +read_context_sptr
> +create_read_context(const std::string& elf_path,
> +                    ir::environment *env);
> +corpus_sptr
> +read_corpus(read_context *ctxt, elf_reader::status& status);
> +corpus_sptr
> +read_corpus(const read_context_sptr &ctxt, elf_reader::status &status);
>  } // end namespace ctf_reader
>  } // end namespace abigail
>  
> diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
> index fd53f8a1..6829e4c0 100644
> --- a/src/abg-ctf-reader.cc
> +++ b/src/abg-ctf-reader.cc
> @@ -1058,11 +1058,12 @@ slurp_elf_info(read_context *ctxt, corpus_sptr corp)
>  /// @param elf_path the patch of some ELF file.
>  /// @param env a libabigail IR environment.
>  
> -read_context *
> +read_context_sptr
>  create_read_context(const std::string& elf_path,
>                      ir::environment *env)
>  {
> -  return new read_context(elf_path, env);
> +  read_context_sptr result(new read_context(elf_path, env));
> +  return result;
>  }
>  
>  /// Read the CTF information from some source described by a given
> @@ -1116,5 +1117,19 @@ read_corpus(read_context *ctxt, elf_reader::status &status)
>    return corp;
>  }
>  
> +/// Read the CTF information from some source described by a given
> +/// read context and process it to create a libabigail IR corpus.
> +/// Store the corpus in the same read context.
> +///
> +/// @param ctxt the read context to use.
> +///
> +/// @param status the resulting status of the corpus read.
> +///
> +/// @return a shared pointer to the read corpus.
> +
> +corpus_sptr
> +read_corpus(const read_context_sptr &ctxt, elf_reader::status &status)
> +{return read_corpus(ctxt.get(), status);}
> +
>  } // End of namespace ctf_reader
>  } // End of namespace abigail
> diff --git a/tools/abidiff.cc b/tools/abidiff.cc
> index f145f4f1..30959616 100644
> --- a/tools/abidiff.cc
> +++ b/tools/abidiff.cc
> @@ -1169,12 +1169,13 @@ main(int argc, char* argv[])
>  #ifdef WITH_CTF
>              if (opts.use_ctf)
>                {
> -                abigail::ctf_reader::read_context *ctxt
> -                  = abigail::ctf_reader::create_read_context (opts.file1,
> -                                                              env.get());
> +                abigail::ctf_reader::read_context_sptr ctxt
> +                  = abigail::ctf_reader::create_read_context(opts.file1,
> +                                                             env.get());
>  
>                  assert (ctxt);
> -                c1 = abigail::ctf_reader::read_corpus (ctxt, c1_status);
> +                c1 = abigail::ctf_reader::read_corpus(ctxt.get(),
> +                                                      c1_status);
>                }
>              else
>  #endif
> @@ -1252,12 +1253,13 @@ main(int argc, char* argv[])
>  #ifdef WITH_CTF
>              if (opts.use_ctf)
>                {
> -                abigail::ctf_reader::read_context *ctxt
> -                  = abigail::ctf_reader::create_read_context (opts.file2,
> -                                                              env.get());
> +                abigail::ctf_reader::read_context_sptr ctxt
> +                  = abigail::ctf_reader::create_read_context(opts.file2,
> +                                                             env.get());
>  
>                  assert (ctxt);
> -                c2 = abigail::ctf_reader::read_corpus (ctxt, c2_status);
> +                c2 = abigail::ctf_reader::read_corpus (ctxt.get(),
> +                                                       c2_status);
>                }
>              else
>  #endif
> diff --git a/tools/abidw.cc b/tools/abidw.cc
> index d2bc029b..f7a8937d 100644
> --- a/tools/abidw.cc
> +++ b/tools/abidw.cc
> @@ -539,7 +539,7 @@ load_corpus_and_write_abixml(char* argv[],
>  #ifdef WITH_CTF
>    if (opts.use_ctf)
>      {
> -      abigail::ctf_reader::read_context *ctxt
> +      abigail::ctf_reader::read_context_sptr ctxt
>          = abigail::ctf_reader::create_read_context (opts.in_file_path,
>                                                      env.get());
>  
> diff --git a/tools/abilint.cc b/tools/abilint.cc
> index 49643b66..2e9bae49 100644
> --- a/tools/abilint.cc
> +++ b/tools/abilint.cc
> @@ -370,12 +370,12 @@ main(int argc, char* argv[])
>  #ifdef WITH_CTF
>              if (opts.use_ctf)
>                {
> -                abigail::ctf_reader::read_context *ctxt
> -                  = abigail::ctf_reader::create_read_context (opts.file_path,
> -                                                              env.get());
> +                abigail::ctf_reader::read_context_sptr ctxt
> +                  = abigail::ctf_reader::create_read_context(opts.file_path,
> +                                                             env.get());
>  
>                  assert (ctxt);
> -                corp = abigail::ctf_reader::read_corpus (ctxt, s);
> +                corp = abigail::ctf_reader::read_corpus (ctxt.get(), s);
>                }
>              else
>  #endif
>
diff mbox series

Patch

diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
index 56b2bf91..c527c2ff 100644
--- a/include/abg-ctf-reader.h
+++ b/include/abg-ctf-reader.h
@@ -25,8 +25,11 @@  namespace ctf_reader
 {
 
 class read_context;
-read_context *create_read_context(const std::string& elf_path,
-                                  ir::environment *env);
+typedef shared_ptr<read_context> read_context_sptr;
+
+read_context_sptr
+create_read_context(const std::string& elf_path,
+                    ir::environment *env);
 corpus_sptr read_corpus(read_context *ctxt,
                         elf_reader::status& status);
 
diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index 2c2c204d..3e17e049 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -1059,11 +1059,12 @@  slurp_elf_info(read_context *ctxt, corpus_sptr corp)
 /// @param elf_path the patch of some ELF file.
 /// @param env a libabigail IR environment.
 
-read_context *
+read_context_sptr
 create_read_context(const std::string& elf_path,
                     ir::environment *env)
 {
-  return new read_context(elf_path, env);
+  read_context_sptr result(new read_context(elf_path, env));
+  return result;
 }
 
 /// Read the CTF information from some source described by a given
diff --git a/tools/abidiff.cc b/tools/abidiff.cc
index f145f4f1..30959616 100644
--- a/tools/abidiff.cc
+++ b/tools/abidiff.cc
@@ -1169,12 +1169,13 @@  main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file1,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file1,
+                                                             env.get());
 
                 assert (ctxt);
-                c1 = abigail::ctf_reader::read_corpus (ctxt, c1_status);
+                c1 = abigail::ctf_reader::read_corpus(ctxt.get(),
+                                                      c1_status);
               }
             else
 #endif
@@ -1252,12 +1253,13 @@  main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file2,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file2,
+                                                             env.get());
 
                 assert (ctxt);
-                c2 = abigail::ctf_reader::read_corpus (ctxt, c2_status);
+                c2 = abigail::ctf_reader::read_corpus (ctxt.get(),
+                                                       c2_status);
               }
             else
 #endif
diff --git a/tools/abilint.cc b/tools/abilint.cc
index 49643b66..2e9bae49 100644
--- a/tools/abilint.cc
+++ b/tools/abilint.cc
@@ -370,12 +370,12 @@  main(int argc, char* argv[])
 #ifdef WITH_CTF
             if (opts.use_ctf)
               {
-                abigail::ctf_reader::read_context *ctxt
-                  = abigail::ctf_reader::create_read_context (opts.file_path,
-                                                              env.get());
+                abigail::ctf_reader::read_context_sptr ctxt
+                  = abigail::ctf_reader::create_read_context(opts.file_path,
+                                                             env.get());
 
                 assert (ctxt);
-                corp = abigail::ctf_reader::read_corpus (ctxt, s);
+                corp = abigail::ctf_reader::read_corpus (ctxt.get(), s);
               }
             else
 #endif