Esempio n. 1
0
static PyObject *
xpyb_add_core(PyObject *self, PyObject *args)
{
    PyTypeObject *value, *setup;
    PyObject *events, *errors;

    if (xpybModule_core != NULL)
	Py_RETURN_NONE;

    if (!PyArg_ParseTuple(args, "O!O!O!O!", &PyType_Type, &value, &PyType_Type, &setup,
			  &PyDict_Type, &events, &PyDict_Type, &errors))
	return NULL;

    if (!PyType_IsSubtype(value, &xpybExt_type)) {
	PyErr_SetString(xpybExcept_base, "Extension type not derived from xcb.Extension.");
	return NULL;
    }
    if (!PyType_IsSubtype(setup, xpybStruct_type)) {
	PyErr_SetString(xpybExcept_base, "Setup type not derived from xcb.Struct.");
	return NULL;
    }

    Py_INCREF(xpybModule_core = value);
    Py_INCREF(xpybModule_core_events = events);
    Py_INCREF(xpybModule_core_errors = errors);
    Py_INCREF(xpybModule_setup = setup);
    Py_RETURN_NONE;
}
Esempio n. 2
0
/**
 * Import an existing talloc pointer into a Python object.
 */
_PUBLIC_ PyObject *pytalloc_steal_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
				     void *ptr)
{
	PyTypeObject *BaseObjectType = pytalloc_GetBaseObjectType();
	PyTypeObject *ObjectType = pytalloc_GetObjectType();

	if (mem_ctx == NULL) {
		return PyErr_NoMemory();
	}

	if (PyType_IsSubtype(py_type, BaseObjectType)) {
		pytalloc_BaseObject *ret
			= (pytalloc_BaseObject *)py_type->tp_alloc(py_type, 0);

		ret->talloc_ctx = talloc_new(NULL);
		if (ret->talloc_ctx == NULL) {
			return NULL;
		}

		/*
		 * This allows us to keep multiple references to this object -
		 * we only reference this context, which is per ptr, not the
		 * talloc_ctx, which is per pytalloc_Object
		 */
		if (talloc_steal(ret->talloc_ctx, mem_ctx) == NULL) {
			return NULL;
		}
		ret->talloc_ptr_ctx = mem_ctx;
		talloc_set_name_const(ret->talloc_ctx, py_type->tp_name);
		ret->ptr = ptr;
		return (PyObject *)ret;

	} else if (PyType_IsSubtype(py_type, ObjectType)) {
		pytalloc_Object *ret
			= (pytalloc_Object *)py_type->tp_alloc(py_type, 0);

		ret->talloc_ctx = talloc_new(NULL);
		if (ret->talloc_ctx == NULL) {
			return NULL;
		}

		if (talloc_steal(ret->talloc_ctx, mem_ctx) == NULL) {
			return NULL;
		}
		talloc_set_name_const(ret->talloc_ctx, py_type->tp_name);
		ret->ptr = ptr;
		return (PyObject *)ret;
	} else {
		PyErr_SetString(PyExc_RuntimeError,
				"pytalloc_steal_ex() called for object type "
				"not based on talloc");
		return NULL;
	}
}
Esempio n. 3
0
NUITKA_MAY_BE_UNUSED static PyObject *SELECT_METACLASS( PyObject *metaclass, PyObject *bases )
{
    CHECK_OBJECT( metaclass );
    CHECK_OBJECT( bases );

    if (likely( PyType_Check( metaclass ) ))
    {
        // Determine the proper metatype
        Py_ssize_t nbases = PyTuple_GET_SIZE( bases );
        PyTypeObject *winner = (PyTypeObject *)metaclass;

        for ( int i = 0; i < nbases; i++ )
        {
            PyObject *base = PyTuple_GET_ITEM( bases, i );

            PyTypeObject *base_type = Py_TYPE( base );

            if ( PyType_IsSubtype( winner, base_type ) )
            {
                // Ignore if current winner is already a subtype.
                continue;
            }
            else if ( PyType_IsSubtype( base_type, winner ) )
            {
                // Use if, if it's a subtype of the current winner.
                winner = base_type;
                continue;
            }
            else
            {
                PyErr_Format(
                    PyExc_TypeError,
                    "metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases"
                );

                return NULL;
            }
        }

        if (unlikely( winner == NULL ))
        {
            return NULL;
        }

        return INCREASE_REFCOUNT( (PyObject *)winner );
    }
    else
    {
        return INCREASE_REFCOUNT( metaclass );
    }
}
Esempio n. 4
0
PyObject *
_pygi_boxed_new (PyTypeObject *type,
                 gpointer      boxed,
                 gboolean      free_on_dealloc)
{
    PyGIBoxed *self;

    if (!boxed) {
        Py_RETURN_NONE;
    }

    if (!PyType_IsSubtype (type, &PyGIBoxed_Type)) {
        PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Boxed");
        return NULL;
    }

    self = (PyGIBoxed *) type->tp_alloc (type, 0);
    if (self == NULL) {
        return NULL;
    }

    ( (PyGBoxed *) self)->gtype = pyg_type_from_object ( (PyObject *) type);
    ( (PyGBoxed *) self)->boxed = boxed;
    ( (PyGBoxed *) self)->free_on_dealloc = free_on_dealloc;
    self->size = 0;
    self->slice_allocated = FALSE;

    return (PyObject *) self;
}
Esempio n. 5
0
static PyObject* osl_setDrawBuffer(PyObject *self,
                                   PyObject *args,
                                   PyObject *kwargs)
{
    PyObject* buffer;

    if (!PyArg_ParseTuple(args, "O:setDrawBuffer"), &buffer)
        return NULL;

    if (PyInt_Check(buffer))
    {
        oslSetDrawBuffer((OSL_IMAGE*)PyInt_AsLong(buffer));
    }
    else if (PyType_IsSubtype(buffer->ob_type, PPyImageType))
    {
        if (currentDrawBuffer)
        {
            Py_DECREF(currentDrawBuffer);
        }

        oslSetDrawBuffer(((PyImage*)buffer)->pImg);

        Py_INCREF(buffer);
        currentDrawBuffer = buffer;
    }
    else
    {
        PyErr_SetString(PyExc_TypeError, "Argument must be an osl.Image or predefined constant");
        return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 6
0
PyObject *
pygi_struct_new_from_g_type (GType g_type,
                             gpointer      pointer,
                             gboolean      free_on_dealloc)
{
    PyGIStruct *self;
    PyTypeObject *type;

    type = (PyTypeObject *)pygi_type_import_by_g_type (g_type);

    if (!type)
        type = (PyTypeObject *)&PyGIStruct_Type; /* fallback */

    if (!PyType_IsSubtype (type, &PyGIStruct_Type)) {
        PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Struct");
        return NULL;
    }

    self = (PyGIStruct *) type->tp_alloc (type, 0);
    if (self == NULL) {
        return NULL;
    }

    pyg_pointer_set_ptr (self, pointer);
    ( (PyGPointer *) self)->gtype = g_type;
    self->free_on_dealloc = free_on_dealloc;

    return (PyObject *) self;
}
Esempio n. 7
0
/* Try a genuine rich comparison, returning an object.  Return:
   NULL for exception;
   NotImplemented if this particular rich comparison is not implemented or
     undefined;
   some object not equal to NotImplemented if it is implemented
     (this latter object may not be a Boolean).
*/
static PyObject *
try_rich_compare(PyObject *v, PyObject *w, int op)
{
	richcmpfunc f;
	PyObject *res;

	if (v->ob_type != w->ob_type &&
	    PyType_IsSubtype(w->ob_type, v->ob_type) &&
	    (f = RICHCOMPARE(w->ob_type)) != NULL) {
		res = (*f)(w, v, swapped_op[op]);
		if (res != Py_NotImplemented)
			return res;
		Py_DECREF(res);
	}
	if ((f = RICHCOMPARE(v->ob_type)) != NULL) {
		res = (*f)(v, w, op);
		if (res != Py_NotImplemented)
			return res;
		Py_DECREF(res);
	}
	if ((f = RICHCOMPARE(w->ob_type)) != NULL) {
		return (*f)(w, v, swapped_op[op]);
	}
	res = Py_NotImplemented;
	Py_INCREF(res);
	return res;
}
Esempio n. 8
0
/* this one method is exposed to Python */
static PyObject *
flextype_new(PyTypeObject *meta, PyObject *args, PyObject *kwds)
{
        PyObject *name, *bases, *dict;
	static char *kwlist[] = {"name", "bases", "dict", 0};
	PyFlexTypeObject *type;
	int basicsize = meta->tp_basicsize;
	int type_size = basicsize;

	if (!PyArg_ParseTupleAndKeywords(args, kwds, "SO!O!:type", kwlist,
					 &name,
					 &PyTuple_Type, &bases,
					 &PyDict_Type, &dict))
		return NULL;
	assert(PyType_IsSubtype(meta, &PyFlexType_Type));
	type_size = find_size(bases, type_size);
	meta->tp_basicsize = type_size;
	type = (PyFlexTypeObject *) PyType_Type.tp_new(meta, args, kwds);
	meta->tp_basicsize = basicsize;
	if (type == NULL) 
		return NULL;
	/* we can't do that in 2.3, it would break */
#if 0
	reset_gc( (PyTypeObject *) type);
#endif
	if (bindmethods((PyTypeObject *) type)) {
		Py_DECREF((PyObject *) type);
		return NULL;
	}
	return (PyObject *) type;
}
Esempio n. 9
0
static PyObject* metaSignalCheck(PyObject* klass, PyObject* args)
{
    if (PyType_IsSubtype(args->ob_type, &PySideSignalInstanceType))
        Py_RETURN_TRUE;
    else
        Py_RETURN_FALSE;
}
Esempio n. 10
0
NPY_NO_EXPORT int
needs_right_binop_forward(PyObject *self, PyObject *other,
                          char *right_name, int inplace_op)
{
    if (other == NULL ||
        self == NULL ||
        Py_TYPE(self) == Py_TYPE(other) ||
        PyArray_CheckExact(other) ||
        PyArray_CheckAnyScalar(other)) {
        /*
         * Quick cases
         */
        return 0;
    }
    if (!inplace_op && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self)) ||
        !PyArray_Check(self)) {
        /*
         * Bail out if Python would already have called the right-hand
         * operation.
         */
        return 0;
    }
    if (has_ufunc_attr(other) &&
        PyObject_HasAttrString(other, right_name)) {
        return 1;
    }
    else {
        return 0;
    }
}
Esempio n. 11
0
static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
{
    if (opid != Py_EQ && opid != Py_NE) {
#if PY_MAJOR_VERSION < 3
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
#else
        Py_RETURN_NOTIMPLEMENTED;
#endif
    }
    if (PyType_IsSubtype(Py_TYPE(_other), &pysqlite_RowType)) {
        pysqlite_Row *other = (pysqlite_Row *)_other;
        PyObject *res = PyObject_RichCompare(self->description, other->description, opid);
        if ((opid == Py_EQ && res == Py_True)
            || (opid == Py_NE && res == Py_False)) {
            Py_DECREF(res);
            return PyObject_RichCompare(self->data, other->data, opid);
        }
    }
#if PY_MAJOR_VERSION < 3
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
#else
    Py_RETURN_NOTIMPLEMENTED;
#endif
}
Esempio n. 12
0
int
PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
{
    if (err == NULL || exc == NULL) {
        /* maybe caused by "import exceptions" that failed early on */
        return 0;
    }
    if (PyTuple_Check(exc)) {
        Py_ssize_t i, n;
        n = PyTuple_Size(exc);
        for (i = 0; i < n; i++) {
            /* Test recursively */
             if (PyErr_GivenExceptionMatches(
                 err, PyTuple_GET_ITEM(exc, i)))
             {
                 return 1;
             }
        }
        return 0;
    }
    /* err might be an instance, so check its class. */
    if (PyExceptionInstance_Check(err))
        err = PyExceptionInstance_Class(err);

    if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
        return PyType_IsSubtype((PyTypeObject *)err, (PyTypeObject *)exc);
    }

    return err == exc;
}
Esempio n. 13
0
// Trawl a type's hierarchy looking for any slots, signals or properties.
static int trawl_hierarchy(PyTypeObject *pytype, qpycore_metaobject *qo,
        QMetaObjectBuilder &builder, QList<const qpycore_pyqtSignal *> &psigs,
        QMap<uint, PropertyData> &pprops)
{
    if (trawl_type(pytype, qo, builder, psigs, pprops) < 0)
        return -1;

    if (!pytype->tp_bases)
        return 0;

    Q_ASSERT(PyTuple_Check(pytype->tp_bases));

    for (SIP_SSIZE_T i = 0; i < PyTuple_GET_SIZE(pytype->tp_bases); ++i)
    {
        PyTypeObject *sup = (PyTypeObject *)PyTuple_GET_ITEM(pytype->tp_bases, i);

#if PY_MAJOR_VERSION < 3
        /* Ignore classic classes as mixins. */
        if (PyClass_Check((PyObject *)sup))
            continue;
#endif

        if (PyType_IsSubtype(sup, sipTypeAsPyTypeObject(sipType_QObject)))
            continue;

        if (trawl_hierarchy(sup, qo, builder, psigs, pprops) < 0)
            return -1;
    }

    return 0;
}
Esempio n. 14
0
PyObject *
_pygi_struct_new (PyTypeObject *type,
                  gpointer      pointer,
                  gboolean      free_on_dealloc)
{
    PyGIStruct *self;
    GType g_type;

    if (!PyType_IsSubtype (type, &PyGIStruct_Type)) {
        PyErr_SetString (PyExc_TypeError, "must be a subtype of gi.Struct");
        return NULL;
    }

    self = (PyGIStruct *) type->tp_alloc (type, 0);
    if (self == NULL) {
        return NULL;
    }

    g_type = pyg_type_from_object ( (PyObject *) type);

    ( (PyGPointer *) self)->gtype = g_type;
    ( (PyGPointer *) self)->pointer = pointer;
    self->free_on_dealloc = free_on_dealloc;

    return (PyObject *) self;
}
Esempio n. 15
0
static PlanarBBoxObject *
BBox_new_from_center(PyTypeObject *type, PyObject *args, PyObject *kwargs) 
{
    PlanarBBoxObject *bbox;
    PyObject *center_arg;
    double width, height, cx, cy;
    static char *kwlist[] = {"center", "width", "height", NULL};

    assert(PyType_IsSubtype(type, &PlanarBBoxType));
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, 
        "Odd:BoundingBox.from_center", kwlist, 
        &center_arg, &width, &height)) {
        return NULL;
    }
    if (!PlanarVec2_Parse(center_arg, &cx, &cy)) {
        PyErr_SetString(PyExc_TypeError,
            "expected Vec2 for argument center");
        return NULL;
    }
    width = fabs(width) * 0.5;
    height = fabs(height) * 0.5;
    bbox = (PlanarBBoxObject *)type->tp_alloc(type, 0);
    if (bbox == NULL) {
        return NULL;
    }
    bbox->min.x = cx - width;
    bbox->min.y = cy - height;
    bbox->max.x = cx + width;
    bbox->max.y = cy + height;
    return bbox;
}
Esempio n. 16
0
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    /* 'cause' is only used in Py3 */
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);

    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }

    if (PyType_Check(type)) {
        /* instantiate the type now (we don't know when and how it will be caught) */
#if CYTHON_COMPILING_IN_PYPY
        /* PyPy can't handle value == NULL */
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);

    } else {
        /* Raising an instance.  The value should be a dummy. */
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }

    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
Esempio n. 17
0
//-------------------------------------------------------------------------------------
Base* Baseapp::onCreateEntityCommon(PyObject* pyEntity, ScriptDefModule* sm, ENTITY_ID eid)
{
	if(PyType_IsSubtype(sm->getScriptType(), Proxy::getScriptType()))
	{
		return new(pyEntity) Proxy(eid, sm);
	}

	return EntityApp<Base>::onCreateEntityCommon(pyEntity, sm, eid);
}
// Return a pointer to the initialised registration structure for a type.
static QQmlPrivate::RegisterSingletonType *init_type(PyTypeObject *py_type,
        PyObject *factory)
{
    // Check the type is derived from QObject.
    if (!PyType_IsSubtype(py_type, sipTypeAsPyTypeObject(sipType_QObject)))
    {
        PyErr_SetString(PyExc_TypeError,
                "type being registered must be a sub-type of QObject");
        return 0;
    }

    // Get the type's number and check there aren't too many.
    int type_nr = QPyQmlSingletonObjectProxy::addType();

    if (type_nr >= NrOfTypes)
    {
        PyErr_Format(PyExc_TypeError,
                "a maximum of %d singleton types may be registered with QML",
                NrOfTypes);
        return 0;
    }

    QQmlPrivate::RegisterSingletonType *rt = &proxy_types[type_nr];

    const QMetaObject *mo = pyqt5_get_qmetaobject(py_type);

    QByteArray ptr_name(py_type->tp_name);
    ptr_name.append('*');

    // Initialise those members that depend on the C++ type.
    switch (type_nr)
    {
        QPYQML_SINGLETON_TYPE_INIT(0);
        QPYQML_SINGLETON_TYPE_INIT(1);
        QPYQML_SINGLETON_TYPE_INIT(2);
        QPYQML_SINGLETON_TYPE_INIT(3);
        QPYQML_SINGLETON_TYPE_INIT(4);
        QPYQML_SINGLETON_TYPE_INIT(5);
        QPYQML_SINGLETON_TYPE_INIT(6);
        QPYQML_SINGLETON_TYPE_INIT(7);
        QPYQML_SINGLETON_TYPE_INIT(8);
        QPYQML_SINGLETON_TYPE_INIT(9);
    }

    // Initialise the remaining members.
    rt->version = 2;
    rt->uri = 0;
    rt->versionMajor = 0;
    rt->versionMinor = 0;
    rt->typeName = 0;
    rt->scriptApi = 0;
    rt->revision = 0;

    Py_INCREF(factory);

    return rt;
}
Esempio n. 19
0
HyReldep
reldepFromPyObject(PyObject *o)
{
    if (!PyType_IsSubtype(o->ob_type, &reldep_Type)) {
	PyErr_SetString(PyExc_TypeError, "Expected a Reldep object.");
	return NULL;
    }
    return ((_ReldepObject*)o)->reldep;
}
Esempio n. 20
0
sipErrorState qpyquick_register_type(PyTypeObject *py_type,
        const QMetaObject *mo, const QByteArray &ptr_name,
        const QByteArray &list_name, QQmlPrivate::RegisterType **rtp)
{
#if QT_VERSION >= 0x050200
    if (PyType_IsSubtype(py_type, sipTypeAsPyTypeObject(sipType_QQuickFramebufferObject)))
        return ((*rtp = QPyQuickFramebufferObject::addType(py_type, mo, ptr_name, list_name)) ? sipErrorNone : sipErrorFail);
#endif

    if (PyType_IsSubtype(py_type, sipTypeAsPyTypeObject(sipType_QQuickPaintedItem)))
        return ((*rtp = QPyQuickPaintedItem::addType(py_type, mo, ptr_name, list_name)) ? sipErrorNone : sipErrorFail);

    if (PyType_IsSubtype(py_type, sipTypeAsPyTypeObject(sipType_QQuickItem)))
        return ((*rtp = QPyQuickItem::addType(py_type, mo, ptr_name, list_name)) ? sipErrorNone : sipErrorFail);

    // We don't recognise the type.
    return sipErrorContinue;
}
Esempio n. 21
0
HyPackage
packageFromPyObject(PyObject *o)
{
    if (!PyType_IsSubtype(o->ob_type, &package_Type)) {
	PyErr_SetString(PyExc_TypeError, "Expected a Package object.");
	return NULL;
    }
    return ((_PackageObject *)o)->package;
}
Esempio n. 22
0
/**
 * Import an existing talloc pointer into a Python object, leaving the
 * original parent, and creating a reference to the object in the python
 * object.
 *
 * We remember the object we hold the reference to (a
 * possibly-non-talloc pointer), the existing parent (typically the
 * start of the array) and the new referenced parent.  That way we can
 * cope with the fact that we will have multiple parents, one per time
 * python sees the object.
 */
_PUBLIC_ PyObject *pytalloc_reference_ex(PyTypeObject *py_type,
					 TALLOC_CTX *mem_ctx, void *ptr)
{
	PyTypeObject *BaseObjectType = pytalloc_GetBaseObjectType();
	PyTypeObject *ObjectType = pytalloc_GetObjectType();

	if (mem_ctx == NULL) {
		return PyErr_NoMemory();
	}

	if (PyType_IsSubtype(py_type, BaseObjectType)) {
		pytalloc_BaseObject *ret
			= (pytalloc_BaseObject *)py_type->tp_alloc(py_type, 0);
		ret->talloc_ctx = talloc_new(NULL);
		if (ret->talloc_ctx == NULL) {
			return NULL;
		}
		if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) {
			return NULL;
		}
		talloc_set_name_const(ret->talloc_ctx, py_type->tp_name);
		ret->talloc_ptr_ctx = mem_ctx;
		ret->ptr = ptr;
		return (PyObject *)ret;
	} else if (PyType_IsSubtype(py_type, ObjectType)) {
		pytalloc_Object *ret
			= (pytalloc_Object *)py_type->tp_alloc(py_type, 0);
		ret->talloc_ctx = talloc_new(NULL);
		if (ret->talloc_ctx == NULL) {
			return NULL;
		}
		if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) {
			return NULL;
		}
		talloc_set_name_const(ret->talloc_ctx, py_type->tp_name);
		ret->ptr = ptr;
		return (PyObject *)ret;
	} else {
		PyErr_SetString(PyExc_RuntimeError,
				"pytalloc_reference_ex() called for object type "
				"not based on talloc");
		return NULL;
	}
}
Esempio n. 23
0
static int
slpmodule_set__tasklet__(PySlpModuleObject *mod, PyTypeObject *type, void *context)
{
	if (!PyType_IsSubtype(type, &PyTasklet_Type))
		TYPE_ERROR("__tasklet__ must be a tasklet subtype", -1);
	Py_INCREF(type);
	Py_CLEAR(mod->__tasklet__);
	mod->__tasklet__ = type;
	return 0;
}
Esempio n. 24
0
PyQtGuiObject* QtBaseWidget::getControl() {
	PyQtGuiObject* control = (PyQtGuiObject*) PyWeakref_GET_OBJECT(controlRef);
	if(!control) return NULL;
	if(!PyType_IsSubtype(Py_TYPE(control), &QtGuiObject_Type)) {
		printf("QtBaseWidget: control is wrong type\n");
		return NULL;
	}
	Py_INCREF(control);
	return control;
}
Esempio n. 25
0
static int
slpmodule_set__channel__(PySlpModuleObject *mod, PyTypeObject *type, void *context)
{
	if (!PyType_IsSubtype(type, &PyChannel_Type))
		TYPE_ERROR("__channel__ must be a channel subtype", -1);
	Py_INCREF(type);
	Py_XDECREF(mod->__channel__);
	mod->__channel__ = type;
	return 0;
}
Esempio n. 26
0
int
selector_converter(PyObject *o, HySelector *sltr_ptr)
{
    if (!PyType_IsSubtype(o->ob_type, &selector_Type)) {
        PyErr_SetString(PyExc_TypeError, "Expected a Selector object.");
        return 0;
    }
    *sltr_ptr = ((_SelectorObject *)o)->sltr;

    return 1;
}
Esempio n. 27
0
static int
hv_cli_class_le(PyObject * self, PyObject *a, PyObject *b)
{
    if (a == b)
        return 1;
    if (PyType_Check(a) && PyType_Check(b))
        return PyType_IsSubtype((PyTypeObject *)a, (PyTypeObject *)b);
    if (PyClass_Check(a) && PyClass_Check(b))
        return PyClass_IsSubclass(a, b);
    return 0;
}
Esempio n. 28
0
File: ext.c Progetto: aosm/X11libs
static PyObject *
xpybExt_send_request(xpybExt *self, PyObject *args, PyObject *kw)
{
    static char *kwlist[] = { "request", "cookie", "reply", NULL };
    xpybRequest *request;
    xpybCookie *cookie;
    PyTypeObject *reply = NULL;
    xcb_protocol_request_t xcb_req;
    struct iovec xcb_parts[4];
    unsigned int seq;
    int flags;
    const void *data;
    Py_ssize_t size;

    /* Parse and check arguments */
    if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|O!", kwlist,
				     &xpybRequest_type, &request,
				     &xpybCookie_type, &cookie,
				     &PyType_Type, &reply))
	return NULL;

    if (!request->is_void)
	if (reply == NULL || !PyType_IsSubtype(reply, &xpybReply_type)) {
	    PyErr_SetString(xpybExcept_base, "Reply type missing or not derived from xcb.Reply.");
	    return NULL;
	}

    /* Set up request structure */
    xcb_req.count = 2;
    xcb_req.ext = (self->key != (xpybExtkey *)Py_None) ? &self->key->key : 0;
    xcb_req.opcode = request->opcode;
    xcb_req.isvoid = request->is_void;

    /* Allocate and fill in data strings */
    if (PyObject_AsReadBuffer(((xpybProtobj *)request)->buf, &data, &size) < 0)
	return NULL;
    xcb_parts[2].iov_base = (void *)data;
    xcb_parts[2].iov_len = size;
    xcb_parts[3].iov_base = 0;
    xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3;

    /* Make request call */
    flags = request->is_checked ? XCB_REQUEST_CHECKED : 0;
    seq = xcb_send_request(self->conn->conn, flags, xcb_parts + 2, &xcb_req);

    /* Set up cookie */
    Py_INCREF(cookie->conn = self->conn);
    Py_INCREF((PyObject *)(cookie->request = request));
    Py_XINCREF(cookie->reply = reply);
    cookie->cookie.sequence = seq;

    Py_INCREF(cookie);
    return (PyObject *)cookie;
}
Esempio n. 29
0
PyObject*
newstyleCheckSubtype(PyObject* self, PyObject* args)
{
	PyObject* nobj = PyTuple_GET_ITEM(args, 0);
	PyTypeObject* supertype = (PyTypeObject*) PyTuple_GET_ITEM(args, 1);
	if (nobj && supertype)
	{
		if (PyType_IsSubtype(Py_TYPE(nobj), supertype)) Py_RETURN_TRUE;
		else Py_RETURN_FALSE;
	} else
		Py_RETURN_NONE;
}
static polypaths_planar_overrideAffineObject *
Affine_new_identity(PyTypeObject *type)
{
    polypaths_planar_overrideAffineObject *t;

    assert(PyType_IsSubtype(type, &polypaths_planar_overrideAffineType));
    t = (polypaths_planar_overrideAffineObject *)type->tp_alloc(type, 0);
    if (t == NULL) {
        return NULL;
    }
    t->a = t->e = 1.0;
    return t;
}