/[escript]/branches/windows_from_1456_trunk_1580_merged_in/paso/src/Common.h
ViewVC logotype

Contents of /branches/windows_from_1456_trunk_1580_merged_in/paso/src/Common.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1587 - (show annotations)
Thu Jun 5 05:50:20 2008 UTC (12 years, 3 months ago) by phornby
File MIME type: text/plain
File size: 8857 byte(s)
define esysUtils::malloc() and friends to dress naked mallocs in C++ code.

Remove unneedded PyObject_NEW macros from Common.h.

Add needed system include files to blocktimer.c

Dress the naked mallocs in DataFactory and DataTagged.


1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #ifndef INC_PASO_COMMON
17 #define INC_PASO_COMMON
18
19 /**************************************************************/
20
21 /* Finley finite element solver: common include file */
22
23 /**************************************************************/
24
25 /* Copyrights by ACcESS Australia, 2003 */
26 /* Version: $Id$ */
27
28 /**************************************************************/
29
30 /* some system values */
31 #if ( defined __INTEL_COMPILER )
32 #include <mathimf.h>
33 #else
34 #include <math.h>
35 #endif
36
37 #if (defined __OPENMP)
38 #include <omp.h>
39 #endif
40
41 #include <float.h>
42 #include <stdio.h>
43 #include <limits.h>
44 #include <stdlib.h>
45 #include <string.h>
46
47 #define LenString_MAX FILENAME_MAX*2
48 #define LenErrorMsg_MAX LenString_MAX
49
50 /* on some arcitectures it could be a good idea to use long rather than int */
51 /* this has not really been tested */
52
53 typedef int dim_t;
54 typedef int index_t;
55 typedef int bool_t;
56 typedef int type_t;
57 typedef int err_t;
58
59 #define INDEX_T_MAX INT_MAX
60 #define EPSILON DBL_EPSILON
61 #define LARGE_POSITIVE_FLOAT DBL_MAX
62
63 /**************************************************************/
64
65 /* some useful functions: */
66
67 #define FALSE 0
68 #define TRUE 1
69 #define UNKNOWN -1
70 #define DBLE(_x_) (double)(_x_)
71 #define INDEX1(_X1_) (_X1_)
72 #define INDEX2(_X1_,_X2_,_N1_) ((_X1_)+(_N1_)*(_X2_))
73 #define INDEX3(_X1_,_X2_,_X3_,_N1_,_N2_) ((_X1_)+(_N1_)*INDEX2(_X2_,_X3_,_N2_))
74 #define INDEX4(_X1_,_X2_,_X3_,_X4_,_N1_,_N2_,_N3_) ((_X1_)+(_N1_)*INDEX3(_X2_,_X3_,_X4_,_N2_,_N3_))
75 #define INDEX5(_X1_,_X2_,_X3_,_X4_,_X5_,_N1_,_N2_,_N3_,_N4_) ((_X1_)+(_N1_)*INDEX4(_X2_,_X3_,_X4_,_X5_,_N2_,_N3_,_N4_))
76 #define INDEX6(_X1_,_X2_,_X3_,_X4_,_X5_,_X6_,_N1_,_N2_,_N3_,_N4_,_N5_) ((_X1_)+(_N1_)*INDEX5(_X2_,_X3_,_X4_,_X5_,_X6_,_N2_,_N3_,_N4_,_N5_))
77
78 #define MAX(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg1_) : (_arg2_))
79 #define MAX3(_arg1_,_arg2_,_arg3_) MAX(_arg1_,MAX(_arg2_,_arg3_))
80 #define MIN(_arg1_,_arg2_) ((_arg1_)>(_arg2_) ? (_arg2_) : (_arg1_))
81 #define MIN3(_arg1_,_arg2_,_arg3_) MIN(_arg1_,MIN(_arg2_,_arg3_))
82 #define ABS(_arg_) MAX((_arg_),-(_arg_))
83 #define SIGN(_arg_) ((_arg_)>0 ? 1 : ((_arg_)<0 ? -1 : 0 ))
84 #define SWAP(_a0_,_a1_,_type_) { \
85 _type_ s; \
86 s=(_a0_); \
87 _a0_= (_a1_); \
88 _a1_=s; \
89 }
90 /**************************************************************/
91
92 /* memory allocation: */
93
94 /*
95 This is useful for seeing what memory is being allocated if you get an "Out of memory" error
96 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (printf("TMPMEMALLOC at %s %d #bytes=%d*%d=%d\n", __FILE__, __LINE__, _LENGTH_, sizeof(_TYPE_), ((size_t)(_LENGTH_) * sizeof(_TYPE_))) , (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)))
97
98 This is useful for seeing where memory is being freed if you get an "glibc detected...free" error
99 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { printf("TMPMEMFREE AAA %s %d\n", __FILE__, __LINE__); free(_PTR_); (_PTR_) = NULL; printf("TMPMEMFREE BBB %s %d\n", __FILE__, __LINE__); }
100 */
101
102
103 #if defined(__ECC)
104 /*#define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_)); if( !(_LENGTH_) ) printf( "Trying malloc(0) at %s %d\n", __FILE__, __LINE__ ); //else printf( "malloc(%d) at %s %d\n", _LENGTH_, __FILE__, __LINE__ );*/
105 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
106 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
107 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
108 #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
109 #ifdef _OPENMP
110 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) kmp_malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
111 #define THREAD_MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { kmp_free(_PTR_); (_PTR_) = NULL; }
112 #else
113 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
114 #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
115 #endif
116
117 /* do {} while(0) - an old trick for bracketing a macro that */
118 /* makes sure a semi-colon does no harm. */
119
120 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) \
121 do \
122 { \
123 if( (_POINTER_)!=NULL ) \
124 { \
125 _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_), \
126 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
127 } \
128 else \
129 { \
130 _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
131 } \
132 } while(0)
133
134 #elif defined(_WIN32)
135
136 #ifdef _DEBUG
137 #define TMP_DEF_FLAG
138 #undef _DEBUG
139 #endif
140 #include <python.h>
141 #ifdef TMP_DEF_FLAG
142 #undef TMP_DEF_FLAG
143 #define _DEBUG
144 #endif
145
146 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) PyMem_Malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
147 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { PyMem_Free(_PTR_); (_PTR_) = NULL; }
148 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) PyMem_Malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
149 #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { PyMem_Free(_PTR_); (_PTR_) = NULL; }
150 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
151 #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
152 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) \
153 do \
154 { \
155 if( (_POINTER_)!=NULL ) \
156 { \
157 _POINTER_ = (_TYPE_*)PyMem_Realloc((void*)(_POINTER_), \
158 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
159 } \
160 else \
161 { \
162 _POINTER_ = (_TYPE_*)PyMem_Malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
163 } \
164 } while(0)
165
166 #else
167 #define TMPMEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
168 #define TMPMEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
169 #define MEMALLOC(_LENGTH_,_TYPE_) (_TYPE_*) malloc(((size_t)(_LENGTH_))*sizeof(_TYPE_))
170 #define MEMFREE(_PTR_) if ((void *)(_PTR_) != NULL ) { free(_PTR_); (_PTR_) = NULL; }
171 #define THREAD_MEMALLOC(_LENGTH_,_TYPE_) TMPMEMALLOC(_LENGTH_,_TYPE_)
172 #define THREAD_MEMFREE(_PTR_) TMPMEMFREE(_PTR_)
173 #define MEMREALLOC(_POINTER_,_LENGTH_,_TYPE_) \
174 do \
175 { \
176 if( (_POINTER_)!=NULL ) \
177 { \
178 _POINTER_ = (_TYPE_*)realloc((void*)(_POINTER_), \
179 ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
180 } \
181 else \
182 { \
183 _POINTER_ = (_TYPE_*)malloc( ((size_t)(_LENGTH_))*sizeof(_TYPE_) ); \
184 } \
185 } while(0)
186
187 #endif
188
189 #define TMPMEMALLOC_AND_PASOCHECK(_LENGTH_,_TYPE_) ( MEMALLOC(_LENGTH_,_TYPE_);
190
191 #endif /* #ifndef INC_PASO_COMMON */

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26