[pywin32-checkins] pywin32/win32/src win32pdhmodule.cpp, 1.17.2.1, 1.17.2.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2008-09-28 19:56:06
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16224 Modified Files: Tag: py3k win32pdhmodule.cpp Log Message: Load unicode function pointers Check return code for PyWinGlobals_Ensure Change string exception to real exception Index: win32pdhmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32pdhmodule.cpp,v retrieving revision 1.17.2.1 retrieving revision 1.17.2.2 diff -C2 -d -r1.17.2.1 -r1.17.2.2 *** win32pdhmodule.cpp 29 Aug 2008 04:59:27 -0000 1.17.2.1 --- win32pdhmodule.cpp 28 Sep 2008 19:55:46 -0000 1.17.2.2 *************** *** 184,187 **** --- 184,190 ---- static PyObject *win32pdh_counter_error; + // ??? Loads all wide-character versions of the functions. Should either + // have a way to switch between *A and *W functions as win32api does, or + // change all TCHAR to explicit WCHAR ??? BOOL LoadPointers() { *************** *** 191,213 **** return FALSE; } ! pPdhEnumObjects = (FuncPdhEnumObjects)GetProcAddress(handle, "PdhEnumObjectsA"); ! pPdhEnumObjectItems = (FuncPdhEnumObjectItems)GetProcAddress(handle, "PdhEnumObjectItemsA"); pPdhCloseQuery = (FuncPdhCloseQuery)GetProcAddress(handle, "PdhCloseQuery"); pPdhRemoveCounter = (FuncPdhRemoveCounter)GetProcAddress(handle, "PdhRemoveCounter"); pPdhOpenQuery = (FuncPdhOpenQuery)GetProcAddress(handle, "PdhOpenQuery"); ! pPdhAddCounter = (FuncPdhAddCounter)GetProcAddress(handle, "PdhAddCounterA"); ! pPdhMakeCounterPath = (FuncPdhMakeCounterPath)GetProcAddress(handle, "PdhMakeCounterPathA"); ! pPdhGetCounterInfo = (FuncPdhGetCounterInfo)GetProcAddress(handle, "PdhGetCounterInfoA"); pPdhGetFormattedCounterValue = (FuncPdhGetFormattedCounterValue)GetProcAddress(handle, "PdhGetFormattedCounterValue"); pPdhCollectQueryData = (FuncPdhCollectQueryData)GetProcAddress(handle, "PdhCollectQueryData"); ! pPdhValidatePath = (FuncPdhValidatePath)GetProcAddress(handle, "PdhValidatePathA"); ! pPdhExpandCounterPath = (FuncPdhExpandCounterPath)GetProcAddress(handle, "PdhExpandCounterPathA"); ! pPdhParseCounterPath = (FuncPdhParseCounterPath)GetProcAddress(handle, "PdhParseCounterPathA"); pPdhSetCounterScaleFactor = (FuncPdhSetCounterScaleFactor)GetProcAddress(handle, "PdhSetCounterScaleFactor"); ! pPdhParseInstanceName = (FuncPdhParseInstanceName)GetProcAddress(handle, "PdhParseInstanceNameA"); ! pPdhBrowseCounters = (FuncPdhBrowseCounters)GetProcAddress(handle, "PdhBrowseCountersA"); ! pPdhConnectMachine = (FuncPdhConnectMachine)GetProcAddress(handle, "PdhConnectMachineA"); ! pPdhLookupPerfNameByIndex = (FuncPdhLookupPerfNameByIndex)GetProcAddress(handle, "PdhLookupPerfNameByIndexA"); ! pPdhLookupPerfIndexByName = (FuncPdhLookupPerfIndexByName)GetProcAddress(handle, "PdhLookupPerfIndexByName"); // Pdh error codes are in 2 different ranges --- 194,216 ---- return FALSE; } ! pPdhEnumObjects = (FuncPdhEnumObjects)GetProcAddress(handle, "PdhEnumObjectsW"); ! pPdhEnumObjectItems = (FuncPdhEnumObjectItems)GetProcAddress(handle, "PdhEnumObjectItemsW"); pPdhCloseQuery = (FuncPdhCloseQuery)GetProcAddress(handle, "PdhCloseQuery"); pPdhRemoveCounter = (FuncPdhRemoveCounter)GetProcAddress(handle, "PdhRemoveCounter"); pPdhOpenQuery = (FuncPdhOpenQuery)GetProcAddress(handle, "PdhOpenQuery"); ! pPdhAddCounter = (FuncPdhAddCounter)GetProcAddress(handle, "PdhAddCounterW"); ! pPdhMakeCounterPath = (FuncPdhMakeCounterPath)GetProcAddress(handle, "PdhMakeCounterPathW"); ! pPdhGetCounterInfo = (FuncPdhGetCounterInfo)GetProcAddress(handle, "PdhGetCounterInfoW"); pPdhGetFormattedCounterValue = (FuncPdhGetFormattedCounterValue)GetProcAddress(handle, "PdhGetFormattedCounterValue"); pPdhCollectQueryData = (FuncPdhCollectQueryData)GetProcAddress(handle, "PdhCollectQueryData"); ! pPdhValidatePath = (FuncPdhValidatePath)GetProcAddress(handle, "PdhValidatePathW"); ! pPdhExpandCounterPath = (FuncPdhExpandCounterPath)GetProcAddress(handle, "PdhExpandCounterPathW"); ! pPdhParseCounterPath = (FuncPdhParseCounterPath)GetProcAddress(handle, "PdhParseCounterPathW"); pPdhSetCounterScaleFactor = (FuncPdhSetCounterScaleFactor)GetProcAddress(handle, "PdhSetCounterScaleFactor"); ! pPdhParseInstanceName = (FuncPdhParseInstanceName)GetProcAddress(handle, "PdhParseInstanceNameW"); ! pPdhBrowseCounters = (FuncPdhBrowseCounters)GetProcAddress(handle, "PdhBrowseCountersW"); ! pPdhConnectMachine = (FuncPdhConnectMachine)GetProcAddress(handle, "PdhConnectMachineW"); ! pPdhLookupPerfNameByIndex = (FuncPdhLookupPerfNameByIndex)GetProcAddress(handle, "PdhLookupPerfNameByIndexW"); ! pPdhLookupPerfIndexByName = (FuncPdhLookupPerfIndexByName)GetProcAddress(handle, "PdhLookupPerfIndexByNameW"); // Pdh error codes are in 2 different ranges *************** *** 893,897 **** DWORD rc = PDH_INVALID_DATA; CEnterLeavePython _celp; ! PyObject *args = Py_BuildValue("(s)", pMy->pcfg->szReturnPathBuffer); PyObject *result = PyEval_CallObject(pMy->func, args); Py_XDECREF(args); --- 896,903 ---- DWORD rc = PDH_INVALID_DATA; CEnterLeavePython _celp; ! /* ??? This does the wrong thing when multiple counters are selected. ! Should use PyWinObject_AsMultipleString, but will break code that expects a single string. ??? ! */ ! PyObject *args = Py_BuildValue("(N)", PyWinObject_FromTCHAR(pMy->pcfg->szReturnPathBuffer)); PyObject *result = PyEval_CallObject(pMy->func, args); Py_XDECREF(args); *************** *** 1100,1114 **** InitializeCriticalSection(&critSec); PyObject *dict, *module; - PyWinGlobals_Ensure(); #if (PY_VERSION_HEX < 0x03000000) module = Py_InitModule("win32pdh", win32pdh_functions); - if (!module) - return; - dict = PyModule_GetDict(module); - if (!dict) - return; #else static PyModuleDef win32pdh_def = { PyModuleDef_HEAD_INIT, --- 1106,1116 ---- InitializeCriticalSection(&critSec); PyObject *dict, *module; #if (PY_VERSION_HEX < 0x03000000) + #define RETURN_ERROR return; module = Py_InitModule("win32pdh", win32pdh_functions); #else + #define RETURN_ERROR return NULL; static PyModuleDef win32pdh_def = { PyModuleDef_HEAD_INIT, *************** *** 1119,1133 **** }; module = PyModule_Create(&win32pdh_def); if (!module) ! return NULL; dict = PyModule_GetDict(module); if (!dict) ! return NULL; ! #endif - Py_INCREF(PyWinExc_ApiError); PyDict_SetItemString(dict, "error", PyWinExc_ApiError); ! win32pdh_counter_error = PyString_FromString("win32pdh counter status error"); ! PyDict_SetItemString(dict, "counter status error", win32pdh_counter_error); LoadPointers(); // Setting an error in this function will cause Python to spew. --- 1121,1137 ---- }; module = PyModule_Create(&win32pdh_def); + #endif + if (!module) ! RETURN_ERROR; dict = PyModule_GetDict(module); if (!dict) ! RETURN_ERROR; ! if (PyWinGlobals_Ensure() == -1) ! RETURN_ERROR; PyDict_SetItemString(dict, "error", PyWinExc_ApiError); ! win32pdh_counter_error = PyErr_NewException("win32pdh.counter_status_error", NULL, NULL); ! PyDict_SetItemString(dict, "counter_status_error", win32pdh_counter_error); LoadPointers(); // Setting an error in this function will cause Python to spew. |