[Python-checkins] CVS: python/dist/src/Modules structmodule.c,2.48,2.49
Tim Peters
tim_one@users.sourceforge.net
Wed, 18 Jul 2001 13:47:33 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv10973/python/dist/src/Modules
Modified Files:
structmodule.c
Log Message:
SF bug #442520: test_struct fails on SPARC.
The ob_sval member of a string object isn't necessarily aligned to better
than a native long, so the new "q" and "Q" struct codes can't get away w/
casting tricks on platforms where LONG_LONG requires stricter-than-long
alignment. After I thought of a few elaborate workarounds, Guido bashed
me over the head with the obvious memcpy approach, herewith implemented.
Index: structmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/structmodule.c,v
retrieving revision 2.48
retrieving revision 2.49
diff -C2 -r2.48 -r2.49
*** structmodule.c 2001/06/13 01:26:35 2.48
--- structmodule.c 2001/07/18 20:47:31 2.49
***************
*** 548,552 ****
nu_longlong(const char *p, const formatdef *f)
{
! return PyLong_FromLongLong(*(LONG_LONG *)p);
}
--- 548,555 ----
nu_longlong(const char *p, const formatdef *f)
{
! /* p may not be properly aligned */
! LONG_LONG x;
! memcpy(&x, p, sizeof(LONG_LONG));
! return PyLong_FromLongLong(x);
}
***************
*** 554,558 ****
nu_ulonglong(const char *p, const formatdef *f)
{
! return PyLong_FromUnsignedLongLong(*(unsigned LONG_LONG *)p);
}
#endif
--- 557,564 ----
nu_ulonglong(const char *p, const formatdef *f)
{
! /* p may not be properly aligned */
! unsigned LONG_LONG x;
! memcpy(&x, p, sizeof(unsigned LONG_LONG));
! return PyLong_FromUnsignedLongLong(x);
}
#endif
***************
*** 701,705 ****
if (get_longlong(v, &x) < 0)
return -1;
! * (LONG_LONG *)p = x;
return 0;
}
--- 707,711 ----
if (get_longlong(v, &x) < 0)
return -1;
! memcpy(p, &x, sizeof(LONG_LONG));
return 0;
}
***************
*** 711,715 ****
if (get_ulonglong(v, &x) < 0)
return -1;
! * (unsigned LONG_LONG *)p = x;
return 0;
}
--- 717,721 ----
if (get_ulonglong(v, &x) < 0)
return -1;
! memcpy(p, &x, sizeof(unsigned LONG_LONG));
return 0;
}