*pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
if (PyErr_Occurred())
return FALSE;
- *pHANDLE = (HKEY)PyInt_AsLong(ob);
}
else {
PyErr_SetString(
if (PyHKEY_Check(obHandle)) {
ok = PyHKEY_Close(obHandle);
}
+#if SIZEOF_LONG >= SIZEOF_HKEY
else if (PyInt_Check(obHandle)) {
long rc = RegCloseKey((HKEY)PyInt_AsLong(obHandle));
ok = (rc == ERROR_SUCCESS);
if (!ok)
PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
}
+#else
+ else if (PyLong_Check(obHandle)) {
+ long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
+ ok = (rc == ERROR_SUCCESS);
+ if (!ok)
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
+ }
+#endif
else {
PyErr_SetString(
PyExc_TypeError,
fixupMultiSZ(str, retDataBuf, retDataSize);
obData = PyList_New(s);
+ if (obData == NULL)
+ return NULL;
for (index = 0; index < s; index++)
{
+ size_t len = _mbstrlen(str[index]);
+ if (len > INT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "registry string is too long for a Python string");
+ Py_DECREF(obData);
+ return NULL;
+ }
PyList_SetItem(obData,
index,
PyUnicode_DecodeMBCS(
(const char *)str[index],
- _mbstrlen(str[index]),
+ (int)len,
NULL)
);
}
static PyObject *msvcrt_get_osfhandle(PyObject *self, PyObject *args)
{
int fd;
- long handle;
+ intptr_t handle;
if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd))
return NULL;
if (handle == -1)
return PyErr_SetFromErrno(PyExc_IOError);
- return PyInt_FromLong(handle);
+ /* technically 'handle' is not a pointer, but a integer as
+ large as a pointer, Python's *VoidPtr interface is the
+ most appropriate here */
+ return PyLong_FromVoidPtr((void*)handle);
}
/* Console I/O */