Cleanup: Move internal guardedalloc headers to C++.

Pull Request: https://projects.blender.org/blender/blender/pulls/124106
This commit is contained in:
Bastien Montagne 2024-07-03 16:04:18 +02:00 committed by Bastien Montagne
parent e2d77fbc1c
commit 4afb48acad
9 changed files with 11 additions and 35 deletions

@ -8,7 +8,7 @@
include(CheckSymbolExists)
# Used for: `intern/guardedalloc/intern/mallocn_intern.h`.
# Used for: `intern/guardedalloc/intern/mallocn_intern.hh`.
# Function `malloc_stats` is only available on GLIBC,
# so check that before defining `HAVE_MALLOC_STATS`.
check_symbol_exists(malloc_stats "malloc.h" HAVE_MALLOC_STATS_H)

@ -26,8 +26,8 @@ set(SRC
./intern/memory_usage.cc
MEM_guardedalloc.h
./intern/mallocn_inline.h
./intern/mallocn_intern.h
./intern/mallocn_inline.hh
./intern/mallocn_intern.hh
# only so the header is known by cmake
../atomic/atomic_ops.h

@ -10,7 +10,7 @@
#include <cstdlib>
#include "MEM_guardedalloc.h"
#include "mallocn_intern.h"
#include "mallocn_intern.hh"
bool leak_detector_has_run = false;
char free_after_leak_detection_message[] =

@ -15,7 +15,7 @@
#include <cassert>
#include "mallocn_intern.h"
#include "mallocn_intern.hh"
#ifdef WITH_JEMALLOC_CONF
/**

@ -29,7 +29,7 @@
#include "../../source/blender/blenlib/BLI_strict_flags.h"
#include "atomic_ops.h"
#include "mallocn_intern.h"
#include "mallocn_intern.hh"
/* Only for debugging:
* store original buffer's name when doing MEM_dupallocN

@ -3,18 +3,12 @@
* SPDX-FileCopyrightText: 2009-2017 Facebook, Inc. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause */
#pragma once
/** \file
* \ingroup intern_mem
*/
#ifndef __MALLOCN_INLINE_H__
#define __MALLOCN_INLINE_H__
#ifdef __cplusplus
extern "C" {
#endif
MEM_INLINE bool MEM_size_safe_multiply(size_t a, size_t b, size_t *result)
{
/* A size_t with its high-half bits all set to 1. */
@ -33,9 +27,3 @@ MEM_INLINE bool MEM_size_safe_multiply(size_t a, size_t b, size_t *result)
*/
return ((high_bits & (a | b)) == 0 || (*result / b == a));
}
#ifdef __cplusplus
}
#endif
#endif /* __MALLOCN_INLINE_H__ */

@ -1,14 +1,12 @@
/* SPDX-FileCopyrightText: 2013 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup intern_mem
*/
#ifndef __MALLOCN_INTERN_H__
#define __MALLOCN_INTERN_H__
#ifdef __GNUC__
# define UNUSED(x) UNUSED_##x __attribute__((__unused__))
#elif defined(_MSC_VER)
@ -95,11 +93,7 @@ size_t malloc_usable_size(void *ptr);
/* Real pointer returned by the malloc or aligned_alloc. */
#define MEMHEAD_REAL_PTR(memh) ((char *)memh - MEMHEAD_ALIGN_PADDING(memh->alignment))
#include "mallocn_inline.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "mallocn_inline.hh"
#define ALIGNED_MALLOC_MINIMUM_ALIGNMENT sizeof(void *)
@ -227,9 +221,3 @@ void mem_guarded_clearmemlist(void);
const char *MEM_guarded_name_ptr(void *vmemh);
void MEM_guarded_name_ptr_set(void *vmemh, const char *str);
#endif
#ifdef __cplusplus
}
#endif
#endif /* __MALLOCN_INTERN_H__ */

@ -26,7 +26,7 @@
#include "../../source/blender/blenlib/BLI_strict_flags.h"
#include "atomic_ops.h"
#include "mallocn_intern.h"
#include "mallocn_intern.hh"
typedef struct MemHead {
/* Length of allocated memory block. */

@ -11,7 +11,7 @@
#include <vector>
#include "MEM_guardedalloc.h"
#include "mallocn_intern.h"
#include "mallocn_intern.hh"
#include "../../source/blender/blenlib/BLI_strict_flags.h"