Blender  V2.93
utildefines.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #ifndef LIBMV_C_API_UTILDEFINES_H_
21 #define LIBMV_C_API_UTILDEFINES_H_
22 
23 #if defined(_MSC_VER) && _MSC_VER < 1900
24 # define __func__ __FUNCTION__
25 # define snprintf _snprintf
26 #endif
27 
28 #ifdef WITH_LIBMV_GUARDED_ALLOC
29 # include "MEM_guardedalloc.h"
30 # define LIBMV_OBJECT_NEW OBJECT_GUARDED_NEW
31 # define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
32 # define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
33 # define LIBMV_STRUCT_NEW(type, count) \
34  (type*)MEM_mallocN(sizeof(type) * count, __func__)
35 # define LIBMV_STRUCT_DELETE(what) MEM_freeN(what)
36 #else
37 // Need this to keep libmv-capi potentially standalone.
38 # if defined __GNUC__ || defined __sun
39 # define LIBMV_OBJECT_NEW(type, args...) \
40  new (malloc(sizeof(type))) type(args)
41 # else
42 # define LIBMV_OBJECT_NEW(type, ...) \
43  new (malloc(sizeof(type))) type(__VA_ARGS__)
44 # endif
45 # define LIBMV_OBJECT_DELETE(what, type) \
46  { \
47  if (what) { \
48  ((type*)(what))->~type(); \
49  free(what); \
50  } \
51  } \
52  (void)0
53 # define LIBMV_STRUCT_NEW(type, count) (type*)malloc(sizeof(type) * count)
54 # define LIBMV_STRUCT_DELETE(what) \
55  { \
56  if (what) \
57  free(what); \
58  } \
59  (void)0
60 #endif
61 
62 #endif // LIBMV_C_API_UTILDEFINES_H_
Read Guarded memory(de)allocation.