* [PATCH] py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier
@ 2017-12-14 19:53 Simon Marchi
2017-12-14 20:48 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2017-12-14 19:53 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
In Python 3, the 'p' format specifier can be passed to
PyArg_ParseTupleAndKeywords to test the argument for truth and convert
it to a boolean value (the p stands for predicate). However, it is not
available in Python 2, causing this error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
b1 = gdb.Breakpoint("foo", qualified=False)
TypeError: argument 10 (impossible<bad format char>)
This patch changes it to the 'O' specifier, which returns the Python
object passed in without transformation, and uses PyObject_IsTrue on it.
This is what is done for the other boolean parameters of this function
(internal and temporary).
This fixes the test gdb.python/py-breakpoint.exp for Python 2.
gdb/ChangeLog:
* python/py-breakpoint.c (bppy_init): Use 'O' format specifier
for "qualified" and use PyObject_IsTrue.
---
gdb/python/py-breakpoint.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index ce680c4..05291b5 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -707,9 +707,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
char *label = NULL;
char *source = NULL;
char *function = NULL;
- int qualified = 0;
+ PyObject * qualified = NULL;
- if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOp", keywords,
+ if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords,
&spec, &type, &access_type,
&internal,
&temporary, &source,
@@ -762,7 +762,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
{
event_location_up location;
symbol_name_match_type func_name_match_type
- = (qualified
+ = (qualified != NULL && PyObject_IsTrue (qualified)
? symbol_name_match_type::FULL
: symbol_name_match_type::WILD);
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier
2017-12-14 19:53 [PATCH] py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier Simon Marchi
@ 2017-12-14 20:48 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2017-12-14 20:48 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
On 2017-12-14 14:53, Simon Marchi wrote:
> In Python 3, the 'p' format specifier can be passed to
> PyArg_ParseTupleAndKeywords to test the argument for truth and convert
> it to a boolean value (the p stands for predicate). However, it is not
> available in Python 2, causing this error:
>
> Traceback (most recent call last):
> File "test.py", line 1, in <module>
> b1 = gdb.Breakpoint("foo", qualified=False)
> TypeError: argument 10 (impossible<bad format char>)
>
> This patch changes it to the 'O' specifier, which returns the Python
> object passed in without transformation, and uses PyObject_IsTrue on
> it.
> This is what is done for the other boolean parameters of this function
> (internal and temporary).
>
> This fixes the test gdb.python/py-breakpoint.exp for Python 2.
>
> gdb/ChangeLog:
>
> * python/py-breakpoint.c (bppy_init): Use 'O' format specifier
> for "qualified" and use PyObject_IsTrue.
> ---
> gdb/python/py-breakpoint.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index ce680c4..05291b5 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -707,9 +707,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject
> *kwargs)
> char *label = NULL;
> char *source = NULL;
> char *function = NULL;
> - int qualified = 0;
> + PyObject * qualified = NULL;
>
> - if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOp",
> keywords,
> + if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO",
> keywords,
> &spec, &type, &access_type,
> &internal,
> &temporary, &source,
> @@ -762,7 +762,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject
> *kwargs)
> {
> event_location_up location;
> symbol_name_match_type func_name_match_type
> - = (qualified
> + = (qualified != NULL && PyObject_IsTrue (qualified)
> ? symbol_name_match_type::FULL
> : symbol_name_match_type::WILD);
Pedro gave me a thumbs up on IRC, so I am pushing it.
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-14 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 19:53 [PATCH] py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier Simon Marchi
2017-12-14 20:48 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox