Update of /cvsroot/pywin32/pywin32/com/win32com/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25507/com/win32com/src
Modified Files:
PyComHelpers.cpp PyRecord.cpp PythonCOM.cpp
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: PythonCOM.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PythonCOM.cpp,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** PythonCOM.cpp 27 Jul 2008 13:01:17 -0000 1.52
--- PythonCOM.cpp 13 Nov 2008 04:04:51 -0000 1.53
***************
*** 15,23 ****
#include "PythonCOMServer.h"
#include "PyFactory.h"
#include "OleAcc.h" // for ObjectFromLresult proto...
- // keep a reference to pythoncom'm __dict__ so the COM currency format can be looked up dynamically
- extern PyObject *pythoncom_dict=NULL;
-
extern int PyCom_RegisterCoreIIDs(PyObject *dict);
--- 15,21 ----
#include "PythonCOMServer.h"
#include "PyFactory.h"
+ #include "PyComTypeObjects.h"
#include "OleAcc.h" // for ObjectFromLresult proto...
extern int PyCom_RegisterCoreIIDs(PyObject *dict);
***************
*** 76,82 ****
// Error related functions
void GetScodeString(SCODE sc, TCHAR *buf, int bufSize);
! LPCSTR GetScodeRangeString(SCODE sc);
! LPCSTR GetSeverityString(SCODE sc);
! LPCSTR GetFacilityString(SCODE sc);
/* Debug/Test helpers */
--- 74,80 ----
// Error related functions
void GetScodeString(SCODE sc, TCHAR *buf, int bufSize);
! LPCTSTR GetScodeRangeString(SCODE sc);
! LPCTSTR GetSeverityString(SCODE sc);
! LPCTSTR GetFacilityString(SCODE sc);
/* Debug/Test helpers */
***************
*** 100,104 ****
static BOOL bHaveDCOM = -1;
if (bHaveDCOM==-1) {
! HMODULE hMod = GetModuleHandle("ole32.dll");
if (hMod) {
FARPROC fp = GetProcAddress(hMod, "CoInitializeEx");
--- 98,102 ----
static BOOL bHaveDCOM = -1;
if (bHaveDCOM==-1) {
! HMODULE hMod = GetModuleHandle(_T("ole32.dll"));
if (hMod) {
FARPROC fp = GetProcAddress(hMod, "CoInitializeEx");
***************
*** 238,242 ****
{ // scoping
HRESULT (STDAPICALLTYPE *mypfn)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *);
! HMODULE hMod = GetModuleHandle("ole32.dll");
if (hMod==0) {
PyCom_BuildInternalPyException("Can not load ole32.dll");
--- 236,240 ----
{ // scoping
HRESULT (STDAPICALLTYPE *mypfn)(REFCLSID, IUnknown *, DWORD, COSERVERINFO *, ULONG, MULTI_QI *);
! HMODULE hMod = GetModuleHandle(_T("ole32.dll"));
if (hMod==0) {
PyCom_BuildInternalPyException("Can not load ole32.dll");
***************
*** 321,325 ****
return NULL;
}
! HMODULE hMod = GetModuleHandle("ole32.dll");
if (hMod==0) return PyCom_BuildInternalPyException("Can not load ole32.dll");
FARPROC fp = GetProcAddress(hMod, "CoInitializeSecurity");
--- 319,323 ----
return NULL;
}
! HMODULE hMod = GetModuleHandle(_T("ole32.dll"));
if (hMod==0) return PyCom_BuildInternalPyException("Can not load ole32.dll");
FARPROC fp = GetProcAddress(hMod, "CoInitializeSecurity");
***************
*** 604,609 ****
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! GetScodeString(scode, buf, sizeof(buf));
! return PyString_FromTCHAR(buf);
// @comm This will obtain the COM Error message for a given HRESULT.
// Internally, PythonCOM uses this function to obtain the description
--- 602,607 ----
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! GetScodeString(scode, buf, sizeof(buf)/sizeof(buf[0]));
! return PyWinObject_FromTCHAR(buf);
// @comm This will obtain the COM Error message for a given HRESULT.
// Internally, PythonCOM uses this function to obtain the description
***************
*** 618,622 ****
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return Py_BuildValue("z", GetScodeRangeString(scode) );
}
--- 616,620 ----
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return PyWinObject_FromTCHAR(GetScodeRangeString(scode));
}
***************
*** 628,632 ****
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return Py_BuildValue("z", GetSeverityString(scode) );
}
--- 626,630 ----
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return PyWinObject_FromTCHAR(GetSeverityString(scode));
}
***************
*** 638,642 ****
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return Py_BuildValue("z", GetFacilityString(scode) );
}
--- 636,640 ----
if (!PyArg_ParseTuple(args, "k", &scode))
return NULL;
! return PyWinObject_FromTCHAR(GetFacilityString(scode));
}
***************
*** 1771,1775 ****
// GIL protects us from races here.
if (pfnObjectFromLresult==NULL) {
! HMODULE hmod = LoadLibrary("oleacc.dll");
if (hmod)
pfnObjectFromLresult = (LPFNOBJECTFROMLRESULT)
--- 1769,1773 ----
// GIL protects us from races here.
if (pfnObjectFromLresult==NULL) {
! HMODULE hmod = LoadLibrary(_T("oleacc.dll"));
if (hmod)
pfnObjectFromLresult = (LPFNOBJECTFROMLRESULT)
***************
*** 2011,2015 ****
PyObject *dict = PyModule_GetDict(oModule);
if (!dict) return; /* Another serious error!*/
- pythoncom_dict=dict;
PyDict_SetItemString(dict, "TypeIIDs", g_obPyCom_MapIIDToType);
--- 2009,2012 ----
***************
*** 2065,2072 ****
PyDict_SetItemString(dict, "PyTimeType", (PyObject *)&PyTimeType);
PyDict_SetItemString(dict, "PyIIDType", (PyObject *)&PyIIDType);
! PyDict_SetItemString(dict, "PyUnicodeType", (PyObject *)&PyUnicodeType);
// Load function pointers.
! HMODULE hModOle32 = GetModuleHandle("ole32.dll");
pfnCoWaitForMultipleHandles = \
(HRESULT (STDAPICALLTYPE *)(DWORD, DWORD, ULONG, LPHANDLE, LPDWORD)) \
--- 2062,2069 ----
PyDict_SetItemString(dict, "PyTimeType", (PyObject *)&PyTimeType);
PyDict_SetItemString(dict, "PyIIDType", (PyObject *)&PyIIDType);
! PyDict_SetItemString(dict, "PyUnicodeType", (PyObject *)&PyUnicode_Type);
// Load function pointers.
! HMODULE hModOle32 = GetModuleHandle(_T("ole32.dll"));
pfnCoWaitForMultipleHandles = \
(HRESULT (STDAPICALLTYPE *)(DWORD, DWORD, ULONG, LPHANDLE, LPDWORD)) \
Index: PyRecord.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyRecord.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** PyRecord.cpp 11 Jul 2006 13:27:48 -0000 1.11
--- PyRecord.cpp 13 Nov 2008 04:04:51 -0000 1.12
***************
*** 3,6 ****
--- 3,21 ----
// @doc
+
+ // A refugee from pywintypes and should die
+ 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;
+ }
+
#ifdef LINK_AGAINST_RECORDINFO
// Helpers to avoid linking directly to these newer functions
***************
*** 10,16 ****
return SafeArrayGetRecordInfo(psa, prinfo);
}
! HRESULT PyGetRecordInfoFromGuids( REFGUID g, ULONG maj, ULONG min, LCID lcid, REFGUID gti, IRecordInfo **ppr)
{
! return GetRecordInfoFromGuids( g, maj, min, lcid, gti, ppr);
}
#else
--- 25,31 ----
return SafeArrayGetRecordInfo(psa, prinfo);
}
! HRESULT PyGetRecordInfoFromGuids( REFGUID g, ULONG major, ULONG minor, LCID lcid, REFGUID gti, IRecordInfo **ppr)
{
! return GetRecordInfoFromGuids( g, major, minor, lcid, gti, ppr);
}
#else
***************
*** 24,28 ****
static HRESULT (STDAPICALLTYPE *pfnSAGRI)(SAFEARRAY *, IRecordInfo **) = NULL;
if (pfnSAGRI==NULL) {
! HMODULE hmod = GetModuleHandle("oleaut32.dll");
if (hmod==NULL)
return E_NOTIMPL;
--- 39,43 ----
static HRESULT (STDAPICALLTYPE *pfnSAGRI)(SAFEARRAY *, IRecordInfo **) = NULL;
if (pfnSAGRI==NULL) {
! HMODULE hmod = GetModuleHandle(_T("oleaut32.dll"));
if (hmod==NULL)
return E_NOTIMPL;
***************
*** 34,42 ****
return (*pfnSAGRI)(psa, prinfo);
}
! HRESULT PyGetRecordInfoFromGuids( REFGUID g, ULONG maj, ULONG min, LCID lcid, REFGUID gti, IRecordInfo **ppr)
{
static HRESULT (STDAPICALLTYPE *pfnGRIFG)(REFGUID, ULONG, ULONG, LCID, REFGUID, IRecordInfo **) = NULL;
if (pfnGRIFG==NULL) {
! HMODULE hmod = GetModuleHandle("oleaut32.dll");
if (hmod==NULL)
return E_NOTIMPL;
--- 49,57 ----
return (*pfnSAGRI)(psa, prinfo);
}
! HRESULT PyGetRecordInfoFromGuids( REFGUID g, ULONG major, ULONG minor, LCID lcid, REFGUID gti, IRecordInfo **ppr)
{
static HRESULT (STDAPICALLTYPE *pfnGRIFG)(REFGUID, ULONG, ULONG, LCID, REFGUID, IRecordInfo **) = NULL;
if (pfnGRIFG==NULL) {
! HMODULE hmod = GetModuleHandle(_T("oleaut32.dll"));
if (hmod==NULL)
return E_NOTIMPL;
***************
*** 46,50 ****
return E_NOTIMPL;
}
! return (*pfnGRIFG)(g, maj, min, lcid, gti, ppr);
}
#endif // LINK_AGAINST_RECORDINFO
--- 61,65 ----
return E_NOTIMPL;
}
! return (*pfnGRIFG)(g, major, minor, lcid, gti, ppr);
}
#endif // LINK_AGAINST_RECORDINFO
***************
*** 210,224 ****
PyObject *pythoncom_GetRecordFromGuids(PyObject *self, PyObject *args)
{
! char *data = NULL;
! PyObject *obGuid, *obInfoGuid;
! int maj, min, lcid;
int cb = 0;
! if (!PyArg_ParseTuple(args, "OiiiO|z#:GetRecordFromGuids",
&obGuid, // @pyparm <o PyIID>|iid||The GUID of the type library
! &maj, // @pyparm int|verMajor||The major version number of the type lib.
! &min, // @pyparm int|verMinor||The minor version number of the type lib.
&lcid, // @pyparm int|lcid||The LCID of the type lib.
&obInfoGuid, // @pyparm <o PyIID>|infoIID||The GUID of the record info in the library
! &data, &cb)) // @pyparm string|data|None|The raw data to initialize the record with.
return NULL;
GUID guid, infoGuid;
--- 225,241 ----
PyObject *pythoncom_GetRecordFromGuids(PyObject *self, PyObject *args)
{
! void *data = NULL;
! PyObject *obGuid, *obInfoGuid, *obdata=Py_None;
! int major, minor, lcid;
int cb = 0;
! if (!PyArg_ParseTuple(args, "OiiiO|O:GetRecordFromGuids",
&obGuid, // @pyparm <o PyIID>|iid||The GUID of the type library
! &major, // @pyparm int|verMajor||The major version number of the type lib.
! &minor, // @pyparm int|verMinor||The minor version number of the type lib.
&lcid, // @pyparm int|lcid||The LCID of the type lib.
&obInfoGuid, // @pyparm <o PyIID>|infoIID||The GUID of the record info in the library
! &obdata)) // @pyparm string or buffer|data|None|The raw data to initialize the record with.
! return NULL;
! if (!PyWinObject_AsReadBuffer(obdata, &data, &cb, TRUE))
return NULL;
GUID guid, infoGuid;
***************
*** 228,232 ****
return NULL;
IRecordInfo *i = NULL;
! HRESULT hr = PyGetRecordInfoFromGuids(guid, maj, min, lcid, infoGuid, &i);
if (FAILED(hr))
return PyCom_BuildPyException(hr);
--- 245,249 ----
return NULL;
IRecordInfo *i = NULL;
! HRESULT hr = PyGetRecordInfoFromGuids(guid, major, minor, lcid, infoGuid, &i);
if (FAILED(hr))
return PyCom_BuildPyException(hr);
***************
*** 342,357 ****
goto done;
}
! { // scope for locals avoiding goto
! PyObject *obtlbguid = PyWinObject_FromIID(pta->guid);
! PyObject *obstructguid = PyWinObject_FromIID(structguid);
! ret = Py_BuildValue("O(NiiiNs#)",
obFunc,
! obtlbguid,
pta->wMajorVerNum,
pta->wMinorVerNum,
pta->lcid,
! obstructguid,
! pyrec->pdata, cb);
! } // end scope
done:
if (pta&& pti)
--- 359,371 ----
goto done;
}
! ret = Py_BuildValue("O(NHHiNN)",
obFunc,
! PyWinObject_FromIID(pta->guid),
pta->wMajorVerNum,
pta->wMinorVerNum,
pta->lcid,
! PyWinObject_FromIID(structguid),
! PyString_FromStringAndSize((char *)pyrec->pdata, cb));
!
done:
if (pta&& pti)
***************
*** 362,365 ****
--- 376,380 ----
return ret;
}
+
// The object itself.
// Any method names should be "__blah__", as they override
***************
*** 400,403 ****
--- 415,419 ----
delete[] strings;
}
+
PyObject *PyRecord::tp_repr(PyObject *self)
{
***************
*** 479,490 ****
HRESULT hr = pyrec->pri->GetFieldNoCopy(pyrec->pdata, wname, &vret, &sub_data);
PY_INTERFACE_POSTCALL;
! PyWinObject_FreeString(wname);
if (FAILED(hr)) {
! if (hr == TYPE_E_FIELDNOTFOUND)
! return PyErr_Format(PyExc_AttributeError,
! "This record has no field named '%s'", name);
return PyCom_BuildPyException(hr, pyrec->pri, g_IID_IRecordInfo);
}
// Short-circuit sub-structs and arrays here, so we dont allocate a new chunk
// of memory and copy it - we need sub-structs to persist.
--- 495,511 ----
HRESULT hr = pyrec->pri->GetFieldNoCopy(pyrec->pdata, wname, &vret, &sub_data);
PY_INTERFACE_POSTCALL;
!
if (FAILED(hr)) {
! if (hr == TYPE_E_FIELDNOTFOUND){
! PyErr_Format(PyExc_AttributeError,
! "This record has no field named '%s'", wname);
! PyWinObject_FreeString(wname);
! return NULL;
! }
! PyWinObject_FreeString(wname);
return PyCom_BuildPyException(hr, pyrec->pri, g_IID_IRecordInfo);
}
+ PyWinObject_FreeString(wname);
// Short-circuit sub-structs and arrays here, so we dont allocate a new chunk
// of memory and copy it - we need sub-structs to persist.
***************
*** 585,592 ****
Py_DECREF(other_sub);
}
}
- Py_XDECREF(self_sub);
PyWinObject_FreeString(name);
}
if (ret != 0)
break;
--- 606,615 ----
Py_DECREF(other_sub);
}
+ Py_DECREF(self_sub);
}
PyWinObject_FreeString(name);
}
+ else
+ PyErr_Clear();
if (ret != 0)
break;
Index: PyComHelpers.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyComHelpers.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** PyComHelpers.cpp 22 Jan 2008 12:09:34 -0000 1.15
--- PyComHelpers.cpp 13 Nov 2008 04:04:51 -0000 1.16
***************
*** 11,15 ****
extern PyObject *g_obPyCom_MapIIDToType;
extern PyObject *g_obPyCom_MapServerIIDToGateway;
- extern PyObject *pythoncom_dict;
// String conversions
--- 11,14 ----
***************
*** 45,96 ****
PyObject *PyObject_FromCurrency(CURRENCY &cy)
{
! static BOOL decimal_imported=FALSE;
static PyObject *decimal_module=NULL;
- static BOOL warned_future_currency=FALSE;
PyObject *result = NULL;
-
- // Use decimal module if available and __future_currency__ evaluates to True, otherwise use old behaviour
- PyObject *__future_currency__;
- BOOL use_decimal;
- __future_currency__=PyDict_GetItemString(pythoncom_dict,"__future_currency__");
- if (__future_currency__==NULL){ // should not happen !
- PyErr_Print();
- use_decimal=FALSE;
- }
- else
- use_decimal=PyObject_IsTrue(__future_currency__);
- if (!use_decimal && !warned_future_currency) {
- #if (PY_VERSION_HEX >= 0x02030000)
- PyErr_Warn(PyExc_FutureWarning,
- "Currency objects will soon be changed so a decimal.Decimal instance is used."
- "\n (set pythoncom.__future_currency__ to get these objects now.)");
- #endif
- warned_future_currency = TRUE;
- }
! if (use_decimal && !decimal_imported){
decimal_module=PyImport_ImportModule("decimal");
if (!decimal_module) {
PyErr_Clear();
decimal_module=PyImport_ImportModule("win32com.decimal_23");
}
! decimal_imported=TRUE;
! if (decimal_module==NULL)
! PyErr_Print();
! }
! if (use_decimal && (decimal_module==NULL)){
! PyErr_Warn(NULL,"Can't find decimal module, reverting to using tuple for currency");
! use_decimal=FALSE;
! }
! if (!use_decimal)
! result = Py_BuildValue("ll", cy.Hi, cy.Lo);
! else {
! PyObject *unscaled_result;
! unscaled_result=PyObject_CallMethod(decimal_module, "Decimal", "L", cy.int64);
! if (unscaled_result!=NULL){
! result=PyObject_CallMethod(unscaled_result, "__div__", "l", 10000);
! Py_DECREF(unscaled_result);
}
- }
return result;
}
--- 44,71 ----
PyObject *PyObject_FromCurrency(CURRENCY &cy)
{
! #if (PY_VERSION_HEX < 0x03000000)
! static char *divname = "__div__";
! #else
! static char *divname = "__truediv__";
! #endif
static PyObject *decimal_module=NULL;
PyObject *result = NULL;
! if (decimal_module==NULL){
decimal_module=PyImport_ImportModule("decimal");
if (!decimal_module) {
PyErr_Clear();
decimal_module=PyImport_ImportModule("win32com.decimal_23");
+ }
}
! if (decimal_module==NULL)
! return NULL;
!
! PyObject *unscaled_result;
! unscaled_result=PyObject_CallMethod(decimal_module, "Decimal", "L", cy.int64);
! if (unscaled_result!=NULL){
! result=PyObject_CallMethod(unscaled_result, divname, "l", 10000);
! Py_DECREF(unscaled_result);
}
return result;
}
***************
*** 298,304 ****
PyObject *obCLSID = NULL;
obSize = PyWinObject_FromULARGE_INTEGER(pStat->cbSize);
! obmtime = new PyTime(pStat->mtime);
! obctime = new PyTime(pStat->ctime);
! obatime = new PyTime(pStat->atime);
obCLSID = PyWinObject_FromIID(pStat->clsid);
--- 273,279 ----
PyObject *obCLSID = NULL;
obSize = PyWinObject_FromULARGE_INTEGER(pStat->cbSize);
! obmtime = PyWinObject_FromFILETIME(pStat->mtime);
! obctime = PyWinObject_FromFILETIME(pStat->ctime);
! obatime = PyWinObject_FromFILETIME(pStat->atime);
obCLSID = PyWinObject_FromIID(pStat->clsid);
|