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