Add Glue_immutable_setattro, DEFINE_CHECK, UNUSED attribute. Remove generic repr...
[dbus-python-phuang.git] / _dbus_bindings / generic-impl.h
blobb9c3129b9202c276b198e6e3029dc689799abc98
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 #define DEFERRED_ADDRESS(ADDR) 0
28 #if defined(__GNUC__)
29 # if __GNUC__ >= 3
30 # define UNUSED __attribute__((__unused__))
31 # else
32 # define UNUSED /*nothing*/
33 # endif
34 #else
35 # define UNUSED /*nothing*/
36 #endif
38 #define DEFINE_CHECK(type) \
39 static inline int type##_Check (PyObject *o) \
40 { \
41 return (o->ob_type == &type##Type) \
42 || PyObject_IsInstance(o, (PyObject *)&type##Type); \
45 static PyObject *empty_tuple = NULL;
47 static int
48 Glue_immutable_setattro(PyObject *obj UNUSED,
49 PyObject *name UNUSED,
50 PyObject *value UNUSED)
52 PyErr_SetString(PyExc_AttributeError, "Object is immutable");
53 return -1;
56 /* Take the global interpreter lock and decrement the reference count.
57 * Suitable for calling from a C callback. */
58 static void
59 Glue_TakeGILAndXDecref(PyObject *obj)
61 PyGILState_STATE gil = PyGILState_Ensure();
62 Py_XDECREF(obj);
63 PyGILState_Release(gil);
66 static inline int
67 init_generic(void)
69 empty_tuple = PyTuple_New(0);
70 if (!empty_tuple) return 0;
71 return 1;
74 /* vim:set ft=c cino< sw=4 sts=4 et: */