[pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.37,1.38
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2004-07-13 07:12:54
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10159/src Modified Files: win32apimodule.cpp Log Message: [ 945636 ] GetLongPathNameW without MAX_PATH limitation (but with the addition of tests, and avoiding double-handling the large Unicode buffer) Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** win32apimodule.cpp 12 Jun 2004 07:45:54 -0000 1.37 --- win32apimodule.cpp 13 Jul 2004 07:12:45 -0000 1.38 *************** *** 1605,1608 **** --- 1605,1609 ---- WCHAR pathBuf[MAX_PATH]; WCHAR *fileName; + PyObject *obLongPathNameW = NULL; if (!myGetLongPathNameW) PyErr_SetString(PyExc_NotImplementedError, "GetLongPathNameW does not exist in this version of Windows"); *************** *** 1614,1628 **** return NULL; PyW32_BEGIN_ALLOW_THREADS ! BOOL ok = (*myGetLongPathNameW)(fileName, pathBuf, sizeof(pathBuf)/sizeof(pathBuf[0])); PyW32_END_ALLOW_THREADS PyWinObject_FreeWCHAR(fileName); ! if (!ok) ! return ReturnAPIError("GetLongPathName"); ! return PyWinObject_FromWCHAR(pathBuf); // @comm This function may raise a NotImplementedError exception if the version // of Windows does not support this function. } - // @pymethod string|win32api|GetTickCount|Returns the number of milliseconds since windows started. static PyObject * --- 1615,1657 ---- return NULL; PyW32_BEGIN_ALLOW_THREADS ! DWORD length = (*myGetLongPathNameW)(fileName, pathBuf, sizeof(pathBuf)/sizeof(pathBuf[0])); PyW32_END_ALLOW_THREADS + if (length) + { + if (length < sizeof(pathBuf)/sizeof(pathBuf[0])) + obLongPathNameW = PyWinObject_FromWCHAR(pathBuf); + else + { + // retry with a buffer that is big enough. Now we know the + // size and that it is big, avoid double-handling. + Py_UNICODE *buf; + // The length is the buffer needed, which includes the NULL. + // PyUnicode_FromUnicode adds one. + obLongPathNameW = PyUnicode_FromUnicode(NULL, length-1); + if (!obLongPathNameW) { + PyWinObject_FreeWCHAR(fileName); + return NULL; + } + buf = PyUnicode_AS_UNICODE(obLongPathNameW); + PyW32_BEGIN_ALLOW_THREADS + DWORD length2 = (*myGetLongPathNameW)(fileName, buf, length); + PyW32_END_ALLOW_THREADS + if (length2==0) { + Py_DECREF(obLongPathNameW); + obLongPathNameW = NULL; + } + // On success, it is the number of chars copied *not* including + // the NULL. Check this is true. + assert(length2+1==length); + } + } PyWinObject_FreeWCHAR(fileName); ! if(!obLongPathNameW) ! return ReturnAPIError("GetLongPathNameW"); ! return obLongPathNameW; // @comm This function may raise a NotImplementedError exception if the version // of Windows does not support this function. } // @pymethod string|win32api|GetTickCount|Returns the number of milliseconds since windows started. static PyObject * |