Patchwork parsers.c: avoid implicit conversion loses integer precision warnings

login
register
mail settings
Submitter André Sintzoff
Date Aug. 18, 2015, 12:59 p.m.
Message ID <99bbcbd8b97420e8a473.1439902787@zibeline.local>
Download mbox | patch
Permalink /patch/10222/
State Superseded
Headers show

Comments

André Sintzoff - Aug. 18, 2015, 12:59 p.m.
# HG changeset patch
# User André Sintzoff <andre.sintzoff@gmail.com>
# Date 1439902654 -7200
#      Tue Aug 18 14:57:34 2015 +0200
# Node ID 99bbcbd8b97420e8a473d0e5f16242625f6ec04c
# Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
parsers.c: avoid implicit conversion loses integer precision warnings

These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
(based on LLVM 3.6.0svn) and were introduced in ff89383a97db
Yuya Nishihara - Aug. 18, 2015, 2:30 p.m.
On Tue, 18 Aug 2015 14:59:47 +0200, André Sintzoff wrote:
> # HG changeset patch
> # User André Sintzoff <andre.sintzoff@gmail.com>
> # Date 1439902654 -7200
> #      Tue Aug 18 14:57:34 2015 +0200
> # Node ID 99bbcbd8b97420e8a473d0e5f16242625f6ec04c
> # Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
> parsers.c: avoid implicit conversion loses integer precision warnings
> 
> These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
> (based on LLVM 3.6.0svn) and were introduced in ff89383a97db
> 
> diff -r 9e7d805925c8 -r 99bbcbd8b974 mercurial/parsers.c
> --- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
> +++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
> @@ -1109,7 +1109,7 @@
>  {
>  
>  	/* Input */
> -	long minroot;
> +	int minroot;

minroot should be long because it is output argument of PyArg_ParseTuple(),
or should it be specified as "i" type?
Jordi Gutiérrez Hermoso - Aug. 18, 2015, 4:29 p.m.
On Tue, 2015-08-18 at 14:59 +0200, André Sintzoff wrote:
> # HG changeset patch
> # User André Sintzoff <andre.sintzoff@gmail.com>
> # Date 1439902654 -7200
> #      Tue Aug 18 14:57:34 2015 +0200
> # Node ID 99bbcbd8b97420e8a473d0e5f16242625f6ec04c
> # Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
> parsers.c: avoid implicit conversion loses integer precision warnings
> 
> These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
> (based on LLVM 3.6.0svn) and were introduced in ff89383a97db

Can you please provide the LLVM diagnostic (error or warning)? This
seems like the wrong fix, since you're calling a function called
PyInt_AsLong and immediately casting it back to int.

> 
> diff -r 9e7d805925c8 -r 99bbcbd8b974 mercurial/parsers.c
> --- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
> +++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
> @@ -1109,7 +1109,7 @@
>  {
>  
>  	/* Input */
> -	long minroot;
> +	int minroot;
>  	PyObject *includepatharg = NULL;
>  	int includepath = 0;
>  	/* heads is a list */
> @@ -1121,7 +1121,7 @@
>  
>  	PyObject *val;
>  	Py_ssize_t len = index_length(self) - 1;
> -	long revnum;
> +	int revnum;
>  	Py_ssize_t k;
>  	Py_ssize_t i;
>  	int r;
> @@ -1166,7 +1166,7 @@
>  	/* Populate tovisit with all the heads */
>  	numheads = PyList_GET_SIZE(heads);
>  	for (i = 0; i < numheads; i++) {
> -		revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
> +		revnum = (int)PyInt_AsLong(PyList_GET_ITEM(heads, i));
>  		if (revnum == -1 && PyErr_Occurred())
>  			goto bail;
>  		if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 9e7d805925c8 -r 99bbcbd8b974 mercurial/parsers.c
--- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
+++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
@@ -1109,7 +1109,7 @@ 
 {
 
 	/* Input */
-	long minroot;
+	int minroot;
 	PyObject *includepatharg = NULL;
 	int includepath = 0;
 	/* heads is a list */
@@ -1121,7 +1121,7 @@ 
 
 	PyObject *val;
 	Py_ssize_t len = index_length(self) - 1;
-	long revnum;
+	int revnum;
 	Py_ssize_t k;
 	Py_ssize_t i;
 	int r;
@@ -1166,7 +1166,7 @@ 
 	/* Populate tovisit with all the heads */
 	numheads = PyList_GET_SIZE(heads);
 	for (i = 0; i < numheads; i++) {
-		revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
+		revnum = (int)PyInt_AsLong(PyList_GET_ITEM(heads, i));
 		if (revnum == -1 && PyErr_Occurred())
 			goto bail;
 		if (revnum + 1 < 0 || revnum + 1 >= len + 1) {