Blender V5.0
utildefines.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#ifndef LIBMV_C_API_UTILDEFINES_H_
6#define LIBMV_C_API_UTILDEFINES_H_
7
8#if defined(_MSC_VER) && _MSC_VER < 1900
9# define __func__ __FUNCTION__
10# define snprintf _snprintf
11#endif
12
13#ifdef WITH_LIBMV_GUARDED_ALLOC
14# include "MEM_guardedalloc.h"
15# if defined __GNUC__
16# define LIBMV_OBJECT_NEW(type, args...) \
17 new (MEM_mallocN(sizeof(type), __func__)) type(args)
18# else
19# define LIBMV_OBJECT_NEW(type, ...) \
20 new (MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__)
21# endif
22# define LIBMV_OBJECT_DELETE(what, type) \
23 { \
24 if (what) { \
25 ((type*)what)->~type(); \
26 MEM_freeN(const_cast<void*>(static_cast<const void*>(what))); \
27 } \
28 } \
29 (void)0
30# define LIBMV_STRUCT_NEW(type, count) \
31 (type*)MEM_mallocN(sizeof(type) * count, __func__)
32# define LIBMV_STRUCT_DELETE(what) \
33 MEM_freeN(const_cast<void*>(static_cast<const void*>(what)))
34#else
35// Need this to keep libmv-capi potentially standalone.
36# if defined __GNUC__ || defined __sun
37# define LIBMV_OBJECT_NEW(type, args...) \
38 new (malloc(sizeof(type))) type(args)
39# else
40# define LIBMV_OBJECT_NEW(type, ...) \
41 new (malloc(sizeof(type))) type(__VA_ARGS__)
42# endif
43# define LIBMV_OBJECT_DELETE(what, type) \
44 { \
45 if (what) { \
46 ((type*)(what))->~type(); \
47 free(what); \
48 } \
49 } \
50 (void)0
51# define LIBMV_STRUCT_NEW(type, count) (type*)malloc(sizeof(type) * count)
52# define LIBMV_STRUCT_DELETE(what) \
53 { \
54 if (what) \
55 free(what); \
56 } \
57 (void)0
58#endif
59
60#endif // LIBMV_C_API_UTILDEFINES_H_
Read Guarded memory(de)allocation.