Skip to content

Commit

Permalink
Replaced memnewOldWithArgs macro with memnewWithArgs function.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterPuma80 committed Jan 17, 2025
1 parent 2513836 commit 244ae07
Show file tree
Hide file tree
Showing 153 changed files with 461 additions and 404 deletions.
4 changes: 2 additions & 2 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,14 @@ void GDExtension::_register_extension_class_method(GDExtensionClassLibraryPtr p_
}

if (method == nullptr) {
method = memnewOldWithArgs(GDExtensionMethodBind(p_method_info));
method = memnewWithArgs<GDExtensionMethodBind>(p_method_info);
method->set_instance_class(class_name);
extension->methods[method_name] = method;
} else {
method->is_reloading = false;
}
#else
GDExtensionMethodBind *method = memnewOldWithArgs(GDExtensionMethodBind(p_method_info));
GDExtensionMethodBind *method = memnewWithArgs<GDExtensionMethodBind>(p_method_info);
method->set_instance_class(class_name);
#endif

Expand Down
6 changes: 3 additions & 3 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ static GDExtensionScriptInstancePtr gdextension_placeholder_script_instance_crea
script.reference_ptr((Script *)p_script);
Object *owner = (Object *)p_owner;

PlaceHolderScriptInstance *placeholder = memnewOldWithArgs(PlaceHolderScriptInstance(language, script, owner));
PlaceHolderScriptInstance *placeholder = memnewWithArgs<PlaceHolderScriptInstance>(language, script, owner);
return reinterpret_cast<GDExtensionScriptInstancePtr>(placeholder);
}

Expand Down Expand Up @@ -1471,12 +1471,12 @@ static GDExtensionScriptInstancePtr gdextension_object_get_script_instance(GDExt

#ifndef DISABLE_DEPRECATED
static void gdextension_callable_custom_create(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo *p_custom_callable_info) {
memnew_placement(r_callable, Callable(memnewOldWithArgs(CallableCustomExtension(p_custom_callable_info))));
memnew_placement(r_callable, Callable(memnewWithArgs<CallableCustomExtension>(p_custom_callable_info)));
}
#endif

static void gdextension_callable_custom_create2(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo2 *p_custom_callable_info) {
memnew_placement(r_callable, Callable(memnewOldWithArgs(CallableCustomExtension(p_custom_callable_info))));
memnew_placement(r_callable, Callable(memnewWithArgs<CallableCustomExtension>(p_custom_callable_info)));
}

static void *gdextension_callable_custom_get_userdata(GDExtensionTypePtr p_callable, void *p_token) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ Rect2i Image::get_used_rect() const {
}

Ref<Image> Image::get_region(const Rect2i &p_region) const {
Ref<Image> img = memnewOldWithArgs(Image(p_region.size.x, p_region.size.y, mipmaps, format));
Ref<Image> img = memnewWithArgs<Image>(p_region.size.x, p_region.size.y, mipmaps, format);
img->blit_rect(Ref<Image>((Image *)this), p_region, Point2i(0, 0));
return img;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
// If we want to ignore cache, but there's another task loading it, we can't add this one to the map.
must_not_register = ignoring_cache && thread_load_tasks.has(local_path);
if (must_not_register) {
load_token->task_if_unregistered = memnewOldWithArgs(ThreadLoadTask(load_task));
load_token->task_if_unregistered = memnewWithArgs<ThreadLoadTask>(load_task);
load_task_ptr = load_token->task_if_unregistered;
} else {
DEV_ASSERT(!thread_load_tasks.has(local_path));
Expand Down
12 changes: 6 additions & 6 deletions core/object/callable_method_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Callable create_custom_callable_function_pointer(T *p_instance,
#endif
void (T::*p_method)(P...)) {
typedef CallableCustomMethodPointer<T, void, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_instance, p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_instance, p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand All @@ -140,7 +140,7 @@ Callable create_custom_callable_function_pointer(T *p_instance,
#endif
R (T::*p_method)(P...)) {
typedef CallableCustomMethodPointer<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_instance, p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_instance, p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand Down Expand Up @@ -196,7 +196,7 @@ Callable create_custom_callable_function_pointer(T *p_instance,
#endif
void (T::*p_method)(P...) const) {
typedef CallableCustomMethodPointerC<T, void, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_instance, p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_instance, p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand All @@ -210,7 +210,7 @@ Callable create_custom_callable_function_pointer(T *p_instance,
#endif
R (T::*p_method)(P...) const) {
typedef CallableCustomMethodPointerC<T, R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_instance, p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_instance, p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand Down Expand Up @@ -268,7 +268,7 @@ Callable create_custom_callable_static_function_pointer(
#endif
void (*p_method)(P...)) {
typedef CallableCustomStaticMethodPointer<void, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand All @@ -282,7 +282,7 @@ Callable create_custom_callable_static_function_pointer(
#endif
R (*p_method)(P...)) {
typedef CallableCustomStaticMethodPointer<R, P...> CCMP; // Messes with memnew otherwise.
CCMP *ccmp = memnewOldWithArgs(CCMP(p_method));
CCMP *ccmp = memnewWithArgs<CCMP>(p_method);
#ifdef DEBUG_METHODS_ENABLED
ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand.
#endif
Expand Down
2 changes: 1 addition & 1 deletion core/object/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ CallQueue::CallQueue(Allocator *p_custom_allocator, uint32_t p_max_pages, const
allocator = p_custom_allocator;
allocator_is_custom = true;
} else {
allocator = memnewOldWithArgs(Allocator(16)); // 16 elements per allocator page, 64kb per allocator page. Anything small will do, though.
allocator = memnewWithArgs<Allocator>(16); // 16 elements per allocator page, 64kb per allocator page. Anything small will do, though.
allocator_is_custom = false;
}
max_pages = p_max_pages;
Expand Down
57 changes: 57 additions & 0 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
#include <stddef.h>
#include <new>
#include <type_traits>
#include <cxxabi.h>
#include <memory>
#include <string>
#include <cstddef>
#include <cstdint>
#include <iostream>

class Memory {
#ifdef DEBUG_ENABLED
Expand Down Expand Up @@ -107,6 +113,57 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
#define memnew_allocator(m_class, m_allocator) _post_initialize(new (m_allocator::alloc) m_class)
#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement) m_class)

template <typename T>
std::string get_type_name() {
const char* name = typeid(T).name();
int status = -4;
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
return (status == 0) ? res.get() : name;
}

template <typename T, typename... Args>
/*_ALWAYS_INLINE_*/ T* memnewWithArgs(Args&&... args) {
T* result = new ("") T(std::forward<Args>(args)...);
/*
std::string type_name = get_type_name<T>();
std::cout << "!!!!! memnewWithArgs: " << type_name << std::endl;
std::cout.flush();
*/
postinitialize_handler(result);
return result;
}

template <typename T>
/*_ALWAYS_INLINE_*/ T* memnewNoConstructor() {
T* result = new ("") T;
/*
std::string type_name = get_type_name<T>();
std::cout << "!!!!! memnewNoArgs: " << type_name << std::endl;
std::cout.flush();
*/
postinitialize_handler(result);
return result;
}

template <typename T>
/*_ALWAYS_INLINE_*/ T* memnewNoArgs() {
T* result = new ("") T;
/*
std::string type_name = get_type_name<T>();
std::cout << "!!!!! memnewNoArgs: " << type_name << std::endl;
std::cout.flush();
*/
postinitialize_handler(result);
return result;
}





_ALWAYS_INLINE_ bool predelete_handler(void *) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void OS::add_logger(Logger *p_logger) {
if (!_logger) {
Vector<Logger *> loggers;
loggers.push_back(p_logger);
_logger = memnewOldWithArgs(CompositeLogger(loggers));
_logger = memnewWithArgs<CompositeLogger>(loggers);
} else {
_logger->add_logger(p_logger);
}
Expand Down Expand Up @@ -705,7 +705,7 @@ OS::OS() {

Vector<Logger *> loggers;
loggers.push_back(memnewOldNoConstructor(StdLogger));
_set_logger(memnewOldWithArgs(CompositeLogger(loggers)));
_set_logger(memnewWithArgs<CompositeLogger>(loggers));
}

OS::~OS() {
Expand Down
2 changes: 1 addition & 1 deletion core/variant/callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Callable Callable::create(const Variant &p_variant, const StringName &p_method)
case Variant::OBJECT:
return Callable(p_variant.operator ObjectID(), p_method);
default:
return Callable(memnewOldWithArgs(VariantCallable(p_variant, p_method)));
return Callable(memnewWithArgs<VariantCallable>(p_variant, p_method));
}
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/coremidi/midi_driver_coremidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Error MIDIDriverCoreMidi::open() {
for (int i = 0; i < source_count; i++) {
MIDIEndpointRef source = MIDIGetSource(i);
if (source) {
InputConnection *conn = memnewOldWithArgs(InputConnection(connection_index, source));
InputConnection *conn = memnewWithArgs<InputConnection>(connection_index, source);
const OSStatus res = MIDIPortConnectSource(port_in, source, static_cast<void *>(conn));
if (res != noErr) {
memdelete(conn);
Expand Down
2 changes: 1 addition & 1 deletion drivers/d3d12/rendering_context_driver_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool RenderingContextDriverD3D12::device_supports_present(uint32_t p_device_inde
}

RenderingDeviceDriver *RenderingContextDriverD3D12::driver_create() {
return memnewOldWithArgs(RenderingDeviceDriverD3D12(this));
return memnewWithArgs<RenderingDeviceDriverD3D12>(this);
}

void RenderingContextDriverD3D12::driver_free(RenderingDeviceDriver *p_driver) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ UnixTerminalLogger::~UnixTerminalLogger() {}
OS_Unix::OS_Unix() {
Vector<Logger *> loggers;
loggers.push_back(memnewOldNoConstructor(UnixTerminalLogger));
_set_logger(memnewOldWithArgs(CompositeLogger(loggers)));
_set_logger(memnewWithArgs<CompositeLogger>(loggers));
}

#endif
2 changes: 1 addition & 1 deletion drivers/vulkan/rendering_context_driver_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ bool RenderingContextDriverVulkan::device_supports_present(uint32_t p_device_ind
}

RenderingDeviceDriver *RenderingContextDriverVulkan::driver_create() {
return memnewOldWithArgs(RenderingDeviceDriverVulkan(this));
return memnewWithArgs<RenderingDeviceDriverVulkan>(this);
}

void RenderingContextDriverVulkan::driver_free(RenderingDeviceDriver *p_driver) {
Expand Down
2 changes: 1 addition & 1 deletion editor/action_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Variant ActionMapEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
}

String name = selected->get_text(0);
Label *label = memnewOldWithArgs(Label(name));
Label *label = memnewWithArgs<Label>(name);
label->set_theme_type_variation("HeaderSmall");
label->set_modulate(Color(1, 1, 1, 1.0f));
action_tree->set_drag_preview(label);
Expand Down
14 changes: 7 additions & 7 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7578,11 +7578,11 @@ AnimationTrackEditor::AnimationTrackEditor() {
ease_fps->set_max(999);
ease_fps->set_step(FPS_DECIMAL);
ease_fps->set_value(30); // Default
ease_grid->add_child(memnewOldWithArgs(Label(TTR("Transition Type:"))));
ease_grid->add_child(memnewWithArgs<Label>(TTR("Transition Type:")));
ease_grid->add_child(transition_selection);
ease_grid->add_child(memnewOldWithArgs(Label(TTR("Ease Type:"))));
ease_grid->add_child(memnewWithArgs<Label>(TTR("Ease Type:")));
ease_grid->add_child(ease_selection);
ease_grid->add_child(memnewOldWithArgs(Label(TTR("FPS:"))));
ease_grid->add_child(memnewWithArgs<Label>(TTR("FPS:")));
ease_grid->add_child(ease_fps);

//
Expand All @@ -7604,13 +7604,13 @@ AnimationTrackEditor::AnimationTrackEditor() {
bake_fps->set_max(999);
bake_fps->set_step(FPS_DECIMAL);
bake_fps->set_value(30); // Default
bake_grid->add_child(memnewOldWithArgs(Label(TTR("3D Pos/Rot/Scl Track:"))));
bake_grid->add_child(memnewWithArgs<Label>(TTR("3D Pos/Rot/Scl Track:")));
bake_grid->add_child(bake_trs);
bake_grid->add_child(memnewOldWithArgs(Label(TTR("Blendshape Track:"))));
bake_grid->add_child(memnewWithArgs<Label>(TTR("Blendshape Track:")));
bake_grid->add_child(bake_blendshape);
bake_grid->add_child(memnewOldWithArgs(Label(TTR("Value Track:"))));
bake_grid->add_child(memnewWithArgs<Label>(TTR("Value Track:")));
bake_grid->add_child(bake_value);
bake_grid->add_child(memnewOldWithArgs(Label(TTR("FPS:"))));
bake_grid->add_child(memnewWithArgs<Label>(TTR("FPS:")));
bake_grid->add_child(bake_fps);

//
Expand Down
12 changes: 6 additions & 6 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ ConnectDialog::ConnectDialog() {
vbc_left->add_margin_child(TTR("From Signal:"), from_signal);
from_signal->set_editable(false);

tree = memnewOldWithArgs(SceneTreeEditor(false));
tree = memnewWithArgs<SceneTreeEditor>(false);
tree->set_connecting_signal(true);
tree->set_show_enabled_subscene(true);
tree->set_v_size_flags(Control::SIZE_FILL | Control::SIZE_EXPAND);
Expand Down Expand Up @@ -780,19 +780,19 @@ ConnectDialog::ConnectDialog() {
method_tree->connect(SceneStringName(item_selected), callable_mp(this, &ConnectDialog::_method_selected));
method_tree->connect("item_activated", callable_mp((Window *)method_popup, &Window::hide));

empty_tree_label = memnewOldWithArgs(Label(TTR("No method found matching given filters.")));
empty_tree_label = memnewWithArgs<Label>(TTR("No method found matching given filters."));
method_popup->add_child(empty_tree_label);
empty_tree_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
empty_tree_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
empty_tree_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD);

script_methods_only = memnewOldWithArgs(CheckButton(TTR("Script Methods Only")));
script_methods_only = memnewWithArgs<CheckButton>(TTR("Script Methods Only"));
method_vbc->add_child(script_methods_only);
script_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
script_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_script_methods_only", true));
script_methods_only->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_method_check_button_pressed).bind(script_methods_only));

compatible_methods_only = memnewOldWithArgs(CheckButton(TTR("Compatible Methods Only")));
compatible_methods_only = memnewWithArgs<CheckButton>(TTR("Compatible Methods Only"));
method_vbc->add_child(compatible_methods_only);
compatible_methods_only->set_h_size_flags(Control::SIZE_SHRINK_END);
compatible_methods_only->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "show_compatible_methods_only", true));
Expand Down Expand Up @@ -858,7 +858,7 @@ ConnectDialog::ConnectDialog() {
open_method_tree->set_text("Pick");
open_method_tree->connect(SceneStringName(pressed), callable_mp(this, &ConnectDialog::_open_method_popup));

advanced = memnewOldWithArgs(CheckButton(TTR("Advanced")));
advanced = memnewWithArgs<CheckButton>(TTR("Advanced"));
vbc_left->add_child(advanced);
advanced->set_h_size_flags(Control::SIZE_SHRINK_BEGIN | Control::SIZE_EXPAND);
advanced->set_pressed(EditorSettings::get_singleton()->get_project_metadata("editor_metadata", "use_advanced_connections", false));
Expand Down Expand Up @@ -900,7 +900,7 @@ Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
return nullptr;
}

EditorHelpBit *help_bit = memnewOldWithArgs(EditorHelpBit(p_text));
EditorHelpBit *help_bit = memnewWithArgs<EditorHelpBit>(p_text);
EditorHelpBitTooltip::show_tooltip(help_bit, const_cast<ConnectionsDockTree *>(this));
return memnewOldNoConstructor(Control); // Make the standard tooltip invisible.
}
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_debugger_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Variant EditorDebuggerTree::get_drag_data(const Point2 &p_point) {
tf->set_texture(selected->get_icon(0));
tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
hb->add_child(tf);
Label *label = memnewOldWithArgs(Label(path));
Label *label = memnewWithArgs<Label>(path);
hb->add_child(label);
set_drag_preview(hb);

Expand Down
8 changes: 4 additions & 4 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ EditorProfiler::EditorProfiler() {
clear_button->set_disabled(true);
hb->add_child(clear_button);

hb->add_child(memnewOldWithArgs(Label(TTR("Measure:"))));
hb->add_child(memnewWithArgs<Label>(TTR("Measure:")));

display_mode = memnewOldNoConstructor(OptionButton);
display_mode->add_item(TTR("Frame Time (ms)"));
Expand All @@ -645,7 +645,7 @@ EditorProfiler::EditorProfiler() {

hb->add_child(display_mode);

hb->add_child(memnewOldWithArgs(Label(TTR("Time:"))));
hb->add_child(memnewWithArgs<Label>(TTR("Time:")));

display_time = memnewOldNoConstructor(OptionButton);
// TRANSLATORS: This is an option in the profiler to display the time spent in a function, including the time spent in other functions called by that function.
Expand All @@ -657,15 +657,15 @@ EditorProfiler::EditorProfiler() {

hb->add_child(display_time);

display_internal_profiles = memnewOldWithArgs(CheckButton(TTR("Display internal functions")));
display_internal_profiles = memnewWithArgs<CheckButton>(TTR("Display internal functions"));
display_internal_profiles->set_visible(EDITOR_GET("debugger/profile_native_calls"));
display_internal_profiles->set_pressed(false);
display_internal_profiles->connect(SceneStringName(pressed), callable_mp(this, &EditorProfiler::_internal_profiles_pressed));
hb->add_child(display_internal_profiles);

hb->add_spacer();

hb->add_child(memnewOldWithArgs(Label(TTR("Frame #:"))));
hb->add_child(memnewWithArgs<Label>(TTR("Frame #:")));

cursor_metric_edit = memnewOldNoConstructor(SpinBox);
cursor_metric_edit->set_h_size_flags(SIZE_FILL);
Expand Down
Loading

0 comments on commit 244ae07

Please sign in to comment.