* dbus.service.Object: don't let the user try to export objects on the local
[dbus-python-phuang.git] / _dbus_bindings / debug.c
blobb684377829a1a45b9bae2a2c0dd8814dc026f64a
1 /* Debug code for _dbus_bindings.
3 * Copyright (C) 2006 Collabora Ltd.
5 * Licensed under the Academic Free License version 2.1
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "dbus_bindings-internal.h"
24 #include <stdlib.h>
26 void
27 _dbus_py_assertion_failed(const char *assertion)
29 PyErr_SetString(PyExc_AssertionError, assertion);
30 #if 1 || defined(USING_DBG) || defined(FATAL_ASSERTIONS)
31 /* print the Python stack, and dump core so we can see the C stack too */
32 PyErr_Print();
33 abort();
34 #endif
37 #ifdef USING_DBG
38 void
39 _dbus_py_whereami(void)
41 PyObject *c, *v, *t;
42 /* This is a little mad. We want to get the traceback without
43 clearing the error indicator, if any. */
44 PyErr_Fetch(&c, &v, &t); /* 3 new refs */
45 Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
46 PyErr_Restore(c, v, t); /* steals 3 refs */
48 if (!PyErr_Occurred()) {
49 PyErr_SetString(PyExc_AssertionError,
50 "No error, but plz provide traceback kthx");
52 PyErr_Print();
54 PyErr_Restore(c, v, t); /* steals another 3 refs */
57 void
58 _dbus_py_dbg_exc(void)
60 PyObject *c, *v, *t;
61 /* This is a little mad. We want to get the traceback without
62 clearing the error indicator. */
63 PyErr_Fetch(&c, &v, &t); /* 3 new refs */
64 Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
65 PyErr_Restore(c, v, t); /* steals 3 refs */
66 PyErr_Print();
67 PyErr_Restore(c, v, t); /* steals another 3 refs */
70 void
71 _dbus_py_dbg_dump_message(DBusMessage *message)
73 const char *s;
74 fprintf(stderr, "DBusMessage at %p\n", message);
76 s = dbus_message_get_destination(message);
77 if (!s) s = "(null)";
78 fprintf(stderr, "\tdestination %s\n", s);
80 s = dbus_message_get_interface(message);
81 if (!s) s = "(null)";
82 fprintf(stderr, "\tinterface %s\n", s);
84 s = dbus_message_get_member(message);
85 if (!s) s = "(null)";
86 fprintf(stderr, "\tmember %s\n", s);
88 s = dbus_message_get_path(message);
89 if (!s) s = "(null)";
90 fprintf(stderr, "\tpath %s\n", s);
92 #endif