Ejemplo n.º 1
0
STDMETHODIMP PyGEnumDebugStackFrames::Next( 
            /* [in] */ ULONG celt,
            /* [length_is][size_is][out] */ DebugStackFrameDescriptor __RPC_FAR *rgVar,
            /* [out] */ ULONG __RPC_FAR *pCeltFetched)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	Py_ssize_t len;
	HRESULT hr = InvokeViaPolicy("Next", &result, "i", celt);
	if ( FAILED(hr) )
		return hr;

	if ( !PySequence_Check(result) )
		goto error;
	len = PyObject_Length(result);
	if ( len == -1 )
		goto error;
	if ( len > (Py_ssize_t)celt)
		len = celt;

	if ( pCeltFetched )
		*pCeltFetched = PyWin_SAFE_DOWNCAST(len, Py_ssize_t, ULONG);

	Py_ssize_t i;
	for ( i = 0; i < len; ++i )
	{
		PyObject *ob = PySequence_GetItem(result, i);
		if ( ob == NULL )
			goto error;
		if (!PyTuple_Check(ob)) {
			Py_DECREF(ob);
			PyErr_SetString(PyExc_TypeError, "PyIEnumDebugStackFrames::Next must return a tuple.");
			goto error;
		}
		PyObject *obEnum, *obUnk;
		if (!PyArg_ParseTuple(ob, "OiiiO", &obEnum, &rgVar[i].dwMin, &rgVar[i].dwLim, &rgVar[i].fFinal, &obUnk)) {
			Py_DECREF(ob);
			goto error;
		}

		if ( !PyCom_InterfaceFromPyInstanceOrObject(obEnum, IID_IDebugStackFrame, (void **)&rgVar[i].pdsf, FALSE) ||
		     !PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&rgVar[i].punkFinal, TRUE) )
		{
			Py_DECREF(ob);
			Py_DECREF(result);
			return PyCom_SetCOMErrorFromPyException(IID_IEnumDebugStackFrames);
		}
		Py_DECREF(ob);
	}

	Py_DECREF(result);

	return len < (Py_ssize_t)celt ? S_FALSE : S_OK;

  error:
	hr = PyErr_Occurred() ? PyCom_SetCOMErrorFromPyException(IID_IEnumDebugStackFrames)
		                          : PyCom_SetCOMErrorFromSimple(E_FAIL, IID_IEnumDebugStackFrames);
	Py_DECREF(result);
	return hr;
}
Ejemplo n.º 2
0
BOOL CATIDsFromPyObject( PyObject *obCatIds, CATID **ppCatIds, UINT *pNumIds)
{
    if (!PySequence_Check(obCatIds)) {
        PyErr_SetString(PyExc_TypeError, "Object must be a sequence of CATIDs");
        return FALSE;
    }
    Py_ssize_t len = PyObject_Length(obCatIds);
    CATID *ids = new CATID[len];
    BOOL rc = TRUE;
    for (Py_ssize_t i=0; rc && i<len; i++) {
        PyObject *obThis = PySequence_GetItem(obCatIds, i);
        if (obThis==NULL) {
            rc = FALSE;
            break;
        }
        if (!PyWinObject_AsIID(obThis, ids+i)) {
            PyErr_SetString(PyExc_TypeError, "CATID is not valid");
            rc = FALSE;
        }
        Py_DECREF(obThis);
    }
    if (rc) {
        *ppCatIds = ids;
        *pNumIds = PyWin_SAFE_DOWNCAST(len, Py_ssize_t, UINT);
    } else {
        delete [] ids;
    }
    return rc;
}
Ejemplo n.º 3
0
// @pymethod |PyICatRegister|RegisterCategories|Registers one or more component categories. Each component category consists of a CATID and a list of locale-dependent description strings.
PyObject *PyICatRegister::RegisterCategories(PyObject *self, PyObject *args)
{
    PyObject *obCatList;
    // @pyparm [ (<o PyIID>, int, string), ...]|[ (catId, lcid, description), ...]||A sequence of category descriptions.
    if ( !PyArg_ParseTuple(args, "O:RegisterCategories", &obCatList) )
        return NULL;

    ICatRegister *pICR = GetI(self);
    if ( pICR == NULL )
        return NULL;

    if (!PySequence_Check(obCatList)) {
        PyErr_SetString(PyExc_TypeError, "Argument must be a list of CATEGORYINFO tuples");
        return NULL;
    }
    Py_ssize_t noInfos = PyObject_Length(obCatList);
    CATEGORYINFO *infos = new CATEGORYINFO [noInfos];
    if (infos==NULL) {
        PyErr_SetString(PyExc_MemoryError, "Allocating CATEGORYINFO array");
        return NULL;
    }
    for (Py_ssize_t i=0; i<noInfos; i++) {
        PyObject *obCatId;
        PyObject *obThis = PySequence_GetItem(obCatList, i);
        if (obThis==NULL) return NULL;
        BOOL ok = TRUE;
        PyObject *obDesc;
        if (!PyArg_ParseTuple(obThis, "OlO", &obCatId, (long *)&infos[i].lcid, &obDesc)) {
            Py_DECREF(obThis);
            PyErr_SetString(PyExc_TypeError, "Category infos must be CATID, lcid, description");
            delete [] infos;
            return NULL;
        }
        Py_DECREF(obThis);
        if (!PyWinObject_AsIID(obCatId, &infos[i].catid)) {
            delete [] infos;
            return NULL;
        }
        OLECHAR *oc;
        if (!PyWinObject_AsWCHAR(obDesc, &oc, FALSE)) {
            delete [] infos;
            return NULL;
        }
        wcsncpy(infos[i].szDescription, oc,
                sizeof(infos->szDescription)/sizeof(infos->szDescription[0]));
        PyWinObject_FreeWCHAR(oc);
    }

    PY_INTERFACE_PRECALL;
    HRESULT hr = pICR->RegisterCategories(PyWin_SAFE_DOWNCAST(noInfos, Py_ssize_t, ULONG),
                                          infos);
    PY_INTERFACE_POSTCALL;
    delete [] infos;
    if ( FAILED(hr) )
        return PyCom_BuildPyException(hr, pICR, IID_ICatRegister);
    Py_INCREF(Py_None);
    return Py_None;
}
Ejemplo n.º 4
0
PyObject *PyACL::PySetEntriesInAcl(PyObject *self, PyObject *args)
{
	PyObject *ret=NULL;
	PEXPLICIT_ACCESS_W pexpl=NULL, pexpl_start=NULL;
	ACL *new_acl=NULL;
	PyACL *This = (PyACL *)self;
	PyObject *obexpl=NULL, *obexpl_list=NULL;
	Py_ssize_t expl_cnt=0, expl_ind=0;
	DWORD err;
	if (!PyArg_ParseTuple(args, "O:SetEntriesInAcl", &obexpl_list))
		return NULL;
	if (!PySequence_Check(obexpl_list)){
		PyErr_SetString(PyExc_TypeError, "Parm must be a list of EXPLICIT_ACCESS dictionaries");
		return NULL;
		}
	expl_cnt=PySequence_Length(obexpl_list);
	Py_ssize_t bytes_allocated=expl_cnt*sizeof(EXPLICIT_ACCESS_W);
	pexpl_start = (PEXPLICIT_ACCESS_W)malloc(bytes_allocated);
	ZeroMemory(pexpl_start,bytes_allocated);
	if (pexpl_start==NULL){
		PyErr_SetString(PyExc_MemoryError,"SetEntriesInAcl: unable to allocate EXPLICIT_ACCESS_W");
		goto done;
		}
	pexpl=pexpl_start;
	for (expl_ind=0; expl_ind<expl_cnt; expl_ind++){
		obexpl = PySequence_GetItem(obexpl_list,expl_ind);
		if (!PyWinObject_AsEXPLICIT_ACCESS(obexpl,pexpl)){
			Py_DECREF(obexpl);
			goto done;
			}
		Py_DECREF(obexpl);
		pexpl++;
		}
	err = ::SetEntriesInAclW(PyWin_SAFE_DOWNCAST(expl_cnt, Py_ssize_t, ULONG),
	                         pexpl_start,This->GetACL(),&new_acl);
	if (err!=ERROR_SUCCESS){
		PyWin_SetAPIError("SetEntriesInAcl",err);
		goto done;
		}
	if (This->SetACL(new_acl))
		ret=Py_None;
	done:
	// have to free WCHAR name from trustee structures also
	if (pexpl_start!=NULL){
		pexpl=pexpl_start;
		for (expl_ind=0; expl_ind<expl_cnt; expl_ind++){
			PyWinObject_FreeTRUSTEE(&pexpl->Trustee);
			pexpl++;
			}
		free(pexpl_start);
		}
	if (new_acl)
		LocalFree(new_acl);
	Py_XINCREF(ret);
	return ret;
}