Convert auto-load.c to type-safe registry API
authorTom Tromey <tom@tromey.com>
Sun, 21 Apr 2019 15:34:16 +0000 (09:34 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 8 May 2019 22:01:47 +0000 (16:01 -0600)
This changes auto-load.c to use the type-safe registry API.  It also
changes a couple of types to "bool", removing uses of "FALSE".

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

* auto-load.c (struct auto_load_pspace_info): Add destructor and
initializers.
<unsupported_script_warning_printed,
script_not_found_warning_printed>: Now bool.
(auto_load_pspace_data): Change type.
(~auto_load_pspace_info): Rename from
auto_load_pspace_data_cleanup.
(get_auto_load_pspace_data, init_loaded_scripts_info)
(clear_section_scripts, maybe_print_unsupported_script_warning)
(maybe_print_script_not_found_warning, _initialize_auto_load):
Update.

gdb/ChangeLog
gdb/auto-load.c

index f57dc4fd2f1eadae473882370ae1d870b093907a..82e55e9b5984a891fc2cc3258992074950bea7b5 100644 (file)
@@ -1,3 +1,17 @@
+2019-05-08  Tom Tromey  <tom@tromey.com>
+
+       * auto-load.c (struct auto_load_pspace_info): Add destructor and
+       initializers.
+       <unsupported_script_warning_printed,
+       script_not_found_warning_printed>: Now bool.
+       (auto_load_pspace_data): Change type.
+       (~auto_load_pspace_info): Rename from
+       auto_load_pspace_data_cleanup.
+       (get_auto_load_pspace_data, init_loaded_scripts_info)
+       (clear_section_scripts, maybe_print_unsupported_script_warning)
+       (maybe_print_script_not_found_warning, _initialize_auto_load):
+       Update.
+
 2019-05-08  Tom Tromey  <tom@tromey.com>
 
        * objfiles.c (objfile_pspace_info): Add destructor and
index ae7a189dc04b5820000d58f6913ef3ad4a848b73..6833c21323ae93ee7914979095f3e17bfb26bc89 100644 (file)
@@ -527,18 +527,21 @@ For more information about this security protection see the\n\
 
 struct auto_load_pspace_info
 {
+  auto_load_pspace_info () = default;
+  ~auto_load_pspace_info ();
+
   /* For each program space we keep track of loaded scripts, both when
      specified as file names and as scripts to be executed directly.  */
-  struct htab *loaded_script_files;
-  struct htab *loaded_script_texts;
+  struct htab *loaded_script_files = nullptr;
+  struct htab *loaded_script_texts = nullptr;
 
   /* Non-zero if we've issued the warning about an auto-load script not being
      supported.  We only want to issue this warning once.  */
-  int unsupported_script_warning_printed;
+  bool unsupported_script_warning_printed = false;
 
   /* Non-zero if we've issued the warning about an auto-load script not being
      found.  We only want to issue this warning once.  */
-  int script_not_found_warning_printed;
+  bool script_not_found_warning_printed = false;
 };
 
 /* Objects of this type are stored in the loaded_script hash table.  */
@@ -559,18 +562,15 @@ struct loaded_script
 };
 
 /* Per-program-space data key.  */
-static const struct program_space_data *auto_load_pspace_data;
+static const struct program_space_key<struct auto_load_pspace_info>
+  auto_load_pspace_data;
 
-static void
-auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg)
+auto_load_pspace_info::~auto_load_pspace_info ()
 {
-  struct auto_load_pspace_info *info = (struct auto_load_pspace_info *) arg;
-
-  if (info->loaded_script_files)
-    htab_delete (info->loaded_script_files);
-  if (info->loaded_script_texts)
-    htab_delete (info->loaded_script_texts);
-  xfree (info);
+  if (loaded_script_files)
+    htab_delete (loaded_script_files);
+  if (loaded_script_texts)
+    htab_delete (loaded_script_texts);
 }
 
 /* Get the current autoload data.  If none is found yet, add it now.  This
@@ -581,13 +581,9 @@ get_auto_load_pspace_data (struct program_space *pspace)
 {
   struct auto_load_pspace_info *info;
 
-  info = ((struct auto_load_pspace_info *)
-         program_space_data (pspace, auto_load_pspace_data));
+  info = auto_load_pspace_data.get (pspace);
   if (info == NULL)
-    {
-      info = XCNEW (struct auto_load_pspace_info);
-      set_program_space_data (pspace, auto_load_pspace_data, info);
-    }
+    info = auto_load_pspace_data.emplace (pspace);
 
   return info;
 }
@@ -632,8 +628,8 @@ init_loaded_scripts_info (struct auto_load_pspace_info *pspace_info)
                                                  eq_loaded_script_entry,
                                                  xfree);
 
-  pspace_info->unsupported_script_warning_printed = FALSE;
-  pspace_info->script_not_found_warning_printed = FALSE;
+  pspace_info->unsupported_script_warning_printed = false;
+  pspace_info->script_not_found_warning_printed = false;
 }
 
 /* Wrapper on get_auto_load_pspace_data to also allocate the hash table
@@ -747,17 +743,9 @@ clear_section_scripts (void)
   struct program_space *pspace = current_program_space;
   struct auto_load_pspace_info *info;
 
-  info = ((struct auto_load_pspace_info *)
-         program_space_data (pspace, auto_load_pspace_data));
+  info = auto_load_pspace_data.get (pspace);
   if (info != NULL && info->loaded_script_files != NULL)
-    {
-      htab_delete (info->loaded_script_files);
-      htab_delete (info->loaded_script_texts);
-      info->loaded_script_files = NULL;
-      info->loaded_script_texts = NULL;
-      info->unsupported_script_warning_printed = FALSE;
-      info->script_not_found_warning_printed = FALSE;
-    }
+    auto_load_pspace_data.clear (pspace);
 }
 
 /* Look for the auto-load script in LANGUAGE associated with OBJFILE where
@@ -1386,7 +1374,7 @@ of file %s.\n\
 Use `info auto-load %s-scripts [REGEXP]' to list them."),
               offset, section_name, objfile_name (objfile),
               ext_lang_name (language));
-      pspace_info->unsupported_script_warning_printed = 1;
+      pspace_info->unsupported_script_warning_printed = true;
     }
 }
 
@@ -1408,7 +1396,7 @@ of file %s.\n\
 Use `info auto-load %s-scripts [REGEXP]' to list them."),
               offset, section_name, objfile_name (objfile),
               ext_lang_name (language));
-      pspace_info->script_not_found_warning_printed = 1;
+      pspace_info->script_not_found_warning_printed = true;
     }
 }
 
@@ -1538,10 +1526,6 @@ _initialize_auto_load (void)
   char *guile_name_help;
   const char *suffix;
 
-  auto_load_pspace_data
-    = register_program_space_data_with_cleanup (NULL,
-                                               auto_load_pspace_data_cleanup);
-
   gdb::observers::new_objfile.attach (auto_load_new_objfile);
 
   add_setshow_boolean_cmd ("gdb-scripts", class_support,