homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _elementtree.c warnings under 64-bit Windows
Type: compile error Stage: patch review
Components: Extension Modules, Windows Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Compilation warnings under x64 Windows
View: 9566
Assigned To: Nosy List: effbot, eli.bendersky, flox, janglin, loewis, pitrou
Priority: normal Keywords: patch

Created on 2010年09月06日 12:49 by pitrou, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9783.diff janglin, 2010年09月24日 02:00 review
Messages (6)
msg115700 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010年09月06日 12:49
Some of these warnings could be serious (e.g. the one where the 64-bit "self" is converted to a 32-bit "long"):
13>..\Modules\_elementtree.c(696) : warning C4244: 'function' : conversion from 'Py_uintptr_t' to 'long', possible loss of data
13>..\Modules\_elementtree.c(1239) : warning C4244: '=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
13>..\Modules\_elementtree.c(1372) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data
13>..\Modules\_elementtree.c(1414) : warning C4244: '+=' : conversion from 'Py_ssize_t' to 'int', possible loss of data
13>..\Modules\_elementtree.c(2076) : warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
13>..\Modules\_elementtree.c(2663) : warning C4244: 'function' : conversion from 'Py_ssize_t' to 'int', possible loss of data
msg116175 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010年09月12日 11:37
Instead of
 PyLong_FromLong((Py_uintptr_t) self);
use
 PyLong_FromVoidPtr(self);
For the others, I suggest making length and allocated Py_ssize_t; this is likely a pervasive change. Of course, very few people will currently run into XML documents where some element has more than 2**31 children... You would need several TiB of main memory to represent it using ElementTree.
Fredrik, please indicate whether it is ok to make this kind of change, or whether it would need your explicit approval.
msg117255 - (view) Author: Jon Anglin (janglin) Date: 2010年09月24日 02:00
issue9783.diff provides a patch that will compile clean on 32 and 64 bit Windows systems. I tried to avoid explicit casts where I could, but it was not always possible. I have ported a lot of my company's code to 64 bit (all Windows based). In my experience many warnings are because of programmers using the int type in places where a size_t may be more appropriate. Most of the warnings here are due to mixing int and Py_ssize_t types.
msg117324 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010年09月24日 18:32
> issue9783.diff provides a patch that will compile clean on 32 and 64
> bit Windows systems. I tried to avoid explicit casts where I could,
> but it was not always possible. I have ported a lot of my company's
> code to 64 bit (all Windows based). In my experience many warnings
> are because of programmers using the int type in places where a
> size_t may be more appropriate. Most of the warnings here are due to
> mixing int and Py_ssize_t types.
I think the patch is incorrect as it stands: the casts may cause
truncation. As you say, int is still being used where size_t was
more appropriate, so I think we should change it in that manner
(e.g. make element_resize accept Py_ssize_t).
In cases where we really can't propagate Py_ssize_t to (e.g.
XML_Parse), we need to check for an int overflow, and raise
an exception if it does overflow.
msg117362 - (view) Author: Jon Anglin (janglin) Date: 2010年09月25日 13:07
Martin is correct about this patch.
> In cases where we really can't propagate Py_ssize_t to (e.g.
> XML_Parse), we need to check for an int overflow, and raise
> an exception if it does overflow.
Is this an appropriate approach?
int
PySize_AsInt(Py_ssize_t value)
{
 if (value > (Py_ssize_t)INT_MAX || value < (Py_ssize_t)INT_MIN) {
 PyErr_SetString(PyExc_OverflowError, 
 "Size value can not be represented as an integer");
 }
 return (int)value;
}
I would only define this when sizeof(Py_ssize_t) > sizeof(int) of course. In other cases it would be a macro that just evaluates to value.
I would most likely need an unsigned version as well (although not for this particular issue).
This code could be used in many C modules. Where in the Python code base should such functions be placed?
msg166019 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2012年07月21日 13:00
This warning is not specific to the _elementtree module.
See related issue #9566.
History
Date User Action Args
2022年04月11日 14:57:06adminsetgithub: 53992
2012年07月21日 13:00:19floxsetstatus: open -> closed

nosy: + eli.bendersky
messages: + msg166019

superseder: Compilation warnings under x64 Windows
resolution: duplicate
2010年12月13日 17:52:54ned.deilyunlinkissue10690 superseder
2010年12月13日 09:43:57ned.deilylinkissue10690 superseder
2010年09月25日 13:07:07janglinsetmessages: + msg117362
2010年09月24日 18:32:12loewissetmessages: + msg117324
2010年09月24日 09:40:11ned.deilysetstage: needs patch -> patch review
2010年09月24日 02:00:32janglinsetfiles: + issue9783.diff
keywords: + patch
messages: + msg117255
2010年09月13日 14:01:37janglinsetnosy: + janglin
2010年09月12日 11:37:51loewissetnosy: + loewis
messages: + msg116175
2010年09月06日 12:49:52pitroucreate

AltStyle によって変換されたページ (->オリジナル) /