New submission from David Edelsohn:

Another endianness bug that causes a failure in test_structmembers.py.

_testcapi reports "string too long" because 
getargs.c:PyArg_ParseTupleAndKeywords() incorrectly returns a huge value for 
string_len.

The problem is FETCH_ARGS is passing the wrong type to va_arg.  It grabs an 
"int" for the size arg, but that is the not the argument type on 64 bit 
platforms.  This happens to work for little endian because the low part of the 
64 bit argument overlaps correctly.  Big endian is not as fortuitous.

If I change "int" to "long", the testcase succeeds.

diff -r a285ce18bd55 Python/getargs.c
--- a/Python/getargs.c  Mon May 06 18:21:10 2013 -0700
+++ b/Python/getargs.c  Tue May 07 11:26:21 2013 -0700
@@ -582,9 +582,9 @@
               char *msgbuf, size_t bufsize, PyObject **freelist)
 {
     /* For # codes */
-#define FETCH_SIZE      int *q=NULL;Py_ssize_t *q2=NULL;\
+#define FETCH_SIZE      long *q=NULL;Py_ssize_t *q2=NULL;\
     if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
-    else q=va_arg(*p_va, int*);
+    else q=va_arg(*p_va, long*);
 #define STORE_SIZE(s)   \
     if (flags & FLAG_SIZE_T) \
         *q2=s; \

I am not certain exactly what type it should be, but it definitely needs to be 
a matching 64 bit type of 64 bit platforms.

I believe that this bug exists in all versions.

----------
components: Interpreter Core
messages: 188677
nosy: David.Edelsohn, pitrou
priority: normal
severity: normal
status: open
title: PowerLinux getargs.c FETCH_SIZE endianness bug
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17928>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to