Complete the .m4 renaming
[dbus-python-phuang.git] / _dbus_bindings / int.c
blobcb27a9f4b33e88aa0060920c603bcd82ebec5633
1 /* Simple D-Bus types: integers of various sizes, and ObjectPath.
3 * Copyright (C) 2006 Collabora Ltd.
5 * Licensed under the Academic Free License version 2.1
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "types-internal.h"
25 /* Specific types =================================================== */
27 /* Boolean, a subclass of DBusPythonInt ============================= */
29 PyDoc_STRVAR(Boolean_tp_doc,
30 "A boolean, represented as a subtype of `int` (not `bool`, because `bool`\n"
31 "cannot be subclassed).\n"
32 "\n"
33 "Constructor::\n"
34 "\n"
35 " dbus.Boolean(value[, variant_level]) -> Boolean\n"
36 "\n"
37 "``value`` is converted to 0 or 1 as if by ``int(bool(value))``.\n"
38 "\n"
39 "``variant_level`` must be non-negative; the default is 0.\n"
40 "\n"
41 ":IVariables:\n"
42 " `variant_level` : int\n"
43 " Indicates how many nested Variant containers this object\n"
44 " is contained in: if a message's wire format has a variant containing a\n"
45 " variant containing a boolean, this is represented in Python by a\n"
46 " Boolean with variant_level==2.\n"
49 static PyObject *
50 Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
52 PyObject *tuple, *self, *value = Py_None;
53 long variantness = 0;
54 static char *argnames[] = {"_", "variant_level", NULL};
56 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Ol:__new__", argnames,
57 &value, &variantness)) return NULL;
58 if (variantness < 0) {
59 PyErr_SetString(PyExc_ValueError,
60 "variant_level must be non-negative");
61 return NULL;
63 tuple = Py_BuildValue("(i)", PyObject_IsTrue(value) ? 1 : 0);
64 if (!tuple) return NULL;
65 self = (DBusPyIntBase_Type.tp_new)(cls, tuple, kwargs);
66 Py_DECREF(tuple);
67 return self;
70 static PyObject *
71 Boolean_tp_repr (PyObject *self)
73 long variant_level = ((DBusPyIntBase *)self)->variant_level;
74 if (variant_level > 0) {
75 return PyString_FromFormat("%s(%s, variant_level=%ld)",
76 self->ob_type->tp_name,
77 PyInt_AsLong(self) ? "True" : "False",
78 variant_level);
80 return PyString_FromFormat("%s(%s)",
81 self->ob_type->tp_name,
82 PyInt_AsLong(self) ? "True" : "False");
85 PyTypeObject DBusPyBoolean_Type = {
86 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
88 "dbus.Boolean",
91 0, /* tp_dealloc */
92 0, /* tp_print */
93 0, /* tp_getattr */
94 0, /* tp_setattr */
95 0, /* tp_compare */
96 Boolean_tp_repr, /* tp_repr */
97 0, /* tp_as_number */
98 0, /* tp_as_sequence */
99 0, /* tp_as_mapping */
100 0, /* tp_hash */
101 0, /* tp_call */
102 0, /* tp_str */
103 0, /* tp_getattro */
104 0, /* tp_setattro */
105 0, /* tp_as_buffer */
106 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
107 Boolean_tp_doc, /* tp_doc */
108 0, /* tp_traverse */
109 0, /* tp_clear */
110 0, /* tp_richcompare */
111 0, /* tp_weaklistoffset */
112 0, /* tp_iter */
113 0, /* tp_iternext */
114 0, /* tp_methods */
115 0, /* tp_members */
116 0, /* tp_getset */
117 DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */
118 0, /* tp_dict */
119 0, /* tp_descr_get */
120 0, /* tp_descr_set */
121 0, /* tp_dictoffset */
122 0, /* tp_init */
123 0, /* tp_alloc */
124 Boolean_tp_new, /* tp_new */
127 /* Int16 ============================================================ */
129 PyDoc_STRVAR(Int16_tp_doc,
130 "A signed 16-bit integer between -0x8000 and +0x7FFF, represented as\n"
131 "a subtype of `int`.\n"
132 "\n"
133 "Constructor::\n"
134 "\n"
135 " dbus.Int16(value: int[, variant_level: int]) -> Int16\n"
136 "\n"
137 "value must be within the allowed range, or OverflowError will be\n"
138 "raised.\n"
139 "\n"
140 " variant_level must be non-negative; the default is 0.\n"
141 "\n"
142 ":IVariables:\n"
143 " `variant_level` : int\n"
144 " Indicates how many nested Variant containers this object\n"
145 " is contained in: if a message's wire format has a variant containing a\n"
146 " variant containing an int16, this is represented in Python by an\n"
147 " Int16 with variant_level==2.\n"
150 dbus_int16_t
151 dbus_py_int16_range_check(PyObject *obj)
153 long i = PyInt_AsLong (obj);
154 if (i == -1 && PyErr_Occurred ()) return -1;
155 if (i < -0x8000 || i > 0x7fff) {
156 PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int16",
157 (int)i);
158 return -1;
160 return i;
163 static PyObject *
164 Int16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
166 PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs);
167 if (self && dbus_py_int16_range_check(self) == -1 && PyErr_Occurred()) {
168 Py_DECREF(self);
169 return NULL;
171 return self;
174 PyTypeObject DBusPyInt16_Type = {
175 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
177 "dbus.Int16",
180 0, /* tp_dealloc */
181 0, /* tp_print */
182 0, /* tp_getattr */
183 0, /* tp_setattr */
184 0, /* tp_compare */
185 0, /* tp_repr */
186 0, /* tp_as_number */
187 0, /* tp_as_sequence */
188 0, /* tp_as_mapping */
189 0, /* tp_hash */
190 0, /* tp_call */
191 0, /* tp_str */
192 0, /* tp_getattro */
193 0, /* tp_setattro */
194 0, /* tp_as_buffer */
195 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
196 Int16_tp_doc, /* tp_doc */
197 0, /* tp_traverse */
198 0, /* tp_clear */
199 0, /* tp_richcompare */
200 0, /* tp_weaklistoffset */
201 0, /* tp_iter */
202 0, /* tp_iternext */
203 0, /* tp_methods */
204 0, /* tp_members */
205 0, /* tp_getset */
206 DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */
207 0, /* tp_dict */
208 0, /* tp_descr_get */
209 0, /* tp_descr_set */
210 0, /* tp_dictoffset */
211 0, /* tp_init */
212 0, /* tp_alloc */
213 Int16_tp_new, /* tp_new */
216 /* UInt16 =========================================================== */
218 PyDoc_STRVAR(UInt16_tp_doc,
219 "An unsigned 16-bit integer between 0 and 0xFFFF, represented as\n"
220 "a subtype of `int`.\n"
221 "\n"
222 "Constructor::\n"
223 "\n"
224 " dbus.UInt16(value: int[, variant_level: int]) -> UInt16\n"
225 "\n"
226 "``value`` must be within the allowed range, or `OverflowError` will be\n"
227 "raised.\n"
228 "\n"
229 "``variant_level`` must be non-negative; the default is 0.\n"
230 "\n"
231 ":IVariables:\n"
232 " `variant_level` : int\n"
233 " Indicates how many nested Variant containers this object\n"
234 " is contained in: if a message's wire format has a variant containing a\n"
235 " variant containing a uint16, this is represented in Python by a\n"
236 " UInt16 with variant_level==2.\n"
239 dbus_uint16_t
240 dbus_py_uint16_range_check(PyObject *obj)
242 long i = PyInt_AsLong(obj);
243 if (i == -1 && PyErr_Occurred()) return (dbus_uint16_t)(-1);
244 if (i < 0 || i > 0xffff) {
245 PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt16",
246 (int)i);
247 return (dbus_uint16_t)(-1);
249 return i;
252 static PyObject *
253 UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
255 PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs);
256 if (self && dbus_py_uint16_range_check(self) == (dbus_uint16_t)(-1)
257 && PyErr_Occurred()) {
258 Py_DECREF (self);
259 return NULL;
261 return self;
264 PyTypeObject DBusPyUInt16_Type = {
265 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
267 "dbus.UInt16",
270 0, /* tp_dealloc */
271 0, /* tp_print */
272 0, /* tp_getattr */
273 0, /* tp_setattr */
274 0, /* tp_compare */
275 0, /* tp_repr */
276 0, /* tp_as_number */
277 0, /* tp_as_sequence */
278 0, /* tp_as_mapping */
279 0, /* tp_hash */
280 0, /* tp_call */
281 0, /* tp_str */
282 0, /* tp_getattro */
283 0, /* tp_setattro */
284 0, /* tp_as_buffer */
285 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
286 UInt16_tp_doc, /* tp_doc */
287 0, /* tp_traverse */
288 0, /* tp_clear */
289 0, /* tp_richcompare */
290 0, /* tp_weaklistoffset */
291 0, /* tp_iter */
292 0, /* tp_iternext */
293 0, /* tp_methods */
294 0, /* tp_members */
295 0, /* tp_getset */
296 DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */
297 0, /* tp_dict */
298 0, /* tp_descr_get */
299 0, /* tp_descr_set */
300 0, /* tp_dictoffset */
301 0, /* tp_init */
302 0, /* tp_alloc */
303 UInt16_tp_new, /* tp_new */
306 /* Int32 ============================================================ */
308 PyDoc_STRVAR(Int32_tp_doc,
309 "A signed 32-bit integer between -0x8000 0000 and +0x7FFF FFFF, represented as\n"
310 "a subtype of `int`.\n"
311 "\n"
312 "Constructor::\n"
313 "\n"
314 " dbus.Int32(value: int[, variant_level: int]) -> Int32\n"
315 "\n"
316 "``value`` must be within the allowed range, or `OverflowError` will be\n"
317 "raised.\n"
318 "\n"
319 "``variant_level`` must be non-negative; the default is 0.\n"
320 "\n"
321 ":IVariables:\n"
322 " `variant_level` : int\n"
323 " Indicates how many nested Variant containers this object\n"
324 " is contained in: if a message's wire format has a variant containing a\n"
325 " variant containing an int32, this is represented in Python by an\n"
326 " Int32 with variant_level==2.\n"
329 dbus_int32_t
330 dbus_py_int32_range_check(PyObject *obj)
332 long i = PyInt_AsLong(obj);
333 if (i == -1 && PyErr_Occurred()) return -1;
334 if (i < INT32_MIN || i > INT32_MAX) {
335 PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int32",
336 (int)i);
337 return -1;
339 return i;
342 static PyObject *
343 Int32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
345 PyObject *self = (DBusPyIntBase_Type.tp_new)(cls, args, kwargs);
346 if (self && dbus_py_int32_range_check(self) == -1 && PyErr_Occurred()) {
347 Py_DECREF(self);
348 return NULL;
350 return self;
353 PyTypeObject DBusPyInt32_Type = {
354 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
356 "dbus.Int32",
359 0, /* tp_dealloc */
360 0, /* tp_print */
361 0, /* tp_getattr */
362 0, /* tp_setattr */
363 0, /* tp_compare */
364 0, /* tp_repr */
365 0, /* tp_as_number */
366 0, /* tp_as_sequence */
367 0, /* tp_as_mapping */
368 0, /* tp_hash */
369 0, /* tp_call */
370 0, /* tp_str */
371 0, /* tp_getattro */
372 0, /* tp_setattro */
373 0, /* tp_as_buffer */
374 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
375 Int32_tp_doc, /* tp_doc */
376 0, /* tp_traverse */
377 0, /* tp_clear */
378 0, /* tp_richcompare */
379 0, /* tp_weaklistoffset */
380 0, /* tp_iter */
381 0, /* tp_iternext */
382 0, /* tp_methods */
383 0, /* tp_members */
384 0, /* tp_getset */
385 DEFERRED_ADDRESS(&DBusPyIntBase_Type), /* tp_base */
386 0, /* tp_dict */
387 0, /* tp_descr_get */
388 0, /* tp_descr_set */
389 0, /* tp_dictoffset */
390 0, /* tp_init */
391 0, /* tp_alloc */
392 Int32_tp_new, /* tp_new */
395 /* UInt32 =========================================================== */
397 PyDoc_STRVAR(UInt32_tp_doc,
398 "An unsigned 32-bit integer between 0 and 0xFFFF FFFF, represented as a\n"
399 "subtype of `long`.\n"
400 "\n"
401 "Note that this may be changed in future to be a subtype of `int` on\n"
402 "64-bit platforms; applications should not rely on either behaviour.\n"
403 "\n"
404 "Constructor::\n"
405 "\n"
406 " dbus.UInt32(value: long[, variant_level: int]) -> UInt32\n"
407 "\n"
408 "``value`` must be within the allowed range, or `OverflowError` will be\n"
409 "raised.\n"
410 "\n"
411 "``variant_level`` must be non-negative; the default is 0.\n"
412 "\n"
413 ":IVariables:\n"
414 " `variant_level` : int\n"
415 " Indicates how many nested Variant containers this object\n"
416 " is contained in: if a message's wire format has a variant containing a\n"
417 " variant containing a uint32, this is represented in Python by a\n"
418 " UInt32 with variant_level==2.\n"
421 dbus_uint32_t
422 dbus_py_uint32_range_check(PyObject *obj)
424 unsigned long i;
425 PyObject *long_obj = PyNumber_Long(obj);
427 if (!long_obj) return (dbus_uint32_t)(-1);
428 i = PyLong_AsUnsignedLong(long_obj);
429 if (i == (unsigned long)(-1) && PyErr_Occurred()) {
430 Py_DECREF(long_obj);
431 return (dbus_uint32_t)(-1);
433 if (i > UINT32_MAX) {
434 PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt32",
435 (int)i);
436 Py_DECREF(long_obj);
437 return (dbus_uint32_t)(-1);
439 Py_DECREF(long_obj);
440 return i;
443 static PyObject *
444 UInt32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
446 PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
447 if (self && dbus_py_uint32_range_check(self) == (dbus_uint32_t)(-1)
448 && PyErr_Occurred()) {
449 Py_DECREF(self);
450 return NULL;
452 return self;
455 PyTypeObject DBusPyUInt32_Type = {
456 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
458 "dbus.UInt32",
461 0, /* tp_dealloc */
462 0, /* tp_print */
463 0, /* tp_getattr */
464 0, /* tp_setattr */
465 0, /* tp_compare */
466 0, /* tp_repr */
467 0, /* tp_as_number */
468 0, /* tp_as_sequence */
469 0, /* tp_as_mapping */
470 0, /* tp_hash */
471 0, /* tp_call */
472 0, /* tp_str */
473 0, /* tp_getattro */
474 0, /* tp_setattro */
475 0, /* tp_as_buffer */
476 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
477 UInt32_tp_doc, /* tp_doc */
478 0, /* tp_traverse */
479 0, /* tp_clear */
480 0, /* tp_richcompare */
481 0, /* tp_weaklistoffset */
482 0, /* tp_iter */
483 0, /* tp_iternext */
484 0, /* tp_methods */
485 0, /* tp_members */
486 0, /* tp_getset */
487 DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */
488 0, /* tp_dict */
489 0, /* tp_descr_get */
490 0, /* tp_descr_set */
491 0, /* tp_dictoffset */
492 0, /* tp_init */
493 0, /* tp_alloc */
494 UInt32_tp_new, /* tp_new */
497 /* Int64 =========================================================== */
499 PyDoc_STRVAR(Int64_tp_doc,
500 "A signed 64-bit integer between -0x8000 0000 0000 0000 and\n"
501 "+0x7FFF FFFF FFFF FFFF, represented as a subtype of `long`.\n"
502 "\n"
503 "Note that this may be changed in future to be a subtype of `int` on\n"
504 "64-bit platforms; applications should not rely on either behaviour.\n"
505 "\n"
506 "This type only works on platforms where the C compiler has suitable\n"
507 "64-bit types, such as C99 ``long long``.\n"
508 "\n"
509 "Constructor::\n"
510 "\n"
511 " dbus.Int64(value: long[, variant_level: int]) -> Int64\n"
512 "\n"
513 "``value`` must be within the allowed range, or `OverflowError` will be\n"
514 "raised.\n"
515 "\n"
516 "``variant_level`` must be non-negative; the default is 0.\n"
517 "\n"
518 ":IVariables:\n"
519 " `variant_level` : int\n"
520 " Indicates how many nested Variant containers this object\n"
521 " is contained in: if a message's wire format has a variant containing a\n"
522 " variant containing an int64, this is represented in Python by an\n"
523 " Int64 with variant_level==2.\n"
526 #ifdef DBUS_PYTHON_64_BIT_WORKS
527 dbus_int64_t
528 dbus_py_int64_range_check(PyObject *obj)
530 PY_LONG_LONG i;
531 PyObject *long_obj = PyNumber_Long(obj);
533 if (!long_obj) return -1;
534 i = PyLong_AsLongLong(long_obj);
535 if (i == -1 && PyErr_Occurred()) {
536 Py_DECREF(long_obj);
537 return -1;
539 if (i < INT64_MIN || i > INT64_MAX) {
540 PyErr_SetString(PyExc_OverflowError, "Value out of range for Int64");
541 Py_DECREF(long_obj);
542 return -1;
544 Py_DECREF(long_obj);
545 return i;
547 #endif
549 static PyObject *
550 Int64_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
552 #ifdef DBUS_PYTHON_64_BIT_WORKS
553 PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
554 if (self && dbus_py_int64_range_check(self) == -1 && PyErr_Occurred()) {
555 Py_DECREF(self);
556 return NULL;
558 return self;
559 #else
560 PyErr_SetString(PyExc_NotImplementedError,
561 "64-bit types are not available on this platform");
562 return NULL;
563 #endif
566 PyTypeObject DBusPyInt64_Type = {
567 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
569 "dbus.Int64",
572 0, /* tp_dealloc */
573 0, /* tp_print */
574 0, /* tp_getattr */
575 0, /* tp_setattr */
576 0, /* tp_compare */
577 0, /* tp_repr */
578 0, /* tp_as_number */
579 0, /* tp_as_sequence */
580 0, /* tp_as_mapping */
581 0, /* tp_hash */
582 0, /* tp_call */
583 0, /* tp_str */
584 0, /* tp_getattro */
585 0, /* tp_setattro */
586 0, /* tp_as_buffer */
587 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
588 Int64_tp_doc, /* tp_doc */
589 0, /* tp_traverse */
590 0, /* tp_clear */
591 0, /* tp_richcompare */
592 0, /* tp_weaklistoffset */
593 0, /* tp_iter */
594 0, /* tp_iternext */
595 0, /* tp_methods */
596 0, /* tp_members */
597 0, /* tp_getset */
598 DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */
599 0, /* tp_dict */
600 0, /* tp_descr_get */
601 0, /* tp_descr_set */
602 0, /* tp_dictoffset */
603 0, /* tp_init */
604 0, /* tp_alloc */
605 Int64_tp_new, /* tp_new */
608 /* UInt64 =========================================================== */
610 PyDoc_STRVAR(UInt64_tp_doc,
611 "An unsigned 64-bit integer between 0 and 0xFFFF FFFF FFFF FFFF,\n"
612 "represented as a subtype of `long`.\n"
613 "\n"
614 "This type only exists on platforms where the C compiler has suitable\n"
615 "64-bit types, such as C99 ``unsigned long long``.\n"
616 "\n"
617 "Constructor::\n"
618 "\n"
619 " dbus.UInt64(value: long[, variant_level: int]) -> UInt64\n"
620 "\n"
621 "``value`` must be within the allowed range, or `OverflowError` will be\n"
622 "raised.\n"
623 "\n"
624 "``variant_level`` must be non-negative; the default is 0.\n"
625 "\n"
626 ":IVariables:\n"
627 " `variant_level` : int\n"
628 " Indicates how many nested Variant containers this object\n"
629 " is contained in: if a message's wire format has a variant containing a\n"
630 " variant containing a uint64, this is represented in Python by a\n"
631 " UInt64 with variant_level==2.\n"
634 dbus_uint64_t
635 dbus_py_uint64_range_check(PyObject *obj)
637 unsigned PY_LONG_LONG i;
638 PyObject *long_obj = PyNumber_Long(obj);
640 if (!long_obj) return (dbus_uint64_t)(-1);
641 i = PyLong_AsUnsignedLongLong(long_obj);
642 if (i == (unsigned PY_LONG_LONG)(-1) && PyErr_Occurred()) {
643 Py_DECREF(long_obj);
644 return (dbus_uint64_t)(-1);
646 if (i > UINT64_MAX) {
647 PyErr_SetString(PyExc_OverflowError, "Value out of range for UInt64");
648 Py_DECREF(long_obj);
649 return (dbus_uint64_t)(-1);
651 Py_DECREF(long_obj);
652 return i;
655 static PyObject *
656 UInt64_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs)
658 #ifdef DBUS_PYTHON_64_BIT_WORKS
659 PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
660 if (self && dbus_py_uint64_range_check(self) == (dbus_uint64_t)(-1)
661 && PyErr_Occurred()) {
662 Py_DECREF(self);
663 return NULL;
665 return self;
666 #else
667 PyErr_SetString(PyExc_NotImplementedError,
668 "64-bit integer types are not supported on this platform");
669 return NULL;
670 #endif
673 PyTypeObject DBusPyUInt64_Type = {
674 PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
676 "dbus.UInt64",
679 0, /* tp_dealloc */
680 0, /* tp_print */
681 0, /* tp_getattr */
682 0, /* tp_setattr */
683 0, /* tp_compare */
684 0, /* tp_repr */
685 0, /* tp_as_number */
686 0, /* tp_as_sequence */
687 0, /* tp_as_mapping */
688 0, /* tp_hash */
689 0, /* tp_call */
690 0, /* tp_str */
691 0, /* tp_getattro */
692 0, /* tp_setattro */
693 0, /* tp_as_buffer */
694 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
695 UInt64_tp_doc, /* tp_doc */
696 0, /* tp_traverse */
697 0, /* tp_clear */
698 0, /* tp_richcompare */
699 0, /* tp_weaklistoffset */
700 0, /* tp_iter */
701 0, /* tp_iternext */
702 0, /* tp_methods */
703 0, /* tp_members */
704 0, /* tp_getset */
705 DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */
706 0, /* tp_dict */
707 0, /* tp_descr_get */
708 0, /* tp_descr_set */
709 0, /* tp_dictoffset */
710 0, /* tp_init */
711 0, /* tp_alloc */
712 UInt64_tp_new, /* tp_new */
715 dbus_bool_t
716 dbus_py_init_int_types(void)
718 DBusPyInt16_Type.tp_base = &DBusPyIntBase_Type;
719 if (PyType_Ready(&DBusPyInt16_Type) < 0) return 0;
720 /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as
721 desired */
722 DBusPyInt16_Type.tp_print = NULL;
724 DBusPyUInt16_Type.tp_base = &DBusPyIntBase_Type;
725 if (PyType_Ready(&DBusPyUInt16_Type) < 0) return 0;
726 DBusPyUInt16_Type.tp_print = NULL;
728 DBusPyInt32_Type.tp_base = &DBusPyIntBase_Type;
729 if (PyType_Ready(&DBusPyInt32_Type) < 0) return 0;
730 DBusPyInt32_Type.tp_print = NULL;
732 DBusPyUInt32_Type.tp_base = &DBusPyLongBase_Type;
733 if (PyType_Ready(&DBusPyUInt32_Type) < 0) return 0;
734 DBusPyUInt32_Type.tp_print = NULL;
736 #if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
737 DBusPyInt64_Type.tp_base = &DBusPyLongBase_Type;
738 if (PyType_Ready(&DBusPyInt64_Type) < 0) return 0;
739 DBusPyInt64_Type.tp_print = NULL;
741 DBusPyUInt64_Type.tp_base = &DBusPyLongBase_Type;
742 if (PyType_Ready(&DBusPyUInt64_Type) < 0) return 0;
743 DBusPyUInt64_Type.tp_print = NULL;
744 #endif
745 return 1;
748 dbus_bool_t
749 dbus_py_insert_int_types(PyObject *this_module)
751 Py_INCREF(&DBusPyInt16_Type);
752 Py_INCREF(&DBusPyUInt16_Type);
753 Py_INCREF(&DBusPyInt32_Type);
754 Py_INCREF(&DBusPyUInt32_Type);
755 Py_INCREF(&DBusPyInt64_Type);
756 Py_INCREF(&DBusPyUInt64_Type);
757 Py_INCREF(&DBusPyBoolean_Type);
758 if (PyModule_AddObject(this_module, "Int16",
759 (PyObject *)&DBusPyInt16_Type) < 0) return 0;
760 if (PyModule_AddObject(this_module, "UInt16",
761 (PyObject *)&DBusPyUInt16_Type) < 0) return 0;
762 if (PyModule_AddObject(this_module, "Int32",
763 (PyObject *)&DBusPyInt32_Type) < 0) return 0;
764 if (PyModule_AddObject(this_module, "UInt32",
765 (PyObject *)&DBusPyUInt32_Type) < 0) return 0;
766 if (PyModule_AddObject(this_module, "Int64",
767 (PyObject *)&DBusPyInt64_Type) < 0) return 0;
768 if (PyModule_AddObject(this_module, "UInt64",
769 (PyObject *)&DBusPyUInt64_Type) < 0) return 0;
770 if (PyModule_AddObject(this_module, "Boolean",
771 (PyObject *)&DBusPyBoolean_Type) < 0) return 0;
773 return 1;
776 /* vim:set ft=c cino< sw=4 sts=4 et: */