Refactor: Move some Editors' data allocation from C alloc/free to C++ new/delete.
Part of the effort to make PointerRNA non-trivial (#122431).
This commit is contained in:
@@ -43,7 +43,7 @@ static void cachefile_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
PropertyPointerRNA *pprop;
|
||||
|
||||
op->customdata = pprop = MEM_cnew<PropertyPointerRNA>("OpenPropertyPointerRNA");
|
||||
op->customdata = pprop = MEM_new<PropertyPointerRNA>("OpenPropertyPointerRNA");
|
||||
UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
|
||||
}
|
||||
|
||||
@@ -67,8 +67,11 @@ static int cachefile_open_invoke(bContext *C, wmOperator *op, const wmEvent * /*
|
||||
|
||||
static void open_cancel(bContext * /*C*/, wmOperator *op)
|
||||
{
|
||||
MEM_freeN(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
if (op->customdata) {
|
||||
PropertyPointerRNA *prop_ptr = static_cast<PropertyPointerRNA *>(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
MEM_delete(prop_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static int cachefile_open_exec(bContext *C, wmOperator *op)
|
||||
|
||||
@@ -2229,7 +2229,7 @@ static int move_to_collection_menus_create(wmOperator *op, MoveToCollectionData
|
||||
int index = menu->index;
|
||||
LISTBASE_FOREACH (CollectionChild *, child, &menu->collection->children) {
|
||||
Collection *collection = child->collection;
|
||||
MoveToCollectionData *submenu = MEM_cnew<MoveToCollectionData>(__func__);
|
||||
MoveToCollectionData *submenu = MEM_new<MoveToCollectionData>(__func__);
|
||||
BLI_addtail(&menu->submenus, submenu);
|
||||
submenu->collection = collection;
|
||||
submenu->index = ++index;
|
||||
@@ -2241,10 +2241,11 @@ static int move_to_collection_menus_create(wmOperator *op, MoveToCollectionData
|
||||
|
||||
static void move_to_collection_menus_free_recursive(MoveToCollectionData *menu)
|
||||
{
|
||||
LISTBASE_FOREACH (MoveToCollectionData *, submenu, &menu->submenus) {
|
||||
LISTBASE_FOREACH_MUTABLE (MoveToCollectionData *, submenu, &menu->submenus) {
|
||||
move_to_collection_menus_free_recursive(submenu);
|
||||
MEM_delete(submenu);
|
||||
}
|
||||
BLI_freelistN(&menu->submenus);
|
||||
BLI_listbase_clear(&menu->submenus);
|
||||
}
|
||||
|
||||
static void move_to_collection_menus_free(MoveToCollectionData **menu)
|
||||
@@ -2254,7 +2255,7 @@ static void move_to_collection_menus_free(MoveToCollectionData **menu)
|
||||
}
|
||||
|
||||
move_to_collection_menus_free_recursive(*menu);
|
||||
MEM_freeN(*menu);
|
||||
MEM_delete(*menu);
|
||||
*menu = nullptr;
|
||||
}
|
||||
|
||||
@@ -2353,7 +2354,7 @@ static int move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
*
|
||||
* So we are left with a memory that will necessarily leak. It's a small leak though. */
|
||||
if (master_collection_menu == nullptr) {
|
||||
master_collection_menu = MEM_cnew<MoveToCollectionData>(
|
||||
master_collection_menu = MEM_new<MoveToCollectionData>(
|
||||
"MoveToCollectionData menu - expected eventual memleak");
|
||||
}
|
||||
|
||||
|
||||
@@ -552,7 +552,7 @@ static bool buttons_context_path(
|
||||
Scene *scene = WM_window_get_active_scene(window);
|
||||
ViewLayer *view_layer = WM_window_get_active_view_layer(window);
|
||||
|
||||
memset(path, 0, sizeof(*path));
|
||||
*path = {};
|
||||
path->flag = flag;
|
||||
|
||||
/* If some ID datablock is pinned, set the root pointer. */
|
||||
@@ -691,7 +691,7 @@ static int buttons_shading_new_context(const bContext *C, int flag)
|
||||
void buttons_context_compute(const bContext *C, SpaceProperties *sbuts)
|
||||
{
|
||||
if (!sbuts->path) {
|
||||
sbuts->path = MEM_callocN(sizeof(ButsContextPath), "ButsContextPath");
|
||||
sbuts->path = MEM_new<ButsContextPath>("ButsContextPath");
|
||||
}
|
||||
|
||||
ButsContextPath *path = static_cast<ButsContextPath *>(sbuts->path);
|
||||
|
||||
@@ -70,7 +70,7 @@ static void buttons_texture_user_socket_property_add(ListBase *users,
|
||||
int icon,
|
||||
const char *name)
|
||||
{
|
||||
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
|
||||
ButsTextureUser *user = MEM_new<ButsTextureUser>("ButsTextureUser");
|
||||
|
||||
user->id = id;
|
||||
user->ptr = ptr;
|
||||
@@ -94,7 +94,7 @@ static void buttons_texture_user_property_add(ListBase *users,
|
||||
int icon,
|
||||
const char *name)
|
||||
{
|
||||
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
|
||||
ButsTextureUser *user = MEM_new<ButsTextureUser>("ButsTextureUser");
|
||||
|
||||
user->id = id;
|
||||
user->ptr = ptr;
|
||||
@@ -117,7 +117,7 @@ static void buttons_texture_user_node_add(ListBase *users,
|
||||
int icon,
|
||||
const char *name)
|
||||
{
|
||||
ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser");
|
||||
ButsTextureUser *user = MEM_new<ButsTextureUser>("ButsTextureUser");
|
||||
|
||||
user->id = id;
|
||||
user->ntree = ntree;
|
||||
@@ -362,7 +362,10 @@ void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
|
||||
sbuts->texuser = ct;
|
||||
}
|
||||
else {
|
||||
BLI_freelistN(&ct->users);
|
||||
LISTBASE_FOREACH_MUTABLE (ButsTextureUser *, user, &ct->users) {
|
||||
MEM_delete(user);
|
||||
}
|
||||
BLI_listbase_clear(&ct->users);
|
||||
}
|
||||
|
||||
buttons_texture_users_from_context(&ct->users, C, sbuts);
|
||||
|
||||
@@ -91,12 +91,15 @@ static void buttons_free(SpaceLink *sl)
|
||||
SpaceProperties *sbuts = (SpaceProperties *)sl;
|
||||
|
||||
if (sbuts->path) {
|
||||
MEM_freeN(sbuts->path);
|
||||
MEM_delete(static_cast<ButsContextPath *>(sbuts->path));
|
||||
}
|
||||
|
||||
if (sbuts->texuser) {
|
||||
ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser);
|
||||
BLI_freelistN(&ct->users);
|
||||
LISTBASE_FOREACH_MUTABLE (ButsTextureUser *, user, &ct->users) {
|
||||
MEM_delete(user);
|
||||
}
|
||||
BLI_listbase_clear(&ct->users);
|
||||
MEM_freeN(ct);
|
||||
}
|
||||
|
||||
@@ -881,7 +884,9 @@ static void buttons_id_remap(ScrArea * /*area*/,
|
||||
if (i != 0) {
|
||||
/* If the first item in the path is cleared, the whole path is cleared, so no need to
|
||||
* clear further items here, see also at the end of this block. */
|
||||
memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i));
|
||||
for (int j = i; j < path->len; j++) {
|
||||
path->ptr[j] = {};
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -890,7 +895,9 @@ static void buttons_id_remap(ScrArea * /*area*/,
|
||||
/* There is no easy way to check/make path downwards valid, just nullify it.
|
||||
* Next redraw will rebuild this anyway. */
|
||||
i++;
|
||||
memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i));
|
||||
for (int j = i; j < path->len; j++) {
|
||||
path->ptr[j] = {};
|
||||
}
|
||||
path->len = i;
|
||||
break;
|
||||
}
|
||||
@@ -902,15 +909,19 @@ static void buttons_id_remap(ScrArea * /*area*/,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (path->len == 0) {
|
||||
MEM_SAFE_FREE(sbuts->path);
|
||||
if (path->len == 0 && sbuts->path) {
|
||||
MEM_delete(static_cast<ButsContextPath *>(sbuts->path));
|
||||
sbuts->path = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (sbuts->texuser) {
|
||||
ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser);
|
||||
mappings.apply(reinterpret_cast<ID **>(&ct->texture), ID_REMAP_APPLY_DEFAULT);
|
||||
BLI_freelistN(&ct->users);
|
||||
LISTBASE_FOREACH_MUTABLE (ButsTextureUser *, user, &ct->users) {
|
||||
MEM_delete(user);
|
||||
}
|
||||
BLI_listbase_clear(&ct->users);
|
||||
ct->user = nullptr;
|
||||
}
|
||||
}
|
||||
@@ -928,7 +939,10 @@ static void buttons_foreach_id(SpaceLink *space_link, LibraryForeachIDData *data
|
||||
}
|
||||
/* NOTE: Restoring path pointers is complicated, if not impossible, because this contains
|
||||
* data pointers too, not just ID ones. See #40046. */
|
||||
MEM_SAFE_FREE(sbuts->path);
|
||||
if (sbuts->path) {
|
||||
MEM_delete(static_cast<ButsContextPath *>(sbuts->path));
|
||||
sbuts->path = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (sbuts->texuser) {
|
||||
@@ -936,7 +950,10 @@ static void buttons_foreach_id(SpaceLink *space_link, LibraryForeachIDData *data
|
||||
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, ct->texture, IDWALK_CB_DIRECT_WEAK_LINK);
|
||||
|
||||
if (!is_readonly) {
|
||||
BLI_freelistN(&ct->users);
|
||||
LISTBASE_FOREACH_MUTABLE (ButsTextureUser *, user, &ct->users) {
|
||||
MEM_delete(user);
|
||||
}
|
||||
BLI_listbase_clear(&ct->users);
|
||||
ct->user = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,14 +166,17 @@ static void open_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
PropertyPointerRNA *pprop;
|
||||
|
||||
op->customdata = pprop = MEM_cnew<PropertyPointerRNA>("OpenPropertyPointerRNA");
|
||||
op->customdata = pprop = MEM_new<PropertyPointerRNA>("OpenPropertyPointerRNA");
|
||||
UI_context_active_but_prop_get_templateID(C, &pprop->ptr, &pprop->prop);
|
||||
}
|
||||
|
||||
static void open_cancel(bContext * /*C*/, wmOperator *op)
|
||||
{
|
||||
MEM_freeN(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
if (op->customdata) {
|
||||
PropertyPointerRNA *pprop = static_cast<PropertyPointerRNA *>(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
MEM_delete(pprop);
|
||||
}
|
||||
}
|
||||
|
||||
static int open_exec(bContext *C, wmOperator *op)
|
||||
|
||||
@@ -1253,8 +1253,7 @@ struct ImageOpenData {
|
||||
static void image_open_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
ImageOpenData *iod;
|
||||
op->customdata = iod = static_cast<ImageOpenData *>(
|
||||
MEM_callocN(sizeof(ImageOpenData), __func__));
|
||||
op->customdata = iod = MEM_new<ImageOpenData>(__func__);
|
||||
iod->iuser = static_cast<ImageUser *>(
|
||||
CTX_data_pointer_get_type(C, "image_user", &RNA_ImageUser).data);
|
||||
UI_context_active_but_prop_get_templateID(C, &iod->pprop.ptr, &iod->pprop.prop);
|
||||
@@ -1262,8 +1261,9 @@ static void image_open_init(bContext *C, wmOperator *op)
|
||||
|
||||
static void image_open_cancel(bContext * /*C*/, wmOperator *op)
|
||||
{
|
||||
MEM_freeN(op->customdata);
|
||||
ImageOpenData *iod = static_cast<ImageOpenData *>(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
MEM_delete(iod);
|
||||
}
|
||||
|
||||
static Image *image_open_single(Main *bmain,
|
||||
@@ -1442,7 +1442,8 @@ static int image_open_exec(bContext *C, wmOperator *op)
|
||||
BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
|
||||
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
|
||||
|
||||
MEM_freeN(op->customdata);
|
||||
op->customdata = nullptr;
|
||||
MEM_delete(iod);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user