This commit makes using (most of) `BKE_report` API safe in
multi-threaded situation.
This is achieved by adding a `std::mutex` lock to the `ReportList`
struct (in a slightly convoluted way unfortunately, due to this being a
DNA struct). This lock is then used to make most operations on
`Reportlist` data thread-safe.
Note that while working on this, a few other minor issues aroze in
existing usages of Reportlist by the WM code, mainly the fact that
`wm_init_reports` and `wm_free_reports` were both useless:
- init was called in a context where there is not yet any WM, so it
was doing nothing.
- free was called on a WM that would be later freed (as part of Main
freeing), which would also call cleanup code for its `reports` data.
Both have been removed.
Further more, `wm_add_default` (which is the only place where a WM ID is
created) did not initialize properly it reports data, this has been
fixed.
This change is related to the wmJob thread-safety tasks and PRs (#112537,
!113548).
Pull Request: https://projects.blender.org/blender/blender/pulls/113561
61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup pythonintern
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#if PY_VERSION_HEX < 0x030a0000
|
|
# error "Python 3.10 or greater is required, you'll need to update your Python."
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct ReportList;
|
|
|
|
/** Error reporting: convert BKE_report (#ReportList) reports into python errors.
|
|
*
|
|
* \param clear: When `true`, #BKE_reports_free is called on the given `reports`, which should
|
|
* then be considered as 'freed' data and not used anymore. */
|
|
short BPy_reports_to_error(struct ReportList *reports, PyObject *exception, bool clear);
|
|
/**
|
|
* A version of #BKE_report_write_file_fp that uses Python's stdout.
|
|
*/
|
|
void BPy_reports_write_stdout(const struct ReportList *reports, const char *header);
|
|
bool BPy_errors_to_report_ex(struct ReportList *reports,
|
|
const char *error_prefix,
|
|
bool use_full,
|
|
bool use_location);
|
|
/**
|
|
* \param reports: When set, an error will be added to this report, when NULL, print the error.
|
|
*
|
|
* \note Unless the caller handles printing the reports (or reports is NULL) it's best to ensure
|
|
* the output is printed to the `stdout/stderr`:
|
|
* \code{.cc}
|
|
* BPy_errors_to_report(reports);
|
|
* if (!BKE_reports_print_test(reports)) {
|
|
* BKE_reports_print(reports);
|
|
* }
|
|
* \endcode
|
|
*
|
|
* \note The caller is responsible for clearing the error (see #PyErr_Clear).
|
|
*/
|
|
bool BPy_errors_to_report(struct ReportList *reports);
|
|
|
|
struct bContext *BPY_context_get(void);
|
|
|
|
extern void bpy_context_set(struct bContext *C, PyGILState_STATE *gilstate);
|
|
/**
|
|
* Context should be used but not now because it causes some bugs.
|
|
*/
|
|
extern void bpy_context_clear(struct bContext *C, const PyGILState_STATE *gilstate);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|