NEWS: update
[dbus-python-phuang.git] / _dbus_bindings / generic.c
blob05e74ea1bf24116e619362b3bdde8eff730bfcb2
1 /* General Python glue code, used in _dbus_bindings but not actually anything
2 * to do with D-Bus.
4 * Copyright (C) 2006 Collabora Ltd.
6 * Licensed under the Academic Free License version 2.1
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "dbus_bindings-internal.h"
26 /* The empty tuple, held globally since dbus-python turns out to use it quite
27 * a lot
29 PyObject *dbus_py_empty_tuple = NULL;
31 PyObject *
32 dbus_py_tp_richcompare_by_pointer(PyObject *self,
33 PyObject *other,
34 int op)
36 if (op == Py_EQ || op == Py_NE) {
37 if (self == other) {
38 return PyInt_FromLong(op == Py_EQ);
40 return PyInt_FromLong(op == Py_NE);
42 PyErr_SetString(PyExc_TypeError,
43 "Instances of this type are not ordered");
44 return NULL;
47 long
48 dbus_py_tp_hash_by_pointer(PyObject *self)
50 long hash = (long)self;
51 return (hash == -1L ? -2L : hash);
54 int
55 dbus_py_immutable_setattro(PyObject *obj UNUSED,
56 PyObject *name UNUSED,
57 PyObject *value UNUSED)
59 PyErr_SetString(PyExc_AttributeError, "Object is immutable");
60 return -1;
63 /* Take the global interpreter lock and decrement the reference count.
64 * Suitable for calling from a C callback. */
65 void
66 dbus_py_take_gil_and_xdecref(PyObject *obj)
68 PyGILState_STATE gil = PyGILState_Ensure();
69 Py_XDECREF(obj);
70 PyGILState_Release(gil);
73 dbus_bool_t
74 dbus_py_init_generic(void)
76 dbus_py_empty_tuple = PyTuple_New(0);
77 if (!dbus_py_empty_tuple) return 0;
78 return 1;
81 /* vim:set ft=c cino< sw=4 sts=4 et: */