From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41774 invoked by alias); 14 Dec 2017 20:48:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 41683 invoked by uid 89); 14 Dec 2017 20:48:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=thumbs, H*f:sk:1513281, H*i:sk:1513281 X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Dec 2017 20:48:01 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id vBEKls5i005291 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Dec 2017 15:47:59 -0500 Received: by simark.ca (Postfix, from userid 112) id CF4701E586; Thu, 14 Dec 2017 15:47:54 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id DF23D1E51A; Thu, 14 Dec 2017 15:47:46 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 14 Dec 2017 20:48:00 -0000 From: Simon Marchi To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier In-Reply-To: <1513281201-9279-1-git-send-email-simon.marchi@ericsson.com> References: <1513281201-9279-1-git-send-email-simon.marchi@ericsson.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.2 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 14 Dec 2017 20:47:54 +0000 X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00358.txt.bz2 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 > b1 = gdb.Breakpoint("foo", qualified=False) > TypeError: argument 10 (impossible) > > 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