Make the objfile constructor private
authorTom Tromey <tom@tromey.com>
Fri, 1 Nov 2019 22:06:37 +0000 (16:06 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 12 Dec 2019 22:50:50 +0000 (15:50 -0700)
This changes the objfile constructor to be private, changing the
callers to use a factory method.  This isn't perhaps strictly needed
for the goal of this series -- changing the container model of
objfiles -- but is a nice symmetry.

gdb/ChangeLog
2019-12-12  Tom Tromey  <tom@tromey.com>

* symfile.c (symbol_file_add_with_addrs): Use objfile::make.
* objfiles.h (struct objfile): Make constructor private.
<make>: New static method.
* jit.c (jit_object_close_impl): Update.

Change-Id: I42e07bc80a88cf3322ace94ffe869ae5788bcb29

gdb/ChangeLog
gdb/jit.c
gdb/objfiles.h
gdb/symfile.c

index 165ffda25109dadc809754104f22655565ebd2a5..393d43ef3169f1e738a6a53fd7dd06b6e8011bb8 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-12  Tom Tromey  <tom@tromey.com>
+
+       * symfile.c (symbol_file_add_with_addrs): Use objfile::make.
+       * objfiles.h (struct objfile): Make constructor private.
+       <make>: New static method.
+       * jit.c (jit_object_close_impl): Update.
+
 2019-12-12  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * jit.c (jit_reader_try_read_symtab): Replace xmalloc/xfree with
index b6e51e4f8b4dc45aababed6d5ed5b7c20edddb3c..2018e2c6f0d2826354817b15f085735add479e81 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -786,8 +786,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb,
 
   priv_data = (jit_dbg_reader_data *) cb->priv_data;
 
-  objfile = new struct objfile (NULL, "<< JIT compiled code >>",
-                               OBJF_NOT_FILENAME);
+  objfile = objfile::make (nullptr, "<< JIT compiled code >>",
+                          OBJF_NOT_FILENAME);
   objfile->per_bfd->gdbarch = target_gdbarch ();
 
   j = NULL;
index 1601cfe591f0b4d7031555e9d67f0b2faac0dd7b..b5c04eb7cb95247b9aeda332dc6a0e7f12d36754 100644 (file)
@@ -394,7 +394,19 @@ private:
 
 struct objfile
 {
+private:
+
+  /* The only way to create an objfile is to call objfile::make.  */
   objfile (bfd *, const char *, objfile_flags);
+
+public:
+
+  /* Create an objfile.  */
+  static objfile *make (bfd *bfd_, const char *name_, objfile_flags flags_)
+  {
+    return new objfile (bfd_, name_, flags_);
+  }
+
   ~objfile ();
 
   DISABLE_COPY_AND_ASSIGN (objfile);
index aec07d7a7abd5d3a788b97c69ce6637707e8b6cc..eef27a8418ebaf1705865827104a44cafb3d9957 100644 (file)
@@ -1093,7 +1093,7 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
 
   if (mainline)
     flags |= OBJF_MAINLINE;
-  objfile = new struct objfile (abfd, name, flags);
+  objfile = objfile::make (abfd, name, flags);
 
   if (parent)
     add_separate_debug_objfile (objfile, parent);
This page took 0.032696 seconds and 4 git commands to generate.