Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: gdb/python/py-param.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gdb/python/py-objfile.c ('k') | gdb/python/py-prettyprint.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gdb/python/py-param.c
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 963427e57d2a32cb9d8d4b60da865776c0cc5057..e7671284dc550c6071ee35d25d86bfda59e92358 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -1,6 +1,6 @@
/* GDB parameters implemented in Python
- Copyright (C) 2008-2012 Free Software Foundation, Inc.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
This file is part of GDB.
@@ -89,7 +89,8 @@ struct parmpy_object
typedef struct parmpy_object parmpy_object;
-static PyTypeObject parmpy_object_type;
+static PyTypeObject parmpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
/* Some handy string constants. */
static PyObject *set_doc_cst;
@@ -102,7 +103,11 @@ static PyObject *
get_attr (PyObject *obj, PyObject *attr_name)
{
if (PyString_Check (attr_name)
+#ifdef IS_PY3K
+ && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
+#else
&& ! strcmp (PyString_AsString (attr_name), "value"))
+#endif
{
parmpy_object *self = (parmpy_object *) obj;
@@ -129,7 +134,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
&& (self->type == var_filename
|| value != Py_None))
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("String required for filename."));
return -1;
@@ -162,7 +167,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
if (! gdbpy_is_string (value))
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("ENUM arguments must be a string."));
return -1;
}
@@ -187,12 +192,12 @@ set_parameter_value (parmpy_object *self, PyObject *value)
case var_boolean:
if (! PyBool_Check (value))
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("A boolean argument is required."));
return -1;
}
cmp = PyObject_IsTrue (value);
- if (cmp < 0)
+ if (cmp < 0)
return -1;
self->value.intval = cmp;
break;
@@ -211,10 +216,10 @@ set_parameter_value (parmpy_object *self, PyObject *value)
{
cmp = PyObject_IsTrue (value);
if (cmp < 0 )
- return -1;
+ return -1;
if (cmp == 1)
self->value.autoboolval = AUTO_BOOLEAN_TRUE;
- else
+ else
self->value.autoboolval = AUTO_BOOLEAN_FALSE;
}
break;
@@ -228,7 +233,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
if (! PyInt_Check (value))
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("The value must be integer."));
return -1;
}
@@ -253,7 +258,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
if (! ok)
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("Range exceeded."));
return -1;
}
@@ -263,7 +268,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
}
default:
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("Unhandled type in parameter value."));
return -1;
}
@@ -276,7 +281,11 @@ static int
set_attr (PyObject *obj, PyObject *attr_name, PyObject *val)
{
if (PyString_Check (attr_name)
+#ifdef IS_PY3K
+ && ! PyUnicode_CompareWithASCIIString (attr_name, "value"))
+#else
&& ! strcmp (PyString_AsString (attr_name), "value"))
+#endif
{
if (!val)
{
@@ -365,8 +374,6 @@ get_set_value (char *args, int from_tty,
if (! set_doc_func)
goto error;
- make_cleanup_py_decref (set_doc_func);
-
if (PyObject_HasAttr (obj, set_doc_func))
{
set_doc_string = call_doc_function (obj, set_doc_func, NULL);
@@ -384,10 +391,12 @@ get_set_value (char *args, int from_tty,
make_cleanup (xfree, set_doc_string);
fprintf_filtered (gdb_stdout, "%s\n", set_doc_string);
+ Py_XDECREF (set_doc_func);
do_cleanups (cleanup);
return;
error:
+ Py_XDECREF (set_doc_func);
gdbpy_print_stack ();
do_cleanups (cleanup);
return;
@@ -413,8 +422,6 @@ get_show_value (struct ui_file *file, int from_tty,
if (! show_doc_func)
goto error;
- make_cleanup_py_decref (show_doc_func);
-
if (PyObject_HasAttr (obj, show_doc_func))
{
PyObject *val_obj = PyString_FromString (value);
@@ -422,9 +429,8 @@ get_show_value (struct ui_file *file, int from_tty,
if (! val_obj)
goto error;
- make_cleanup_py_decref (val_obj);
-
show_doc_string = call_doc_function (obj, show_doc_func, val_obj);
+ Py_DECREF (val_obj);
if (! show_doc_string)
goto error;
@@ -442,10 +448,12 @@ get_show_value (struct ui_file *file, int from_tty,
fprintf_filtered (file, "%s %s\n", show_doc_string, value);
}
+ Py_XDECREF (show_doc_func);
do_cleanups (cleanup);
return;
error:
+ Py_XDECREF (show_doc_func);
gdbpy_print_stack ();
do_cleanups (cleanup);
return;
@@ -462,7 +470,7 @@ add_setshow_generic (int parmclass, enum command_class cmdclass,
struct cmd_list_element **show_list)
{
struct cmd_list_element *param = NULL;
- char *tmp_name = NULL;
+ const char *tmp_name = NULL;
switch (parmclass)
{
@@ -572,7 +580,7 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
if (! PySequence_Check (enum_values))
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("The enumeration is not a sequence."));
return 0;
}
@@ -582,7 +590,7 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
return 0;
if (size == 0)
{
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("The enumeration is empty."));
return 0;
}
@@ -602,12 +610,14 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
}
if (! gdbpy_is_string (item))
{
+ Py_DECREF (item);
do_cleanups (back_to);
- PyErr_SetString (PyExc_RuntimeError,
+ PyErr_SetString (PyExc_RuntimeError,
_("The enumeration item not a string."));
return 0;
}
self->enumeration[i] = python_string_to_host_string (item);
+ Py_DECREF (item);
if (self->enumeration[i] == NULL)
{
do_cleanups (back_to);
@@ -740,41 +750,39 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
/* Initialize the 'parameters' module. */
-void
+int
gdbpy_initialize_parameters (void)
{
int i;
parmpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&parmpy_object_type) < 0)
- return;
+ return -1;
set_doc_cst = PyString_FromString ("set_doc");
if (! set_doc_cst)
- return;
+ return -1;
show_doc_cst = PyString_FromString ("show_doc");
if (! show_doc_cst)
- return;
+ return -1;
for (i = 0; parm_constants[i].name; ++i)
{
if (PyModule_AddIntConstant (gdb_module,
parm_constants[i].name,
parm_constants[i].value) < 0)
- return;
+ return -1;
}
- Py_INCREF (&parmpy_object_type);
- PyModule_AddObject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return gdb_pymodule_addobject (gdb_module, "Parameter",
+ (PyObject *) &parmpy_object_type);
}
static PyTypeObject parmpy_object_type =
{
- PyObject_HEAD_INIT (NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT (NULL, 0)
"gdb.Parameter", /*tp_name*/
sizeof (parmpy_object), /*tp_basicsize*/
0, /*tp_itemsize*/
« no previous file with comments | « gdb/python/py-objfile.c ('k') | gdb/python/py-prettyprint.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698