1 /* Simple D-Bus types: Double and (with appropriate #defines) Float
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
27 #include <structmember.h>
29 #include "dbus_bindings-internal.h"
30 #include "types-internal.h"
32 PyDoc_STRVAR(Double_tp_doc,
33 "A double-precision floating point number (a subtype of float).");
35 #ifdef WITH_DBUS_FLOAT32
36 PyDoc_STRVAR(Float_tp_doc,
37 "A single-precision floating point number (a subtype of float).");
40 PyTypeObject DBusPyDouble_Type = {
41 PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
52 0, /* tp_as_sequence */
53 0, /* tp_as_mapping */
60 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
61 Double_tp_doc, /* tp_doc */
64 0, /* tp_richcompare */
65 0, /* tp_weaklistoffset */
71 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
75 0, /* tp_dictoffset */
81 #ifdef WITH_DBUS_FLOAT32
83 PyTypeObject DBusPyFloat_Type = {
84 PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
95 0, /* tp_as_sequence */
96 0, /* tp_as_mapping */
102 0, /* tp_as_buffer */
103 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
104 Float_tp_doc, /* tp_doc */
107 0, /* tp_richcompare */
108 0, /* tp_weaklistoffset */
114 DEFERRED_ADDRESS(&DBusPythonFloatType), /* tp_base */
116 0, /* tp_descr_get */
117 0, /* tp_descr_set */
118 0, /* tp_dictoffset */
123 #endif /* defined(WITH_DBUS_FLOAT32) */
126 dbus_py_init_float_types(void)
128 DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type;
129 if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0;
130 DBusPyDouble_Type.tp_print = NULL;
132 #ifdef WITH_DBUS_FLOAT32
133 DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type;
134 if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0;
135 DBusPyFloat_Type.tp_print = NULL;
142 dbus_py_insert_float_types(PyObject *this_module)
144 /* PyModule_AddObject steals a ref */
145 Py_INCREF(&DBusPyDouble_Type);
146 if (PyModule_AddObject(this_module, "Double",
147 (PyObject *)&DBusPyDouble_Type) < 0) return 0;
148 #ifdef WITH_DBUS_FLOAT32
149 Py_INCREF(&DBusPyFloat_Type);
150 if (PyModule_AddObject(this_module, "Float",
151 (PyObject *)&DBusPyFloat_Type) < 0) return 0;