debug_new.h 1.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1
/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
羽飞's avatar
羽飞 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */

//
// Created by Longda on 2010
//

羽飞's avatar
羽飞 已提交
15
#pragma once
羽飞's avatar
羽飞 已提交
16 17 18 19 20 21 22 23 24 25 26 27

#include <new>
#include <stdlib.h>
namespace common {

/* Prototypes */
bool check_leaks();
void *operator new(size_t size, const char *file, int line);
void *operator new[](size_t size, const char *file, int line);
#ifndef NO_PLACEMENT_DELETE
void operator delete(void *pointer, const char *file, int line);
void operator delete[](void *pointer, const char *file, int line);
28 29
#endif                           // NO_PLACEMENT_DELETE
void operator delete[](void *);  // MSVC 6 requires this declaration
羽飞's avatar
羽飞 已提交
30 31 32 33 34 35 36 37

/* Macros */
#ifndef DEBUG_NEW_NO_NEW_REDEFINITION
#define new DEBUG_NEW
#define DEBUG_NEW new (__FILE__, __LINE__)
#define debug_new new
#else
#define debug_new new (__FILE__, __LINE__)
38
#endif  // DEBUG_NEW_NO_NEW_REDEFINITION
羽飞's avatar
羽飞 已提交
39 40 41 42
#ifdef DEBUG_NEW_EMULATE_MALLOC

#define malloc(s) ((void *)(debug_new char[s]))
#define free(p) delete[](char *)(p)
43
#endif  // DEBUG_NEW_EMULATE_MALLOC
羽飞's avatar
羽飞 已提交
44 45

/* Control flags */
46 47
extern bool new_verbose_flag;    // default to false: no verbose information
extern bool new_autocheck_flag;  // default to true: call check_leaks() on exit
羽飞's avatar
羽飞 已提交
48

49
}  // namespace common