Update NEWS, README for 0.80.0
[dbus-python-phuang.git] / _dbus_bindings / debug.c
blob16138e9e3529dcfe630ff0ff58a7433a5c46bd2f
1 /* Debug code for _dbus_bindings.
3 * Copyright (C) 2006 Collabora Ltd.
5 * Licensed under the Academic Free License version 2.1
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "dbus_bindings-internal.h"
26 #include <stdlib.h>
28 void
29 _dbus_py_assertion_failed(const char *assertion)
31 PyErr_SetString(PyExc_AssertionError, assertion);
32 #if 1 || defined(USING_DBG) || defined(FATAL_ASSERTIONS)
33 /* print the Python stack, and dump core so we can see the C stack too */
34 PyErr_Print();
35 abort();
36 #endif
39 #ifdef USING_DBG
40 void
41 _dbus_py_whereami(void)
43 PyObject *c, *v, *t;
44 /* This is a little mad. We want to get the traceback without
45 clearing the error indicator, if any. */
46 PyErr_Fetch(&c, &v, &t); /* 3 new refs */
47 Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
48 PyErr_Restore(c, v, t); /* steals 3 refs */
50 if (!PyErr_Occurred()) {
51 PyErr_SetString(PyExc_AssertionError,
52 "No error, but plz provide traceback kthx");
54 PyErr_Print();
56 PyErr_Restore(c, v, t); /* steals another 3 refs */
59 void
60 _dbus_py_dbg_exc(void)
62 PyObject *c, *v, *t;
63 /* This is a little mad. We want to get the traceback without
64 clearing the error indicator. */
65 PyErr_Fetch(&c, &v, &t); /* 3 new refs */
66 Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
67 PyErr_Restore(c, v, t); /* steals 3 refs */
68 PyErr_Print();
69 PyErr_Restore(c, v, t); /* steals another 3 refs */
72 void
73 _dbus_py_dbg_dump_message(DBusMessage *message)
75 const char *s;
76 fprintf(stderr, "DBusMessage at %p\n", message);
78 s = dbus_message_get_destination(message);
79 if (!s) s = "(null)";
80 fprintf(stderr, "\tdestination %s\n", s);
82 s = dbus_message_get_interface(message);
83 if (!s) s = "(null)";
84 fprintf(stderr, "\tinterface %s\n", s);
86 s = dbus_message_get_member(message);
87 if (!s) s = "(null)";
88 fprintf(stderr, "\tmember %s\n", s);
90 s = dbus_message_get_path(message);
91 if (!s) s = "(null)";
92 fprintf(stderr, "\tpath %s\n", s);
94 #endif