Blame _dbus_bindings/int.c

Packit 130fc8
/* Simple D-Bus types: integers of various sizes, and ObjectPath.
Packit 130fc8
 *
Packit 130fc8
 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
Packit 130fc8
 *
Packit 130fc8
 * Permission is hereby granted, free of charge, to any person
Packit 130fc8
 * obtaining a copy of this software and associated documentation
Packit 130fc8
 * files (the "Software"), to deal in the Software without
Packit 130fc8
 * restriction, including without limitation the rights to use, copy,
Packit 130fc8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 130fc8
 * of the Software, and to permit persons to whom the Software is
Packit 130fc8
 * furnished to do so, subject to the following conditions:
Packit 130fc8
 *
Packit 130fc8
 * The above copyright notice and this permission notice shall be
Packit 130fc8
 * included in all copies or substantial portions of the Software.
Packit 130fc8
 *
Packit 130fc8
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 130fc8
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 130fc8
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 130fc8
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 130fc8
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Packit 130fc8
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit 130fc8
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 130fc8
 * DEALINGS IN THE SOFTWARE.
Packit 130fc8
 */
Packit 130fc8
Packit 130fc8
#include "dbus_bindings-internal.h"
Packit 130fc8
Packit 130fc8
#include "types-internal.h"
Packit 130fc8
Packit 130fc8
#ifdef PY3
Packit 130fc8
#define INTBASE (DBusPyLongBase_Type)
Packit 130fc8
#else
Packit 130fc8
#define INTBASE (DBusPyIntBase_Type)
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
/* Specific types =================================================== */
Packit 130fc8
Packit 130fc8
/* Boolean, a subclass of DBusPythonInt ============================= */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(Boolean_tp_doc,
Packit 130fc8
"A boolean, represented as a subtype of `int` (not `bool`, because `bool`\n"
Packit 130fc8
"cannot be subclassed).\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.Boolean(value[, variant_level]) -> Boolean\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` is converted to 0 or 1 as if by ``int(bool(value))``.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing a boolean, this is represented in Python by a\n"
Packit 130fc8
"    Boolean with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
    PyObject *tuple, *self, *value = Py_None;
Packit 130fc8
    long variantness = 0;
Packit 130fc8
    static char *argnames[] = {"_", "variant_level", NULL};
Packit 130fc8
Packit 130fc8
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Ol:__new__", argnames,
Packit 130fc8
                                     &value, &variantness)) return NULL;
Packit 130fc8
    if (variantness < 0) {
Packit 130fc8
        PyErr_SetString(PyExc_ValueError,
Packit 130fc8
                        "variant_level must be non-negative");
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    tuple = Py_BuildValue("(i)", PyObject_IsTrue(value) ? 1 : 0);
Packit 130fc8
    if (!tuple) return NULL;
Packit 130fc8
    self = (INTBASE.tp_new)(cls, tuple, kwargs);
Packit 130fc8
    Py_CLEAR(tuple);
Packit 130fc8
    return self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
Boolean_tp_repr(PyObject *self)
Packit 130fc8
{
Packit 130fc8
    int is_true = PyObject_IsTrue(self);
Packit 130fc8
#ifdef PY3
Packit 130fc8
    long variant_level = dbus_py_variant_level_get(self);
Packit 130fc8
    if (variant_level < 0)
Packit 130fc8
        return NULL;
Packit 130fc8
#else
Packit 130fc8
    long variant_level = ((DBusPyIntBase *)self)->variant_level;
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
    if (is_true == -1)
Packit 130fc8
        return NULL;
Packit 130fc8
Packit 130fc8
    if (variant_level > 0) {
Packit 130fc8
        return PyUnicode_FromFormat("%s(%s, variant_level=%ld)",
Packit 130fc8
                                    Py_TYPE(self)->tp_name,
Packit 130fc8
                                    is_true ? "True" : "False",
Packit 130fc8
                                    variant_level);
Packit 130fc8
    }
Packit 130fc8
    return PyUnicode_FromFormat("%s(%s)",
Packit 130fc8
                                Py_TYPE(self)->tp_name,
Packit 130fc8
                                is_true ? "True" : "False");
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyBoolean_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.Boolean",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    Boolean_tp_repr,                        /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    Boolean_tp_doc,                         /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&INTBASE),             /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    Boolean_tp_new,                         /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* Int16 ============================================================ */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(Int16_tp_doc,
Packit 130fc8
"A signed 16-bit integer between -0x8000 and +0x7FFF, represented as\n"
Packit 130fc8
"a subtype of `int`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.Int16(value: int[, variant_level: int]) -> Int16\n"
Packit 130fc8
"\n"
Packit 130fc8
"value must be within the allowed range, or OverflowError will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"    variant_level must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing an int16, this is represented in Python by an\n"
Packit 130fc8
"    Int16 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
dbus_int16_t
Packit 130fc8
dbus_py_int16_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    long i = PyLong_AsLong(obj);
Packit 130fc8
    if (i == -1 && PyErr_Occurred())
Packit 130fc8
        return -1;
Packit 130fc8
Packit 130fc8
    if (i < -0x8000 || i > 0x7fff) {
Packit 130fc8
        PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int16",
Packit 130fc8
                     (int)i);
Packit 130fc8
        return -1;
Packit 130fc8
    }
Packit 130fc8
    return (dbus_int16_t)i;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
Int16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
    PyObject *self = (INTBASE.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_int16_range_check(self) == -1 && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyInt16_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.Int16",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    Int16_tp_doc,                           /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&INTBASE),             /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    Int16_tp_new,                           /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* UInt16 =========================================================== */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(UInt16_tp_doc,
Packit 130fc8
"An unsigned 16-bit integer between 0 and 0xFFFF, represented as\n"
Packit 130fc8
"a subtype of `int`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.UInt16(value: int[, variant_level: int]) -> UInt16\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` must be within the allowed range, or `OverflowError` will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing a uint16, this is represented in Python by a\n"
Packit 130fc8
"    UInt16 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
dbus_uint16_t
Packit 130fc8
dbus_py_uint16_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    long i = PyLong_AsLong(obj);
Packit 130fc8
    if (i == -1 && PyErr_Occurred())
Packit 130fc8
        return (dbus_uint16_t)(-1);
Packit 130fc8
Packit 130fc8
    if (i < 0 || i > 0xffff) {
Packit 130fc8
        PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt16",
Packit 130fc8
                     (int)i);
Packit 130fc8
        return (dbus_uint16_t)(-1);
Packit 130fc8
    }
Packit 130fc8
    return (dbus_uint16_t)i;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
    PyObject *self = (INTBASE.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_uint16_range_check(self) == (dbus_uint16_t)(-1)
Packit 130fc8
        && PyErr_Occurred())
Packit 130fc8
    {
Packit 130fc8
        Py_CLEAR (self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyUInt16_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.UInt16",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    UInt16_tp_doc,                          /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&INTBASE),             /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    UInt16_tp_new,                          /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* Int32 ============================================================ */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(Int32_tp_doc,
Packit 130fc8
"A signed 32-bit integer between -0x8000 0000 and +0x7FFF FFFF, represented as\n"
Packit 130fc8
"a subtype of `int`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.Int32(value: int[, variant_level: int]) -> Int32\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` must be within the allowed range, or `OverflowError` will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing an int32, this is represented in Python by an\n"
Packit 130fc8
"    Int32 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
dbus_int32_t
Packit 130fc8
dbus_py_int32_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    long i = PyLong_AsLong(obj);
Packit 130fc8
    if (i == -1 && PyErr_Occurred())
Packit 130fc8
        return -1;
Packit 130fc8
Packit 130fc8
    if (i < INT32_MIN || i > INT32_MAX) {
Packit 130fc8
        PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int32",
Packit 130fc8
                     (int)i);
Packit 130fc8
        return -1;
Packit 130fc8
    }
Packit 130fc8
    return (dbus_int32_t)i;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
Int32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
    PyObject *self = (INTBASE.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_int32_range_check(self) == -1 && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyInt32_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.Int32",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    Int32_tp_doc,                           /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&INTBASE),             /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    Int32_tp_new,                           /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* UInt32 =========================================================== */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(UInt32_tp_doc,
Packit 130fc8
"An unsigned 32-bit integer between 0 and 0xFFFF FFFF, represented as a\n"
Packit 130fc8
"subtype of `long`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Note that this may be changed in future to be a subtype of `int` on\n"
Packit 130fc8
"64-bit platforms; applications should not rely on either behaviour.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.UInt32(value: long[, variant_level: int]) -> UInt32\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` must be within the allowed range, or `OverflowError` will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing a uint32, this is represented in Python by a\n"
Packit 130fc8
"    UInt32 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
dbus_uint32_t
Packit 130fc8
dbus_py_uint32_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    unsigned long i;
Packit 130fc8
    PyObject *long_obj = PyNumber_Long(obj);
Packit 130fc8
Packit 130fc8
    if (!long_obj) return (dbus_uint32_t)(-1);
Packit 130fc8
    i = PyLong_AsUnsignedLong(long_obj);
Packit 130fc8
    if (i == (unsigned long)(-1) && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return (dbus_uint32_t)(-1);
Packit 130fc8
    }
Packit 130fc8
    if (i > UINT32_MAX) {
Packit 130fc8
        PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt32",
Packit 130fc8
                     (int)i);
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return (dbus_uint32_t)(-1);
Packit 130fc8
    }
Packit 130fc8
    Py_CLEAR(long_obj);
Packit 130fc8
    return i;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
UInt32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
    PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_uint32_range_check(self) == (dbus_uint32_t)(-1)
Packit 130fc8
        && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyUInt32_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.UInt32",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    UInt32_tp_doc,                          /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&DBusPyLongBase_Type),  /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    UInt32_tp_new,                          /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* Int64 =========================================================== */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(Int64_tp_doc,
Packit 130fc8
"A signed 64-bit integer between -0x8000 0000 0000 0000 and\n"
Packit 130fc8
"+0x7FFF FFFF FFFF FFFF, represented as a subtype of `long`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Note that this may be changed in future to be a subtype of `int` on\n"
Packit 130fc8
"64-bit platforms; applications should not rely on either behaviour.\n"
Packit 130fc8
"\n"
Packit 130fc8
"This type only works on platforms where the C compiler has suitable\n"
Packit 130fc8
"64-bit types, such as C99 ``long long``.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.Int64(value: long[, variant_level: int]) -> Int64\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` must be within the allowed range, or `OverflowError` will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing an int64, this is represented in Python by an\n"
Packit 130fc8
"    Int64 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
#ifdef DBUS_PYTHON_64_BIT_WORKS
Packit 130fc8
dbus_int64_t
Packit 130fc8
dbus_py_int64_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    PY_LONG_LONG i;
Packit 130fc8
    PyObject *long_obj = PyNumber_Long(obj);
Packit 130fc8
Packit 130fc8
    if (!long_obj) return -1;
Packit 130fc8
    i = PyLong_AsLongLong(long_obj);
Packit 130fc8
    if (i == -1 && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return -1;
Packit 130fc8
    }
Packit 130fc8
    if (i < INT64_MIN || i > INT64_MAX) {
Packit 130fc8
        PyErr_SetString(PyExc_OverflowError, "Value out of range for Int64");
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return -1;
Packit 130fc8
    }
Packit 130fc8
    Py_CLEAR(long_obj);
Packit 130fc8
    return i;
Packit 130fc8
}
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
Int64_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
#ifdef DBUS_PYTHON_64_BIT_WORKS
Packit 130fc8
    PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_int64_range_check(self) == -1 && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
#else
Packit 130fc8
    PyErr_SetString(PyExc_NotImplementedError,
Packit 130fc8
                    "64-bit types are not available on this platform");
Packit 130fc8
    return NULL;
Packit 130fc8
#endif
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyInt64_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.Int64",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    Int64_tp_doc,                           /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&DBusPyLongBase_Type),  /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    Int64_tp_new,                           /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
/* UInt64 =========================================================== */
Packit 130fc8
Packit 130fc8
PyDoc_STRVAR(UInt64_tp_doc,
Packit 130fc8
"An unsigned 64-bit integer between 0 and 0xFFFF FFFF FFFF FFFF,\n"
Packit 130fc8
"represented as a subtype of `long`.\n"
Packit 130fc8
"\n"
Packit 130fc8
"This type only exists on platforms where the C compiler has suitable\n"
Packit 130fc8
"64-bit types, such as C99 ``unsigned long long``.\n"
Packit 130fc8
"\n"
Packit 130fc8
"Constructor::\n"
Packit 130fc8
"\n"
Packit 130fc8
"    dbus.UInt64(value: long[, variant_level: int]) -> UInt64\n"
Packit 130fc8
"\n"
Packit 130fc8
"``value`` must be within the allowed range, or `OverflowError` will be\n"
Packit 130fc8
"raised.\n"
Packit 130fc8
"\n"
Packit 130fc8
"``variant_level`` must be non-negative; the default is 0.\n"
Packit 130fc8
"\n"
Packit 130fc8
":IVariables:\n"
Packit 130fc8
"  `variant_level` : int\n"
Packit 130fc8
"    Indicates how many nested Variant containers this object\n"
Packit 130fc8
"    is contained in: if a message's wire format has a variant containing a\n"
Packit 130fc8
"    variant containing a uint64, this is represented in Python by a\n"
Packit 130fc8
"    UInt64 with variant_level==2.\n"
Packit 130fc8
);
Packit 130fc8
Packit 130fc8
dbus_uint64_t
Packit 130fc8
dbus_py_uint64_range_check(PyObject *obj)
Packit 130fc8
{
Packit 130fc8
    unsigned PY_LONG_LONG i;
Packit 130fc8
    PyObject *long_obj = PyNumber_Long(obj);
Packit 130fc8
Packit 130fc8
    if (!long_obj) return (dbus_uint64_t)(-1);
Packit 130fc8
    i = PyLong_AsUnsignedLongLong(long_obj);
Packit 130fc8
    if (i == (unsigned PY_LONG_LONG)(-1) && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return (dbus_uint64_t)(-1);
Packit 130fc8
    }
Packit 130fc8
    if (i > UINT64_MAX) {
Packit 130fc8
        PyErr_SetString(PyExc_OverflowError, "Value out of range for UInt64");
Packit 130fc8
        Py_CLEAR(long_obj);
Packit 130fc8
        return (dbus_uint64_t)(-1);
Packit 130fc8
    }
Packit 130fc8
    Py_CLEAR(long_obj);
Packit 130fc8
    return i;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
static PyObject *
Packit 130fc8
UInt64_tp_new (PyTypeObject *cls, PyObject *args, PyObject *kwargs)
Packit 130fc8
{
Packit 130fc8
#ifdef DBUS_PYTHON_64_BIT_WORKS
Packit 130fc8
    PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs);
Packit 130fc8
    if (self && dbus_py_uint64_range_check(self) == (dbus_uint64_t)(-1)
Packit 130fc8
        && PyErr_Occurred()) {
Packit 130fc8
        Py_CLEAR(self);
Packit 130fc8
        return NULL;
Packit 130fc8
    }
Packit 130fc8
    return self;
Packit 130fc8
#else
Packit 130fc8
    PyErr_SetString(PyExc_NotImplementedError,
Packit 130fc8
                    "64-bit integer types are not supported on this platform");
Packit 130fc8
    return NULL;
Packit 130fc8
#endif
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
PyTypeObject DBusPyUInt64_Type = {
Packit 130fc8
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
Packit 130fc8
    "dbus.UInt64",
Packit 130fc8
    0,
Packit 130fc8
    0,
Packit 130fc8
    0,                                      /* tp_dealloc */
Packit 130fc8
    0,                                      /* tp_print */
Packit 130fc8
    0,                                      /* tp_getattr */
Packit 130fc8
    0,                                      /* tp_setattr */
Packit 130fc8
    0,                                      /* tp_compare */
Packit 130fc8
    0,                                      /* tp_repr */
Packit 130fc8
    0,                                      /* tp_as_number */
Packit 130fc8
    0,                                      /* tp_as_sequence */
Packit 130fc8
    0,                                      /* tp_as_mapping */
Packit 130fc8
    0,                                      /* tp_hash */
Packit 130fc8
    0,                                      /* tp_call */
Packit 130fc8
    0,                                      /* tp_str */
Packit 130fc8
    0,                                      /* tp_getattro */
Packit 130fc8
    0,                                      /* tp_setattro */
Packit 130fc8
    0,                                      /* tp_as_buffer */
Packit 130fc8
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
Packit 130fc8
    UInt64_tp_doc,                          /* tp_doc */
Packit 130fc8
    0,                                      /* tp_traverse */
Packit 130fc8
    0,                                      /* tp_clear */
Packit 130fc8
    0,                                      /* tp_richcompare */
Packit 130fc8
    0,                                      /* tp_weaklistoffset */
Packit 130fc8
    0,                                      /* tp_iter */
Packit 130fc8
    0,                                      /* tp_iternext */
Packit 130fc8
    0,                                      /* tp_methods */
Packit 130fc8
    0,                                      /* tp_members */
Packit 130fc8
    0,                                      /* tp_getset */
Packit 130fc8
    DEFERRED_ADDRESS(&DBusPyLongBase_Type),  /* tp_base */
Packit 130fc8
    0,                                      /* tp_dict */
Packit 130fc8
    0,                                      /* tp_descr_get */
Packit 130fc8
    0,                                      /* tp_descr_set */
Packit 130fc8
    0,                                      /* tp_dictoffset */
Packit 130fc8
    0,                                      /* tp_init */
Packit 130fc8
    0,                                      /* tp_alloc */
Packit 130fc8
    UInt64_tp_new,                          /* tp_new */
Packit 130fc8
};
Packit 130fc8
Packit 130fc8
dbus_bool_t
Packit 130fc8
dbus_py_init_int_types(void)
Packit 130fc8
{
Packit 130fc8
    DBusPyInt16_Type.tp_base = &INTBASE;
Packit 130fc8
    if (PyType_Ready(&DBusPyInt16_Type) < 0) return 0;
Packit 130fc8
    /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as
Packit 130fc8
    desired */
Packit 130fc8
    DBusPyInt16_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
    DBusPyUInt16_Type.tp_base = &INTBASE;
Packit 130fc8
    if (PyType_Ready(&DBusPyUInt16_Type) < 0) return 0;
Packit 130fc8
    DBusPyUInt16_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
    DBusPyInt32_Type.tp_base = &INTBASE;
Packit 130fc8
    if (PyType_Ready(&DBusPyInt32_Type) < 0) return 0;
Packit 130fc8
    DBusPyInt32_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
    DBusPyUInt32_Type.tp_base = &DBusPyLongBase_Type;
Packit 130fc8
    if (PyType_Ready(&DBusPyUInt32_Type) < 0) return 0;
Packit 130fc8
    DBusPyUInt32_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
#if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG)
Packit 130fc8
    DBusPyInt64_Type.tp_base = &DBusPyLongBase_Type;
Packit 130fc8
    if (PyType_Ready(&DBusPyInt64_Type) < 0) return 0;
Packit 130fc8
    DBusPyInt64_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
    DBusPyUInt64_Type.tp_base = &DBusPyLongBase_Type;
Packit 130fc8
    if (PyType_Ready(&DBusPyUInt64_Type) < 0) return 0;
Packit 130fc8
    DBusPyUInt64_Type.tp_print = NULL;
Packit 130fc8
#endif
Packit 130fc8
Packit 130fc8
    DBusPyBoolean_Type.tp_base = &INTBASE;
Packit 130fc8
    if (PyType_Ready(&DBusPyBoolean_Type) < 0) return 0;
Packit 130fc8
    DBusPyBoolean_Type.tp_print = NULL;
Packit 130fc8
Packit 130fc8
    return 1;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
dbus_bool_t
Packit 130fc8
dbus_py_insert_int_types(PyObject *this_module)
Packit 130fc8
{
Packit 130fc8
    /* PyModule_AddObject steals a ref */
Packit 130fc8
    Py_INCREF(&DBusPyInt16_Type);
Packit 130fc8
    Py_INCREF(&DBusPyUInt16_Type);
Packit 130fc8
    Py_INCREF(&DBusPyInt32_Type);
Packit 130fc8
    Py_INCREF(&DBusPyUInt32_Type);
Packit 130fc8
    Py_INCREF(&DBusPyInt64_Type);
Packit 130fc8
    Py_INCREF(&DBusPyUInt64_Type);
Packit 130fc8
    Py_INCREF(&DBusPyBoolean_Type);
Packit 130fc8
    if (PyModule_AddObject(this_module, "Int16",
Packit 130fc8
                           (PyObject *)&DBusPyInt16_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "UInt16",
Packit 130fc8
                           (PyObject *)&DBusPyUInt16_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "Int32",
Packit 130fc8
                           (PyObject *)&DBusPyInt32_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "UInt32",
Packit 130fc8
                           (PyObject *)&DBusPyUInt32_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "Int64",
Packit 130fc8
                           (PyObject *)&DBusPyInt64_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "UInt64",
Packit 130fc8
                           (PyObject *)&DBusPyUInt64_Type) < 0) return 0;
Packit 130fc8
    if (PyModule_AddObject(this_module, "Boolean",
Packit 130fc8
                           (PyObject *)&DBusPyBoolean_Type) < 0) return 0;
Packit 130fc8
Packit 130fc8
    return 1;
Packit 130fc8
}
Packit 130fc8
Packit 130fc8
/* vim:set ft=c cino< sw=4 sts=4 et: */