Remove from EXTRA_DIST files we'd already be distributing
[dbus-python-phuang.git] / _dbus_bindings / generic.c
blobff4d2f693ae572e16095796db095d10756ee4b12
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 program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "dbus_bindings-internal.h"
28 /* The empty tuple, held globally since dbus-python turns out to use it quite
29 * a lot
31 PyObject *dbus_py_empty_tuple = NULL;
33 PyObject *
34 dbus_py_tp_richcompare_by_pointer(PyObject *self,
35 PyObject *other,
36 int op)
38 if (op == Py_EQ || op == Py_NE) {
39 if (self == other) {
40 return PyInt_FromLong(op == Py_EQ);
42 return PyInt_FromLong(op == Py_NE);
44 PyErr_SetString(PyExc_TypeError,
45 "Instances of this type are not ordered");
46 return NULL;
49 long
50 dbus_py_tp_hash_by_pointer(PyObject *self)
52 long hash = (long)self;
53 return (hash == -1L ? -2L : hash);
56 int
57 dbus_py_immutable_setattro(PyObject *obj UNUSED,
58 PyObject *name UNUSED,
59 PyObject *value UNUSED)
61 PyErr_SetString(PyExc_AttributeError, "Object is immutable");
62 return -1;
65 /* Take the global interpreter lock and decrement the reference count.
66 * Suitable for calling from a C callback. */
67 void
68 dbus_py_take_gil_and_xdecref(PyObject *obj)
70 PyGILState_STATE gil = PyGILState_Ensure();
71 Py_XDECREF(obj);
72 PyGILState_Release(gil);
75 dbus_bool_t
76 dbus_py_init_generic(void)
78 dbus_py_empty_tuple = PyTuple_New(0);
79 if (!dbus_py_empty_tuple) return 0;
80 return 1;
83 /* vim:set ft=c cino< sw=4 sts=4 et: */