From 23013477f373aae9569e05bf793dcb3ec92530fb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 14 Nov 2006 14:12:11 +0000 Subject: [PATCH] - Add Double type (and Float type #if'd out, ready for Alp's 32-bit float type if/when it's added to libdbus) - Include "abstract" base classes and float types in module.c --- _dbus_bindings/floattypes-impl.h | 159 +++++++++++++++++++++++++++++++++++++++ _dbus_bindings/module.c | 8 +- 2 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 _dbus_bindings/floattypes-impl.h diff --git a/_dbus_bindings/floattypes-impl.h b/_dbus_bindings/floattypes-impl.h new file mode 100644 index 0000000..c7100df --- /dev/null +++ b/_dbus_bindings/floattypes-impl.h @@ -0,0 +1,159 @@ +/* Simple D-Bus types: Double and (with appropriate #defines) Float + * + * 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 + * + */ + +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)."); + +#ifdef WITH_DBUS_FLOAT32 +PyDoc_STRVAR(Float_tp_doc, +"A single-precision floating point number (a subtype of float)."); +#endif + +static PyTypeObject DoubleType = { + PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) + 0, + "dbus.Double", + 0, + 0, + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Double_tp_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +#ifdef WITH_DBUS_FLOAT32 + +static PyTypeObject FloatType = { + PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) + 0, + "dbus.Float", + 0, + 0, + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_compare */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Float_tp_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; +#endif /* defined(WITH_DBUS_FLOAT32) */ + +static inline int +init_float_types(void) +{ + DoubleType.tp_base = &DBusPythonFloatType; + if (PyType_Ready(&DoubleType) < 0) return 0; + DoubleType.tp_print = NULL; + +#ifdef WITH_DBUS_FLOAT32 + FloatType.tp_base = &DBusPythonFloatType; + if (PyType_Ready(&FloatType) < 0) return 0; + FloatType.tp_print = NULL; +#endif + + return 1; +} + +static inline int +insert_float_types(PyObject *this_module) +{ + Py_INCREF(&DoubleType); + if (PyModule_AddObject(this_module, "Double", + (PyObject *)&DoubleType) < 0) return 0; +#ifdef WITH_DBUS_FLOAT32 + Py_INCREF(&FloatType); + if (PyModule_AddObject(this_module, "Float", + (PyObject *)&FloatType) < 0) return 0; +#endif + + return 1; +} diff --git a/_dbus_bindings/module.c b/_dbus_bindings/module.c index 4c47cec..20d6dbf 100644 --- a/_dbus_bindings/module.c +++ b/_dbus_bindings/module.c @@ -35,8 +35,10 @@ 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" /* IntNN, UIntNN, ObjectPath */ +#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 */ @@ -64,8 +66,10 @@ init_dbus_bindings(void) if (!init_generic()) return; if (!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; @@ -77,8 +81,10 @@ init_dbus_bindings(void) if (!this_module) return; if (!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; -- 2.11.4.GIT