Rename _const functions to use overloading instead
[deliverable/binutils-gdb.git] / gdb / python / py-breakpoint.c
index f268b2bb44627943ff5f2f511fd3a1dea64b3118..d57c2fa05e5145e46c61d6015ebfbdd2c617b1ac 100644 (file)
@@ -41,7 +41,7 @@ static int bppy_live;
 gdbpy_breakpoint_object *bppy_pending_object;
 
 /* Function that is called when a Python condition is evaluated.  */
-static char * const stop_func = "stop";
+static const char stop_func[] = "stop";
 
 /* This is used to initialize various gdb.bp_* constants.  */
 struct pybp_code
@@ -390,7 +390,7 @@ bppy_get_location (PyObject *self, void *closure)
   if (obj->bp->type != bp_breakpoint)
     Py_RETURN_NONE;
 
-  str = event_location_to_string (obj->bp->location);
+  str = event_location_to_string (obj->bp->location.get ());
   if (! str)
     str = "";
   return host_string_to_python_string (str);
@@ -400,7 +400,7 @@ bppy_get_location (PyObject *self, void *closure)
 static PyObject *
 bppy_get_expression (PyObject *self, void *closure)
 {
-  char *str;
+  const char *str;
   gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
   struct watchpoint *wp;
 
@@ -485,19 +485,16 @@ bppy_get_commands (PyObject *self, void *closure)
   gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
   struct breakpoint *bp = self_bp->bp;
   long length;
-  struct ui_file *string_file;
   PyObject *result;
-  struct cleanup *chain;
 
   BPPY_REQUIRE_VALID (self_bp);
 
   if (! self_bp->bp->commands)
     Py_RETURN_NONE;
 
-  string_file = mem_fileopen ();
-  chain = make_cleanup_ui_file_delete (string_file);
+  string_file stb;
 
-  current_uiout->redirect (string_file);
+  current_uiout->redirect (&stb);
   TRY
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
@@ -505,17 +502,13 @@ bppy_get_commands (PyObject *self, void *closure)
   CATCH (except, RETURN_MASK_ALL)
     {
       current_uiout->redirect (NULL);
-      do_cleanups (chain);
       gdbpy_convert_exception (except);
       return NULL;
     }
   END_CATCH
 
   current_uiout->redirect (NULL);
-  std::string cmdstr = ui_file_as_string (string_file);
-  result = host_string_to_python_string (cmdstr.c_str ());
-  do_cleanups (chain);
-  return result;
+  return host_string_to_python_string (stb.c_str ());
 }
 
 /* Python function to get the breakpoint type.  */
@@ -644,8 +637,8 @@ bppy_get_ignore_count (PyObject *self, void *closure)
 static int
 bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 {
-  static char *keywords[] = { "spec", "type", "wp_class", "internal",
-                             "temporary", NULL };
+  static const char *keywords[] = { "spec", "type", "wp_class", "internal",
+                                   "temporary", NULL };
   const char *spec;
   int type = bp_breakpoint;
   int access_type = hw_write;
@@ -654,9 +647,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   int internal_bp = 0;
   int temporary_bp = 0;
 
-  if (! PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
-                                    &spec, &type, &access_type,
-                                    &internal, &temporary))
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "s|iiOO", keywords,
+                                       &spec, &type, &access_type,
+                                       &internal, &temporary))
     return -1;
 
   if (internal)
@@ -680,29 +673,23 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   TRY
     {
       gdb::unique_xmalloc_ptr<char>
-       copy_holder (xstrdup (skip_spaces_const (spec)));
+       copy_holder (xstrdup (skip_spaces (spec)));
       char *copy = copy_holder.get ();
 
       switch (type)
        {
        case bp_breakpoint:
          {
-           struct event_location *location;
-           struct cleanup *cleanup;
-
-           location
+           event_location_up location
              = string_to_event_location_basic (&copy, current_language);
-           cleanup = make_cleanup_delete_event_location (location);
            create_breakpoint (python_gdbarch,
-                              location, NULL, -1, NULL,
+                              location.get (), NULL, -1, NULL,
                               0,
                               temporary_bp, bp_breakpoint,
                               0,
                               AUTO_BOOLEAN_TRUE,
                               &bkpt_breakpoint_ops,
                               0, 1, internal_bp, 0);
-
-           do_cleanups (cleanup);
            break;
          }
         case bp_watchpoint:
@@ -765,7 +752,7 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
   if (bppy_live == 0)
     return PyTuple_New (0);
 
-  gdbpy_ref list (PyList_New (0));
+  gdbpy_ref<> list (PyList_New (0));
   if (list == NULL)
     return NULL;
 
@@ -805,7 +792,7 @@ gdbpy_breakpoint_cond_says_stop (const struct extension_language_defn *extlang,
 
   if (PyObject_HasAttrString (py_bp, stop_func))
     {
-      gdbpy_ref result (PyObject_CallMethod (py_bp, stop_func, NULL));
+      gdbpy_ref<> result (PyObject_CallMethod (py_bp, stop_func, NULL));
 
       stop = 1;
       if (result != NULL)
@@ -918,25 +905,23 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
   int num = b->number;
   PyGILState_STATE state;
   struct breakpoint *bp = NULL;
-  gdbpy_breakpoint_object *bp_obj;
 
   state = PyGILState_Ensure ();
   bp = get_breakpoint (num);
   if (bp)
     {
-      bp_obj = bp->py_bp_object;
-      if (bp_obj)
+      gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
+      if (bp_obj != NULL)
        {
          if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_deleted))
            {
-             if (evpy_emit_event ((PyObject *) bp_obj,
+             if (evpy_emit_event ((PyObject *) bp_obj.get (),
                                   gdb_py_events.breakpoint_deleted) < 0)
                gdbpy_print_stack ();
            }
 
          bp_obj->bp = NULL;
          --bppy_live;
-         Py_DECREF (bp_obj);
        }
     }
   PyGILState_Release (state);
@@ -1041,15 +1026,12 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v)
        extlang = get_breakpoint_cond_ext_lang (obj->bp, EXT_LANG_PYTHON);
       if (extlang != NULL)
        {
-         char *error_text;
-
-         error_text
-           = xstrprintf (_("Only one stop condition allowed.  There is"
-                           " currently a %s stop condition defined for"
-                           " this breakpoint."),
-                         ext_lang_capitalized_name (extlang));
-         PyErr_SetString (PyExc_RuntimeError, error_text);
-         xfree (error_text);
+         std::string error_text
+           = string_printf (_("Only one stop condition allowed.  There is"
+                              " currently a %s stop condition defined for"
+                              " this breakpoint."),
+                            ext_lang_capitalized_name (extlang));
+         PyErr_SetString (PyExc_RuntimeError, error_text.c_str ());
          return -1;
        }
     }
@@ -1057,7 +1039,7 @@ local_setattro (PyObject *self, PyObject *name, PyObject *v)
   return PyObject_GenericSetAttr ((PyObject *)self, name, v);
 }
 
-static PyGetSetDef breakpoint_object_getset[] = {
+static gdb_PyGetSetDef breakpoint_object_getset[] = {
   { "enabled", bppy_get_enabled, bppy_set_enabled,
     "Boolean telling whether the breakpoint is enabled.", NULL },
   { "silent", bppy_get_silent, bppy_set_silent,
This page took 0.043681 seconds and 4 git commands to generate.