Update of /cvsroot/pywin32/pywin32/win32/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25507/win32/src
Modified Files:
PyIID.cpp PyUnicode.cpp PyWinTypes.h PyWinTypesmodule.cpp
win32process.i win32security.i
Log Message:
Lots of stuff from Roger's work on the py3k branch:
* Lots of string and 64bit enhancements, particularly
in pythonwin which only accepted plain string objects
in many cases. pywintypes and some of the other extension
code get cleanups in this area too.
* Consolidation of more structure conversions and other helpers
into pywintypes.
* Additional pythonwin tooltip notification fixes.
* Some '#if (PY_VERSION_HEX < 0x03000000)' blocks have been
incorporated, but in general, no py3k specific code has
been merged yet.
* Better error handling in pythonwin; less exceptions should be
left lingering, be overridden or simply ignored.
* Drop support for pythoncom.__future_currency__ - the
decimal module is now always used.
* A couple of very early interface implementations are upgraded to have
unicode passed instead of strings - if you *implement* (not use) any
of these interfaces, you may need to test to ensure you work when
args are passed as unicode objects instead of strings. Affected are
IErrorLog, IPropertyBag, ICatInformation and IStorage.
Index: win32process.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32process.i,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** win32process.i 24 May 2008 00:29:55 -0000 1.33
--- win32process.i 13 Nov 2008 04:04:51 -0000 1.34
***************
*** 154,159 ****
memcpy(&m_startupinfo, pSI, sizeof(m_startupinfo));
m_obStdIn = m_obStdOut = m_obStdErr = NULL;
! m_obDesktop = pSI->lpDesktop ? PyWinObject_FromTCHAR(pSI->lpDesktop) : NULL;
! m_obTitle = pSI->lpTitle ? PyWinObject_FromTCHAR(pSI->lpTitle) : NULL;
}
--- 154,161 ----
memcpy(&m_startupinfo, pSI, sizeof(m_startupinfo));
m_obStdIn = m_obStdOut = m_obStdErr = NULL;
! if (pSI->lpDesktop)
! m_startupinfo.lpDesktop = PyWin_CopyString(pSI->lpDesktop);
! if (pSI->lpTitle)
! m_startupinfo.lpTitle = PyWin_CopyString(pSI->lpTitle);
}
***************
*** 163,168 ****
Py_XDECREF(m_obStdOut);
Py_XDECREF(m_obStdErr);
! Py_XDECREF(m_obDesktop);
! Py_XDECREF(m_obTitle);
}
--- 165,170 ----
Py_XDECREF(m_obStdOut);
Py_XDECREF(m_obStdErr);
! PyWinObject_FreeTCHAR(m_startupinfo.lpDesktop);
! PyWinObject_FreeTCHAR(m_startupinfo.lpTitle);
}
***************
*** 499,503 ****
} else if (PyUnicode_Check(key)) {
bIsUnicode = TRUE;
! bufLen += PyUnicode_Size(key) + 1;
} else {
PyErr_SetString(PyExc_TypeError, "dictionary must have keys and values as strings or unicode objects.");
--- 501,505 ----
} else if (PyUnicode_Check(key)) {
bIsUnicode = TRUE;
! bufLen += PyUnicode_GET_SIZE(key) + 1;
} else {
PyErr_SetString(PyExc_TypeError, "dictionary must have keys and values as strings or unicode objects.");
***************
*** 510,514 ****
goto done;
}
! bufLen += PyUnicode_Size(key) + 1;
}
else {
--- 512,516 ----
goto done;
}
! bufLen += PyUnicode_GET_SIZE(key) + 1;
}
else {
***************
*** 526,530 ****
goto done;
}
! bufLen += PyUnicode_Size(val) + 2; // For the '=' and '\0'
}
else {
--- 528,532 ----
goto done;
}
! bufLen += PyUnicode_GET_SIZE(val) + 2; // For the '=' and '\0'
}
else {
Index: PyIID.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyIID.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PyIID.cpp 24 May 2007 06:01:05 -0000 1.8
--- PyIID.cpp 13 Nov 2008 04:04:51 -0000 1.9
***************
*** 11,15 ****
PyObject *PyWinMethod_NewIID(PyObject *self, PyObject *args)
{
! BSTR bstrIID;
PyObject *obIID;
IID iid;
--- 11,15 ----
PyObject *PyWinMethod_NewIID(PyObject *self, PyObject *args)
{
! WCHAR *bstrIID;
PyObject *obIID;
IID iid;
***************
*** 39,43 ****
return obIID;
}
! if (!PyWinObject_AsBstr(obIID, &bstrIID))
return NULL;
--- 39,43 ----
return obIID;
}
! if (!PyWinObject_AsWCHAR(obIID, &bstrIID))
return NULL;
***************
*** 50,54 ****
{
#endif
! PyWinObject_FreeBstr(bstrIID);
PyWin_SetBasicCOMError(hr);
return NULL;
--- 50,54 ----
{
#endif
! PyWinObject_FreeWCHAR(bstrIID);
PyWin_SetBasicCOMError(hr);
return NULL;
***************
*** 57,61 ****
#endif
}
! PyWinObject_FreeBstr(bstrIID);
/* iid -> PyObject */
return PyWinObject_FromIID(iid);
--- 57,61 ----
#endif
}
! PyWinObject_FreeWCHAR(bstrIID);
/* iid -> PyObject */
return PyWinObject_FromIID(iid);
***************
*** 104,108 ****
}
! PyObject *PyWinStringObject_FromIID(const IID &riid)
{
OLECHAR oleRes[128];
--- 104,108 ----
}
! PyObject *PyWinCoreString_FromIID(const IID &riid)
{
OLECHAR oleRes[128];
***************
*** 112,133 ****
return NULL;
}
! char *szResult;
! if (!PyWin_WCHAR_AsString(oleRes, (DWORD)-1, &szResult))
! return NULL;
! PyObject *rc = PyString_FromString(szResult);
! PyWinObject_FreeString(szResult);
! return rc;
}
- PyObject *PyWinUnicodeObject_FromIID(const IID &riid)
- {
- OLECHAR oleRes[128];
- if (StringFromGUID2(riid, oleRes, sizeof(oleRes))==0) {
- // Should never happen - 128 should be heaps big enough.
- PyErr_SetString(PyExc_ValueError, "The string is too long");
- return NULL;
- }
- return PyWinObject_FromOLECHAR(oleRes);
- }
static Py_ssize_t getreadbuf(PyObject *self, Py_ssize_t index, void **ptr)
--- 112,118 ----
return NULL;
}
! return PyWinCoreString_FromString(oleRes);
}
static Py_ssize_t getreadbuf(PyObject *self, Py_ssize_t index, void **ptr)
***************
*** 232,236 ****
PyObject *PyIID::str(void)
{
! return PyWinStringObject_FromIID(m_iid);
}
--- 217,221 ----
PyObject *PyIID::str(void)
{
! return PyWinCoreString_FromIID(m_iid);
}
***************
*** 239,245 ****
OLECHAR oleRes[128];
StringFromGUID2(m_iid, oleRes, sizeof(oleRes));
! TCHAR buf[128];
! wsprintf(buf, _T("IID('%ws')"), oleRes);
! return PyString_FromString(buf);
}
--- 224,230 ----
OLECHAR oleRes[128];
StringFromGUID2(m_iid, oleRes, sizeof(oleRes));
! WCHAR buf[128];
! wsprintfW(buf, L"IID('%ws')", oleRes);
! return PyWinCoreString_FromString(buf);
}
Index: PyUnicode.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyUnicode.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** PyUnicode.cpp 10 Feb 2008 13:46:57 -0000 1.27
--- PyUnicode.cpp 13 Nov 2008 04:04:51 -0000 1.28
***************
*** 81,85 ****
/* Implement our Windows Unicode API using the Python widestring object */
! PyObject *PyUnicodeObject_FromString(const char *string)
{
if (string==NULL) {
--- 81,85 ----
/* Implement our Windows Unicode API using the Python widestring object */
! PyObject *PyUnicodeObject_FromString(const char *string, Py_ssize_t len /* = -1 */)
{
if (string==NULL) {
***************
*** 87,91 ****
return Py_None;
}
! return (PyObject *)PyUnicode_DecodeMBCS(string, strlen(string), NULL);
}
--- 87,93 ----
return Py_None;
}
! if (len==(Py_ssize_t)-1)
! len = strlen(string);
! return (PyObject *)PyUnicode_DecodeMBCS(string, len, NULL);
}
***************
*** 227,252 ****
}
- PyObject *PyString_FromUnicode( const OLECHAR *str )
- {
- if (str==NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- PyObject *uo = PyWinObject_FromOLECHAR(str);
- if (uo==NULL) return NULL;
- PyObject *ret = PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(uo), PyUnicode_GET_SIZE(uo), NULL);
- Py_DECREF(uo);
- return ret;
- }
-
- int PyUnicode_Size(PyObject *op)
- {
- if (!PyUnicode_Check(op)) {
- PyErr_BadInternalCall();
- return -1;
- }
- return PyUnicode_GET_SIZE(op);
- }
-
PyObject *PyWinObject_FromBstr(const BSTR bstr, BOOL takeOwnership /*=FALSE*/)
{
--- 229,232 ----
***************
*** 383,387 ****
else if (PyUnicode_Check(stringObject))
{
! resultLen = PyUnicode_Size(stringObject);
size_t cb = sizeof(WCHAR) * (resultLen+1);
*pResult = (WCHAR *)PyMem_Malloc(cb);
--- 363,367 ----
else if (PyUnicode_Check(stringObject))
{
! resultLen = PyUnicode_GET_SIZE(stringObject);
size_t cb = sizeof(WCHAR) * (resultLen+1);
*pResult = (WCHAR *)PyMem_Malloc(cb);
***************
*** 652,653 ****
--- 632,650 ----
return ret;
}
+
+ // Copy s null terminated string so that it can be deallocated with PyWinObject_FreeString
+ WCHAR *PyWin_CopyString(const WCHAR *input){
+ size_t len=wcslen(input);
+ WCHAR *output=(WCHAR *)PyMem_Malloc((len+1) * sizeof(WCHAR));
+ if (output==NULL)
+ return NULL;
+ return wcsncpy(output, input, len+1);
+ }
+
+ char *PyWin_CopyString(const char *input){
+ size_t len=strlen(input);
+ char *output=(char *)PyMem_Malloc((len+1) * sizeof(char));
+ if (output==NULL)
+ return NULL;
+ return strncpy(output, input, len+1);
+ }
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** PyWinTypesmodule.cpp 11 Nov 2008 00:38:23 -0000 1.43
--- PyWinTypesmodule.cpp 13 Nov 2008 04:04:51 -0000 1.44
***************
*** 292,296 ****
TCHAR buf[255];
! int bufSize = sizeof(buf);
int numCopied = ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, buf, bufSize, NULL );
if (numCopied>0) {
--- 292,296 ----
TCHAR buf[255];
! int bufSize = sizeof(buf)/sizeof(TCHAR);
int numCopied = ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, buf, bufSize, NULL );
if (numCopied>0) {
***************
*** 303,309 ****
wsprintf(buf, _T("COM Error 0x%x"), hr);
}
! PyObject *obBuf = PyString_FromTCHAR(buf);
! PyObject *evalue = Py_BuildValue("iOzz", hr, obBuf, NULL, NULL);
! Py_XDECREF(obBuf);
PyErr_SetObject(PyWinExc_COMError, evalue);
Py_XDECREF(evalue);
--- 303,307 ----
wsprintf(buf, _T("COM Error 0x%x"), hr);
}
! PyObject *evalue = Py_BuildValue("iNzz", hr, PyWinObject_FromTCHAR(buf), NULL, NULL);
PyErr_SetObject(PyWinExc_COMError, evalue);
Py_XDECREF(evalue);
***************
*** 314,318 ****
PYWINTYPES_EXPORT PyObject *PyWin_NewUnicode(PyObject *self, PyObject *args)
{
- #ifdef PYWIN_USE_PYUNICODE
char *string;
int slen;
--- 312,315 ----
***************
*** 320,335 ****
return NULL;
return PyUnicode_DecodeMBCS(string, slen, NULL);
- #else
- PyObject *obString;
- // @pyparm string|str||The string to convert.
- if (!PyArg_ParseTuple(args, "O", &obString))
- return NULL;
- PyUnicode *result = new PyUnicode(obString);
- if ( result->m_bstrValue )
- return result;
- Py_DECREF(result);
- /* an error should have been raised */
- return NULL;
- #endif
}
--- 317,320 ----
***************
*** 343,357 ****
if (!PyArg_ParseTuple(args, "s#", &value, &numBytes))
return NULL;
-
- #ifdef PYWIN_USE_PYUNICODE
return PyWinObject_FromOLECHAR( (OLECHAR *)value, numBytes/sizeof(OLECHAR) );
- #else
- PyUnicode *result = new PyUnicode(value, numBytes);
- if ( result->m_bstrValue )
- return result;
- Py_DECREF(result);
- /* an error should have been raised */
- return NULL;
- #endif
}
--- 328,332 ----
***************
*** 396,400 ****
if (!DosDateTimeToFileTime(wFatDate, wFatTime, &fd))
return PyWin_SetAPIError("DosDateTimeToFileTime");
! return new PyTime(fd);
}
#endif /* MS_WINCE */
--- 371,375 ----
if (!DosDateTimeToFileTime(wFatDate, wFatTime, &fd))
return PyWin_SetAPIError("DosDateTimeToFileTime");
! return PyWinObject_FromFILETIME(fd);
}
#endif /* MS_WINCE */
***************
*** 633,647 ****
}
#endif
! PyBufferProcs *pb = ob->ob_type->tp_as_buffer;
! if (pb != NULL && pb->bf_getreadbuffer)
! return pb->bf_getreadbuffer(ob,0,(VOID **)pparam)!=-1;
if (PyWinLong_AsVoidPtr(ob, (void **)pparam))
return TRUE;
! if (!PyErr_Occurred())
! PyErr_Format(PyExc_TypeError,
! "WPARAM must be a " TCHAR_DESC ", int, or buffer object (got %s)",
! ob->ob_type->tp_name);
return FALSE;
}
--- 608,622 ----
}
#endif
! DWORD bufsize;
! if (PyWinObject_AsReadBuffer(ob, (VOID **)pparam, &bufsize))
! return TRUE;
+ PyErr_Clear();
if (PyWinLong_AsVoidPtr(ob, (void **)pparam))
return TRUE;
! PyErr_Format(PyExc_TypeError,
! "WPARAM must be a " TCHAR_DESC ", int, or buffer object (got %s)",
! ob->ob_type->tp_name);
return FALSE;
}
***************
*** 804,808 ****
};
! void PyWinGlobals_Ensure()
{
PyEval_InitThreads();
--- 779,783 ----
};
! int PyWinGlobals_Ensure()
{
PyEval_InitThreads();
***************
*** 815,835 ****
PyObject *d = PyDict_New();
if (!d)
! return;
! PyObject *name = PyString_FromString("pywintypes");
if (!name) {
Py_DECREF(d);
! return;
}
PyDict_SetItemString(d, "Exception", PyExc_Exception);
PyDict_SetItemString(d, "__name__", name);
Py_DECREF(name);
! PyObject *bimod = PyImport_ImportModule("__builtin__");
! if (bimod) {
! PyDict_SetItemString(d, "__builtins__", bimod);
! Py_DECREF(bimod);
! }
// Note using 'super()' doesn't work as expected on py23...
// Need to be careful to support "insane" args...
! PyRun_String("class error(Exception):\n"
" def __init__(self, *args, **kw):\n"
" nargs = len(args)\n"
--- 790,819 ----
PyObject *d = PyDict_New();
if (!d)
! return -1;
! PyObject *name = PyWinCoreString_FromString("pywintypes");
if (!name) {
Py_DECREF(d);
! return -1;
}
PyDict_SetItemString(d, "Exception", PyExc_Exception);
PyDict_SetItemString(d, "__name__", name);
Py_DECREF(name);
! PyObject *bimod = PyImport_ImportModule(
! #if PY_VERSION_HEX >= 0x03000000
! "builtins");
! #else
! "__builtin__");
! #endif
! if ((bimod == NULL)
! ||PyDict_SetItemString(d, "__builtins__", bimod) == -1){
! Py_XDECREF(bimod);
! return -1;
! }
! Py_DECREF(bimod);
!
// Note using 'super()' doesn't work as expected on py23...
// Need to be careful to support "insane" args...
! PyObject *res=PyRun_String(
! "class error(Exception):\n"
" def __init__(self, *args, **kw):\n"
" nargs = len(args)\n"
***************
*** 855,858 ****
--- 839,846 ----
,
Py_file_input, d, d);
+ if (res==NULL)
+ return -1;
+ Py_DECREF(res);
+
PyWinExc_ApiError = PyDict_GetItemString(d, "error");
Py_XINCREF(PyWinExc_ApiError);
***************
*** 921,937 ****
}
- static int AddConstant(PyObject *dict, const char *key, long value)
- {
- PyObject *oval = PyInt_FromLong(value);
- if (!oval)
- {
- return 1;
- }
- int rc = PyDict_SetItemString(dict, (char*)key, oval);
- Py_DECREF(oval);
- return rc;
- }
! #define ADD_CONSTANT(tok) AddConstant(dict, #tok, tok)
extern "C" __declspec(dllexport)
--- 909,919 ----
}
! #define ADD_CONSTANT(tok) if (PyModule_AddIntConstant(module, #tok, tok) == -1) RETURN_ERROR;
!
! #define ADD_TYPE(type_name) \
! if (PyType_Ready(&Py##type_name)==-1 \
! || PyDict_SetItemString(dict, #type_name, (PyObject *)&Py##type_name) == -1) \
! RETURN_ERROR;
extern "C" __declspec(dllexport)
***************
*** 943,946 ****
--- 925,931 ----
// Note we assume the Python global lock has been acquired for us already.
PyObject *dict, *module;
+
+ #define RETURN_ERROR return; // path to py3k...
+
module = Py_InitModule("pywintypes", pywintypes_functions);
if (!module) /* Eeek - some serious error! */
***************
*** 967,971 ****
PyDict_SetItemString(dict, "IIDType", (PyObject *)&PyIIDType);
#endif // NO_PYWINTYPES_IID
! PyDict_SetItemString(dict, "UnicodeType", (PyObject *)&PyUnicodeType);
#ifndef NO_PYWINTYPES_SECURITY
PyDict_SetItemString(dict, "SECURITY_ATTRIBUTESType", (PyObject *)&PySECURITY_ATTRIBUTESType);
--- 952,956 ----
PyDict_SetItemString(dict, "IIDType", (PyObject *)&PyIIDType);
#endif // NO_PYWINTYPES_IID
! PyDict_SetItemString(dict, "UnicodeType", (PyObject *)&PyUnicode_Type);
#ifndef NO_PYWINTYPES_SECURITY
PyDict_SetItemString(dict, "SECURITY_ATTRIBUTESType", (PyObject *)&PySECURITY_ATTRIBUTESType);
***************
*** 989,995 ****
FARPROC fp;
// dll usually will already be loaded
! HMODULE hmodule=GetModuleHandle("AdvAPI32.dll");
if (hmodule==NULL)
! hmodule=LoadLibrary("AdvAPI32.dll");
if (hmodule){
fp=GetProcAddress(hmodule,"AddAccessAllowedAce");
--- 974,980 ----
FARPROC fp;
// dll usually will already be loaded
! HMODULE hmodule=GetModuleHandle(_T("AdvAPI32.dll"));
if (hmodule==NULL)
! hmodule=LoadLibrary(_T("AdvAPI32.dll"));
if (hmodule){
fp=GetProcAddress(hmodule,"AddAccessAllowedAce");
***************
*** 1082,1083 ****
--- 1067,1163 ----
}
+ // Function to format a python traceback into a character string.
+ #define GPEM_ERROR(what) {errorMsg = "<Error getting traceback - " ## what ## ">";goto done;}
+ char *GetPythonTraceback(PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb)
+ {
+ // Sleep (30000); // Time enough to attach the debugger (barely)
+ char *result = NULL;
+ char *errorMsg = NULL;
+ PyObject *modStringIO = NULL;
+ PyObject *modTB = NULL;
+ PyObject *obFuncStringIO = NULL;
+ PyObject *obStringIO = NULL;
+ PyObject *obFuncTB = NULL;
+ PyObject *argsTB = NULL;
+ PyObject *obResult = NULL;
+
+ /* Import the modules we need - cStringIO and traceback */
+ #if (PY_VERSION_HEX < 0x03000000)
+ modStringIO = PyImport_ImportModule("cStringIO");
+ #else
+ // In py3k, cStringIO is in "io"
+ modStringIO = PyImport_ImportModule("io");
+ #endif
+
+ if (modStringIO==NULL) GPEM_ERROR("cant import cStringIO");
+ modTB = PyImport_ImportModule("traceback");
+ if (modTB==NULL) GPEM_ERROR("cant import traceback");
+
+ /* Construct a cStringIO object */
+ obFuncStringIO = PyObject_GetAttrString(modStringIO, "StringIO");
+ if (obFuncStringIO==NULL) GPEM_ERROR("cant find cStringIO.StringIO");
+ obStringIO = PyObject_CallObject(obFuncStringIO, NULL);
+ if (obStringIO==NULL) GPEM_ERROR("cStringIO.StringIO() failed");
+
+ /* Get the traceback.print_exception function, and call it. */
+ obFuncTB = PyObject_GetAttrString(modTB, "print_exception");
+ if (obFuncTB==NULL) GPEM_ERROR("cant find traceback.print_exception");
+ argsTB = Py_BuildValue("OOOOO"
+ #if (PY_VERSION_HEX >= 0x03000000)
+ "i"
+ // Py3k has added an undocumented 'chain' argument which defaults to True
+ // and causes all kinds of exceptions while trying to print a goddam exception
+ #endif
+ ,
+ exc_type ? exc_type : Py_None,
+ exc_value ? exc_value : Py_None,
+ exc_tb ? exc_tb : Py_None,
+ Py_None, // limit
+ obStringIO
+ #if (PY_VERSION_HEX >= 0x03000000)
+ ,0 // Goddam undocumented 'chain' param, which defaults to True
+ #endif
+ );
+ if (argsTB==NULL) GPEM_ERROR("cant make print_exception arguments");
+
+ obResult = PyObject_CallObject(obFuncTB, argsTB);
+ if (obResult==NULL){
+ // Chain parameter when True causes traceback.print_exception to fail, leaving no
+ // way to see what the original problem is, or even what error print_exc raises
+ // PyObject *t, *v, *tb;
+ // PyErr_Fetch(&t, &v, &tb);
+ // PyUnicodeObject *uo=(PyUnicodeObject *)v;
+ // DebugBreak();
+ GPEM_ERROR("traceback.print_exception() failed");
+ }
+ /* Now call the getvalue() method in the StringIO instance */
+ Py_DECREF(obFuncStringIO);
+ obFuncStringIO = PyObject_GetAttrString(obStringIO, "getvalue");
+ if (obFuncStringIO==NULL) GPEM_ERROR("cant find getvalue function");
+ Py_DECREF(obResult);
+ obResult = PyObject_CallObject(obFuncStringIO, NULL);
+ if (obResult==NULL) GPEM_ERROR("getvalue() failed.");
+
+ /* And it should be a string all ready to go - duplicate it. */
+ if (PyString_Check(obResult))
+ result = strdup(PyString_AsString(obResult));
+ #if (PY_VERSION_HEX >= 0x03000000)
+ else if (PyUnicode_Check(obResult))
+ result = strdup(_PyUnicode_AsString(obResult));
+ #endif
+ else
+ GPEM_ERROR("getvalue() did not return a string");
+
+ done:
+ if (result==NULL && errorMsg != NULL)
+ result = strdup(errorMsg);
+ Py_XDECREF(modStringIO);
+ Py_XDECREF(modTB);
+ Py_XDECREF(obFuncStringIO);
+ Py_XDECREF(obStringIO);
+ Py_XDECREF(obFuncTB);
+ Py_XDECREF(argsTB);
+ Py_XDECREF(obResult);
+ return result;
+ }
+
Index: win32security.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** win32security.i 29 Nov 2007 06:46:12 -0000 1.47
--- win32security.i 13 Nov 2008 04:04:51 -0000 1.48
***************
*** 2505,2509 ****
PyObject *dns_domain_name = PyWinObject_FromLSA_UNICODE_STRING(info->DnsDomainName);
PyObject *dns_forest_name = PyWinObject_FromLSA_UNICODE_STRING(info->DnsForestName);
! PyObject *domain_guid = PyWinUnicodeObject_FromIID(info->DomainGuid);
PyObject *domain_sid = PyWinObject_FromSID(info->Sid);
ret = Py_BuildValue("(OOOOO)",domain_name,dns_domain_name,dns_forest_name,domain_guid,domain_sid);
--- 2505,2509 ----
PyObject *dns_domain_name = PyWinObject_FromLSA_UNICODE_STRING(info->DnsDomainName);
PyObject *dns_forest_name = PyWinObject_FromLSA_UNICODE_STRING(info->DnsForestName);
! PyObject *domain_guid = PyWinCoreString_FromIID(info->DomainGuid);
PyObject *domain_sid = PyWinObject_FromSID(info->Sid);
ret = Py_BuildValue("(OOOOO)",domain_name,dns_domain_name,dns_forest_name,domain_guid,domain_sid);
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** PyWinTypes.h 20 Oct 2008 03:22:25 -0000 1.52
--- PyWinTypes.h 13 Nov 2008 04:04:51 -0000 1.53
***************
*** 42,47 ****
#include "mmsystem.h"
- // This can be removed once we are confident noone else uses it...
- #define PYWIN_USE_PYUNICODE
// *** NOTE *** FREEZE_PYWINTYPES is deprecated. It used to be used
--- 42,45 ----
***************
*** 68,71 ****
--- 66,72 ----
#endif // FREEZE_PYWINTYPES
+ // Formats a python traceback into a character string - result must be free()ed
+ PYWINTYPES_EXPORT char *GetPythonTraceback(PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb);
+
#include <tchar.h>
/*
***************
*** 92,126 ****
PYWINTYPES_EXPORT PyObject *PyWin_SetBasicCOMError(HRESULT hr);
- /*
- ** String/UniCode support
- */
- #ifdef PYWIN_USE_PYUNICODE
- /* Python has built-in Unicode String support */
- #define PyUnicodeType PyUnicode_Type
- // PyUnicode_Check is defined.
-
- #else
-
- /* If a Python Unicode object exists, disable it. */
- #ifdef PyUnicode_Check
- #undef PyUnicode_Check
- #define PyUnicode_Check(ob) ((ob)->ob_type == &PyUnicodeType)
- #endif /* PyUnicode_Check */
-
- /* Need our custom Unicode object */
- extern PYWINTYPES_EXPORT PyTypeObject PyUnicodeType; // the Type for PyUnicode
- #define PyUnicode_Check(ob) ((ob)->ob_type == &PyUnicodeType)
-
-
- // PyUnicode_AsUnicode clashes with the standard Python name -
- // so if we are not using Python Unicode objects, we hide the
- // name with a #define.
- #define PyUnicode_AsUnicode(op) (((PyUnicode *)op)->m_bstrValue)
- //extern PYWINTYPES_EXPORT WCHAR *PyUnicode_AsUnicode(PyObject *op);
-
- #endif /* PYWIN_USE_PYUNICODE */
-
- extern PYWINTYPES_EXPORT int PyUnicode_Size(PyObject *op);
-
// Given a PyObject (string, Unicode, etc) create a "BSTR" with the value
PYWINTYPES_EXPORT BOOL PyWinObject_AsBstr(PyObject *stringObject, BSTR *pResult, BOOL bNoneOK = FALSE, DWORD *pResultLen = NULL);
--- 93,96 ----
***************
*** 186,215 ****
*/
! #ifdef UNICODE
! #define PyWinObject_AsTCHAR PyWinObject_AsWCHAR
! #define PyWinObject_FreeTCHAR PyWinObject_FreeWCHAR
! #define PyWinObject_FromTCHAR PyWinObject_FromOLECHAR
! #define PyString_FromTCHAR PyString_FromUnicode
! #else /* not UNICODE */
! #define PyWinObject_AsTCHAR PyWinObject_AsString
! #define PyWinObject_FreeTCHAR PyWinObject_FreeString
! inline PyObject *PyWinObject_FromTCHAR( TCHAR *str )
{
! if (str==NULL){
! Py_INCREF(Py_None);
! return Py_None;
! }
! return PyString_FromString(str);
}
! inline PyObject *PyWinObject_FromTCHAR( TCHAR *str, int numChars )
{
! if (str==NULL){
! Py_INCREF(Py_None);
! return Py_None;
! }
! return PyString_FromStringAndSize(str, numChars);
! }
! #define PyString_FromTCHAR PyString_FromString
#endif
#define PyWinObject_FromWCHAR PyWinObject_FromOLECHAR
--- 156,187 ----
*/
! // Helpers with py3k in mind: the result object is always a "core string"
! // object; ie, a string in py2k and unicode in py3k. Mainly to be used for
! // objects that *must* be that type - tp_str slots, __dict__ items, etc. If
! // Python doesn't *insist* the result be this type, consider using a function
! // that always returns a unicode object (ie, most of the "PyWinObject_From*CHAR"
! // functions)
! // XXX - move these from being inlines...
! inline PyObject *PyWinCoreString_FromString(const char *str, Py_ssize_t len=(Py_ssize_t)-1)
{
! if (len==(Py_ssize_t)-1)
! len = strlen(str);
! #if (PY_VERSION_HEX < 0x03000000)
! return PyString_FromStringAndSize(str, len);
! #else
! return PyUnicode_DecodeMBCS(str, len, "ignore");
! #endif
}
!
! inline PyObject *PyWinCoreString_FromString(const WCHAR *str, Py_ssize_t len=(Py_ssize_t)-1)
{
! if (len==(Py_ssize_t)-1)
! len = wcslen(str);
! #if (PY_VERSION_HEX < 0x03000000)
! return PyUnicode_EncodeMBCS(str, len, "ignore");
! #else
! return PyUnicode_FromWideChar(str, len);
#endif
+ }
#define PyWinObject_FromWCHAR PyWinObject_FromOLECHAR
***************
*** 236,241 ****
PYWINTYPES_EXPORT BOOL PyWinObject_AsCharArray(PyObject *str_seq, char ***pchars, DWORD *str_cnt, BOOL bNoneOK = FALSE);
! PYWINTYPES_EXPORT PyObject *PyString_FromUnicode( const OLECHAR *str );
! PYWINTYPES_EXPORT PyObject *PyUnicodeObject_FromString(const char *string);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str, int numChars);
--- 208,212 ----
PYWINTYPES_EXPORT BOOL PyWinObject_AsCharArray(PyObject *str_seq, char ***pchars, DWORD *str_cnt, BOOL bNoneOK = FALSE);
! PYWINTYPES_EXPORT PyObject *PyUnicodeObject_FromString(const char *string, Py_ssize_t len=(Py_ssize_t)-1);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromOLECHAR(const OLECHAR * str, int numChars);
***************
*** 248,251 ****
--- 219,253 ----
DWORD *pResultLen = NULL);
+ #ifdef UNICODE
+ // XXX - "AsTCHAR" functions should all die - the type of the Python object
+ // being returned should not depend on UNICODE or not.
+ #define PyWinObject_AsTCHAR PyWinObject_AsWCHAR
+ #define PyWinObject_FreeTCHAR PyWinObject_FreeWCHAR
+ #define PyWinObject_FromTCHAR PyWinObject_FromOLECHAR
+ #else /* not UNICODE */
+ #define PyWinObject_AsTCHAR PyWinObject_AsString
+ #define PyWinObject_FreeTCHAR PyWinObject_FreeString
+
+ inline PyObject *PyWinObject_FromTCHAR(const char *str, Py_ssize_t len=(Py_ssize_t)-1)
+ {
+ if (str==NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ // PyWinObject_FromTCHAR in a non-unicode build still depends on py3k or not:
+ // py2x a string object is returned (no conversions). py3x a unicode object
+ // is returned (ie, the string is decoded)
+ #if (PY_VERSION_HEX < 0x03000000)
+ if (len==(Py_ssize_t)-1)
+ return PyString_FromString(str);
+ else
+ return PyString_FromStringAndSize(str, len);
+ #else
+ return PyUnicodeObject_FromString(str, len);
+ #endif
+ }
+ #define PyString_FromTCHAR PyString_FromString
+ #endif
+
// String support for buffers allocated via CoTaskMemAlloc and CoTaskMemFree
PYWINTYPES_EXPORT BOOL PyWinObject_AsTaskAllocatedWCHAR(PyObject *stringObject, WCHAR **ppResult, BOOL bNoneOK /*= FALSE*/,DWORD *pResultLen /*= NULL*/);
***************
*** 259,262 ****
--- 261,269 ----
PYWINTYPES_EXPORT void PyWinObject_FreeString(WCHAR *str);
+ // Copy null terminated string with same allocator as PyWinObject_AsWCHAR, etc
+ PYWINTYPES_EXPORT WCHAR *PyWin_CopyString(const WCHAR *input);
+ PYWINTYPES_EXPORT char *PyWin_CopyString(const char *input);
+
+
// Pointers.
// Substitute for Python's inconsistent PyLong_AsVoidPtr
***************
*** 275,285 ****
inline PyObject *PyLong_FromTwoI32(int hidword, unsigned lodword) {return PyLong_FromTwoInts(hidword, lodword);}
! //AsLARGE_INTEGER takes either PyInteger, PyLong, (PyInteger, PyInteger)
PYWINTYPES_EXPORT BOOL PyWinObject_AsLARGE_INTEGER(PyObject *ob, LARGE_INTEGER *pResult);
PYWINTYPES_EXPORT BOOL PyWinObject_AsULARGE_INTEGER(PyObject *ob, ULARGE_INTEGER *pResult);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromLARGE_INTEGER(LARGE_INTEGER &val);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromULARGE_INTEGER(ULARGE_INTEGER &val);
- #define PyLong_FromLARGE_INTEGER PyWinObject_FromLARGE_INTEGER
- #define PyLong_FromULARGE_INTEGER PyWinObject_FromULARGE_INTEGER
// Helpers that take a Py_LONG_LONG, but (a) have pywin32 consistent signatures
// and (b) handle int *and* long (where Python only starts doing that in the
--- 282,290 ----
inline PyObject *PyLong_FromTwoI32(int hidword, unsigned lodword) {return PyLong_FromTwoInts(hidword, lodword);}
! //AsLARGE_INTEGER takes either int or long
PYWINTYPES_EXPORT BOOL PyWinObject_AsLARGE_INTEGER(PyObject *ob, LARGE_INTEGER *pResult);
PYWINTYPES_EXPORT BOOL PyWinObject_AsULARGE_INTEGER(PyObject *ob, ULARGE_INTEGER *pResult);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromLARGE_INTEGER(LARGE_INTEGER &val);
PYWINTYPES_EXPORT PyObject *PyWinObject_FromULARGE_INTEGER(ULARGE_INTEGER &val);
// Helpers that take a Py_LONG_LONG, but (a) have pywin32 consistent signatures
// and (b) handle int *and* long (where Python only starts doing that in the
***************
*** 349,354 ****
// return a string/Unicode object representing an IID
! PYWINTYPES_EXPORT PyObject *PyWinStringObject_FromIID(const IID &riid);
! PYWINTYPES_EXPORT PyObject *PyWinUnicodeObject_FromIID(const IID &riid);
// A global function that can work as a module method for making an IID object.
--- 354,358 ----
// return a string/Unicode object representing an IID
! PYWINTYPES_EXPORT PyObject *PyWinCoreString_FromIID(const IID &riid);
// A global function that can work as a module method for making an IID object.
***************
*** 644,648 ****
extern PYWINTYPES_EXPORT void PyWinInterpreterLock_Release();
! extern PYWINTYPES_EXPORT void PyWinGlobals_Ensure();
extern PYWINTYPES_EXPORT void PyWinGlobals_Free();
#else
--- 648,652 ----
extern PYWINTYPES_EXPORT void PyWinInterpreterLock_Release();
! extern PYWINTYPES_EXPORT int PyWinGlobals_Ensure();
extern PYWINTYPES_EXPORT void PyWinGlobals_Free();
#else
|