SlotConnectorBase::SlotConnectorBase(PyObject* slot, int n_sig_args) { function = 0; klass = 0; PyObject* instance = 0; cfunction = 0; if (PyMethod_Check(slot)) { instance = PyMethod_GET_SELF(slot); klass = PyMethod_GET_CLASS(slot); function = PyMethod_GET_FUNCTION(slot); Py_INCREF(klass); Py_INCREF(function); PyObject* func_code = PyObject_GetAttrString(function, "func_code"); PyObject* co_argcount = PyObject_GetAttrString(func_code, "co_argcount"); n_slot_args = PyInt_AsLong(co_argcount)-1; if (n_slot_args == -1) { PyErr_SetString(PyExc_TypeError, "Slot method should at least have a 'self' argument"); return; } core = ((Wt::WObject*)(((PyCPPClassInstance*)instance)->proxy->getCoreAsVoid())); Py_DECREF(func_code); Py_DECREF(co_argcount); } else if PyCFunction_Check(slot) { instance = PyCFunction_GET_SELF(slot); cfunction = PyCFunction_GET_FUNCTION(slot); flags = PyCFunction_GET_FLAGS(slot); n_slot_args = PyCFunction_GET_NARGS(slot); core = ((Wt::WObject*)(((PyCPPClassInstance*)instance)->proxy->getCoreAsVoid())); } else {
PyObject* PyObject_CallAsPyString(PyObject* object) { PyObject *result, *module, *module_tmp, *self; PyObject *function, *function_tmp, *class; if (PyFunction_Check(object)) { module = ModuleAsPyString(((PyFunctionObject*)object)->func_module); function = ((PyFunctionObject*)object)->func_name; result = PyString_JoinWithDots(module, function); //Py_XDECREF(module); return result; } else if (PyCFunction_Check(object)) { module = ModuleAsPyString(((PyCFunctionObject*)object)->m_module); self = PyObject_AsPyString(((PyCFunctionObject*)object)->m_self); function = PyString_FromString(((PyCFunctionObject*)object)->m_ml->ml_name); result = PyString_JoinWithDots(module, self, function); //Py_XDECREF(module); Py_XDECREF(self); Py_DECREF(function); return result; } else if (PyMethod_Check(object)) { // See the implementation of instancemethod_repr class = NULL; if (PyMethod_GET_CLASS(object) != NULL) { class = PyObject_CallAsPyString(PyMethod_GET_CLASS(object)); } if (PyFunction_Check(PyMethod_GET_FUNCTION(object))) { function = ((PyFunctionObject*)PyMethod_GET_FUNCTION(object))->func_name; Py_XINCREF(function); } else { function = PyString_InternFromString("???"); } if (PyMethod_GET_SELF(object) == NULL) { // Unbounded method function_tmp = function; function = PyString_FromFormat("%s<U>", PyString_AsString(function_tmp)); Py_DECREF(function_tmp); } result = PyString_JoinWithDots(class, function); Py_XDECREF(class); Py_XDECREF(function); return result; } else if (PyType_Check(object)) {
/* * Compare two slots to see if they are the same. */ int sip_api_same_slot(const sipSlot *sp, PyObject *rxObj, const char *slot) { assert(sipQtSupport); assert(sipQtSupport->qt_same_name); /* See if they are signals or Qt slots, ie. they have a name. */ if (slot != NULL) { if (sp->name == NULL || sp->name[0] == '\0') return 0; return (sipQtSupport->qt_same_name(sp->name, slot) && sp->pyobj == rxObj); } /* See if they are pure Python methods. */ if (PyMethod_Check(rxObj)) { if (sp->pyobj != NULL) return 0; return (sp->meth.mfunc == PyMethod_GET_FUNCTION(rxObj) && sp->meth.mself == PyMethod_GET_SELF(rxObj) #if PY_MAJOR_VERSION < 3 && sp->meth.mclass == PyMethod_GET_CLASS(rxObj) #endif ); } /* See if they are wrapped C++ methods. */ if (PyCFunction_Check(rxObj)) { if (sp->name == NULL || sp->name[0] != '\0') return 0; return (sp->pyobj == PyCFunction_GET_SELF(rxObj) && strcmp(&sp->name[1], ((PyCFunctionObject *)rxObj)->m_ml->ml_name) == 0); } /* The objects must be the same. */ return (sp->pyobj == rxObj); }
static PyObject* copyrec(PyObject* o) { PyTypeObject* t; PyObject* n; PyObject* key; KeyObject* fkey; if (o == Py_None || o->ob_type == &PyInt_Type || o->ob_type == &PyString_Type) { Py_INCREF(o); return o; } if (ss_next_in_block < 0) { struct key_block* b = (struct key_block*) malloc(sizeof(struct key_block)); if (!b) { PyErr_NoMemory(); goto fail1; } b->next = ss_block; ss_block = b; ss_next_in_block = KEYS_BY_BLOCK - 1; } fkey = ss_block->keys + ss_next_in_block; fkey->ob_refcnt = 1; fkey->ob_type = &keytype; fkey->o = o; key = (PyObject*) fkey; n = PyDict_GetItem(ss_memo, key); if (n) { Py_INCREF(n); return n; } ss_next_in_block--; Py_INCREF(o); /* reference stored in 'fkey->o' */ t = o->ob_type; if (t == &PyTuple_Type) { int i, count = PyTuple_GET_SIZE(o); n = PyTuple_New(count); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; for (i=0; i<count; i++) PyTuple_SET_ITEM(n, i, copyrec(PyTuple_GET_ITEM(o, i))); return n; } if (t == &PyList_Type) { int i, count = PyList_GET_SIZE(o); n = PyList_New(count); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; for (i=0; i<count; i++) PyList_SET_ITEM(n, i, copyrec(PyList_GET_ITEM(o, i))); return n; } if (t == &PyDict_Type) { int i = 0; PyObject* dictkey; PyObject* dictvalue; n = PyDict_New(); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; while (PyDict_Next(o, &i, &dictkey, &dictvalue)) if (PyDict_SetItem(n, copyrec(dictkey), copyrec(dictvalue))) goto fail; return n; } if (t == &PyInstance_Type) { int i = 0; PyObject* dictkey; PyObject* dictvalue; PyObject* dsrc; PyObject* ddest; PyObject* inst_build = PyObject_GetAttr(o, str_inst_build); if (inst_build == NULL) { PyErr_Clear(); goto unmodified; } n = PyObject_CallObject(inst_build, NULL); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; dsrc = ((PyInstanceObject*) o)->in_dict; ddest = ((PyInstanceObject*) n)->in_dict; while (PyDict_Next(dsrc, &i, &dictkey, &dictvalue)) if (PyDict_SetItem(ddest, copyrec(dictkey), copyrec(dictvalue))) goto fail; return n; } if (t == &PyFunction_Type) { int i, count; PyObject* tsrc = PyFunction_GET_DEFAULTS(o); PyObject* tdest; if (!tsrc) goto unmodified; count = PyTuple_GET_SIZE(tsrc); if (count == 0) goto unmodified; n = PyFunction_New(PyFunction_GET_CODE(o), PyFunction_GET_GLOBALS(o)); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; tdest = PyTuple_New(count); if (!tdest) goto fail; for (i=0; i<count; i++) PyTuple_SET_ITEM(tdest, i, copyrec(PyTuple_GET_ITEM(tsrc, i))); i = PyFunction_SetDefaults(n, tdest); Py_DECREF(tdest); if (i) goto fail; return n; } if (t == &PyMethod_Type) { PyObject* x; n = PyMethod_New(PyMethod_GET_FUNCTION(o), PyMethod_GET_SELF(o), PyMethod_GET_CLASS(o)); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; x = copyrec(PyMethod_GET_FUNCTION(n)); Py_DECREF(PyMethod_GET_FUNCTION(n)); PyMethod_GET_FUNCTION(n) = x; x = copyrec(PyMethod_GET_SELF(n)); Py_DECREF(PyMethod_GET_SELF(n)); PyMethod_GET_SELF(n) = x; return n; } if (t == GeneratorType) { n = genbuild(o); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; if (gencopy(n, o)) goto fail; return n; } if (t == &PySeqIter_Type) { n = seqiterbuild(o); if (!n || PyDict_SetItem(ss_memo, key, n)) goto fail; if (seqitercopy(n, o)) goto fail; return n; } ss_next_in_block++; return o; /* reference no longer stored in 'fkey->o' */ unmodified: PyDict_SetItem(ss_memo, key, o); Py_INCREF(o); return o; fail1: n = NULL; fail: Py_INCREF(o); Py_XDECREF(n); return o; }