summaryrefslogtreecommitdiff
path: root/PC/winreg.c
diff options
context:
space:
mode:
Diffstat (limited to 'PC/winreg.c')
-rw-r--r--PC/winreg.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/PC/winreg.c b/PC/winreg.c
index f08d9a47ff..5efdc5e0ef 100644
--- a/PC/winreg.c
+++ b/PC/winreg.c
@@ -549,7 +549,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
if (value != Py_None && !PyLong_Check(value))
return FALSE;
*retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
- if (*retDataBuf==NULL){
+ if (*retDataBuf == NULL){
PyErr_NoMemory();
return FALSE;
}
@@ -563,6 +563,24 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
memcpy(*retDataBuf, &d, sizeof(DWORD));
}
break;
+ case REG_QWORD:
+ if (value != Py_None && !PyLong_Check(value))
+ return FALSE;
+ *retDataBuf = (BYTE *)PyMem_NEW(DWORD64, 1);
+ if (*retDataBuf == NULL){
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ *retDataSize = sizeof(DWORD64);
+ if (value == Py_None) {
+ DWORD64 zero = 0;
+ memcpy(*retDataBuf, &zero, sizeof(DWORD64));
+ }
+ else {
+ DWORD64 d = PyLong_AsUnsignedLongLong(value);
+ memcpy(*retDataBuf, &d, sizeof(DWORD64));
+ }
+ break;
case REG_SZ:
case REG_EXPAND_SZ:
{
@@ -619,7 +637,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
*retDataSize = size + 2;
*retDataBuf = (BYTE *)PyMem_NEW(char,
*retDataSize);
- if (*retDataBuf==NULL){
+ if (*retDataBuf == NULL){
PyErr_NoMemory();
return FALSE;
}
@@ -665,7 +683,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
return FALSE;
*retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
- if (*retDataBuf==NULL){
+ if (*retDataBuf == NULL){
PyBuffer_Release(&view);
PyErr_NoMemory();
return FALSE;
@@ -690,19 +708,24 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
if (retDataSize == 0)
obData = PyLong_FromUnsignedLong(0);
else
- obData = PyLong_FromUnsignedLong(*(int *)retDataBuf);
+ obData = PyLong_FromUnsignedLong(*(DWORD *)retDataBuf);
+ break;
+ case REG_QWORD:
+ if (retDataSize == 0)
+ obData = PyLong_FromUnsignedLongLong(0);
+ else
+ obData = PyLong_FromUnsignedLongLong(*(DWORD64 *)retDataBuf);
break;
case REG_SZ:
case REG_EXPAND_SZ:
{
- /* the buffer may or may not have a trailing NULL */
+ /* REG_SZ should be a NUL terminated string, but only by
+ * convention. The buffer may have been saved without a NUL
+ * or with embedded NULs. To be consistent with reg.exe and
+ * regedit.exe, consume only up to the first NUL. */
wchar_t *data = (wchar_t *)retDataBuf;
- int len = retDataSize / 2;
- if (retDataSize && data[len-1] == '\0')
- retDataSize -= 2;
- if (retDataSize <= 0)
- data = L"";
- obData = PyUnicode_FromWideChar(data, retDataSize/2);
+ size_t len = wcsnlen(data, retDataSize / sizeof(wchar_t));
+ obData = PyUnicode_FromWideChar(data, len);
break;
}
case REG_MULTI_SZ:
@@ -1599,7 +1622,7 @@ winreg.SetValueEx
An integer that specifies the type of the data, one of:
REG_BINARY -- Binary data in any form.
REG_DWORD -- A 32-bit number.
- REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format.
+ REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD
REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.
REG_EXPAND_SZ -- A null-terminated string that contains unexpanded
references to environment variables (for example,
@@ -1609,6 +1632,8 @@ winreg.SetValueEx
by two null characters. Note that Python handles
this termination automatically.
REG_NONE -- No defined value type.
+ REG_QWORD -- A 64-bit number.
+ REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.
REG_RESOURCE_LIST -- A device-driver resource list.
REG_SZ -- A null-terminated string.
value: object
@@ -1631,7 +1656,7 @@ the configuration registry to help the registry perform efficiently.
static PyObject *
winreg_SetValueEx_impl(PyObject *module, HKEY key, Py_UNICODE *value_name,
PyObject *reserved, DWORD type, PyObject *value)
-/*[clinic end generated code: output=c88c8426b6c00ec7 input=f1b16cbcc3ed4101]*/
+/*[clinic end generated code: output=c88c8426b6c00ec7 input=900a9e3990bfb196]*/
{
BYTE *data;
DWORD len;
@@ -1918,6 +1943,8 @@ PyMODINIT_FUNC PyInit_winreg(void)
ADD_INT(REG_DWORD);
ADD_INT(REG_DWORD_LITTLE_ENDIAN);
ADD_INT(REG_DWORD_BIG_ENDIAN);
+ ADD_INT(REG_QWORD);
+ ADD_INT(REG_QWORD_LITTLE_ENDIAN);
ADD_INT(REG_LINK);
ADD_INT(REG_MULTI_SZ);
ADD_INT(REG_RESOURCE_LIST);