示例#1
0
CVirtualHelper::~CVirtualHelper()
{
	// This is called for each window message, so should be as fast
	// as possible - but DECREF is not atomic on multi-core CPU's, so
	// take the reliable option...
	if (py_ob || handler || retVal) { 
		CEnterLeavePython _celp;
		XDODECREF(retVal);
		XDODECREF(handler);
		XDODECREF(py_ob);
	}
}
示例#2
0
// @pymethod |PyAssocObject|AttachObject|Attaches a Python object for lookup of "virtual" functions.
PyObject *
ui_assoc_object::AttachObject(PyObject *self, PyObject *args)
{
	PyObject *ob;
	ui_assoc_object *pAssoc = (ui_assoc_object *)self;
	if (pAssoc==NULL) return NULL;
	if (!PyArg_ParseTuple(args, "O:AttachObject", &ob ))
		return NULL;
	// Possibility for recursion here if we re-attach the
	// same instance to the same win32ui type object.
	// decref of the instance may trigger instance delete,
	// which may trigger AttachObject(None), which will
	// attempt to decref etc.  
	// So set the instance to NULL _before_ we decref it, and only
	// do the decref after we've incref'd the new object - if it is the
	// same object we may otherwise transition it via a refcount of 0.
	PyObject *old = pAssoc->virtualInst;
	pAssoc->virtualInst = NULL;
	if (ob!=Py_None) {
		pAssoc->virtualInst = ob;
		DOINCREF(ob);
	}
	XDODECREF(old);
	RETURN_NONE;
}
示例#3
0
ui_prinfo_object::~ui_prinfo_object()
{
  if (m_deletePrInfo) {
    CPrintInfo *pPrInfo = GetPrintInfo(this);
    if (pPrInfo) {
      if (pPrInfo->m_lpUserData) {
        XDODECREF((PyObject*)pPrInfo->m_lpUserData);
        pPrInfo->m_lpUserData = NULL;
      }
      if (pPrInfo->m_pPD->m_pd.lCustData) {
        XDODECREF((PyObject*)pPrInfo->m_pPD->m_pd.lCustData);
        pPrInfo->m_pPD->m_pd.lCustData = NULL;
      }
    };
  }
}
示例#4
0
// @pymethod |PyCPrintInfo|SetUserData|Set a user-created structure.
// @pyseemfc CPrintInfo|m_lpUserData
static PyObject *ui_set_user_data(PyObject * self, PyObject * args)
{
  PyObject *var;
  if (!PyArg_ParseTuple(args,"O:SetUserData",&var))
    return NULL;
  CPrintInfo *pInfo = ui_prinfo_object::GetPrintInfo(self);
  if (!pInfo)
    return NULL;
  if (pInfo->m_lpUserData) XDODECREF((PyObject*)pInfo->m_lpUserData);
  pInfo->m_lpUserData = var;
  DOINCREF(var);
  RETURN_NONE;
}
示例#5
0
BOOL CVirtualHelper::do_call(PyObject *args)
{
	USES_CONVERSION;
	XDODECREF(retVal);	// our old one.
	retVal = NULL;
	ASSERT(handler);	// caller must trap this.
	ASSERT(args);
	PyObject *result = gui_call_object(handler,args);
	DODECREF(args);
	if (result==NULL) {
		if (vehErrorHandling==VEH_PRINT_ERROR) {
			char msg[256];
			TRACE("CallVirtual : callback failed with exception\n");
			gui_print_error();
			// this will probably fail if we are already inside the exception handler
			PyObject *obRepr = PyObject_Repr(handler);
			char *szRepr = "<no representation (PyObject_Repr failed)>";
			if (obRepr){
				if (PyString_Check(obRepr))
					szRepr = PyString_AS_STRING(obRepr);
				else if (PyUnicode_Check(obRepr))
					szRepr=W2A(PyUnicode_AS_UNICODE(obRepr));
				}
			else
				PyErr_Clear();

			LPTSTR HandlerName=csHandlerName.GetBuffer(csHandlerName.GetLength());
			snprintf(msg, sizeof(msg)/sizeof(msg[0]),  "%s() virtual handler (%s) raised an exception", 
				T2A(HandlerName),
				szRepr);
			csHandlerName.ReleaseBuffer();
			Py_XDECREF(obRepr);
			PyErr_SetString(ui_module_error, msg);
			// send to the debugger
			TRACE(msg);
			TRACE("\n");
			// send to the app.
			gui_print_error();
		} else {
			// Error dialog.
			CString csAddnMsg = " when executing ";
			csAddnMsg += csHandlerName;
			csAddnMsg += " handler";

			ExceptionHandler(EHA_DISPLAY_DIALOG, NULL, csAddnMsg);
		}
		return FALSE;
	}
	retVal = result;
	return TRUE;
}
示例#6
0
PyCWinApp::~PyCWinApp()
{
	XDODECREF(pExistingAppObject);
	pExistingAppObject = NULL;
}