Patchwork [7,of,7] parsers: use PyVarObject_HEAD_INIT

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 8, 2016, 8:48 p.m.
Message ID <ad527a4c62ad35b84c4a.1475959693@gps-mbp.local>
Download mbox | patch
Permalink /patch/16966/
State Accepted
Headers show

Comments

Gregory Szorc - Oct. 8, 2016, 8:48 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1475959442 -7200
#      Sat Oct 08 22:44:02 2016 +0200
# Node ID ad527a4c62ad35b84c4ad25d080ee427528966fa
# Parent  40775aad0c78f6c1fd07e7160d50426efbe032ed
parsers: use PyVarObject_HEAD_INIT

The macro changed slightly in Python 3, introducing curly brackets
that somehow confuse Clang into issuing a ton of compiler warnings.
Using PyVarObject_HEAD_INIT makes these go away.

It's worth noting that the code is identical: the 2nd argument to
PyVarObject_HEAD_INIT is assigned to the ob_size field and is
inserted immediately after "PyObject_HEAD_INIT(type)" is generated.
Compilers are weird.
Augie Fackler - Oct. 9, 2016, 8:51 a.m.
On Sat, Oct 08, 2016 at 10:48:13PM +0200, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1475959442 -7200
> #      Sat Oct 08 22:44:02 2016 +0200
> # Node ID ad527a4c62ad35b84c4ad25d080ee427528966fa
> # Parent  40775aad0c78f6c1fd07e7160d50426efbe032ed
> parsers: use PyVarObject_HEAD_INIT

Queued these with enthusiasm!

>
> The macro changed slightly in Python 3, introducing curly brackets
> that somehow confuse Clang into issuing a ton of compiler warnings.
> Using PyVarObject_HEAD_INIT makes these go away.
>
> It's worth noting that the code is identical: the 2nd argument to
> PyVarObject_HEAD_INIT is assigned to the ob_size field and is
> inserted immediately after "PyObject_HEAD_INIT(type)" is generated.
> Compilers are weird.
>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -2515,10 +2515,9 @@ static PyGetSetDef index_getset[] = {
>       {NULL} /* Sentinel */
>  };
>
>  static PyTypeObject indexType = {
> -	PyObject_HEAD_INIT(NULL)
> -	0,                         /* ob_size */
> +	PyVarObject_HEAD_INIT(NULL, 0)
>       "parsers.index",           /* tp_name */
>       sizeof(indexObject),       /* tp_basicsize */
>       0,                         /* tp_itemsize */
>       (destructor)index_dealloc, /* tp_dealloc */
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -2515,10 +2515,9 @@  static PyGetSetDef index_getset[] = {
 	{NULL} /* Sentinel */
 };
 
 static PyTypeObject indexType = {
-	PyObject_HEAD_INIT(NULL)
-	0,                         /* ob_size */
+	PyVarObject_HEAD_INIT(NULL, 0)
 	"parsers.index",           /* tp_name */
 	sizeof(indexObject),       /* tp_basicsize */
 	0,                         /* tp_itemsize */
 	(destructor)index_dealloc, /* tp_dealloc */