[pywin32-checkins] pywin32/win32/src win32inet.i,1.11,1.12
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-02-15 23:51:27
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9937/src Modified Files: win32inet.i Log Message: fix InternetGetCookie failures when UNICODE is defined on win2k Index: win32inet.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32inet.i,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** win32inet.i 8 Dec 2008 13:14:24 -0000 1.11 --- win32inet.i 15 Feb 2009 23:51:20 -0000 1.12 *************** *** 371,375 **** PyObject *ret = NULL; BOOL ok = FALSE; ! DWORD cb = 0; TCHAR *buf=NULL, *szUrl = NULL, *szCookieName = NULL; if (!PyArg_ParseTuple(args, "OO:InternetGetCookie", --- 371,375 ---- PyObject *ret = NULL; BOOL ok = FALSE; ! DWORD cch, cchallocated = 0; TCHAR *buf=NULL, *szUrl = NULL, *szCookieName = NULL; if (!PyArg_ParseTuple(args, "OO:InternetGetCookie", *************** *** 381,404 **** if (!PyWinObject_AsTCHAR(obCookieName, &szCookieName, TRUE)) goto done; ! InternetGetCookie(szUrl, szCookieName, NULL, &cb); ! if (!cb) { // assume this means some other failure. PyWin_SetAPIError("InternetGetCookie"); goto done; } ! // cb includes the NULL - Python adds one for the null. ! buf = (TCHAR *)malloc(cb * sizeof(TCHAR)); if (buf==NULL){ PyErr_NoMemory(); goto done; } Py_BEGIN_ALLOW_THREADS ! ok = InternetGetCookie(szUrl, szCookieName, buf, &cb); Py_END_ALLOW_THREADS if (!ok) PyWin_SetAPIError("InternetGetCookie"); ! else ! ret=PyWinObject_FromTCHAR(buf, cb-1); done: ! if (buf) free(buf); if (szUrl) PyWinObject_FreeTCHAR(szUrl); if (szCookieName) PyWinObject_FreeTCHAR(szCookieName); --- 381,421 ---- if (!PyWinObject_AsTCHAR(obCookieName, &szCookieName, TRUE)) goto done; ! InternetGetCookie(szUrl, szCookieName, NULL, &cchallocated); ! if (!cchallocated) { // assume this means some other failure. PyWin_SetAPIError("InternetGetCookie"); goto done; } ! // Note: the docs for InternetGetCookie appear to lie: when NULL is passed ! // you get back the number of *bytes* needed, not TCHARs - however, if ! // NULL is not passed, you do get TCHARs back. In other words, if UNICODE ! // is defined, 'cchallocated' is double the value we get back for 'cch' in ! // our next call which actually gets the data. However - we don't rely on ! // this behaviour - it just means we actually end up allocating double the ! // buffer we need. ! // The number of chars theoretically includes the \0 - but see below. ! buf = (TCHAR *)malloc(cchallocated * sizeof(TCHAR)); if (buf==NULL){ PyErr_NoMemory(); goto done; } + cch = cchallocated; Py_BEGIN_ALLOW_THREADS ! ok = InternetGetCookie(szUrl, szCookieName, buf, &cch); Py_END_ALLOW_THREADS if (!ok) PyWin_SetAPIError("InternetGetCookie"); ! else { ! // Note that on win2k only, and only when UNICODE is defined, we ! // see 'cch' be one less than we expect - ie, it is the number of ! // chars *not* including the NULL. ! #ifdef UNICODE ! if (LOBYTE(LOWORD(GetVersion())) <= 5 && cch && cch < cchallocated && ! buf[cch-1] != _T('\0')) ! cch += 1; ! #endif ! ret=PyWinObject_FromTCHAR(buf, cch-1); ! } done: ! if (buf) free(buf); if (szUrl) PyWinObject_FreeTCHAR(szUrl); if (szCookieName) PyWinObject_FreeTCHAR(szCookieName); |