Blender V4.3
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(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) MEM_freeN(what)
33#else
34// Need this to keep libmv-capi potentially standalone.
35# if defined __GNUC__ || defined __sun
36# define LIBMV_OBJECT_NEW(type, args...) \
37 new (malloc(sizeof(type))) type(args)
38# else
39# define LIBMV_OBJECT_NEW(type, ...) \
40 new (malloc(sizeof(type))) type(__VA_ARGS__)
41# endif
42# define LIBMV_OBJECT_DELETE(what, type) \
43 { \
44 if (what) { \
45 ((type*)(what))->~type(); \
46 free(what); \
47 } \
48 } \
49 (void)0
50# define LIBMV_STRUCT_NEW(type, count) (type*)malloc(sizeof(type) * count)
51# define LIBMV_STRUCT_DELETE(what) \
52 { \
53 if (what) \
54 free(what); \
55 } \
56 (void)0
57#endif
58
59#endif // LIBMV_C_API_UTILDEFINES_H_
Read Guarded memory(de)allocation.