Cleanup: python: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on allocated type possible. This is a serious source of annoyance (and crashes) when making some low-level structs non-trivial, as tracking down all usages of these structs in higher-level other structs and their allocation is... really painful. MEM_[cm]allocN<T> templates on the other hand do check that the given type is trivial, at build time (static assert), which makes such issue... trivial to catch. NOTE: New code should strive to use MEM_new (i.e. allocation and construction) as much as possible, even for trivial PoD types. Pull Request: https://projects.blender.org/blender/blender/pulls/135852
This commit is contained in:
committed by
Bastien Montagne
parent
9f697c7cc6
commit
bb89c89e7f
@@ -229,7 +229,7 @@ static PyObject *pyop_call(PyObject * /*self*/, PyObject *args)
|
||||
if (error_val == 0) {
|
||||
ReportList *reports;
|
||||
|
||||
reports = static_cast<ReportList *>(MEM_mallocN(sizeof(ReportList), "wmOperatorReportList"));
|
||||
reports = MEM_mallocN<ReportList>("wmOperatorReportList");
|
||||
|
||||
/* Own so these don't move into global reports. */
|
||||
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD | RPT_PRINT_HANDLED_BY_OWNER);
|
||||
|
||||
Reference in New Issue
Block a user