Index: Modules/_struct.c =================================================================== --- Modules/_struct.c (revision 72551) +++ Modules/_struct.c (working copy) @@ -314,6 +314,9 @@ return res; } #endif + v = get_pylong(v); + if (v == NULL) + return -1; wrapped = PyNumber_And(v, pylong_ulong_mask); if (wrapped == NULL) return -1; Index: Lib/test/test_struct.py =================================================================== --- Lib/test/test_struct.py (revision 72551) +++ Lib/test/test_struct.py (working copy) @@ -101,6 +101,8 @@ self.assertRaises(struct.error, struct.pack, 'i', 3, 3, 3) self.assertRaises(struct.error, struct.pack, 'i', 'foo') self.assertRaises(struct.error, struct.pack, 'P', 'foo') + self.assertRaises(struct.error, struct.pack, 'I', 'foobar') + self.assertRaises(struct.error, struct.pack, 'L', 'foobar') self.assertRaises(struct.error, struct.unpack, 'd', 'flap') s = struct.pack('ii', 1, 2) self.assertRaises(struct.error, struct.unpack, 'iii', s)