classification
Title: fix gcc -Wextra warnings (compare signed/unsigned)
Type: Stage:
Components: Library (Lib) Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: georg.brandl, mark.dickinson, vstinner
Priority: normal Keywords: patch

Created on 2009-05-05 00:24 by vstinner, last changed 2009-05-08 21:15 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
sign_warning_resource-2.patch vstinner, 2009-05-06 08:17
Messages (9)
msg87192 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-05-05 00:24
Simple patch to fix some gcc warnings (when using gcc -Wall -Wextra).
msg87193 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-05-05 00:26
Another patch to fix similar warnings in resource modules.
msg87240 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-05-05 09:58
About sign_warning_resource.patch: I don't know if RLIM_INFINITY 
constant is standard (always defined if getrlimit() is present).
msg87255 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-05 16:57
Thanks for the patches.

The first patch looks fine;  I'll apply it shortly.

For the second, I don't understand why you want to
compare the return result with RLIM_INFINITY:  PyInt_AsLong
returns -1 to signal failure;  is there some guarantee that
RLIM_INFINITY == -1 if it's defined?
msg87266 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-05 18:10
Applied the first patch in r72344, r72345, r72346, r72347.
msg87318 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-05-06 08:17
> For the second, I don't understand why you want to
> compare the return result with RLIM_INFINITY:  PyInt_AsLong
> returns -1 to signal failure;  is there some guarantee that
> RLIM_INFINITY == -1 if it's defined?

rlim_t is an unsigned type. The idea of sign_warning_resource.patch 
was to make gcc quiet about signed/unsigned comparaisons.

RLIM_INFINITY is defined as (rlim_t)-1. But it looks that it's not 
clear, so I wrote another patch to fix the warnings.
msg87338 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-06 16:28
Yes, that looks better.

PS: Do not remove applied patches.
msg87339 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-05-06 16:45
> PS: Do not remove applied patches.

Oh ok, sorry.
msg87471 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-05-08 21:15
Applied in r72479, r72481, r72482, r72483.

As a side note, I'm not 100% convinced of the correctness of the resource_setrlimit code.  If rlim_t is smaller than an unsigned long then input values might be wrapped to a smaller 
value (by the implicit long -> rlim_t conversion) when they should be signaling 
OverflowError instead.  Perhaps there should be a bunch of PySAFE_DOWNCASTs here?

Or maybe rlim_t is never smaller than a long in practice.

About RLIM_INFINITY:  I can't find it documented anywhere that RLIM_INFINITY is (rlim_t)-1, 
though I dare say that's true on many platforms.  Still, it doesn't seem like a safe 
assumption.
History
Date User Action Args
2009-05-08 21:15:28mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg87471
2009-05-06 16:45:09vstinnersetmessages: + msg87339
2009-05-06 16:28:54georg.brandlsetnosy: + georg.brandl
messages: + msg87338
2009-05-06 08:17:44vstinnersetfiles: - sign_warning.patch
2009-05-06 08:17:42vstinnersetfiles: - sign_warning_resource.patch
2009-05-06 08:17:37vstinnersetfiles: + sign_warning_resource-2.patch

messages: + msg87318
2009-05-05 18:10:16mark.dickinsonsetmessages: + msg87266
2009-05-05 16:57:47mark.dickinsonsetmessages: + msg87255
2009-05-05 09:58:05vstinnersetmessages: + msg87240
2009-05-05 09:17:18georg.brandlsetassignee: mark.dickinson

nosy: + mark.dickinson
2009-05-05 00:26:22vstinnersetfiles: + sign_warning_resource.patch

messages: + msg87193
2009-05-05 00:24:58vstinnercreate