Revert "Make sure extensions are built before docs; get rid of strange inter-director...
[dbus-python-phuang.git] / _dbus_bindings / generic.c
blobcda138d6c63d5cfc4e23edbce3386c39d482e90a
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. <http://www.collabora.co.uk/>
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #include "dbus_bindings-internal.h"
29 /* The empty tuple, held globally since dbus-python turns out to use it quite
30 * a lot
32 PyObject *dbus_py_empty_tuple = NULL;
34 PyObject *
35 dbus_py_tp_richcompare_by_pointer(PyObject *self,
36 PyObject *other,
37 int op)
39 if (op == Py_EQ || op == Py_NE) {
40 if (self == other) {
41 return PyInt_FromLong(op == Py_EQ);
43 return PyInt_FromLong(op == Py_NE);
45 PyErr_SetString(PyExc_TypeError,
46 "Instances of this type are not ordered");
47 return NULL;
50 long
51 dbus_py_tp_hash_by_pointer(PyObject *self)
53 long hash = (long)self;
54 return (hash == -1L ? -2L : hash);
57 int
58 dbus_py_immutable_setattro(PyObject *obj UNUSED,
59 PyObject *name UNUSED,
60 PyObject *value UNUSED)
62 PyErr_SetString(PyExc_AttributeError, "Object is immutable");
63 return -1;
66 /* Take the global interpreter lock and decrement the reference count.
67 * Suitable for calling from a C callback. */
68 void
69 dbus_py_take_gil_and_xdecref(PyObject *obj)
71 PyGILState_STATE gil = PyGILState_Ensure();
72 Py_XDECREF(obj);
73 PyGILState_Release(gil);
76 dbus_bool_t
77 dbus_py_init_generic(void)
79 dbus_py_empty_tuple = PyTuple_New(0);
80 if (!dbus_py_empty_tuple) return 0;
81 return 1;
84 /* vim:set ft=c cino< sw=4 sts=4 et: */