Skip to content

Commit

Permalink
Made all memnew functions and macros print info.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterPuma80 committed Jan 17, 2025
1 parent 8d66a9a commit be2c7d5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Ref {

template <typename... VarArgs>
void instantiate(VarArgs... p_params) {
ref(memnewOld(T(p_params...)));
ref(memnewWithArgs<T>(p_params...));
}

Ref() {}
Expand Down
56 changes: 33 additions & 23 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,10 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
return p_obj;
}

#define memnewOld(m_class) _post_initialize(new ("") m_class)
//#define memnewOldNoArgs(m_class) _post_initialize(new ("") m_class)
#define memnewOldNoConstructor(m_class) _post_initialize(new ("") m_class)
#define memnewOldWithArgs(m_class) _post_initialize(new ("") m_class)
//#define memnew(m_class) _post_initialize(new ("") m_class)

#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();
Expand All @@ -124,46 +119,61 @@ std::string get_type_name() {
return (status == 0) ? res.get() : name;
}

template <typename T>
void print_type_info(const char* message) {
std::string type_name = get_type_name<T>();
std::cout << "!!!!! " << message << ": " << type_name << std::endl;
std::cout.flush();
}

#define memnewOldWithArgs2(T, m_class) \
({ \
print_type_info<T>("memnewOldWithArgs2"); \
_post_initialize(new ("") m_class); \
})

#define memnewOldWithArgs3(name, m_class) \
({ \
std::cout << "!!!!! memnewOldWithArgs3: " << name << std::endl; \
std::cout.flush(); \
_post_initialize(new ("") m_class); \
})

#define memnewOldNoConstructor(T) \
({ \
T* result = new ("") T; \
print_type_info<T>("memnewOldNoConstructor"); \
_post_initialize(result); \
result; \
})

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();
*/
print_type_info<T>("memnewWithArgs");
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();
*/
print_type_info<T>("memnewNoConstructor");
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();
*/
print_type_info<T>("memnewNoArgs");
postinitialize_handler(result);
return result;
}





_ALWAYS_INLINE_ bool predelete_handler(void *) {
return true;
}
Expand Down Expand Up @@ -278,7 +288,7 @@ template <typename T>
class DefaultTypedAllocator {
public:
template <typename... Args>
_FORCE_INLINE_ T *new_allocation(const Args &&...p_args) { return memnewOld(T(p_args...)); }
_FORCE_INLINE_ T *new_allocation(const Args &&...p_args) { return memnewWithArgs<T>(p_args...); }
_FORCE_INLINE_ void delete_allocation(T *p_allocation) { memdelete(p_allocation); }
};

Expand Down
2 changes: 1 addition & 1 deletion modules/enet/enet_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void ENetConnection::Compressor::setup(ENetHost *p_host, CompressionMode p_mode)
case COMPRESS_FASTLZ:
case COMPRESS_ZLIB:
case COMPRESS_ZSTD: {
Compressor *compressor = memnewOldWithArgs(Compressor(p_mode));
Compressor *compressor = memnewOldWithArgs2(Compressor, Compressor(p_mode));
enet_host_compress(p_host, &(compressor->enet_compressor));
} break;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/navigation/3d/godot_navigation_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using namespace NavigationUtilities;
} \
}; \
void GodotNavigationServer3D::F_NAME(T_0 D_0) { \
auto cmd = memnewOldWithArgs(MERGE(F_NAME, _command)( \
auto cmd = memnewOldWithArgs3("MERGE", MERGE(F_NAME, _command)( \
D_0)); \
add_command(cmd); \
} \
Expand All @@ -75,7 +75,7 @@ using namespace NavigationUtilities;
} \
}; \
void GodotNavigationServer3D::F_NAME(T_0 D_0, T_1 D_1) { \
auto cmd = memnewOldWithArgs(MERGE(F_NAME, _command)( \
auto cmd = memnewOldWithArgs3("MERGE", MERGE(F_NAME, _command)( \
D_0, \
D_1)); \
add_command(cmd); \
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ int TreeItem::get_custom_minimum_height() const {
/* Item manipulation */

TreeItem *TreeItem::create_child(int p_index) {
TreeItem *ti = memnewOldWithArgs(TreeItem(tree));
TreeItem *ti = memnewOldWithArgs2(TreeItem, TreeItem(tree));
if (tree) {
ti->cells.resize(tree->columns.size());
tree->queue_redraw();
Expand Down Expand Up @@ -4478,7 +4478,7 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_index) {
} else {
if (!root) {
// No root exists, make the given item the new root.
ti = memnewOldWithArgs(TreeItem(this));
ti = memnewOldWithArgs2(TreeItem, TreeItem(this));
ERR_FAIL_NULL_V(ti, nullptr);
ti->cells.resize(columns.size());
ti->is_root = true;
Expand Down

0 comments on commit be2c7d5

Please sign in to comment.