Commit 9a928e78 authored by Georg Brandl's avatar Georg Brandl

Patch #977553: speed up RegEnumKey call

parent 093ab1aa
...@@ -1033,30 +1033,23 @@ PyEnumKey(PyObject *self, PyObject *args) ...@@ -1033,30 +1033,23 @@ PyEnumKey(PyObject *self, PyObject *args)
long rc; long rc;
PyObject *retStr; PyObject *retStr;
char *retBuf; char *retBuf;
DWORD len; DWORD len = 256; /* includes NULL terminator */
char tmpbuf[256]; /* max key name length is 255 */
if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index)) if (!PyArg_ParseTuple(args, "Oi:EnumKey", &obKey, &index))
return NULL; return NULL;
if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE)) if (!PyHKEY_AsHKEY(obKey, &hKey, FALSE))
return NULL; return NULL;
if ((rc = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, &len, Py_BEGIN_ALLOW_THREADS
NULL, NULL, NULL, NULL, NULL, NULL)) rc = RegEnumKeyEx(hKey, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
!= ERROR_SUCCESS) Py_END_ALLOW_THREADS
return PyErr_SetFromWindowsErrWithFunction(rc, if (rc != ERROR_SUCCESS)
"RegQueryInfoKey"); return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
++len; /* include null terminator */
retStr = PyString_FromStringAndSize(NULL, len);
if (retStr == NULL)
return NULL;
retBuf = PyString_AS_STRING(retStr);
if ((rc = RegEnumKey(hKey, index, retBuf, len)) != ERROR_SUCCESS) { ++len; /* include null terminator */
Py_DECREF(retStr); retStr = PyString_FromStringAndSize(tmpbuf, len);
return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKey"); return retStr; /* can be NULL */
}
_PyString_Resize(&retStr, strlen(retBuf));
return retStr;
} }
static PyObject * static PyObject *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment