summaryrefslogtreecommitdiffstats
path: root/Modules/structmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-07-18 20:47:31 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-07-18 20:47:31 (GMT)
commit3dac559299100c135fded9bb22536dbb1379a9bc (patch)
tree3a026da48e984aaf08e47be1bc3f93f625be6f0a /Modules/structmodule.c
parentcdab3bf7eb0810fcda21be065868f3da330779a1 (diff)
downloadcpython-3dac559299100c135fded9bb22536dbb1379a9bc.zip
cpython-3dac559299100c135fded9bb22536dbb1379a9bc.tar.gz
cpython-3dac559299100c135fded9bb22536dbb1379a9bc.tar.bz2
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.
Diffstat (limited to 'Modules/structmodule.c')
-rw-r--r--Modules/structmodule.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c
index 66b3ac3..46aa75b 100644
--- a/Modules/structmodule.c
+++ b/Modules/structmodule.c
@@ -547,13 +547,19 @@ nu_ulong(const char *p, const formatdef *f)
static PyObject *
nu_longlong(const char *p, const formatdef *f)
{
- return PyLong_FromLongLong(*(LONG_LONG *)p);
+ /* p may not be properly aligned */
+ LONG_LONG x;
+ memcpy(&x, p, sizeof(LONG_LONG));
+ return PyLong_FromLongLong(x);
}
static PyObject *
nu_ulonglong(const char *p, const formatdef *f)
{
- return PyLong_FromUnsignedLongLong(*(unsigned LONG_LONG *)p);
+ /* p may not be properly aligned */
+ unsigned LONG_LONG x;
+ memcpy(&x, p, sizeof(unsigned LONG_LONG));
+ return PyLong_FromUnsignedLongLong(x);
}
#endif
@@ -700,7 +706,7 @@ np_longlong(char *p, PyObject *v, const formatdef *f)
LONG_LONG x;
if (get_longlong(v, &x) < 0)
return -1;
- * (LONG_LONG *)p = x;
+ memcpy(p, &x, sizeof(LONG_LONG));
return 0;
}
@@ -710,7 +716,7 @@ np_ulonglong(char *p, PyObject *v, const formatdef *f)
unsigned LONG_LONG x;
if (get_ulonglong(v, &x) < 0)
return -1;
- * (unsigned LONG_LONG *)p = x;
+ memcpy(p, &x, sizeof(unsigned LONG_LONG));
return 0;
}
#endif