[issue9783] _elementtree.c warnings under 64-bit Windows
Florent Xicluna florent.xicl...@gmail.com added the comment: This warning is not specific to the _elementtree module. See related issue #9566. -- nosy: +eli.bendersky resolution: - duplicate status: open - closed superseder: - Compilation warnings under x64 Windows ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Jon Anglin jang...@fortresgrand.com added the comment: 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? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Changes by Ned Deily n...@acm.org: -- stage: needs patch - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Martin v. Löwis mar...@v.loewis.de added the comment: 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. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Jon Anglin jang...@fortresgrand.com added the comment: 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. -- keywords: +patch Added file: http://bugs.python.org/file18988/issue9783.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Changes by Jon Anglin jang...@fortresgrand.com: -- nosy: +janglin ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
Martin v. Löwis mar...@v.loewis.de added the comment: 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. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9783] _elementtree.c warnings under 64-bit Windows
New submission from Antoine Pitrou pit...@free.fr: 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 -- components: Extension Modules, Windows messages: 115700 nosy: effbot, flox, pitrou priority: normal severity: normal stage: needs patch status: open title: _elementtree.c warnings under 64-bit Windows type: compile error versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9783 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com