diff options
-rw-r--r-- | _dbus_bindings/abstract-impl.h | 143 | ||||
-rw-r--r-- | _dbus_bindings/bus.c | 4 | ||||
-rw-r--r-- | _dbus_bindings/bytes-impl.h | 48 | ||||
-rw-r--r-- | _dbus_bindings/conn.c | 14 | ||||
-rw-r--r-- | _dbus_bindings/containers-impl.h | 141 | ||||
-rw-r--r-- | _dbus_bindings/dbus_bindings-internal.h | 45 | ||||
-rw-r--r-- | _dbus_bindings/exceptions.c (renamed from _dbus_bindings/exceptions-impl.h) | 19 | ||||
-rw-r--r-- | _dbus_bindings/floattypes-impl.h | 34 | ||||
-rw-r--r-- | _dbus_bindings/generic-impl.h | 13 | ||||
-rw-r--r-- | _dbus_bindings/mainloop-impl.h | 30 | ||||
-rw-r--r-- | _dbus_bindings/message-append-impl.h | 70 | ||||
-rw-r--r-- | _dbus_bindings/message-get-args-impl.h | 55 | ||||
-rw-r--r-- | _dbus_bindings/message.c (renamed from _dbus_bindings/message-impl.h) | 33 | ||||
-rw-r--r-- | _dbus_bindings/module.c | 15 | ||||
-rw-r--r-- | _dbus_bindings/pending-call.c (renamed from _dbus_bindings/pending-call-impl.h) | 12 | ||||
-rw-r--r-- | _dbus_bindings/signature-impl.h | 24 | ||||
-rw-r--r-- | _dbus_bindings/types-impl.h | 261 | ||||
-rw-r--r-- | _dbus_bindings/types-internal.h | 81 | ||||
-rw-r--r-- | setup.py | 3 |
19 files changed, 524 insertions, 521 deletions
diff --git a/_dbus_bindings/abstract-impl.h b/_dbus_bindings/abstract-impl.h index c0362ba..53e5dfe 100644 --- a/_dbus_bindings/abstract-impl.h +++ b/_dbus_bindings/abstract-impl.h @@ -22,20 +22,12 @@ * */ -static PyObject *variant_level_const; +#include "types-internal.h" /* Support code for int subclasses. ================================== */ -static PyTypeObject DBusPythonIntType; -DEFINE_CHECK(DBusPythonInt) - -typedef struct { - PyIntObject base; - long variant_level; -} DBusPythonInt; - static PyMemberDef DBusPythonInt_tp_members[] = { - {"variant_level", T_LONG, offsetof(DBusPythonInt, variant_level), + {"variant_level", T_LONG, offsetof(DBusPyIntBase, variant_level), READONLY, "The number of nested variants wrapping the real data. " "0 if not in a variant."}, @@ -54,7 +46,7 @@ DBusPythonInt_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes at most one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|l:__new__", argnames, &variantness)) return NULL; if (variantness < 0) { @@ -65,7 +57,7 @@ DBusPythonInt_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyInt_Type.tp_new)(cls, args, NULL); if (self) { - ((DBusPythonInt *)self)->variant_level = variantness; + ((DBusPyIntBase *)self)->variant_level = variantness; } return self; } @@ -74,7 +66,7 @@ static PyObject * DBusPythonInt_tp_repr(PyObject *self) { PyObject *parent_repr = (PyInt_Type.tp_repr)(self); - long variant_level = ((DBusPythonInt *)self)->variant_level; + long variant_level = ((DBusPyIntBase *)self)->variant_level; PyObject *my_repr; if (!parent_repr) return NULL; @@ -93,11 +85,11 @@ DBusPythonInt_tp_repr(PyObject *self) return my_repr; } -static PyTypeObject DBusPythonIntType = { +PyTypeObject DBusPyIntBase_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, - "_dbus_bindings._DBusPythonInt", - sizeof(DBusPythonInt), + "_dbus_bindings._IntBase", + sizeof(DBusPyIntBase), 0, 0, /* tp_dealloc */ 0, /* tp_print */ @@ -140,16 +132,8 @@ static PyTypeObject DBusPythonIntType = { /* There's only one subclass at the moment (Double) but these are factored out to make room for Float later. (Float is implemented and #if'd out) */ -static PyTypeObject DBusPythonFloatType; -DEFINE_CHECK(DBusPythonFloat) - -typedef struct { - PyFloatObject base; - long variant_level; -} DBusPythonFloat; - static PyMemberDef DBusPythonFloat_tp_members[] = { - {"variant_level", T_LONG, offsetof(DBusPythonFloat, variant_level), + {"variant_level", T_LONG, offsetof(DBusPyFloatBase, variant_level), READONLY, "The number of nested variants wrapping the real data. " "0 if not in a variant."}, @@ -168,7 +152,7 @@ DBusPythonFloat_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes at most one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|l:__new__", argnames, &variantness)) return NULL; if (variantness < 0) { @@ -179,7 +163,7 @@ DBusPythonFloat_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyFloat_Type.tp_new)(cls, args, NULL); if (self) { - ((DBusPythonFloat *)self)->variant_level = variantness; + ((DBusPyFloatBase *)self)->variant_level = variantness; } return self; } @@ -188,7 +172,7 @@ static PyObject * DBusPythonFloat_tp_repr(PyObject *self) { PyObject *parent_repr = (PyFloat_Type.tp_repr)(self); - long variant_level = ((DBusPythonFloat *)self)->variant_level; + long variant_level = ((DBusPyFloatBase *)self)->variant_level; PyObject *my_repr; if (!parent_repr) return NULL; @@ -207,11 +191,11 @@ DBusPythonFloat_tp_repr(PyObject *self) return my_repr; } -static PyTypeObject DBusPythonFloatType = { +PyTypeObject DBusPyFloatBase_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, - "_dbus_bindings._DBusPythonFloat", - sizeof(DBusPythonFloat), + "_dbus_bindings._FloatBase", + sizeof(DBusPyFloatBase), 0, 0, /* tp_dealloc */ 0, /* tp_print */ @@ -251,9 +235,6 @@ static PyTypeObject DBusPythonFloatType = { /* Support code for str subclasses ================================== */ -static PyTypeObject DBusPythonStringType; -DEFINE_CHECK(DBusPythonString) - static PyObject * DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { @@ -266,7 +247,7 @@ DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes at most one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|O!:__new__", argnames, &PyInt_Type, &variantness)) return NULL; if (!variantness) { @@ -281,7 +262,7 @@ DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyString_Type.tp_new)(cls, args, NULL); if (self) { - PyObject_GenericSetAttr(self, variant_level_const, variantness); + PyObject_GenericSetAttr(self, dbus_py_variant_level_const, variantness); } return self; } @@ -295,7 +276,7 @@ DBusPythonString_tp_repr(PyObject *self) long variant_level; if (!parent_repr) return NULL; - vl_obj = PyObject_GetAttr(self, variant_level_const); + vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) return NULL; variant_level = PyInt_AsLong(vl_obj); if (variant_level > 0) { @@ -313,10 +294,10 @@ DBusPythonString_tp_repr(PyObject *self) return my_repr; } -static PyTypeObject DBusPythonStringType = { +PyTypeObject DBusPyStrBase_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, - "_dbus_bindings._DBusPythonString", + "_dbus_bindings._StrBase", INT_MAX, /* placeholder */ 0, 0, /* tp_dealloc */ @@ -357,9 +338,6 @@ static PyTypeObject DBusPythonStringType = { /* Support code for long subclasses ================================= */ -static PyTypeObject DBusPythonLongType; -DEFINE_CHECK(DBusPythonLong) - static PyObject * DBusPythonLong_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { @@ -372,7 +350,7 @@ DBusPythonLong_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes at most one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|O!:__new__", argnames, &PyInt_Type, &variantness)) return NULL; if (!variantness) { @@ -387,7 +365,7 @@ DBusPythonLong_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyLong_Type.tp_new)(cls, args, NULL); if (self) { - PyObject_GenericSetAttr(self, variant_level_const, variantness); + PyObject_GenericSetAttr(self, dbus_py_variant_level_const, variantness); } return self; } @@ -401,7 +379,7 @@ DBusPythonLong_tp_repr(PyObject *self) long variant_level; if (!parent_repr) return NULL; - vl_obj = PyObject_GetAttr(self, variant_level_const); + vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) return 0; variant_level = PyInt_AsLong(vl_obj); if (variant_level) { @@ -419,10 +397,10 @@ DBusPythonLong_tp_repr(PyObject *self) return my_repr; } -static PyTypeObject DBusPythonLongType = { +PyTypeObject DBusPyLongBase_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, - "_dbus_bindings._DBusPythonLong", + "_dbus_bindings._LongBase", INT_MAX, /* placeholder */ 0, 0, /* tp_dealloc */ @@ -464,36 +442,39 @@ static PyTypeObject DBusPythonLongType = { static inline int init_abstract(void) { - variant_level_const = PyString_InternFromString("variant_level"); - if (!variant_level_const) return 0; + dbus_py_variant_level_const = PyString_InternFromString("variant_level"); + if (!dbus_py_variant_level_const) return 0; + + dbus_py_signature_const = PyString_InternFromString("signature"); + if (!dbus_py_signature_const) return 0; - DBusPythonIntType.tp_base = &PyInt_Type; - if (PyType_Ready(&DBusPythonIntType) < 0) return 0; + DBusPyIntBase_Type.tp_base = &PyInt_Type; + if (PyType_Ready(&DBusPyIntBase_Type) < 0) return 0; /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as desired */ - DBusPythonIntType.tp_print = NULL; + DBusPyIntBase_Type.tp_print = NULL; - DBusPythonFloatType.tp_base = &PyFloat_Type; - if (PyType_Ready(&DBusPythonFloatType) < 0) return 0; - DBusPythonFloatType.tp_print = NULL; + DBusPyFloatBase_Type.tp_base = &PyFloat_Type; + if (PyType_Ready(&DBusPyFloatBase_Type) < 0) return 0; + DBusPyFloatBase_Type.tp_print = NULL; /* Add a pointer for the instance dict, aligning to sizeof(PyObject *) * to make sure the offset of -sizeof(PyObject *) is right. */ - DBusPythonLongType.tp_basicsize = PyLong_Type.tp_basicsize + DBusPyLongBase_Type.tp_basicsize = PyLong_Type.tp_basicsize + + 2*sizeof(PyObject *) - 1; + DBusPyLongBase_Type.tp_basicsize /= sizeof(PyObject *); + DBusPyLongBase_Type.tp_basicsize *= sizeof(PyObject *); + DBusPyLongBase_Type.tp_base = &PyLong_Type; + if (PyType_Ready(&DBusPyLongBase_Type) < 0) return 0; + DBusPyLongBase_Type.tp_print = NULL; + + DBusPyStrBase_Type.tp_basicsize = PyString_Type.tp_basicsize + 2*sizeof(PyObject *) - 1; - DBusPythonLongType.tp_basicsize /= sizeof(PyObject *); - DBusPythonLongType.tp_basicsize *= sizeof(PyObject *); - DBusPythonLongType.tp_base = &PyLong_Type; - if (PyType_Ready(&DBusPythonLongType) < 0) return 0; - DBusPythonLongType.tp_print = NULL; - - DBusPythonStringType.tp_basicsize = PyString_Type.tp_basicsize - + 2*sizeof(PyObject *) - 1; - DBusPythonStringType.tp_basicsize /= sizeof(PyObject *); - DBusPythonStringType.tp_basicsize *= sizeof(PyObject *); - DBusPythonStringType.tp_base = &PyString_Type; - if (PyType_Ready(&DBusPythonStringType) < 0) return 0; - DBusPythonStringType.tp_print = NULL; + DBusPyStrBase_Type.tp_basicsize /= sizeof(PyObject *); + DBusPyStrBase_Type.tp_basicsize *= sizeof(PyObject *); + DBusPyStrBase_Type.tp_base = &PyString_Type; + if (PyType_Ready(&DBusPyStrBase_Type) < 0) return 0; + DBusPyStrBase_Type.tp_print = NULL; return 1; } @@ -501,18 +482,18 @@ init_abstract(void) static inline int insert_abstract_types(PyObject *this_module) { - Py_INCREF(&DBusPythonIntType); - Py_INCREF(&DBusPythonLongType); - Py_INCREF(&DBusPythonStringType); - Py_INCREF(&DBusPythonFloatType); - if (PyModule_AddObject(this_module, "_DBusPythonInt", - (PyObject *)&DBusPythonIntType) < 0) return 0; - if (PyModule_AddObject(this_module, "_DBusPythonLong", - (PyObject *)&DBusPythonLongType) < 0) return 0; - if (PyModule_AddObject(this_module, "_DBusPythonString", - (PyObject *)&DBusPythonStringType) < 0) return 0; - if (PyModule_AddObject(this_module, "_DBusPythonFloat", - (PyObject *)&DBusPythonFloatType) < 0) return 0; + Py_INCREF(&DBusPyIntBase_Type); + Py_INCREF(&DBusPyLongBase_Type); + Py_INCREF(&DBusPyStrBase_Type); + Py_INCREF(&DBusPyFloatBase_Type); + if (PyModule_AddObject(this_module, "_IntBase", + (PyObject *)&DBusPyIntBase_Type) < 0) return 0; + if (PyModule_AddObject(this_module, "_LongBase", + (PyObject *)&DBusPyLongBase_Type) < 0) return 0; + if (PyModule_AddObject(this_module, "_StrBase", + (PyObject *)&DBusPyStrBase_Type) < 0) return 0; + if (PyModule_AddObject(this_module, "_FloatBase", + (PyObject *)&DBusPyFloatBase_Type) < 0) return 0; return 1; } diff --git a/_dbus_bindings/bus.c b/_dbus_bindings/bus.c index 66e0d11..ca7a673 100644 --- a/_dbus_bindings/bus.c +++ b/_dbus_bindings/bus.c @@ -60,7 +60,7 @@ Bus_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (first && PyString_Check(first)) { /* It's a custom address. First connect to it, then register. */ - self = (Connection *)(DBusPyConnectionType.tp_new)(cls, args, kwargs); + self = (Connection *)(DBusPyConnection_Type.tp_new)(cls, args, kwargs); if (!self) return NULL; Py_BEGIN_ALLOW_THREADS @@ -401,7 +401,7 @@ static PyTypeObject BusType = { dbus_bool_t dbus_py_init_bus_types (void) { - BusType.tp_base = &DBusPyConnectionType; + BusType.tp_base = &DBusPyConnection_Type; if (PyType_Ready (&BusType) < 0) return 0; return 1; } diff --git a/_dbus_bindings/bytes-impl.h b/_dbus_bindings/bytes-impl.h index 62b4571..beb1bbc 100644 --- a/_dbus_bindings/bytes-impl.h +++ b/_dbus_bindings/bytes-impl.h @@ -22,20 +22,6 @@ * */ -static PyTypeObject ByteType, ByteArrayType; - -static inline int Byte_Check(PyObject *o) -{ - return (o->ob_type == &ByteType) - || PyObject_IsInstance(o, (PyObject *)&ByteType); -} - -static inline int ByteArray_Check(PyObject *o) -{ - return (o->ob_type == &ByteArrayType) - || PyObject_IsInstance(o, (PyObject *)&ByteArrayType); -} - PyDoc_STRVAR(Byte_tp_doc, "Byte(integer or str of length 1[, variant_level])\n" "\n" @@ -57,7 +43,7 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "than one positional argument"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|l:__new__", argnames, &variantness)) return NULL; if (variantness < 0) { @@ -80,7 +66,7 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) long i = PyInt_AS_LONG(obj); if (obj->ob_type == cls && - ((DBusPythonInt *)obj)->variant_level == variantness) { + ((DBusPyIntBase *)obj)->variant_level == variantness) { Py_INCREF(obj); return obj; } @@ -97,7 +83,7 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) Py_DECREF(obj); obj = NULL; - obj = DBusPythonIntType.tp_new(cls, tuple, kwargs); + obj = DBusPyIntBase_Type.tp_new(cls, tuple, kwargs); Py_DECREF(tuple); tuple = NULL; return obj; @@ -118,7 +104,7 @@ Byte_tp_str(PyObject *self) return PyString_FromStringAndSize((char *)str, 1); } -static PyTypeObject ByteType = { +PyTypeObject DBusPyByte_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Byte", @@ -184,7 +170,7 @@ ByteArray_sq_item (PyObject *self, int i) args = Py_BuildValue("(l)", (long)c); if (!args) return NULL; - return PyObject_Call((PyObject *)&ByteType, args, NULL); + return PyObject_Call((PyObject *)&DBusPyByte_Type, args, NULL); } static PyObject * @@ -225,7 +211,7 @@ static PySequenceMethods ByteArray_tp_as_sequence = { 0, /* sq_contains */ }; -static PyTypeObject ByteArrayType = { +PyTypeObject DBusPyByteArray_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.ByteArray", @@ -257,7 +243,7 @@ static PyTypeObject ByteArrayType = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonStringType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyStrBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -270,13 +256,13 @@ static PyTypeObject ByteArrayType = { static inline int init_byte_types(void) { - ByteType.tp_base = &DBusPythonIntType; - if (PyType_Ready(&ByteType) < 0) return 0; - ByteType.tp_print = NULL; + DBusPyByte_Type.tp_base = &DBusPyIntBase_Type; + if (PyType_Ready(&DBusPyByte_Type) < 0) return 0; + DBusPyByte_Type.tp_print = NULL; - ByteArrayType.tp_base = &DBusPythonStringType; - if (PyType_Ready(&ByteArrayType) < 0) return 0; - ByteArrayType.tp_print = NULL; + DBusPyByteArray_Type.tp_base = &DBusPyStrBase_Type; + if (PyType_Ready(&DBusPyByteArray_Type) < 0) return 0; + DBusPyByteArray_Type.tp_print = NULL; return 1; } @@ -284,12 +270,12 @@ init_byte_types(void) static inline int insert_byte_types(PyObject *this_module) { - Py_INCREF(&ByteType); + Py_INCREF(&DBusPyByte_Type); if (PyModule_AddObject(this_module, "Byte", - (PyObject *)&ByteType) < 0) return 0; - Py_INCREF(&ByteArrayType); + (PyObject *)&DBusPyByte_Type) < 0) return 0; + Py_INCREF(&DBusPyByteArray_Type); if (PyModule_AddObject(this_module, "ByteArray", - (PyObject *)&ByteArrayType) < 0) return 0; + (PyObject *)&DBusPyByteArray_Type) < 0) return 0; return 1; } diff --git a/_dbus_bindings/conn.c b/_dbus_bindings/conn.c index ed79096..ba57990 100644 --- a/_dbus_bindings/conn.c +++ b/_dbus_bindings/conn.c @@ -322,7 +322,7 @@ static void Connection_tp_dealloc(Connection *self) /* Connection type object =========================================== */ -static PyTypeObject ConnectionType = { +PyTypeObject DBusPyConnection_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "_dbus_bindings.Connection", /*tp_name*/ @@ -367,23 +367,23 @@ static PyTypeObject ConnectionType = { 0, /*tp_is_gc*/ }; -static inline dbus_bool_t -init_conn_types(void) +dbus_bool_t +dbus_py_init_conn_types(void) { /* Get a slot to store our weakref on DBus Connections */ _connection_python_slot = -1; if (!dbus_connection_allocate_data_slot(&_connection_python_slot)) return FALSE; - if (PyType_Ready(&ConnectionType) < 0) + if (PyType_Ready(&DBusPyConnection_Type) < 0) return FALSE; return TRUE; } -static inline dbus_bool_t -insert_conn_types(PyObject *this_module) +dbus_bool_t +dbus_py_insert_conn_types(PyObject *this_module) { if (PyModule_AddObject(this_module, "Connection", - (PyObject *)&ConnectionType) < 0) return FALSE; + (PyObject *)&DBusPyConnection_Type) < 0) return FALSE; return TRUE; } diff --git a/_dbus_bindings/containers-impl.h b/_dbus_bindings/containers-impl.h index 89c63a0..a7055dd 100644 --- a/_dbus_bindings/containers-impl.h +++ b/_dbus_bindings/containers-impl.h @@ -22,14 +22,8 @@ * */ -static PyObject *signature_const; - /* Array ============================================================ */ -static PyTypeObject ArrayType; - -DEFINE_CHECK(Array) - PyDoc_STRVAR(Array_tp_doc, "An array of similar items, implemented as a subtype of list.\n" "\n" @@ -57,17 +51,11 @@ PyDoc_STRVAR(Array_tp_doc, " Array with variant_level==2.\n" ); -typedef struct { - PyListObject super; - PyObject *signature; - long variant_level; -} Array; - static struct PyMemberDef Array_tp_members[] = { - {"signature", T_OBJECT, offsetof(Array, signature), READONLY, + {"signature", T_OBJECT, offsetof(DBusPyArray, signature), READONLY, "The D-Bus signature of each element of this Array (a Signature " "instance)"}, - {"variant_level", T_LONG, offsetof(Array, variant_level), + {"variant_level", T_LONG, offsetof(DBusPyArray, variant_level), READONLY, "The number of nested variants wrapping the real data. " "0 if not in a variant."}, @@ -75,7 +63,7 @@ static struct PyMemberDef Array_tp_members[] = { }; static void -Array_tp_dealloc (Array *self) +Array_tp_dealloc (DBusPyArray *self) { Py_XDECREF(self->signature); self->signature = NULL; @@ -83,7 +71,7 @@ Array_tp_dealloc (Array *self) } static PyObject * -Array_tp_repr(Array *self) +Array_tp_repr(DBusPyArray *self) { PyObject *parent_repr = (PyList_Type.tp_repr)((PyObject *)self); PyObject *sig_repr = PyObject_Repr(self->signature); @@ -116,7 +104,7 @@ static PyObject * Array_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) { PyObject *variant_level = NULL; - Array *self = (Array *)(PyList_Type.tp_new)(cls, args, kwargs); + DBusPyArray *self = (DBusPyArray *)(PyList_Type.tp_new)(cls, args, kwargs); /* variant_level is immutable, so handle it in __new__ rather than __init__ */ @@ -125,7 +113,7 @@ Array_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) self->signature = Py_None; self->variant_level = 0; if (kwargs) { - variant_level = PyDict_GetItem(kwargs, variant_level_const); + variant_level = PyDict_GetItem(kwargs, dbus_py_variant_level_const); } if (variant_level) { self->variant_level = PyInt_AsLong(variant_level); @@ -138,9 +126,9 @@ Array_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) } static int -Array_tp_init (Array *self, PyObject *args, PyObject *kwargs) +Array_tp_init (DBusPyArray *self, PyObject *args, PyObject *kwargs) { - PyObject *obj = empty_tuple; + PyObject *obj = dbus_py_empty_tuple; PyObject *signature = NULL; PyObject *tuple; PyObject *variant_level; @@ -157,12 +145,12 @@ Array_tp_init (Array *self, PyObject *args, PyObject *kwargs) of type Signature (or None) */ if (!signature) signature = Py_None; if (signature == Py_None - || PyObject_IsInstance(signature, (PyObject *)&SignatureType)) { + || PyObject_IsInstance(signature, (PyObject *)&DBusPySignature_Type)) { Py_INCREF(signature); } else { - signature = PyObject_CallFunction((PyObject *)&SignatureType, "(O)", - signature); + signature = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, + "(O)", signature); if (!signature) return -1; } @@ -183,11 +171,11 @@ Array_tp_init (Array *self, PyObject *args, PyObject *kwargs) return 0; } -static PyTypeObject ArrayType = { +PyTypeObject DBusPyArray_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Array", - sizeof(Array), + sizeof(DBusPyArray), 0, (destructor)Array_tp_dealloc, /* tp_dealloc */ 0, /* tp_print */ @@ -227,10 +215,6 @@ static PyTypeObject ArrayType = { /* Dict ============================================================= */ -static PyTypeObject DictType; - -DEFINE_CHECK(Dict) - PyDoc_STRVAR(Dict_tp_doc, "An mapping whose keys are similar and whose values are similar,\n" "implemented as a subtype of dict.\n" @@ -260,17 +244,11 @@ PyDoc_STRVAR(Dict_tp_doc, " Python by a Dictionary with variant_level==2.\n" ); -typedef struct { - PyDictObject super; - PyObject *signature; - long variant_level; -} Dict; - static struct PyMemberDef Dict_tp_members[] = { - {"signature", T_OBJECT, offsetof(Dict, signature), READONLY, + {"signature", T_OBJECT, offsetof(DBusPyDict, signature), READONLY, "The D-Bus signature of each key in this Dictionary, followed by " "that of each value in this Dictionary, as a Signature instance."}, - {"variant_level", T_LONG, offsetof(Dict, variant_level), + {"variant_level", T_LONG, offsetof(DBusPyDict, variant_level), READONLY, "The number of nested variants wrapping the real data. " "0 if not in a variant."}, @@ -278,7 +256,7 @@ static struct PyMemberDef Dict_tp_members[] = { }; static void -Dict_tp_dealloc (Dict *self) +Dict_tp_dealloc (DBusPyDict *self) { Py_XDECREF(self->signature); self->signature = NULL; @@ -286,7 +264,7 @@ Dict_tp_dealloc (Dict *self) } static PyObject * -Dict_tp_repr(Dict *self) +Dict_tp_repr(DBusPyDict *self) { PyObject *parent_repr = (PyDict_Type.tp_repr)((PyObject *)self); PyObject *sig_repr = PyObject_Repr(self->signature); @@ -318,7 +296,7 @@ finally: static PyObject * Dict_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - Dict *self = (Dict *)(PyDict_Type.tp_new)(cls, args, kwargs); + DBusPyDict *self = (DBusPyDict *)(PyDict_Type.tp_new)(cls, args, kwargs); PyObject *variant_level = NULL; /* variant_level is immutable, so handle it in __new__ rather than @@ -328,7 +306,7 @@ Dict_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self->signature = Py_None; self->variant_level = 0; if (kwargs) { - variant_level = PyDict_GetItem(kwargs, variant_level_const); + variant_level = PyDict_GetItem(kwargs, dbus_py_variant_level_const); } if (variant_level) { self->variant_level = PyInt_AsLong(variant_level); @@ -341,9 +319,9 @@ Dict_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) } static int -Dict_tp_init(Dict *self, PyObject *args, PyObject *kwargs) +Dict_tp_init(DBusPyDict *self, PyObject *args, PyObject *kwargs) { - PyObject *obj = empty_tuple; + PyObject *obj = dbus_py_empty_tuple; PyObject *signature = NULL; PyObject *tuple; PyObject *variant_level; /* ignored here - __new__ uses it */ @@ -359,12 +337,12 @@ Dict_tp_init(Dict *self, PyObject *args, PyObject *kwargs) of type Signature (or None) */ if (!signature) signature = Py_None; if (signature == Py_None - || PyObject_IsInstance(signature, (PyObject *)&SignatureType)) { + || PyObject_IsInstance(signature, (PyObject *)&DBusPySignature_Type)) { Py_INCREF(signature); } else { - signature = PyObject_CallFunction((PyObject *)&SignatureType, "(O)", - signature); + signature = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, + "(O)", signature); if (!signature) return -1; } @@ -386,11 +364,11 @@ Dict_tp_init(Dict *self, PyObject *args, PyObject *kwargs) return 0; } -static PyTypeObject DictType = { +PyTypeObject DBusPyDict_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Dictionary", - sizeof(Dict), + sizeof(DBusPyDict), 0, (destructor)Dict_tp_dealloc, /* tp_dealloc */ 0, /* tp_print */ @@ -430,10 +408,6 @@ static PyTypeObject DictType = { /* Struct =========================================================== */ -static PyTypeObject StructType; - -DEFINE_CHECK(Struct) - PyDoc_STRVAR(Struct_tp_doc, "An structure containing items of possibly distinct types.\n" "\n" @@ -468,11 +442,11 @@ Struct_tp_repr(PyObject *self) PyObject *my_repr = NULL; if (!parent_repr) goto finally; - sig = PyObject_GetAttr(self, signature_const); + sig = PyObject_GetAttr(self, dbus_py_signature_const); if (!sig) goto finally; sig_repr = PyObject_Repr(sig); if (!sig_repr) goto finally; - vl_obj = PyObject_GetAttr(self, variant_level_const); + vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) goto finally; variant_level = PyInt_AsLong(vl_obj); if (variant_level > 0) { @@ -509,7 +483,7 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes exactly one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|OO!:__new__", argnames, &signature, &PyInt_Type, &variantness)) { @@ -528,7 +502,7 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) return NULL; } - if (PyObject_GenericSetAttr(self, variant_level_const, variantness) < 0) { + if (PyObject_GenericSetAttr(self, dbus_py_variant_level_const, variantness) < 0) { Py_DECREF(self); return NULL; } @@ -537,19 +511,19 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) of type Signature (or None) */ if (!signature) signature = Py_None; if (signature == Py_None - || PyObject_IsInstance(signature, (PyObject *)&SignatureType)) { + || PyObject_IsInstance(signature, (PyObject *)&DBusPySignature_Type)) { Py_INCREF(signature); } else { - signature = PyObject_CallFunction((PyObject *)&SignatureType, "(O)", - signature); + signature = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, + "(O)", signature); if (!signature) { Py_DECREF(self); return NULL; } } - if (PyObject_GenericSetAttr(self, signature_const, signature) < 0) { + if (PyObject_GenericSetAttr(self, dbus_py_signature_const, signature) < 0) { Py_DECREF(self); Py_DECREF(signature); return NULL; @@ -558,7 +532,7 @@ Struct_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) return self; } -static PyTypeObject StructType = { +PyTypeObject DBusPyStruct_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Struct", @@ -603,24 +577,21 @@ static PyTypeObject StructType = { static inline int init_container_types(void) { - signature_const = PyString_InternFromString("signature"); - if (!signature_const) return 0; - - ArrayType.tp_base = &PyList_Type; - if (PyType_Ready(&ArrayType) < 0) return 0; - ArrayType.tp_print = NULL; - - DictType.tp_base = &PyDict_Type; - if (PyType_Ready(&DictType) < 0) return 0; - DictType.tp_print = NULL; - - StructType.tp_basicsize = PyTuple_Type.tp_basicsize - + 2*sizeof(PyObject *) - 1; - StructType.tp_basicsize /= sizeof(PyObject *); - StructType.tp_basicsize *= sizeof(PyObject *); - StructType.tp_base = &PyTuple_Type; - if (PyType_Ready(&StructType) < 0) return 0; - StructType.tp_print = NULL; + DBusPyArray_Type.tp_base = &PyList_Type; + if (PyType_Ready(&DBusPyArray_Type) < 0) return 0; + DBusPyArray_Type.tp_print = NULL; + + DBusPyDict_Type.tp_base = &PyDict_Type; + if (PyType_Ready(&DBusPyDict_Type) < 0) return 0; + DBusPyDict_Type.tp_print = NULL; + + DBusPyStruct_Type.tp_basicsize = PyTuple_Type.tp_basicsize + + 2*sizeof(PyObject *) - 1; + DBusPyStruct_Type.tp_basicsize /= sizeof(PyObject *); + DBusPyStruct_Type.tp_basicsize *= sizeof(PyObject *); + DBusPyStruct_Type.tp_base = &PyTuple_Type; + if (PyType_Ready(&DBusPyStruct_Type) < 0) return 0; + DBusPyStruct_Type.tp_print = NULL; return 1; } @@ -628,17 +599,17 @@ init_container_types(void) static inline int insert_container_types(PyObject *this_module) { - Py_INCREF(&ArrayType); + Py_INCREF(&DBusPyArray_Type); if (PyModule_AddObject(this_module, "Array", - (PyObject *)&ArrayType) < 0) return 0; + (PyObject *)&DBusPyArray_Type) < 0) return 0; - Py_INCREF(&DictType); + Py_INCREF(&DBusPyDict_Type); if (PyModule_AddObject(this_module, "Dictionary", - (PyObject *)&DictType) < 0) return 0; + (PyObject *)&DBusPyDict_Type) < 0) return 0; - Py_INCREF(&StructType); + Py_INCREF(&DBusPyStruct_Type); if (PyModule_AddObject(this_module, "Struct", - (PyObject *)&StructType) < 0) return 0; + (PyObject *)&DBusPyStruct_Type) < 0) return 0; return 1; } diff --git a/_dbus_bindings/dbus_bindings-internal.h b/_dbus_bindings/dbus_bindings-internal.h index eace329..77190df 100644 --- a/_dbus_bindings/dbus_bindings-internal.h +++ b/_dbus_bindings/dbus_bindings-internal.h @@ -35,9 +35,15 @@ #undef USING_DBG /* #define USING_DBG */ +#define DEFINE_CHECK(type) \ +static inline int type##_Check (PyObject *o) \ +{ \ + return (PyObject_TypeCheck (o, &type##_Type)); \ +} + /* conn.c */ -extern PyTypeObject DBusPyConnectionType; -#define DBusPyConnection_Check(o) PyObject_TypeCheck(o, &DBusPyConnectionType) +extern PyTypeObject DBusPyConnection_Type; +DEFINE_CHECK(DBusPyConnection) extern PyObject *DBusPyConnection_NewConsumingDBusConnection(PyTypeObject *, DBusConnection *, PyObject *); @@ -51,17 +57,52 @@ extern dbus_bool_t dbus_py_insert_bus_types(PyObject *this_module); /* exceptions.c */ extern PyObject *DBusPyException; extern PyObject *DBusPyException_ConsumeError(DBusError *error); +extern dbus_bool_t dbus_py_init_exception_types(void); +extern dbus_bool_t dbus_py_insert_exception_types(PyObject *this_module); + +/* types */ +extern PyTypeObject DBusPyBoolean_Type; +DEFINE_CHECK(DBusPyBoolean) +extern PyTypeObject DBusPyObjectPath_Type, DBusPySignature_Type; +DEFINE_CHECK(DBusPyObjectPath) +DEFINE_CHECK(DBusPySignature) +extern PyTypeObject DBusPyArray_Type, DBusPyDict_Type, DBusPyStruct_Type; +DEFINE_CHECK(DBusPyArray) +DEFINE_CHECK(DBusPyDict) +DEFINE_CHECK(DBusPyStruct) +extern PyTypeObject DBusPyByte_Type, DBusPyByteArray_Type; +DEFINE_CHECK(DBusPyByteArray) +DEFINE_CHECK(DBusPyByte) +extern PyTypeObject DBusPyUTF8String_Type, DBusPyString_Type; +DEFINE_CHECK(DBusPyUTF8String) +DEFINE_CHECK(DBusPyString) +extern PyTypeObject DBusPyDouble_Type; +DEFINE_CHECK(DBusPyDouble) +extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type; +DEFINE_CHECK(DBusPyInt16) +DEFINE_CHECK(DBusPyUInt16) +extern PyTypeObject DBusPyInt32_Type, DBusPyUInt32_Type; +DEFINE_CHECK(DBusPyInt32) +DEFINE_CHECK(DBusPyUInt32) +extern PyTypeObject DBusPyInt64_Type, DBusPyUInt64_Type; +DEFINE_CHECK(DBusPyInt64) +DEFINE_CHECK(DBusPyUInt64) /* generic */ extern void dbus_py_take_gil_and_xdecref(PyObject *); +extern PyObject *dbus_py_empty_tuple; /* message.c */ extern DBusMessage *DBusPyMessage_BorrowDBusMessage(PyObject *msg); extern PyObject *DBusPyMessage_ConsumeDBusMessage(DBusMessage *); +extern dbus_bool_t dbus_py_init_message_types(void); +extern dbus_bool_t dbus_py_insert_message_types(PyObject *this_module); /* pending-call.c */ extern PyObject *DBusPyPendingCall_ConsumeDBusPendingCall(DBusPendingCall *, PyObject *); +extern dbus_bool_t dbus_py_init_pending_call(void); +extern dbus_bool_t dbus_py_insert_pending_call(PyObject *this_module); /* mainloop.c */ extern dbus_bool_t dbus_py_set_up_connection(PyObject *conn, diff --git a/_dbus_bindings/exceptions-impl.h b/_dbus_bindings/exceptions.c index 690f402..ffe8fe9 100644 --- a/_dbus_bindings/exceptions-impl.h +++ b/_dbus_bindings/exceptions.c @@ -22,6 +22,8 @@ * */ +#include "dbus_bindings-internal.h" + PyObject *DBusPyException; PyDoc_STRVAR(DBusException__doc__, "Represents any D-Bus-related error."); @@ -34,17 +36,8 @@ DBusPyException_ConsumeError(DBusError *error) return NULL; } -static inline PyObject * -DBusException_UnusableMessage(void) -{ - PyErr_SetString(DBusPyException, - "Message object is uninitialized, or has become unusable " - "due to error while appending arguments"); - return NULL; -} - -static inline int -init_exception_types(void) +dbus_bool_t +dbus_py_init_exception_types(void) { PyObject *docstring; @@ -59,8 +52,8 @@ init_exception_types(void) return 1; } -static inline int -insert_exception_types(PyObject *this_module) +dbus_bool_t +dbus_py_insert_exception_types(PyObject *this_module) { if (PyModule_AddObject(this_module, "DBusException", DBusPyException) < 0) { return 0; diff --git a/_dbus_bindings/floattypes-impl.h b/_dbus_bindings/floattypes-impl.h index c7100df..0864be8 100644 --- a/_dbus_bindings/floattypes-impl.h +++ b/_dbus_bindings/floattypes-impl.h @@ -22,16 +22,6 @@ * */ -static PyTypeObject DoubleType; -#ifdef WITH_DBUS_FLOAT32 -static PyTypeObject FloatType; -#endif - -DEFINE_CHECK(Double) -#ifdef WITH_DBUS_FLOAT32 -DEFINE_CHECK(Float) -#endif - PyDoc_STRVAR(Double_tp_doc, "A double-precision floating point number (a subtype of float)."); @@ -40,7 +30,7 @@ PyDoc_STRVAR(Float_tp_doc, "A single-precision floating point number (a subtype of float)."); #endif -static PyTypeObject DoubleType = { +PyTypeObject DBusPyDouble_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Double", @@ -84,7 +74,7 @@ static PyTypeObject DoubleType = { #ifdef WITH_DBUS_FLOAT32 -static PyTypeObject FloatType = { +PyTypeObject DBusPyFloat_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Float", @@ -130,14 +120,14 @@ static PyTypeObject FloatType = { static inline int init_float_types(void) { - DoubleType.tp_base = &DBusPythonFloatType; - if (PyType_Ready(&DoubleType) < 0) return 0; - DoubleType.tp_print = NULL; + DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type; + if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0; + DBusPyDouble_Type.tp_print = NULL; #ifdef WITH_DBUS_FLOAT32 - FloatType.tp_base = &DBusPythonFloatType; - if (PyType_Ready(&FloatType) < 0) return 0; - FloatType.tp_print = NULL; + DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type; + if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0; + DBusPyFloat_Type.tp_print = NULL; #endif return 1; @@ -146,13 +136,13 @@ init_float_types(void) static inline int insert_float_types(PyObject *this_module) { - Py_INCREF(&DoubleType); + Py_INCREF(&DBusPyDouble_Type); if (PyModule_AddObject(this_module, "Double", - (PyObject *)&DoubleType) < 0) return 0; + (PyObject *)&DBusPyDouble_Type) < 0) return 0; #ifdef WITH_DBUS_FLOAT32 - Py_INCREF(&FloatType); + Py_INCREF(&DBusPyFloat_Type); if (PyModule_AddObject(this_module, "Float", - (PyObject *)&FloatType) < 0) return 0; + (PyObject *)&DBusPyFloat_Type) < 0) return 0; #endif return 1; diff --git a/_dbus_bindings/generic-impl.h b/_dbus_bindings/generic-impl.h index cae3f43..362d5e3 100644 --- a/_dbus_bindings/generic-impl.h +++ b/_dbus_bindings/generic-impl.h @@ -23,14 +23,7 @@ * */ -#define DEFINE_CHECK(type) \ -static inline int type##_Check (PyObject *o) \ -{ \ - return (o->ob_type == &type##Type) \ - || PyObject_IsInstance(o, (PyObject *)&type##Type); \ -} - -static PyObject *empty_tuple = NULL; +PyObject *dbus_py_empty_tuple = NULL; static PyObject * Glue_tp_richcompare_by_pointer(PyObject *self, @@ -77,8 +70,8 @@ dbus_py_take_gil_and_xdecref(PyObject *obj) static inline int init_generic(void) { - empty_tuple = PyTuple_New(0); - if (!empty_tuple) return 0; + dbus_py_empty_tuple = PyTuple_New(0); + if (!dbus_py_empty_tuple) return 0; return 1; } diff --git a/_dbus_bindings/mainloop-impl.h b/_dbus_bindings/mainloop-impl.h index 9242154..2b7bcb9 100644 --- a/_dbus_bindings/mainloop-impl.h +++ b/_dbus_bindings/mainloop-impl.h @@ -29,7 +29,7 @@ PyDoc_STRVAR(Watch_tp_doc, "Cannot be instantiated from Python.\n" ); -static PyTypeObject WatchType; +static PyTypeObject Watch_Type; DEFINE_CHECK(Watch) @@ -139,7 +139,7 @@ Watch_BorrowFromDBusWatch(DBusWatch *watch, PyObject *mainloop) return NULL; } - self = PyObject_New(Watch, &WatchType); + self = PyObject_New(Watch, &Watch_Type); if (!self) { return NULL; } @@ -168,7 +168,7 @@ static void Watch_tp_dealloc(PyObject *self) PyObject_Del(self); } -static PyTypeObject WatchType = { +static PyTypeObject Watch_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "_dbus_bindings.Watch", @@ -218,7 +218,7 @@ PyDoc_STRVAR(Timeout_tp_doc, "Cannot be instantiated from Python.\n" ); -static PyTypeObject TimeoutType; +static PyTypeObject Timeout_Type; DEFINE_CHECK(Timeout) @@ -295,7 +295,7 @@ Timeout_BorrowFromDBusTimeout(DBusTimeout *timeout, PyObject *mainloop) return NULL; } - self = PyObject_New(Timeout, &TimeoutType); + self = PyObject_New(Timeout, &Timeout_Type); if (!self) { return NULL; } @@ -322,7 +322,7 @@ static void Timeout_tp_dealloc(PyObject *self) PyObject_Del(self); } -static PyTypeObject TimeoutType = { +static PyTypeObject Timeout_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "_dbus_bindings.Timeout", @@ -372,7 +372,7 @@ PyDoc_STRVAR(NativeMainLoop_tp_doc, "Cannot be instantiated directly.\n" ); -static PyTypeObject NativeMainLoopType; +static PyTypeObject NativeMainLoop_Type; DEFINE_CHECK(NativeMainLoop) @@ -394,7 +394,7 @@ static void NativeMainLoop_tp_dealloc(NativeMainLoop *self) PyObject_Del((PyObject *)self); } -static PyTypeObject NativeMainLoopType = { +static PyTypeObject NativeMainLoop_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.mainloop.NativeMainLoop", @@ -544,7 +544,7 @@ DBusPyNativeMainLoop_New4(dbus_bool_t (*conn_cb)(DBusConnection *, void *), void (*free_cb)(void *), void *data) { - NativeMainLoop *self = PyObject_New(NativeMainLoop, &NativeMainLoopType); + NativeMainLoop *self = PyObject_New(NativeMainLoop, &NativeMainLoop_Type); if (self) { self->data = data; self->free_cb = free_cb; @@ -572,9 +572,9 @@ init_mainloop (void) { default_main_loop = NULL; - if (PyType_Ready (&WatchType) < 0) return 0; - if (PyType_Ready (&TimeoutType) < 0) return 0; - if (PyType_Ready (&NativeMainLoopType) < 0) return 0; + if (PyType_Ready (&Watch_Type) < 0) return 0; + if (PyType_Ready (&Timeout_Type) < 0) return 0; + if (PyType_Ready (&NativeMainLoop_Type) < 0) return 0; /* placate -Wunused */ (void)&Watch_BorrowFromDBusWatch; @@ -593,11 +593,11 @@ insert_mainloop_types (PyObject *this_module) if (!null_main_loop) return 0; if (PyModule_AddObject (this_module, "Watch", - (PyObject *)&WatchType) < 0) return 0; + (PyObject *)&Watch_Type) < 0) return 0; if (PyModule_AddObject (this_module, "Timeout", - (PyObject *)&TimeoutType) < 0) return 0; + (PyObject *)&Timeout_Type) < 0) return 0; if (PyModule_AddObject (this_module, "NativeMainLoop", - (PyObject *)&NativeMainLoopType) < 0) return 0; + (PyObject *)&NativeMainLoop_Type) < 0) return 0; if (PyModule_AddObject (this_module, "NULL_MAIN_LOOP", null_main_loop) < 0) return 0; return 1; diff --git a/_dbus_bindings/message-append-impl.h b/_dbus_bindings/message-append-impl.h index 8367f65..2f36670 100644 --- a/_dbus_bindings/message-append-impl.h +++ b/_dbus_bindings/message-append-impl.h @@ -23,29 +23,31 @@ * */ +#include "types-internal.h" + /* Return the number of variants wrapping the given object. Return 0 * if the object is not a D-Bus type. */ static long get_variant_level(PyObject *obj) { - if (DBusPythonInt_Check(obj)) { - return ((DBusPythonInt *)obj)->variant_level; + if (DBusPyIntBase_Check(obj)) { + return ((DBusPyIntBase *)obj)->variant_level; } - else if (DBusPythonFloat_Check(obj)) { - return ((DBusPythonFloat *)obj)->variant_level; + else if (DBusPyFloatBase_Check(obj)) { + return ((DBusPyFloatBase *)obj)->variant_level; } - else if (Array_Check(obj)) { - return ((Array *)obj)->variant_level; + else if (DBusPyArray_Check(obj)) { + return ((DBusPyArray *)obj)->variant_level; } - else if (Dict_Check(obj)) { - return ((Dict *)obj)->variant_level; + else if (DBusPyDict_Check(obj)) { + return ((DBusPyDict *)obj)->variant_level; } - else if (DBusPythonLong_Check(obj) || - DBusPythonString_Check(obj) || - String_Check(obj) || - Struct_Check(obj)) { - return PyInt_AsLong(PyObject_GetAttr(obj, variant_level_const)); + else if (DBusPyLongBase_Check(obj) || + DBusPyStrBase_Check(obj) || + DBusPyString_Check(obj) || + DBusPyStruct_Check(obj)) { + return PyInt_AsLong(PyObject_GetAttr(obj, dbus_py_variant_level_const)); } else { return 0; @@ -128,25 +130,25 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) return PyString_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); } else if (PyInt_Check(obj)) { - if (Int16_Check(obj)) + if (DBusPyInt16_Check(obj)) return PyString_FromString(DBUS_TYPE_INT16_AS_STRING); - else if (Int32_Check(obj)) + else if (DBusPyInt32_Check(obj)) return PyString_FromString(DBUS_TYPE_INT32_AS_STRING); - else if (Byte_Check(obj)) + else if (DBusPyByte_Check(obj)) return PyString_FromString(DBUS_TYPE_BYTE_AS_STRING); - else if (UInt16_Check(obj)) + else if (DBusPyUInt16_Check(obj)) return PyString_FromString(DBUS_TYPE_UINT16_AS_STRING); - else if (Boolean_Check(obj)) + else if (DBusPyBoolean_Check(obj)) return PyString_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); else return PyString_FromString(DBUS_TYPE_INT32_AS_STRING); } else if (PyLong_Check(obj)) { - if (Int64_Check(obj)) + if (DBusPyInt64_Check(obj)) return PyString_FromString(DBUS_TYPE_INT64_AS_STRING); - else if (UInt32_Check (obj)) + else if (DBusPyUInt32_Check (obj)) return PyString_FromString(DBUS_TYPE_UINT32_AS_STRING); - else if (UInt64_Check (obj)) + else if (DBusPyUInt64_Check (obj)) return PyString_FromString(DBUS_TYPE_UINT64_AS_STRING); else return PyString_FromString(DBUS_TYPE_INT64_AS_STRING); @@ -155,20 +157,20 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) return PyString_FromString(DBUS_TYPE_STRING_AS_STRING); else if (PyFloat_Check(obj)) { #ifdef WITH_DBUS_FLOAT32 - if (Double_Check(obj)) + if (DBusPyDouble_Check(obj)) return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING); - else if (Float_Check(obj)) + else if (DBusPyFloat_Check(obj)) return PyString_FromString(DBUS_TYPE_FLOAT_AS_STRING); else #endif return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING); } else if (PyString_Check(obj)) { - if (ObjectPath_Check(obj)) + if (DBusPyObjectPath_Check(obj)) return PyString_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); - else if (Signature_Check(obj)) + else if (DBusPySignature_Check(obj)) return PyString_FromString(DBUS_TYPE_SIGNATURE_AS_STRING); - else if (ByteArray_Check(obj)) + else if (DBusPyByteArray_Check(obj)) return PyString_FromString(DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING); else @@ -238,8 +240,8 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) PyObject *tmp; PyObject *ret = PyString_FromString(DBUS_TYPE_ARRAY_AS_STRING); if (!ret) return NULL; - if (Array_Check(obj) && PyString_Check(((Array *)obj)->signature)) { - PyString_Concat(&ret, ((Array *)obj)->signature); + if (DBusPyArray_Check(obj) && PyString_Check(((DBusPyArray *)obj)->signature)) { + PyString_Concat(&ret, ((DBusPyArray *)obj)->signature); return ret; } if (PyList_GET_SIZE(obj) == 0) { @@ -259,8 +261,8 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) int pos = 0; PyObject *ret = NULL; - if (Dict_Check(obj) && PyString_Check(((Dict *)obj)->signature)) { - const char *sig = PyString_AS_STRING(((Dict *)obj)->signature); + if (DBusPyDict_Check(obj) && PyString_Check(((DBusPyDict *)obj)->signature)) { + const char *sig = PyString_AS_STRING(((DBusPyDict *)obj)->signature); return PyString_FromFormat((DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING @@ -323,7 +325,7 @@ Message_guess_signature(PyObject *unused UNUSED, PyObject *args) /* if there were no args, easy */ if (PyTuple_GET_SIZE(args) == 0) { DBG("%s", "Message_guess_signature: no args, so return Signature('')"); - return PyObject_CallFunction((PyObject *)&SignatureType, "(s)", ""); + return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", ""); } /* if there were args, the signature we want is, by construction, @@ -341,7 +343,7 @@ Message_guess_signature(PyObject *unused UNUSED, PyObject *args) Py_DECREF(tmp); return NULL; } - ret = PyObject_CallFunction((PyObject *)&SignatureType, "(s#)", + ret = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s#)", PyString_AS_STRING (tmp) + 1, PyString_GET_SIZE (tmp) - 2); DBG("Message_guess_signature: returning Signature at %p \"%s\"", ret, @@ -787,7 +789,7 @@ _message_iter_append_pyobject(DBusMessageIter *appender, /* The integer types are all basically the same - we delegate to intNN_range_check() */ #define PROCESS_INTEGER(size) \ - u.size = size##_range_check (obj);\ + u.size = dbus_py_##size##_range_check (obj);\ if (u.size == (dbus_##size##_t)(-1) && PyErr_Occurred()) {\ ret = -1; \ break; \ @@ -921,7 +923,7 @@ Message_append(Message *self, PyObject *args, PyObject *kwargs) #endif /* only use kwargs for this step: deliberately ignore args for now */ - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, "|z:append", + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|z:append", argnames, &signature)) return NULL; if (!signature) { diff --git a/_dbus_bindings/message-get-args-impl.h b/_dbus_bindings/message-get-args-impl.h index 28cc038..f3db0be 100644 --- a/_dbus_bindings/message-get-args-impl.h +++ b/_dbus_bindings/message-get-args-impl.h @@ -23,6 +23,8 @@ * */ +#include "types-internal.h" + PyDoc_STRVAR(Message_get_args_list__doc__, "get_args_list(**kwargs) -> list\n\n" "Return the message's arguments. Keyword arguments control the translation\n" @@ -85,8 +87,7 @@ _message_iter_append_all_to_list(DBusMessageIter *iter, PyObject *list, #ifdef USING_DBG fprintf(stderr, "DBG/%ld: appending to list: %p == ", (long)getpid(), item); PyObject_Print(item, stderr, 0); - fprintf(stderr, " of type %p (Byte is %p)\n", item->ob_type, - &ByteType); + fprintf(stderr, " of type %p\n", item->ob_type); #endif ret = PyList_Append(list, item); Py_DECREF(item); @@ -113,15 +114,15 @@ _message_iter_get_dict(DBusMessageIter *iter, PyObject *ret; int status; - sig = PyObject_CallFunction((PyObject *)&SignatureType, + sig = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s#)", sig_str+2, strlen(sig_str)-3); - status = PyDict_SetItem(kwargs, signature_const, sig); + status = PyDict_SetItem(kwargs, dbus_py_signature_const, sig); Py_DECREF(sig); if (status < 0) { return NULL; } - ret = PyObject_Call((PyObject *)&DictType, empty_tuple, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyDict_Type, dbus_py_empty_tuple, kwargs); if (!ret) { return NULL; } @@ -205,7 +206,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, Py_DECREF(variant_level_int); return NULL; } - if (PyDict_SetItem(kwargs, variant_level_const, + if (PyDict_SetItem(kwargs, dbus_py_variant_level_const, variant_level_int) < 0) { Py_DECREF(variant_level_int); Py_DECREF(kwargs); @@ -224,7 +225,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, if (opts->utf8_strings) { args = Py_BuildValue("(s)", u.s); if (!args) break; - ret = PyObject_Call((PyObject *)&UTF8StringType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyUTF8String_Type, + args, kwargs); } else { args = Py_BuildValue("(O)", PyUnicode_DecodeUTF8(u.s, @@ -233,7 +235,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, if (!args) { break; } - ret = PyObject_Call((PyObject *)&StringType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyString_Type, + args, kwargs); } break; @@ -242,7 +245,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.s); args = Py_BuildValue("(s)", u.s); if (!args) break; - ret = PyObject_Call((PyObject *)&SignatureType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPySignature_Type, args, kwargs); break; case DBUS_TYPE_OBJECT_PATH: @@ -250,7 +253,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.s); args = Py_BuildValue("(s)", u.s); if (!args) break; - ret = PyObject_Call((PyObject *)&ObjectPathType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyObjectPath_Type, args, kwargs); break; case DBUS_TYPE_DOUBLE: @@ -258,7 +261,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.d); args = Py_BuildValue("(f)", u.d); if (!args) break; - ret = PyObject_Call((PyObject *)&DoubleType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyDouble_Type, args, kwargs); break; #ifdef WITH_DBUS_FLOAT32 @@ -267,7 +270,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.f); args = Py_BuildValue("(f)", (double)u.f); if (!args) break; - ret = PyObject_Call((PyObject *)&FloatType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyFloat_Type, args, kwargs); break; #endif @@ -276,7 +279,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.i16); args = Py_BuildValue("(i)", (int)u.i16); if (!args) break; - ret = PyObject_Call((PyObject *)&Int16Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyInt16_Type, args, kwargs); break; case DBUS_TYPE_UINT16: @@ -284,7 +287,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.u16); args = Py_BuildValue("(i)", (int)u.u16); if (!args) break; - ret = PyObject_Call((PyObject *)&UInt16Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyUInt16_Type, args, kwargs); break; case DBUS_TYPE_INT32: @@ -292,7 +295,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.i32); args = Py_BuildValue("(l)", (long)u.i32); if (!args) break; - ret = PyObject_Call((PyObject *)&Int32Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyInt32_Type, args, kwargs); break; case DBUS_TYPE_UINT32: @@ -300,7 +303,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.u32); args = Py_BuildValue("(k)", (unsigned long)u.u32); if (!args) break; - ret = PyObject_Call((PyObject *)&UInt32Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyUInt32_Type, args, kwargs); break; #if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) @@ -309,7 +312,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.i64); args = Py_BuildValue("(L)", (PY_LONG_LONG)u.i64); if (!args) break; - ret = PyObject_Call((PyObject *)&Int64Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyInt64_Type, args, kwargs); break; case DBUS_TYPE_UINT64: @@ -317,7 +320,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_get_basic(iter, &u.u64); args = Py_BuildValue("(K)", (unsigned PY_LONG_LONG)u.u64); if (!args) break; - ret = PyObject_Call((PyObject *)&UInt64Type, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyUInt64_Type, args, kwargs); break; #else case DBUS_TYPE_INT64: @@ -334,7 +337,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, args = Py_BuildValue("(l)", (long)u.y); if (!args) break; - ret = PyObject_Call((PyObject *)&ByteType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyByte_Type, args, kwargs); break; case DBUS_TYPE_BOOLEAN: @@ -343,7 +346,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, args = Py_BuildValue("(l)", (long)u.b); if (!args) break; - ret = PyObject_Call((PyObject *)&BooleanType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyBoolean_Type, args, kwargs); break; case DBUS_TYPE_ARRAY: @@ -370,7 +373,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, &n); args = Py_BuildValue("(s#)", u.s, n); if (!args) break; - ret = PyObject_Call((PyObject *)&ByteArrayType, args, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyByteArray_Type, + args, kwargs); } else { DBusMessageIter sub; @@ -386,14 +390,15 @@ _message_iter_get_pyobject(DBusMessageIter *iter, dbus_message_iter_recurse(iter, &sub); sig = dbus_message_iter_get_signature(&sub); if (!sig) break; - sig_obj = PyObject_CallFunction((PyObject *)&SignatureType, + sig_obj = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", sig); dbus_free(sig); if (!sig_obj) break; - status = PyDict_SetItem(kwargs, signature_const, sig_obj); + status = PyDict_SetItem(kwargs, dbus_py_signature_const, sig_obj); Py_DECREF(sig_obj); if (status < 0) break; - ret = PyObject_Call((PyObject *)&ArrayType, empty_tuple, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyArray_Type, + dbus_py_empty_tuple, kwargs); if (!ret) break; if (_message_iter_append_all_to_list(&sub, ret, opts) < 0) { Py_DECREF(ret); @@ -417,7 +422,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, } tuple = Py_BuildValue("(O)", list); if (tuple) { - ret = PyObject_Call((PyObject *)&StructType, tuple, kwargs); + ret = PyObject_Call((PyObject *)&DBusPyStruct_Type, tuple, kwargs); } else { ret = NULL; diff --git a/_dbus_bindings/message-impl.h b/_dbus_bindings/message.c index e0189a7..2310091 100644 --- a/_dbus_bindings/message-impl.h +++ b/_dbus_bindings/message.c @@ -23,6 +23,8 @@ * */ +#include "dbus_bindings-internal.h" + static PyTypeObject MessageType, SignalMessageType, ErrorMessageType; static PyTypeObject MethodReturnMessageType, MethodCallMessageType; @@ -32,6 +34,15 @@ static inline int Message_Check (PyObject *o) || PyObject_IsInstance(o, (PyObject *)&MessageType); } +static inline PyObject * +DBusException_UnusableMessage(void) +{ + PyErr_SetString(DBusPyException, + "Message object is uninitialized, or has become unusable " + "due to error while appending arguments"); + return NULL; +} + typedef struct { PyObject_HEAD DBusMessage *msg; @@ -186,8 +197,8 @@ DBusPyMessage_BorrowDBusMessage(PyObject *msg) return ((Message *)msg)->msg; } -static PyObject * -Message_ConsumeDBusMessage (DBusMessage *msg) +PyObject * +DBusPyMessage_ConsumeDBusMessage(DBusMessage *msg) { PyTypeObject *type; Message *self; @@ -209,7 +220,7 @@ Message_ConsumeDBusMessage (DBusMessage *msg) type = &MessageType; } - self = (Message *)(type->tp_new) (type, empty_tuple, NULL); + self = (Message *)(type->tp_new) (type, dbus_py_empty_tuple, NULL); if (!self) { dbus_message_unref(msg); return NULL; @@ -228,7 +239,7 @@ Message_copy (Message *self, PyObject *args UNUSED) if (!self->msg) return DBusException_UnusableMessage(); msg = dbus_message_copy(self->msg); if (!msg) return PyErr_NoMemory(); - return Message_ConsumeDBusMessage(msg); + return DBusPyMessage_ConsumeDBusMessage(msg); } PyDoc_STRVAR(Message_get_auto_start__doc__, @@ -436,7 +447,7 @@ Message_get_path (Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return PyObject_CallFunction((PyObject *)&ObjectPathType, "(s)", c_str); + return PyObject_CallFunction((PyObject *)&DBusPyObjectPath_Type, "(s)", c_str); } PyDoc_STRVAR(Message_get_path_decomposed__doc__, @@ -519,9 +530,9 @@ Message_get_signature (Message *self, PyObject *unused UNUSED) if (!self->msg) return DBusException_UnusableMessage(); c_str = dbus_message_get_signature (self->msg); if (!c_str) { - return PyObject_CallFunction((PyObject *)&SignatureType, "(s)", ""); + return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", ""); } - return PyObject_CallFunction((PyObject *)&SignatureType, "(s)", c_str); + return PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s)", c_str); } PyDoc_STRVAR(Message_has_signature__doc__, @@ -995,8 +1006,8 @@ static PyTypeObject ErrorMessageType = { 0, /* tp_new */ }; -static inline int -init_message_types(void) +dbus_bool_t +dbus_py_init_message_types(void) { if (PyType_Ready(&MessageType) < 0) return 0; @@ -1015,8 +1026,8 @@ init_message_types(void) return 1; } -static inline int -insert_message_types(PyObject *this_module) +dbus_bool_t +dbus_py_insert_message_types(PyObject *this_module) { if (PyModule_AddObject(this_module, "Message", (PyObject *)&MessageType) < 0) return 0; diff --git a/_dbus_bindings/module.c b/_dbus_bindings/module.c index 3d7d361..f9cd36f 100644 --- a/_dbus_bindings/module.c +++ b/_dbus_bindings/module.c @@ -38,15 +38,12 @@ PyDoc_STRVAR(module_doc, #include "generic-impl.h" /* Non D-Bus support code */ #include "validation-impl.h" /* Interface name, etc., validation */ -#include "exceptions-impl.h" /* Exception base classes */ #include "abstract-impl.h" /* DBusPythonInt, etc. */ #include "signature-impl.h" /* Signature and its custom iterator */ #include "types-impl.h" /* Boolean, IntNN, UIntNN, ObjectPath */ #include "floattypes-impl.h" /* Float, Double */ #include "containers-impl.h" /* Array, Dict, Variant */ #include "bytes-impl.h" /* Byte, ByteArray */ -#include "message-impl.h" /* Message and subclasses */ -#include "pending-call-impl.h" /* PendingCall */ #include "mainloop-impl.h" /* NativeMainLoop */ static PyMethodDef module_functions[] = { @@ -76,15 +73,15 @@ init_dbus_bindings(void) dbus_bindings_API[2] = (void *)NativeMainLoop_New4; if (!init_generic()) return; - if (!init_exception_types()) return; + if (!dbus_py_init_exception_types()) return; if (!init_abstract()) return; if (!init_signature()) return; if (!init_types()) return; if (!init_float_types()) return; if (!init_container_types()) return; if (!init_byte_types()) return; - if (!init_message_types()) return; - if (!init_pending_call()) return; + if (!dbus_py_init_message_types()) return; + if (!dbus_py_init_pending_call()) return; if (!init_mainloop()) return; if (!dbus_py_init_conn_types()) return; if (!dbus_py_init_bus_types()) return; @@ -92,15 +89,15 @@ init_dbus_bindings(void) this_module = Py_InitModule3("_dbus_bindings", module_functions, module_doc); if (!this_module) return; - if (!insert_exception_types(this_module)) return; + if (!dbus_py_insert_exception_types(this_module)) return; if (!insert_abstract_types(this_module)) return; if (!insert_signature(this_module)) return; if (!insert_types(this_module)) return; if (!insert_float_types(this_module)) return; if (!insert_container_types(this_module)) return; if (!insert_byte_types(this_module)) return; - if (!insert_message_types(this_module)) return; - if (!insert_pending_call(this_module)) return; + if (!dbus_py_insert_message_types(this_module)) return; + if (!dbus_py_insert_pending_call(this_module)) return; if (!insert_mainloop_types(this_module)) return; if (!dbus_py_insert_conn_types(this_module)) return; if (!dbus_py_insert_bus_types(this_module)) return; diff --git a/_dbus_bindings/pending-call-impl.h b/_dbus_bindings/pending-call.c index 25965d4..17234f1 100644 --- a/_dbus_bindings/pending-call-impl.h +++ b/_dbus_bindings/pending-call.c @@ -22,6 +22,8 @@ * */ +#include "dbus_bindings-internal.h" + PyDoc_STRVAR(PendingCall_tp_doc, "Object representing a pending D-Bus call, returned by\n" "Connection.send_message_with_reply(). Cannot be instantiated directly.\n" @@ -103,7 +105,7 @@ _pending_call_notify_function(DBusPendingCall *pc, PyErr_Warn(PyExc_UserWarning, "D-Bus notify function was called " "for an incomplete pending call (shouldn't happen)"); } else { - Message *msg_obj = (Message *)Message_ConsumeDBusMessage(msg); + PyObject *msg_obj = DBusPyMessage_ConsumeDBusMessage(msg); if (msg_obj) { PyObject *ret = PyObject_CallFunctionObjArgs(handler, msg_obj, NULL); @@ -272,15 +274,15 @@ static PyTypeObject PendingCallType = { 0, /* tp_new */ }; -static inline int -init_pending_call (void) +dbus_bool_t +dbus_py_init_pending_call (void) { if (PyType_Ready (&PendingCallType) < 0) return 0; return 1; } -static inline int -insert_pending_call (PyObject *this_module) +dbus_bool_t +dbus_py_insert_pending_call (PyObject *this_module) { if (PyModule_AddObject (this_module, "PendingCall", (PyObject *)&PendingCallType) < 0) return 0; diff --git a/_dbus_bindings/signature-impl.h b/_dbus_bindings/signature-impl.h index 1312ae6..70a4f53 100644 --- a/_dbus_bindings/signature-impl.h +++ b/_dbus_bindings/signature-impl.h @@ -43,14 +43,6 @@ PyDoc_STRVAR(Signature_tp_doc, " Signature with variant_level==2.\n" ); -static PyTypeObject SignatureType; - -static inline int Signature_Check(PyObject *o) -{ - return (o->ob_type == &SignatureType) - || PyObject_IsInstance(o, (PyObject *)&SignatureType); -} - typedef struct { PyObject_HEAD PyObject *string; @@ -76,7 +68,7 @@ SignatureIter_tp_iternext (SignatureIter *self) sig = dbus_signature_iter_get_signature(&(self->iter)); if (!sig) return PyErr_NoMemory(); - obj = PyObject_CallFunction((PyObject *)&SignatureType, "s", sig); + obj = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "s", sig); dbus_free(sig); if (!obj) return NULL; @@ -171,10 +163,10 @@ Signature_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) PyErr_SetString(PyExc_ValueError, "Corrupt type signature"); return NULL; } - return (DBusPythonStringType.tp_new)(cls, args, kwargs); + return (DBusPyStrBase_Type.tp_new)(cls, args, kwargs); } -static PyTypeObject SignatureType = { +PyTypeObject DBusPySignature_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Signature", @@ -222,9 +214,9 @@ init_signature(void) { if (PyType_Ready(&SignatureIterType) < 0) return 0; - SignatureType.tp_base = &DBusPythonStringType; - if (PyType_Ready(&SignatureType) < 0) return 0; - SignatureType.tp_print = NULL; + DBusPySignature_Type.tp_base = &DBusPyStrBase_Type; + if (PyType_Ready(&DBusPySignature_Type) < 0) return 0; + DBusPySignature_Type.tp_print = NULL; return 1; } @@ -232,9 +224,9 @@ init_signature(void) static inline int insert_signature (PyObject *this_module) { - Py_INCREF(&SignatureType); + Py_INCREF(&DBusPySignature_Type); if (PyModule_AddObject(this_module, "Signature", - (PyObject *)&SignatureType) < 0) return 0; + (PyObject *)&DBusPySignature_Type) < 0) return 0; Py_INCREF(&SignatureIterType); if (PyModule_AddObject(this_module, "_SignatureIter", (PyObject *)&SignatureIterType) < 0) return 0; diff --git a/_dbus_bindings/types-impl.h b/_dbus_bindings/types-impl.h index e4bb567..91ef2b2 100644 --- a/_dbus_bindings/types-impl.h +++ b/_dbus_bindings/types-impl.h @@ -22,16 +22,12 @@ * */ -#include <stdint.h> +#include "types-internal.h" /* Specific types =================================================== */ /* Boolean, a subclass of DBusPythonInt ============================= */ -static PyTypeObject BooleanType; - -DEFINE_CHECK(Boolean) - PyDoc_STRVAR(Boolean_tp_doc, "A boolean, represented as a subtype of `int` (not `bool`, because `bool`\n" "cannot be subclassed).\n" @@ -70,7 +66,7 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) } tuple = Py_BuildValue("(i)", PyObject_IsTrue(value) ? 1 : 0); if (!tuple) return NULL; - self = (DBusPythonIntType.tp_new)(cls, tuple, kwargs); + self = (DBusPyIntBase_Type.tp_new)(cls, tuple, kwargs); Py_DECREF(tuple); return self; } @@ -78,7 +74,7 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) static PyObject * Boolean_tp_repr (PyObject *self) { - long variant_level = ((DBusPythonInt *)self)->variant_level; + long variant_level = ((DBusPyIntBase *)self)->variant_level; if (variant_level > 0) { return PyString_FromFormat("%s(%s, variant_level=%ld)", self->ob_type->tp_name, @@ -90,7 +86,7 @@ Boolean_tp_repr (PyObject *self) PyInt_AsLong(self) ? "True" : "False"); } -static PyTypeObject BooleanType = { +PyTypeObject DBusPyBoolean_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Boolean", @@ -122,7 +118,7 @@ static PyTypeObject BooleanType = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonInt_Type), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -134,10 +130,6 @@ static PyTypeObject BooleanType = { /* Int16 ============================================================ */ -static PyTypeObject Int16Type; - -DEFINE_CHECK(Int16) - PyDoc_STRVAR(Int16_tp_doc, "A signed 16-bit integer between -0x8000 and +0x7FFF, represented as\n" "a subtype of `int`.\n" @@ -159,8 +151,8 @@ PyDoc_STRVAR(Int16_tp_doc, " Int16 with variant_level==2.\n" ); -static dbus_int16_t -int16_range_check(PyObject *obj) +dbus_int16_t +dbus_py_int16_range_check(PyObject *obj) { long i = PyInt_AsLong (obj); if (i == -1 && PyErr_Occurred ()) return -1; @@ -175,15 +167,15 @@ int16_range_check(PyObject *obj) static PyObject * Int16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (DBusPythonIntType.tp_new)(cls, args, kwargs); - if (self && int16_range_check(self) == -1 && PyErr_Occurred()) { + PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_int16_range_check(self) == -1 && PyErr_Occurred()) { Py_DECREF(self); return NULL; } return self; } -static PyTypeObject Int16Type = { +PyTypeObject DBusPyInt16_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Int16", @@ -215,7 +207,7 @@ static PyTypeObject Int16Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonIntType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -227,10 +219,6 @@ static PyTypeObject Int16Type = { /* UInt16 =========================================================== */ -static PyTypeObject UInt16Type; - -DEFINE_CHECK(UInt16) - PyDoc_STRVAR(UInt16_tp_doc, "An unsigned 16-bit integer between 0 and 0xFFFF, represented as\n" "a subtype of `int`.\n" @@ -252,8 +240,8 @@ PyDoc_STRVAR(UInt16_tp_doc, " UInt16 with variant_level==2.\n" ); -static dbus_uint16_t -uint16_range_check(PyObject *obj) +dbus_uint16_t +dbus_py_uint16_range_check(PyObject *obj) { long i = PyInt_AsLong(obj); if (i == -1 && PyErr_Occurred()) return (dbus_uint16_t)(-1); @@ -268,8 +256,8 @@ uint16_range_check(PyObject *obj) static PyObject * UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (DBusPythonIntType.tp_new)(cls, args, kwargs); - if (self && uint16_range_check(self) == (dbus_uint16_t)(-1) + PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_uint16_range_check(self) == (dbus_uint16_t)(-1) && PyErr_Occurred()) { Py_DECREF (self); return NULL; @@ -277,7 +265,7 @@ UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return self; } -static PyTypeObject UInt16Type = { +PyTypeObject DBusPyUInt16_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.UInt16", @@ -309,7 +297,7 @@ static PyTypeObject UInt16Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonIntType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -321,10 +309,6 @@ static PyTypeObject UInt16Type = { /* Int32 ============================================================ */ -static PyTypeObject Int32Type; - -DEFINE_CHECK(Int32) - PyDoc_STRVAR(Int32_tp_doc, "A signed 32-bit integer between -0x8000 0000 and +0x7FFF FFFF, represented as\n" "a subtype of `int`.\n" @@ -346,8 +330,8 @@ PyDoc_STRVAR(Int32_tp_doc, " Int32 with variant_level==2.\n" ); -static dbus_int32_t -int32_range_check(PyObject *obj) +dbus_int32_t +dbus_py_int32_range_check(PyObject *obj) { long i = PyInt_AsLong(obj); if (i == -1 && PyErr_Occurred()) return -1; @@ -362,15 +346,15 @@ int32_range_check(PyObject *obj) static PyObject * Int32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (DBusPythonIntType.tp_new)(cls, args, kwargs); - if (self && int32_range_check(self) == -1 && PyErr_Occurred()) { + PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_int32_range_check(self) == -1 && PyErr_Occurred()) { Py_DECREF(self); return NULL; } return self; } -static PyTypeObject Int32Type = { +PyTypeObject DBusPyInt32_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Int32", @@ -402,7 +386,7 @@ static PyTypeObject Int32Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonIntType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -414,10 +398,6 @@ static PyTypeObject Int32Type = { /* UInt32 =========================================================== */ -static PyTypeObject UInt32Type; - -DEFINE_CHECK(UInt32) - PyDoc_STRVAR(UInt32_tp_doc, "An unsigned 32-bit integer between 0 and 0xFFFF FFFF, represented as a\n" "subtype of `long`.\n" @@ -442,8 +422,8 @@ PyDoc_STRVAR(UInt32_tp_doc, " UInt32 with variant_level==2.\n" ); -static dbus_uint32_t -uint32_range_check(PyObject *obj) +dbus_uint32_t +dbus_py_uint32_range_check(PyObject *obj) { unsigned long i; PyObject *long_obj = PyNumber_Long(obj); @@ -467,8 +447,8 @@ uint32_range_check(PyObject *obj) static PyObject * UInt32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (DBusPythonLongType.tp_new)(cls, args, kwargs); - if (self && uint32_range_check(self) == (dbus_uint32_t)(-1) + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_uint32_range_check(self) == (dbus_uint32_t)(-1) && PyErr_Occurred()) { Py_DECREF(self); return NULL; @@ -476,7 +456,7 @@ UInt32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return self; } -static PyTypeObject UInt32Type = { +PyTypeObject DBusPyUInt32_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.UInt32", @@ -508,7 +488,7 @@ static PyTypeObject UInt32Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonLongType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -520,16 +500,6 @@ static PyTypeObject UInt32Type = { /* Int64 =========================================================== */ -#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) -# define DBUS_PYTHON_64_BIT_WORKS 1 -#else -# undef DBUS_PYTHON_64_BIT_WORKS -#endif /* defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) */ - -static PyTypeObject Int64Type; - -DEFINE_CHECK(Int64) - PyDoc_STRVAR(Int64_tp_doc, "A signed 64-bit integer between -0x8000 0000 0000 0000 and\n" "+0x7FFF FFFF FFFF FFFF, represented as a subtype of `long`.\n" @@ -565,8 +535,8 @@ PyDoc_STRVAR(Int64_tp_doc, ); #ifdef DBUS_PYTHON_64_BIT_WORKS -static dbus_int64_t -int64_range_check(PyObject *obj) +dbus_int64_t +dbus_py_int64_range_check(PyObject *obj) { PY_LONG_LONG i; PyObject *long_obj = PyNumber_Long(obj); @@ -591,8 +561,8 @@ static PyObject * Int64_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { #ifdef DBUS_PYTHON_64_BIT_WORKS - PyObject *self = (DBusPythonLongType.tp_new)(cls, args, kwargs); - if (self && int64_range_check(self) == -1 && PyErr_Occurred()) { + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_int64_range_check(self) == -1 && PyErr_Occurred()) { Py_DECREF(self); return NULL; } @@ -604,7 +574,7 @@ Int64_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) #endif } -static PyTypeObject Int64Type = { +PyTypeObject DBusPyInt64_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.Int64", @@ -636,7 +606,7 @@ static PyTypeObject Int64Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonLongType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -648,10 +618,6 @@ static PyTypeObject Int64Type = { /* UInt64 =========================================================== */ -static PyTypeObject UInt64Type; - -DEFINE_CHECK(UInt64) - PyDoc_STRVAR(UInt64_tp_doc, "An unsigned 64-bit integer between 0 and 0xFFFF FFFF FFFF FFFF,\n" "represented as a subtype of `long`.\n" @@ -680,8 +646,8 @@ PyDoc_STRVAR(UInt64_tp_doc, " UInt64 with variant_level==2.\n" ); -static dbus_uint64_t -uint64_range_check(PyObject *obj) +dbus_uint64_t +dbus_py_uint64_range_check(PyObject *obj) { unsigned PY_LONG_LONG i; PyObject *long_obj = PyNumber_Long(obj); @@ -705,8 +671,8 @@ static PyObject * UInt64_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) { #ifdef DBUS_PYTHON_64_BIT_WORKS - PyObject *self = (DBusPythonLongType.tp_new)(cls, args, kwargs); - if (self && uint64_range_check(self) == (dbus_uint64_t)(-1) + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); + if (self && dbus_py_uint64_range_check(self) == (dbus_uint64_t)(-1) && PyErr_Occurred()) { Py_DECREF(self); return NULL; @@ -719,7 +685,7 @@ UInt64_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs) #endif } -static PyTypeObject UInt64Type = { +PyTypeObject DBusPyUInt64_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.UInt64", @@ -751,7 +717,7 @@ static PyTypeObject UInt64Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonLongType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -763,10 +729,6 @@ static PyTypeObject UInt64Type = { /* UTF-8 string representation ====================================== */ -static PyTypeObject UTF8StringType; - -DEFINE_CHECK(UTF8String) - PyDoc_STRVAR(UTF8String_tp_doc, "A string represented using UTF-8 - a subtype of `str`.\n" "\n" @@ -798,10 +760,10 @@ UTF8String_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) unicode = PyUnicode_DecodeUTF8(str, strlen(str), NULL); if (!unicode) return NULL; Py_DECREF(unicode); - return (DBusPythonStringType.tp_new)(cls, args, kwargs); + return (DBusPyStrBase_Type.tp_new)(cls, args, kwargs); } -static PyTypeObject UTF8StringType = { +PyTypeObject DBusPyUTF8String_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.UTF8String", @@ -833,7 +795,7 @@ static PyTypeObject UTF8StringType = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonStringType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyStrBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -845,10 +807,6 @@ static PyTypeObject UTF8StringType = { /* Object path ====================================================== */ -static PyTypeObject ObjectPathType; - -DEFINE_CHECK(ObjectPath) - PyDoc_STRVAR(ObjectPath_tp_doc, "A D-Bus object path, such as '/com/example/MyApp/Documents/abc'.\n" "\n" @@ -879,10 +837,10 @@ ObjectPath_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (!dbus_py_validate_object_path(str)) { return NULL; } - return (DBusPythonStringType.tp_new)(cls, args, kwargs); + return (DBusPyStrBase_Type.tp_new)(cls, args, kwargs); } -static PyTypeObject ObjectPathType = { +PyTypeObject DBusPyObjectPath_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.ObjectPath", @@ -914,7 +872,7 @@ static PyTypeObject ObjectPathType = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPythonStringType), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyStrBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -926,9 +884,6 @@ static PyTypeObject ObjectPathType = { /* Unicode string representation ==================================== */ -static PyTypeObject StringType; -DEFINE_CHECK(String) - PyDoc_STRVAR(String_tp_doc, "A string represented using Unicode - a subtype of `unicode`.\n" "\n" @@ -957,7 +912,7 @@ String_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) "__new__ takes at most one positional parameter"); return NULL; } - if (!PyArg_ParseTupleAndKeywords(empty_tuple, kwargs, + if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, "|O!:__new__", argnames, &PyInt_Type, &variantness)) return NULL; if (!variantness) { @@ -972,7 +927,7 @@ String_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) self = (PyUnicode_Type.tp_new)(cls, args, NULL); if (self) { - PyObject_GenericSetAttr(self, variant_level_const, variantness); + PyObject_GenericSetAttr(self, dbus_py_variant_level_const, variantness); } return self; } @@ -986,7 +941,7 @@ String_tp_repr(PyObject *self) long variant_level; if (!parent_repr) return NULL; - vl_obj = PyObject_GetAttr(self, variant_level_const); + vl_obj = PyObject_GetAttr(self, dbus_py_variant_level_const); if (!vl_obj) return NULL; variant_level = PyInt_AsLong(vl_obj); if (variant_level > 0) { @@ -1004,7 +959,7 @@ String_tp_repr(PyObject *self) return my_repr; } -static PyTypeObject StringType = { +PyTypeObject DBusPyString_Type = { PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) 0, "dbus.String", @@ -1049,57 +1004,57 @@ static PyTypeObject StringType = { static inline int init_types(void) { - Int16Type.tp_base = &DBusPythonIntType; - if (PyType_Ready(&Int16Type) < 0) return 0; + DBusPyInt16_Type.tp_base = &DBusPyIntBase_Type; + if (PyType_Ready(&DBusPyInt16_Type) < 0) return 0; /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as desired */ - Int16Type.tp_print = NULL; + DBusPyInt16_Type.tp_print = NULL; - UInt16Type.tp_base = &DBusPythonIntType; - if (PyType_Ready(&UInt16Type) < 0) return 0; - UInt16Type.tp_print = NULL; + DBusPyUInt16_Type.tp_base = &DBusPyIntBase_Type; + if (PyType_Ready(&DBusPyUInt16_Type) < 0) return 0; + DBusPyUInt16_Type.tp_print = NULL; - Int32Type.tp_base = &DBusPythonIntType; - if (PyType_Ready(&Int32Type) < 0) return 0; - Int32Type.tp_print = NULL; + DBusPyInt32_Type.tp_base = &DBusPyIntBase_Type; + if (PyType_Ready(&DBusPyInt32_Type) < 0) return 0; + DBusPyInt32_Type.tp_print = NULL; - UInt32Type.tp_base = &DBusPythonLongType; - if (PyType_Ready(&UInt32Type) < 0) return 0; - UInt32Type.tp_print = NULL; + DBusPyUInt32_Type.tp_base = &DBusPyLongBase_Type; + if (PyType_Ready(&DBusPyUInt32_Type) < 0) return 0; + DBusPyUInt32_Type.tp_print = NULL; #if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) - Int64Type.tp_base = &DBusPythonLongType; - if (PyType_Ready(&Int64Type) < 0) return 0; - Int64Type.tp_print = NULL; + DBusPyInt64_Type.tp_base = &DBusPyLongBase_Type; + if (PyType_Ready(&DBusPyInt64_Type) < 0) return 0; + DBusPyInt64_Type.tp_print = NULL; - UInt64Type.tp_base = &DBusPythonLongType; - if (PyType_Ready(&UInt64Type) < 0) return 0; - UInt64Type.tp_print = NULL; + DBusPyUInt64_Type.tp_base = &DBusPyLongBase_Type; + if (PyType_Ready(&DBusPyUInt64_Type) < 0) return 0; + DBusPyUInt64_Type.tp_print = NULL; #endif - StringType.tp_basicsize = PyUnicode_Type.tp_basicsize - + 2*sizeof(PyObject *) - 1; - StringType.tp_basicsize /= sizeof(PyObject *); - StringType.tp_basicsize *= sizeof(PyObject *); - StringType.tp_base = &PyUnicode_Type; - if (PyType_Ready(&StringType) < 0) return 0; - StringType.tp_print = NULL; + DBusPyString_Type.tp_basicsize = PyUnicode_Type.tp_basicsize + + 2*sizeof(PyObject *) - 1; + DBusPyString_Type.tp_basicsize /= sizeof(PyObject *); + DBusPyString_Type.tp_basicsize *= sizeof(PyObject *); + DBusPyString_Type.tp_base = &PyUnicode_Type; + if (PyType_Ready(&DBusPyString_Type) < 0) return 0; + DBusPyString_Type.tp_print = NULL; - UTF8StringType.tp_basicsize = PyUnicode_Type.tp_basicsize + DBusPyUTF8String_Type.tp_basicsize = PyUnicode_Type.tp_basicsize + 2*sizeof(PyObject *) - 1; - UTF8StringType.tp_basicsize /= sizeof(PyObject *); - UTF8StringType.tp_basicsize *= sizeof(PyObject *); - UTF8StringType.tp_base = &DBusPythonStringType; - if (PyType_Ready(&UTF8StringType) < 0) return 0; - UTF8StringType.tp_print = NULL; + DBusPyUTF8String_Type.tp_basicsize /= sizeof(PyObject *); + DBusPyUTF8String_Type.tp_basicsize *= sizeof(PyObject *); + DBusPyUTF8String_Type.tp_base = &DBusPyStrBase_Type; + if (PyType_Ready(&DBusPyUTF8String_Type) < 0) return 0; + DBusPyUTF8String_Type.tp_print = NULL; - ObjectPathType.tp_base = &DBusPythonStringType; - if (PyType_Ready(&ObjectPathType) < 0) return 0; - ObjectPathType.tp_print = NULL; + DBusPyObjectPath_Type.tp_base = &DBusPyStrBase_Type; + if (PyType_Ready(&DBusPyObjectPath_Type) < 0) return 0; + DBusPyObjectPath_Type.tp_print = NULL; - BooleanType.tp_base = &DBusPythonIntType; - if (PyType_Ready(&BooleanType) < 0) return 0; - BooleanType.tp_print = NULL; + DBusPyBoolean_Type.tp_base = &DBusPyIntBase_Type; + if (PyType_Ready(&DBusPyBoolean_Type) < 0) return 0; + DBusPyBoolean_Type.tp_print = NULL; return 1; } @@ -1107,37 +1062,37 @@ init_types(void) static inline int insert_types(PyObject *this_module) { - Py_INCREF(&Int16Type); - Py_INCREF(&UInt16Type); - Py_INCREF(&Int32Type); - Py_INCREF(&UInt32Type); - Py_INCREF(&Int64Type); - Py_INCREF(&UInt64Type); - Py_INCREF(&BooleanType); + Py_INCREF(&DBusPyInt16_Type); + Py_INCREF(&DBusPyUInt16_Type); + Py_INCREF(&DBusPyInt32_Type); + Py_INCREF(&DBusPyUInt32_Type); + Py_INCREF(&DBusPyInt64_Type); + Py_INCREF(&DBusPyUInt64_Type); + Py_INCREF(&DBusPyBoolean_Type); if (PyModule_AddObject(this_module, "Int16", - (PyObject *)&Int16Type) < 0) return 0; + (PyObject *)&DBusPyInt16_Type) < 0) return 0; if (PyModule_AddObject(this_module, "UInt16", - (PyObject *)&UInt16Type) < 0) return 0; + (PyObject *)&DBusPyUInt16_Type) < 0) return 0; if (PyModule_AddObject(this_module, "Int32", - (PyObject *)&Int32Type) < 0) return 0; + (PyObject *)&DBusPyInt32_Type) < 0) return 0; if (PyModule_AddObject(this_module, "UInt32", - (PyObject *)&UInt32Type) < 0) return 0; + (PyObject *)&DBusPyUInt32_Type) < 0) return 0; if (PyModule_AddObject(this_module, "Int64", - (PyObject *)&Int64Type) < 0) return 0; + (PyObject *)&DBusPyInt64_Type) < 0) return 0; if (PyModule_AddObject(this_module, "UInt64", - (PyObject *)&UInt64Type) < 0) return 0; + (PyObject *)&DBusPyUInt64_Type) < 0) return 0; if (PyModule_AddObject(this_module, "Boolean", - (PyObject *)&BooleanType) < 0) return 0; + (PyObject *)&DBusPyBoolean_Type) < 0) return 0; - Py_INCREF(&ObjectPathType); - Py_INCREF(&UTF8StringType); - Py_INCREF(&StringType); + Py_INCREF(&DBusPyObjectPath_Type); + Py_INCREF(&DBusPyUTF8String_Type); + Py_INCREF(&DBusPyString_Type); if (PyModule_AddObject(this_module, "ObjectPath", - (PyObject *)&ObjectPathType) < 0) return 0; + (PyObject *)&DBusPyObjectPath_Type) < 0) return 0; if (PyModule_AddObject(this_module, "UTF8String", - (PyObject *)&UTF8StringType) < 0) return 0; + (PyObject *)&DBusPyUTF8String_Type) < 0) return 0; if (PyModule_AddObject(this_module, "String", - (PyObject *)&StringType) < 0) return 0; + (PyObject *)&DBusPyString_Type) < 0) return 0; return 1; } diff --git a/_dbus_bindings/types-internal.h b/_dbus_bindings/types-internal.h new file mode 100644 index 0000000..6042f1c --- /dev/null +++ b/_dbus_bindings/types-internal.h @@ -0,0 +1,81 @@ +/* D-Bus types: implementation internals + * + * Copyright (C) 2006 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef DBUS_BINDINGS_TYPES_INTERNAL_H +#define DBUS_BINDINGS_TYPES_INTERNAL_H + +#include <stdint.h> + +#include "dbus_bindings-internal.h" + +extern PyTypeObject DBusPyIntBase_Type; +DEFINE_CHECK(DBusPyIntBase) + +typedef struct { + PyIntObject base; + long variant_level; +} DBusPyIntBase; + +extern PyTypeObject DBusPyLongBase_Type; +DEFINE_CHECK(DBusPyLongBase) + +extern PyTypeObject DBusPyFloatBase_Type; +DEFINE_CHECK(DBusPyFloatBase) + +typedef struct { + PyFloatObject base; + long variant_level; +} DBusPyFloatBase; + +extern PyTypeObject DBusPyStrBase_Type; +DEFINE_CHECK(DBusPyStrBase) + +dbus_int16_t dbus_py_int16_range_check(PyObject *); +dbus_uint16_t dbus_py_uint16_range_check(PyObject *); +dbus_int32_t dbus_py_int32_range_check(PyObject *); +dbus_uint32_t dbus_py_uint32_range_check(PyObject *); + +#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) +# define DBUS_PYTHON_64_BIT_WORKS 1 +dbus_int64_t dbus_py_int64_range_check(PyObject *); +dbus_uint64_t dbus_py_uint64_range_check(PyObject *); +#else +# undef DBUS_PYTHON_64_BIT_WORKS +#endif /* defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) */ + +PyObject *dbus_py_variant_level_const, *dbus_py_signature_const; + +typedef struct { + PyListObject super; + PyObject *signature; + long variant_level; +} DBusPyArray; + +typedef struct { + PyDictObject super; + PyObject *signature; + long variant_level; +} DBusPyDict; + +#endif @@ -160,6 +160,9 @@ setup( "_dbus_bindings/conn.c", "_dbus_bindings/conn-methods.c", "_dbus_bindings/debug.c", + "_dbus_bindings/exceptions.c", + "_dbus_bindings/pending-call.c", + "_dbus_bindings/message.c", "_dbus_bindings/bus.c", ], include_dirs=dbus_includes, |