cpython: b9752b6c40f8 (original) (raw)
Mercurial > cpython
changeset 81083:b9752b6c40f8 3.2
Fix #14420. Use PyLong_AsUnsignedLong to support the full range of DWORD. This fixes an OverflowError seen in winreg.SetValueEx when passed winreg.REG_DWORD values that should be supported by the underlying API. [#14420]
Brian Curtin brian@python.org | |
---|---|
date | Thu, 27 Dec 2012 10:12:45 -0600 |
parents | 62f67a52b0c2 |
children | 94a76b49dc69 cd2b4074a2d9 4b7e60e05027 |
files | Lib/test/test_winreg.py Misc/NEWS PC/winreg.c |
diffstat | 3 files changed, 16 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_winreg.py 12 Misc/NEWS 3 PC/winreg.c 2 |
line wrap: on
line diff
--- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -323,6 +323,18 @@ class LocalWinregTests(BaseWinregTests): finally: DeleteKey(HKEY_CURRENT_USER, test_key_name)
- def test_setvalueex_value_range(self):
# Test for Issue #14420, accept proper ranges for SetValueEx.[](#l1.8)
# Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong,[](#l1.9)
# thus raising OverflowError. The implementation now uses[](#l1.10)
# PyLong_AsUnsignedLong to match DWORD's size.[](#l1.11)
try:[](#l1.12)
with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:[](#l1.13)
self.assertNotEqual(ck.handle, 0)[](#l1.14)
SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000)[](#l1.15)
finally:[](#l1.16)
DeleteKey(HKEY_CURRENT_USER, test_key_name)[](#l1.17)
+ @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.4 Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg
- Issue #16602: When a weakref's target was part of a long deallocation chain, the object could remain reachable through its weakref even though its refcount had dropped to zero.
--- a/PC/winreg.c +++ b/PC/winreg.c @@ -785,7 +785,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE memcpy(*retDataBuf, &zero, sizeof(DWORD)); } else {
DWORD d = PyLong_AsLong(value);[](#l3.7)
DWORD d = PyLong_AsUnsignedLong(value);[](#l3.8) memcpy(*retDataBuf, &d, sizeof(DWORD));[](#l3.9) }[](#l3.10) break;[](#l3.11)