2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2002-2022 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-08-18 15:20:29 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
2021-12-14 18:35:31 +11:00
|
|
|
* \ingroup intern_mem
|
2011-02-25 11:41:12 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-07-03 17:23:03 +02:00
|
|
|
#include <cstddef>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <new>
|
2009-08-18 15:20:29 +00:00
|
|
|
|
2024-07-03 17:23:03 +02:00
|
|
|
#include "../intern/mallocn_intern_function_pointers.hh"
|
|
|
|
|
|
|
|
|
|
using namespace mem_guarded::internal;
|
|
|
|
|
|
2020-05-14 11:24:50 +02:00
|
|
|
void *operator new(size_t size, const char *str);
|
|
|
|
|
void *operator new[](size_t size, const char *str);
|
2012-11-10 05:42:50 +00:00
|
|
|
|
2012-06-25 10:35:24 +00:00
|
|
|
/* not default but can be used when needing to set a string */
|
2020-05-14 11:24:50 +02:00
|
|
|
void *operator new(size_t size, const char *str)
|
2009-08-18 15:20:29 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
return mem_mallocN_aligned_ex(size, 1, str, AllocationType::NEW_DELETE);
|
2009-08-18 15:20:29 +00:00
|
|
|
}
|
2020-05-14 11:24:50 +02:00
|
|
|
void *operator new[](size_t size, const char *str)
|
2009-08-18 15:20:29 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
return mem_mallocN_aligned_ex(size, 1, str, AllocationType::NEW_DELETE);
|
2009-08-18 15:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-14 11:24:50 +02:00
|
|
|
void *operator new(size_t size)
|
2012-06-25 10:35:24 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
return mem_mallocN_aligned_ex(size, 1, "C++/anonymous", AllocationType::NEW_DELETE);
|
2012-06-25 10:35:24 +00:00
|
|
|
}
|
2020-05-14 11:24:50 +02:00
|
|
|
void *operator new[](size_t size)
|
2012-06-25 10:35:24 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
return mem_mallocN_aligned_ex(size, 1, "C++/anonymous[]", AllocationType::NEW_DELETE);
|
2012-06-25 10:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-28 12:32:06 +00:00
|
|
|
void operator delete(void *p) throw()
|
2012-06-25 10:35:24 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
/* `delete nullptr` is valid in c++. */
|
2023-09-12 14:48:20 +10:00
|
|
|
if (p) {
|
2024-07-03 17:23:03 +02:00
|
|
|
mem_freeN_ex(p, AllocationType::NEW_DELETE);
|
2023-09-12 14:48:20 +10:00
|
|
|
}
|
2012-06-25 10:35:24 +00:00
|
|
|
}
|
2012-06-28 12:32:06 +00:00
|
|
|
void operator delete[](void *p) throw()
|
2009-08-18 15:20:29 +00:00
|
|
|
{
|
2024-07-03 17:23:03 +02:00
|
|
|
/* `delete nullptr` is valid in c++. */
|
2023-09-12 14:48:20 +10:00
|
|
|
if (p) {
|
2024-07-03 17:23:03 +02:00
|
|
|
mem_freeN_ex(p, AllocationType::NEW_DELETE);
|
2023-09-12 14:48:20 +10:00
|
|
|
}
|
2009-08-18 15:20:29 +00:00
|
|
|
}
|