Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11699/win32/src
Modified Files:
PyWinTypes.h PyWinTypesmodule.cpp win32apimodule.cpp
win32file.i
Log Message:
Move PyWinObject_AsReadBuffer into Pywintypes
Fix some 's#' 64-bit issues in win32api
Fix memory leak in GetShortPathName
Index: win32apimodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v
retrieving revision 1.74
retrieving revision 1.75
diff -C2 -d -r1.74 -r1.75
*** win32apimodule.cpp 6 Mar 2007 19:42:34 -0000 1.74
--- win32apimodule.cpp 27 May 2007 17:32:14 -0000 1.75
***************
*** 1330,1339 ****
{
char *key;
- int len;
// @pyparm chr|char||Specifies a character
! if (!PyArg_ParseTuple(args, "s#:VkKeyScan", &key, &len))
return (NULL);
- if (len != 1)
- return PyErr_Format(PyExc_ValueError, "arg must be a string of length 1");
int ret;
PyW32_BEGIN_ALLOW_THREADS
--- 1330,1336 ----
{
char *key;
// @pyparm chr|char||Specifies a character
! if (!PyArg_ParseTuple(args, "c:VkKeyScan", &key))
return (NULL);
int ret;
PyW32_BEGIN_ALLOW_THREADS
***************
*** 1403,1407 ****
return ReturnAPIError("GetLogicalDriveStrings");
} else {
! PyObject * retval = Py_BuildValue ("s#", buffer, result);
delete [] buffer;
return (retval);
--- 1400,1404 ----
return ReturnAPIError("GetLogicalDriveStrings");
} else {
! PyObject * retval = PyString_FromStringAndSize (buffer, result);
delete [] buffer;
return (retval);
***************
*** 1797,1804 ****
char *szSection;
char *data;
- int dataSize;
// @pyparm string|section||The section in the INI file to retrieve a entries for.
// @pyparm string|data||The data to write. This must be string, with each entry terminated with '\0', followed by another terminating '\0'
! if (!PyArg_ParseTuple(args, "ss#:WriteProfileSection", &szSection, &data, &dataSize))
return NULL;
PyW32_BEGIN_ALLOW_THREADS
--- 1794,1800 ----
char *szSection;
char *data;
// @pyparm string|section||The section in the INI file to retrieve a entries for.
// @pyparm string|data||The data to write. This must be string, with each entry terminated with '\0', followed by another terminating '\0'
! if (!PyArg_ParseTuple(args, "ss:WriteProfileSection", &szSection, &data))
return NULL;
PyW32_BEGIN_ALLOW_THREADS
***************
*** 1806,1810 ****
PyW32_END_ALLOW_THREADS
if (!ok)
! return ReturnAPIError("GetTempPath");
Py_INCREF(Py_None);
return Py_None;
--- 1802,1806 ----
PyW32_END_ALLOW_THREADS
if (!ok)
! return ReturnAPIError("WriteProfileSection");
Py_INCREF(Py_None);
return Py_None;
***************
*** 1872,1875 ****
--- 1868,1872 ----
DWORD rc = GetShortPathName(path, szOutPath, sizeof(szOutPath));
PyW32_END_ALLOW_THREADS
+ PyWinObject_FreeString(path);
if (rc==0)
return ReturnAPIError("GetShortPathName");
***************
*** 1886,1889 ****
--- 1883,1887 ----
DWORD rc = GetShortPathNameW(path, szOutPath, sizeof(szOutPath));
PyW32_END_ALLOW_THREADS
+ PyWinObject_FreeWCHAR(path);
if (rc==0)
return ReturnAPIError("GetShortPathNameW");
***************
*** 3207,3211 ****
obData = Py_None;
} else
! obData = Py_BuildValue("s#", (char *)retDataBuf, retDataSize);
break;
}
--- 3205,3209 ----
obData = Py_None;
} else
! obData = PyString_FromStringAndSize((char *)retDataBuf, retDataSize);
break;
}
***************
*** 4738,4741 ****
--- 4736,4740 ----
PyObject *obName;
PyObject *ret=NULL;
+ PyObject *obData;
LPVOID lpData;
DWORD cbData;
***************
*** 4743,4752 ****
LPWSTR lpType=NULL,lpName=NULL;
! if ( !PyArg_ParseTuple(args, "OOOs#|H:UpdateResource",
&obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle.
&obType, // @pyparm <o PyResourceId>|type||The type of resource to update
&obName, // @pyparm <o PyResourceId>|name||The id/name of the resource to update
! &lpData, // @pyparm string|data||The data to place into the resource.
! &cbData,
&wLanguage // @pyparm int|language|NEUTRAL|Language to use, defaults to LANG_NEUTRAL.
) )
--- 4742,4750 ----
LPWSTR lpType=NULL,lpName=NULL;
! if ( !PyArg_ParseTuple(args, "OOOO|H:UpdateResource",
&obhUpdate, // @pyparm <o PyHANDLE>|handle||The update-file handle.
&obType, // @pyparm <o PyResourceId>|type||The type of resource to update
&obName, // @pyparm <o PyResourceId>|name||The id/name of the resource to update
! &obData, // @pyparm string|data||The data to place into the resource.
&wLanguage // @pyparm int|language|NEUTRAL|Language to use, defaults to LANG_NEUTRAL.
) )
***************
*** 4755,4759 ****
if (PyWinObject_AsHANDLE(obhUpdate, (HANDLE *)&hUpdate, FALSE)
&&PyWinObject_AsResourceIdW(obType, &lpType)
! &&PyWinObject_AsResourceIdW(obName, &lpName)){
if (UpdateResourceW(hUpdate, lpType, lpName, wLanguage, lpData, cbData)){
Py_INCREF(Py_None);
--- 4753,4758 ----
if (PyWinObject_AsHANDLE(obhUpdate, (HANDLE *)&hUpdate, FALSE)
&&PyWinObject_AsResourceIdW(obType, &lpType)
! &&PyWinObject_AsResourceIdW(obName, &lpName)
! &&PyWinObject_AsReadBuffer(obData, &lpData, &cbData, FALSE)){
if (UpdateResourceW(hUpdate, lpType, lpName, wLanguage, lpData, cbData)){
Py_INCREF(Py_None);
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** PyWinTypesmodule.cpp 7 May 2007 03:41:21 -0000 1.28
--- PyWinTypesmodule.cpp 27 May 2007 17:32:14 -0000 1.29
***************
*** 669,672 ****
--- 669,725 ----
}
+ // Buffer conversion functions that use DWORD for length
+ BOOL PyWinObject_AsReadBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk)
+ {
+ if (ob==Py_None){
+ if (bNoneOk){
+ *buf_len=0;
+ *buf=NULL;
+ return TRUE;
+ }
+ PyErr_SetString(PyExc_TypeError, "Buffer cannot be None");
+ return FALSE;
+ }
+ Py_ssize_t py_len;
+ if (PyObject_AsReadBuffer(ob, (const void **)buf, &py_len)==-1)
+ return FALSE;
+
+ #ifdef _WIN64
+ if (py_len>MAXDWORD){
+ PyErr_Format(PyExc_ValueError,"Buffer length can be at most %d characters", MAXDWORD);
+ return FALSE;
+ }
+ #endif
+
+ *buf_len=(DWORD)py_len;
+ return TRUE;
+ }
+
+ BOOL PyWinObject_AsWriteBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk)
+ {
+ if (ob==Py_None){
+ if (bNoneOk){
+ *buf_len=0;
+ *buf=NULL;
+ return TRUE;
+ }
+ PyErr_SetString(PyExc_TypeError, "Buffer cannot be None");
+ return FALSE;
+ }
+ Py_ssize_t py_len;
+ if (PyObject_AsWriteBuffer(ob, buf, &py_len)==-1)
+ return FALSE;
+
+ #ifdef _WIN64
+ if (py_len>MAXDWORD){
+ PyErr_Format(PyExc_ValueError,"Buffer length can be at most %d characters", MAXDWORD);
+ return FALSE;
+ }
+ #endif
+
+ *buf_len=(DWORD)py_len;
+ return TRUE;
+ }
+
/* List of functions exported by this module */
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** PyWinTypes.h 24 May 2007 06:54:50 -0000 1.40
--- PyWinTypes.h 27 May 2007 17:32:14 -0000 1.41
***************
*** 155,158 ****
--- 155,159 ----
#endif // NO_PYWINTYPES_BSTR
+
// Given a string or Unicode object, get WCHAR characters.
PYWINTYPES_EXPORT BOOL PyWinObject_AsWCHAR(PyObject *stringObject, WCHAR **pResult, BOOL bNoneOK = FALSE, DWORD *pResultLen = NULL);
***************
*** 174,178 ****
#endif
-
// Given a PyObject (string, Unicode, etc) create a "char *" with the value
// if pResultLen != NULL, it will be set to the result size NOT INCLUDING
--- 175,178 ----
***************
*** 183,186 ****
--- 183,191 ----
PYWINTYPES_EXPORT void PyWinObject_FreeString(WCHAR *pResult);
+ // Buffer functions that can be used in place of 's#' input format or PyString_AsStringAndSize
+ // for 64-bit compatibility and API consistency
+ PYWINTYPES_EXPORT BOOL PyWinObject_AsReadBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk=FALSE);
+ PYWINTYPES_EXPORT BOOL PyWinObject_AsWriteBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk=FALSE);
+
/* ANSI/Unicode Support */
/* If UNICODE defined, will be a BSTR - otherwise a char *
Index: win32file.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v
retrieving revision 1.81
retrieving revision 1.82
diff -C2 -d -r1.81 -r1.82
*** win32file.i 26 May 2007 15:45:38 -0000 1.81
--- win32file.i 27 May 2007 17:32:14 -0000 1.82
***************
*** 26,84 ****
%include "pywin32.i"
- %{
- // Helper functions that use DWORD for length
- BOOL PyWinObject_AsReadBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk=FALSE)
- {
- if (ob==Py_None){
- if (bNoneOk){
- *buf_len=0;
- *buf=NULL;
- return TRUE;
- }
- PyErr_SetString(PyExc_TypeError, "Buffer cannot be None");
- return FALSE;
- }
- Py_ssize_t py_len;
- if (PyObject_AsReadBuffer(ob, (const void **)buf, &py_len)==-1)
- return FALSE;
-
- #ifdef _WIN64
- if (py_len>MAXDWORD){
- PyErr_Format(PyExc_ValueError,"Buffer length can be at most %d characters", MAXDWORD);
- return FALSE;
- }
- #endif
-
- *buf_len=(DWORD)py_len;
- return TRUE;
- }
-
- BOOL PyWinObject_AsWriteBuffer(PyObject *ob, void **buf, DWORD *buf_len, BOOL bNoneOk=FALSE)
- {
- if (ob==Py_None){
- if (bNoneOk){
- *buf_len=0;
- *buf=NULL;
- return TRUE;
- }
- PyErr_SetString(PyExc_TypeError, "Buffer cannot be None");
- return FALSE;
- }
- Py_ssize_t py_len;
- if (PyObject_AsWriteBuffer(ob, buf, &py_len)==-1)
- return FALSE;
-
- #ifdef _WIN64
- if (py_len>MAXDWORD){
- PyErr_Format(PyExc_ValueError,"Buffer length can be at most %d characters", MAXDWORD);
- return FALSE;
- }
- #endif
-
- *buf_len=(DWORD)py_len;
- return TRUE;
- }
- %}
-
#define FILE_GENERIC_READ FILE_GENERIC_READ
#define FILE_GENERIC_WRITE FILE_GENERIC_WRITE
--- 26,29 ----
***************
*** 1487,1491 ****
else{
PyErr_Clear();
! if (!PyWinObject_AsReadBuffer(obBuffer, &buf, &bufSize, FALSE)){
PyErr_SetString(PyExc_TypeError, "buffer param must be an integer or a buffer object");
goto done;
--- 1432,1436 ----
else{
PyErr_Clear();
! if (!PyWinObject_AsWriteBuffer(obBuffer, &buf, &bufSize, FALSE)){
PyErr_SetString(PyExc_TypeError, "buffer param must be an integer or a buffer object");
goto done;
***************
*** 3567,3572 ****
HANDLE h;
BYTE *buf;
! Py_ssize_t buflen;
! DWORD bytes_requested, bytes_read;
BOOL bAbort,bProcessSecurity;
LPVOID ctxt;
--- 3512,3516 ----
HANDLE h;
BYTE *buf;
! DWORD buflen, bytes_requested, bytes_read;
BOOL bAbort,bProcessSecurity;
LPVOID ctxt;
***************
*** 3583,3587 ****
if (obbufout==NULL)
return NULL;
! if (PyObject_AsWriteBuffer(obbufout, (void **)&buf, &buflen)==-1){
Py_DECREF(obbufout);
return NULL;
--- 3527,3531 ----
if (obbufout==NULL)
return NULL;
! if (!PyWinObject_AsWriteBuffer(obbufout, (void **)&buf, &buflen)){
Py_DECREF(obbufout);
return NULL;
***************
*** 3590,3596 ****
else{
obbufout=obbuf;
! if (PyObject_AsWriteBuffer(obbufout, (void **)&buf, &buflen)==-1)
return NULL;
! if ((DWORD)buflen < bytes_requested)
return PyErr_Format(PyExc_ValueError,"Buffer size (%d) less than requested read size (%d)", buflen, bytes_requested);
Py_INCREF(obbufout);
--- 3534,3540 ----
else{
obbufout=obbuf;
! if (!PyWinObject_AsWriteBuffer(obbufout, (void **)&buf, &buflen))
return NULL;
! if (buflen < bytes_requested)
return PyErr_Format(PyExc_ValueError,"Buffer size (%d) less than requested read size (%d)", buflen, bytes_requested);
Py_INCREF(obbufout);
|