Commit | Line | Data |
---|---|---|
7085eeaa | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
7085eeaa PP |
4 | * Copyright (c) 2019 EfficiOS Inc. and Linux Foundation |
5 | * Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright (c) 2019 Simon Marchi <simon.marchi@efficios.com> | |
7085eeaa PP |
7 | */ |
8 | ||
0235b0db MJ |
9 | #ifndef BABELTRACE_PY_COMMON_INTERNAL_H |
10 | #define BABELTRACE_PY_COMMON_INTERNAL_H | |
11 | ||
7085eeaa | 12 | #include <glib.h> |
cacd0713 | 13 | #include <Python.h> |
4b3b8e4a | 14 | #include <stdbool.h> |
7085eeaa PP |
15 | |
16 | #include "common/macros.h" | |
17 | ||
332c7e11 SM |
18 | /* |
19 | * Formats the Python traceback `py_exc_tb` using traceback.format_tb, from the | |
20 | * Python standard library, and return it as a Gstring. | |
21 | */ | |
22 | BT_HIDDEN | |
23 | GString *bt_py_common_format_tb(PyObject *py_exc_tb, int log_level); | |
24 | ||
7085eeaa | 25 | /* |
cacd0713 SM |
26 | * Formats the Python exception described by `py_exc_type`, `py_exc_value` |
27 | * and `py_exc_tb` and returns the formatted string, or `NULL` on error. The | |
28 | * returned string does NOT end with a newline. | |
29 | * | |
30 | * If `chain` is true, include all exceptions in the causality chain | |
31 | * (see parameter `chain` of Python's traceback.format_exception). | |
32 | */ | |
33 | BT_HIDDEN | |
34 | GString *bt_py_common_format_exception(PyObject *py_exc_type, | |
35 | PyObject *py_exc_value, PyObject *py_exc_tb, | |
36 | int log_level, bool chain); | |
37 | ||
38 | /* | |
39 | * Wrapper for `bt_py_common_format_exception` that passes the Python error | |
40 | * indicator (the exception currently being raised). Always include the | |
41 | * full exception chain. | |
7085eeaa PP |
42 | * |
43 | * You must ensure that the error indicator is set with PyErr_Occurred() | |
44 | * before you call this function. | |
45 | * | |
46 | * This function does not modify the error indicator, that is, anything | |
47 | * that is fetched is always restored. | |
48 | */ | |
49 | BT_HIDDEN | |
cacd0713 | 50 | GString *bt_py_common_format_current_exception(int log_level); |
7085eeaa PP |
51 | |
52 | #endif /* BABELTRACE_PY_COMMON_INTERNAL_H */ |