Initial import package dbus-python: D-Bus Python Bindings
[profile/ivi/dbus-python.git] / _dbus_bindings / debug.c
1 /* Debug code for _dbus_bindings.
2  *
3  * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25
26 #include "dbus_bindings-internal.h"
27 #include <stdlib.h>
28
29 void
30 _dbus_py_assertion_failed(const char *assertion)
31 {
32     PyErr_SetString(PyExc_AssertionError, assertion);
33 #if 1 || defined(USING_DBG) || defined(FATAL_ASSERTIONS)
34     /* print the Python stack, and dump core so we can see the C stack too */
35     PyErr_Print();
36     abort();
37 #endif
38 }
39
40 #ifdef USING_DBG
41 void
42 _dbus_py_whereami(void)
43 {
44     PyObject *c, *v, *t;
45     /* This is a little mad. We want to get the traceback without
46     clearing the error indicator, if any. */
47     PyErr_Fetch(&c, &v, &t); /* 3 new refs */
48     Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
49     PyErr_Restore(c, v, t); /* steals 3 refs */
50
51     if (!PyErr_Occurred()) {
52         PyErr_SetString(PyExc_AssertionError,
53                         "No error, but plz provide traceback kthx");
54     }
55     PyErr_Print();
56
57     PyErr_Restore(c, v, t); /* steals another 3 refs */
58 }
59
60 void
61 _dbus_py_dbg_exc(void)
62 {
63     PyObject *c, *v, *t;
64     /* This is a little mad. We want to get the traceback without
65     clearing the error indicator. */
66     PyErr_Fetch(&c, &v, &t); /* 3 new refs */
67     Py_XINCREF(c); Py_XINCREF(v); Py_XINCREF(t); /* now we own 6 refs */
68     PyErr_Restore(c, v, t); /* steals 3 refs */
69     PyErr_Print();
70     PyErr_Restore(c, v, t); /* steals another 3 refs */
71 }
72
73 void
74 _dbus_py_dbg_dump_message(DBusMessage *message)
75 {
76     const char *s;
77     fprintf(stderr, "DBusMessage at %p\n", message);
78
79     s = dbus_message_get_destination(message);
80     if (!s) s = "(null)";
81     fprintf(stderr, "\tdestination %s\n", s);
82
83     s = dbus_message_get_interface(message);
84     if (!s) s = "(null)";
85     fprintf(stderr, "\tinterface %s\n", s);
86
87     s = dbus_message_get_member(message);
88     if (!s) s = "(null)";
89     fprintf(stderr, "\tmember %s\n", s);
90
91     s = dbus_message_get_path(message);
92     if (!s) s = "(null)";
93     fprintf(stderr, "\tpath %s\n", s);
94 }
95 #endif