@@ -103,98 +103,83 @@ extern "C" {
103103#define MPIR_CHKMEM_SETERR (rc_ ,nbytes_ ,name_ ) rc_=MPI_ERR_OTHER
104104#endif /* HAVE_ERROR_CHECKING */
105105
106- /* CHKPMEM_REGISTER is used for memory allocated within another routine */
107-
108- #define MPIR_CHKLMEM_DECL (n_ ) \
109- void *(mpiu_chklmem_stk_[n_]) = { NULL }; \
110- int mpiu_chklmem_stk_sp_=0; \
111- MPIR_AssertDeclValue(const int mpiu_chklmem_stk_sz_,n_)
112-
113- #define MPIR_CHKLMEM_MALLOC_ORSTMT (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ,stmt_ ) \
114- { \
115- pointer_ = (type_)MPL_malloc(nbytes_,class_); \
116- if (pointer_) { \
117- MPIR_Assert(mpiu_chklmem_stk_sp_<mpiu_chklmem_stk_sz_); \
118- mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = (void *) pointer_; \
119- } else if (nbytes_ > 0) { \
120- MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
121- stmt_; \
122- } \
123- }
106+
107+ #define MPIR_CHKLMEM_MAX 10
108+ #define MPIR_CHKLMEM_DECL () \
109+ void *(mpiu_chklmem_stk_[MPIR_CHKLMEM_MAX]) = { NULL }; \
110+ int mpiu_chklmem_stk_sp_=0;
111+
112+ #define MPIR_CHKLMEM_REGISTER (pointer_ ) \
113+ do { \
114+ MPIR_Assert(mpiu_chklmem_stk_sp_<MPIR_CHKLMEM_MAX); \
115+ mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = pointer_; \
116+ } while (0)
117+
118+ #define MPIR_CHKLMEM_MALLOC (pointer_ ,nbytes_ ) \
119+ do { \
120+ pointer_ = MPL_malloc(nbytes_,MPL_MEM_LOCAL); \
121+ if (pointer_) { \
122+ MPIR_Assert(mpiu_chklmem_stk_sp_<MPIR_CHKLMEM_MAX); \
123+ mpiu_chklmem_stk_[mpiu_chklmem_stk_sp_++] = pointer_; \
124+ } else if (nbytes_ > 0) { \
125+ MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
126+ } \
127+ } while (0)
128+
124129#define MPIR_CHKLMEM_FREEALL () \
125130 do { \
126131 while (mpiu_chklmem_stk_sp_ > 0) { \
127132 MPL_free(mpiu_chklmem_stk_[--mpiu_chklmem_stk_sp_]); \
128133 } \
129134 } while (0)
130135
131- #define MPIR_CHKLMEM_MALLOC (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
132- MPIR_CHKLMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
133- #define MPIR_CHKLMEM_MALLOC_ORJUMP (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
134- MPIR_CHKLMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
135136
136137/* Persistent memory that we may want to recover if something goes wrong */
137- #define MPIR_CHKPMEM_DECL (n_ ) \
138- void *(mpiu_chkpmem_stk_[n_]) = { NULL }; \
139- int mpiu_chkpmem_stk_sp_=0; \
140- MPIR_AssertDeclValue(const int mpiu_chkpmem_stk_sz_,n_)
141- #define MPIR_CHKPMEM_MALLOC_ORSTMT (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ,stmt_ ) \
142- { \
143- pointer_ = (type_)MPL_malloc(nbytes_,class_); \
144- if (pointer_) { \
145- MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
146- mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
147- } else if (nbytes_ > 0) { \
148- MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
149- stmt_; \
150- } \
151- }
152- #define MPIR_CHKPMEM_REGISTER (pointer_ ) \
153- { \
154- MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
155- mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
156- }
157- #define MPIR_CHKPMEM_REAP () \
158- { \
159- while (mpiu_chkpmem_stk_sp_ > 0) { \
160- MPL_free(mpiu_chkpmem_stk_[--mpiu_chkpmem_stk_sp_]); \
161- } \
162- }
163- #define MPIR_CHKPMEM_COMMIT () \
138+ #define MPIR_CHKPMEM_MAX 10
139+ #define MPIR_CHKPMEM_DECL () \
140+ void *(mpiu_chkpmem_stk_[MPIR_CHKPMEM_MAX]) = { NULL }; \
141+ int mpiu_chkpmem_stk_sp_=0;
142+
143+ #define MPIR_CHKPMEM_MALLOC (pointer_ ,nbytes_ ,class_ ) \
144+ do { \
145+ pointer_ = MPL_malloc(nbytes_,class_); \
146+ if (pointer_) { \
147+ MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
148+ mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
149+ } else if (nbytes_ > 0) { \
150+ MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
151+ } \
152+ } while (0)
153+
154+ #define MPIR_CHKPMEM_REGISTER (pointer_ ) \
155+ do { \
156+ MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
157+ mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
158+ } while (0)
159+
160+ #define MPIR_CHKPMEM_REAP () \
161+ do { \
162+ while (mpiu_chkpmem_stk_sp_ > 0) { \
163+ MPL_free(mpiu_chkpmem_stk_[--mpiu_chkpmem_stk_sp_]); \
164+ } \
165+ } while (0)
166+
167+ /* NOTE: unnecessary to commit if all memory allocations need be freed at fail */
168+ #define MPIR_CHKPMEM_COMMIT () \
164169 mpiu_chkpmem_stk_sp_ = 0
165- #define MPIR_CHKPMEM_MALLOC (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
166- MPIR_CHKPMEM_MALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
167- #define MPIR_CHKPMEM_MALLOC_ORJUMP (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
168- MPIR_CHKPMEM_MALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
169170
170171/* now the CALLOC version for zeroed memory */
171- #define MPIR_CHKPMEM_CALLOC (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
172- MPIR_CHKPMEM_CALLOC_ORJUMP(pointer_,type_,nbytes_,rc_,name_,class_)
173- #define MPIR_CHKPMEM_CALLOC_ORJUMP (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ) \
174- MPIR_CHKPMEM_CALLOC_ORSTMT(pointer_,type_,nbytes_,rc_,name_,class_,goto fn_fail)
175- #define MPIR_CHKPMEM_CALLOC_ORSTMT (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ,stmt_ ) \
176- do { \
177- pointer_ = (type_)MPL_calloc(1, (nbytes_), (class_)); \
178- if (pointer_) { \
179- MPIR_Assert(mpiu_chkpmem_stk_sp_<mpiu_chkpmem_stk_sz_); \
180- mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
181- } \
182- else if (nbytes_ > 0) { \
183- MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
184- stmt_; \
185- } \
172+ #define MPIR_CHKPMEM_CALLOC (pointer_ ,nbytes_ ,class_ ) \
173+ do { \
174+ pointer_ = MPL_calloc(1, nbytes_, class_); \
175+ if (pointer_) { \
176+ MPIR_Assert(mpiu_chkpmem_stk_sp_<MPIR_CHKPMEM_MAX); \
177+ mpiu_chkpmem_stk_[mpiu_chkpmem_stk_sp_++] = pointer_; \
178+ } else if (nbytes_ > 0) { \
179+ MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OTHER, "**nomem"); \
180+ } \
186181 } while (0)
187182
188- /* A special version for routines that only allocate one item */
189- #define MPIR_CHKPMEM_MALLOC1 (pointer_ ,type_ ,nbytes_ ,rc_ ,name_ ,class_ ,stmt_ ) \
190- { \
191- pointer_ = (type_)MPL_malloc(nbytes_,class_); \
192- if (!(pointer_) && (nbytes_ > 0)) { \
193- MPIR_CHKMEM_SETERR(rc_,nbytes_,name_); \
194- stmt_; \
195- } \
196- }
197-
198183/* Provides a easy way to use realloc safely and avoid the temptation to use
199184 * realloc unsafely (direct ptr assignment). Zero-size reallocs returning NULL
200185 * are handled and are not considered an error. */
0 commit comments