(original) (raw)
changeset: 81083:b9752b6c40f8 branch: 3.2 parent: 81079:62f67a52b0c2 user: Brian Curtin brian@python.org date: Thu Dec 27 10:12:45 2012 -0600 files: Lib/test/test_winreg.py Misc/NEWS PC/winreg.c description: 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. diff -r 62f67a52b0c2 -r b9752b6c40f8 Lib/test/test_winreg.py --- a/Lib/test/test_winreg.py Thu Dec 27 10:10:11 2012 +0100 +++ b/Lib/test/test_winreg.py Thu Dec 27 10:12:45 2012 -0600 @@ -323,6 +323,18 @@ finally: DeleteKey(HKEY_CURRENT_USER, test_key_name) + def test_setvalueex_value_range(self): + # Test for Issue #14420, accept proper ranges for SetValueEx. + # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong, + # thus raising OverflowError. The implementation now uses + # PyLong_AsUnsignedLong to match DWORD's size. + try: + with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck: + self.assertNotEqual(ck.handle, 0) + SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000) + finally: + DeleteKey(HKEY_CURRENT_USER, test_key_name) + @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") class RemoteWinregTests(BaseWinregTests): diff -r 62f67a52b0c2 -r b9752b6c40f8 Misc/NEWS --- a/Misc/NEWS Thu Dec 27 10:10:11 2012 +0100 +++ b/Misc/NEWS Thu Dec 27 10:12:45 2012 -0600 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #14420: Support the full DWORD (unsigned long) range in Py2Reg + when passed a REG_DWORD value. Fixes OverflowError in winreg.SetValueEx. + - 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. diff -r 62f67a52b0c2 -r b9752b6c40f8 PC/winreg.c --- a/PC/winreg.c Thu Dec 27 10:10:11 2012 +0100 +++ b/PC/winreg.c Thu Dec 27 10:12:45 2012 -0600 @@ -785,7 +785,7 @@ memcpy(*retDataBuf, &zero, sizeof(DWORD)); } else { - DWORD d = PyLong_AsLong(value); + DWORD d = PyLong_AsUnsignedLong(value); memcpy(*retDataBuf, &d, sizeof(DWORD)); } break; /brian@python.org