@@ -231,13 +231,10 @@ typedef struct pmix_tma {
231231 * Like memmove(), it returns a pointer to the content's destination.
232232 */
233233 void * (* tma_memmove )(struct pmix_tma * tma , const void * src , size_t n );
234+ /** Pointer to the TMA's free() function. */
235+ void (* tma_free )(struct pmix_tma * , void * );
234236 /** Pointer inside the memory allocation arena. */
235237 void * arena ;
236- /**
237- * When true free() and realloc() cannot be used,
238- * and memory allocation functions cannot fail.
239- */
240- bool dontfree ;
241238} pmix_tma_t ;
242239
243240static inline void * pmix_tma_malloc (pmix_tma_t * tma , size_t size )
@@ -249,6 +246,15 @@ static inline void *pmix_tma_malloc(pmix_tma_t *tma, size_t size)
249246 }
250247}
251248
249+ static inline void * pmix_tma_calloc (pmix_tma_t * tma , size_t nmemb , size_t size )
250+ {
251+ if (NULL != tma ) {
252+ return tma -> tma_calloc (tma , nmemb , size );
253+ } else {
254+ return calloc (nmemb , size );
255+ }
256+ }
257+
252258static inline void * pmix_tma_realloc (pmix_tma_t * tma , void * ptr , size_t size )
253259{
254260 if (NULL != tma ) {
@@ -267,6 +273,15 @@ static inline char *pmix_tma_strdup(pmix_tma_t *tma, const char *src)
267273 }
268274}
269275
276+ static inline void pmix_tma_free (pmix_tma_t * tma , void * ptr )
277+ {
278+ if (NULL != tma ) {
279+ tma -> tma_free (tma , ptr );
280+ } else {
281+ free (ptr );
282+ }
283+ }
284+
270285/**
271286 * Class descriptor.
272287 *
@@ -306,8 +321,8 @@ PMIX_EXPORT extern int pmix_class_init_epoch;
306321 .obj_tma.tma_realloc = NULL, \
307322 .obj_tma.tma_strdup = NULL, \
308323 .obj_tma.tma_memmove = NULL, \
324+ .obj_tma.tma_free = NULL, \
309325 .obj_tma.arena = NULL, \
310- .obj_tma.dontfree = false, \
311326 .cls_init_file_name = __FILE__, \
312327 .cls_init_lineno = __LINE__ \
313328 }
@@ -322,8 +337,8 @@ PMIX_EXPORT extern int pmix_class_init_epoch;
322337 .obj_tma.tma_realloc = NULL, \
323338 .obj_tma.tma_strdup = NULL, \
324339 .obj_tma.tma_memmove = NULL, \
325- .obj_tma.arena = NULL, \
326- .obj_tma.dontfree = false \
340+ .obj_tma.tma_free = NULL, \
341+ .obj_tma.arena = NULL \
327342 }
328343#endif
329344
@@ -412,12 +427,12 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
412427 ((type *)pmix_obj_new_debug_tma(PMIX_CLASS(type), NULL, __FILE__, __LINE__))
413428
414429#define PMIX_NEW_TMA (type , tma ) \
415- ((type *)pmix_obj_new_debug_tma(PMIX_CLASS(type), tma, __FILE__, __LINE__))
430+ ((type *)pmix_obj_new_debug_tma(PMIX_CLASS(type), ( tma) , __FILE__, __LINE__))
416431
417432#else
418433#define PMIX_NEW_NO_TMA (type ) ((type *)pmix_obj_new_tma(PMIX_CLASS(type), NULL))
419434
420- #define PMIX_NEW_TMA (type , tma ) ((type *)pmix_obj_new_tma(PMIX_CLASS(type), tma))
435+ #define PMIX_NEW_TMA (type , tma ) ((type *)pmix_obj_new_tma(PMIX_CLASS(type), ( tma) ))
421436
422437#endif /* PMIX_ENABLE_DEBUG */
423438
@@ -486,7 +501,10 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
486501 PMIX_SET_MAGIC_ID((object), 0); \
487502 pmix_obj_run_destructors(_obj); \
488503 PMIX_REMEMBER_FILE_AND_LINENO(object, __FILE__, __LINE__); \
489- if (!(_obj->obj_tma.dontfree)) { \
504+ if (NULL != _obj->obj_tma.tma_free) { \
505+ pmix_tma_free(&_obj->obj_tma, object); \
506+ } \
507+ else { \
490508 free(object); \
491509 } \
492510 object = NULL; \
@@ -498,7 +516,10 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
498516 pmix_object_t *_obj = (pmix_object_t *) object; \
499517 if (0 == pmix_obj_update(_obj, -1)) { \
500518 pmix_obj_run_destructors(_obj); \
501- if (!(_obj->obj_tma.dontfree)) { \
519+ if (NULL != _obj->obj_tma.tma_free) { \
520+ pmix_tma_free(&_obj->obj_tma, object); \
521+ } \
522+ else { \
502523 free(object); \
503524 } \
504525 object = NULL; \
@@ -512,32 +533,26 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
512533 * @param object Pointer to the object
513534 * @param type The object type
514535 */
515- static inline void pmix_obj_construct_tma (pmix_object_t * obj , pmix_tma_t * t )
536+ static inline void pmix_obj_construct_tma (pmix_object_t * obj , pmix_tma_t * tma )
516537{
517- if (NULL == t ) {
538+ if (NULL == tma ) {
518539 obj -> obj_tma .tma_malloc = NULL ;
519540 obj -> obj_tma .tma_calloc = NULL ;
520541 obj -> obj_tma .tma_realloc = NULL ;
521542 obj -> obj_tma .tma_strdup = NULL ;
522543 obj -> obj_tma .tma_memmove = NULL ;
544+ obj -> obj_tma .tma_free = NULL ;
523545 obj -> obj_tma .arena = NULL ;
524- obj -> obj_tma .dontfree = false;
525546 } else {
526- obj -> obj_tma .tma_malloc = t -> tma_malloc ;
527- obj -> obj_tma .tma_calloc = t -> tma_calloc ;
528- obj -> obj_tma .tma_realloc = t -> tma_realloc ;
529- obj -> obj_tma .tma_strdup = t -> tma_strdup ;
530- obj -> obj_tma .tma_memmove = t -> tma_memmove ;
531- obj -> obj_tma .arena = t -> arena ;
532- obj -> obj_tma .dontfree = t -> dontfree ;
547+ obj -> obj_tma = * tma ;
533548 }
534549}
535550
536551#define PMIX_CONSTRUCT_INTERNAL_TMA (object , type , t ) \
537552 do { \
538553 PMIX_SET_MAGIC_ID((object), PMIX_OBJ_MAGIC_ID); \
539554 if (pmix_class_init_epoch != (type)->cls_initialized) { \
540- pmix_class_initialize((type)); \
555+ pmix_class_initialize((type), (t)); \
541556 } \
542557 ((pmix_object_t *) (object))->obj_class = (type); \
543558 ((pmix_object_t *) (object))->obj_reference_count = 1; \
@@ -547,9 +562,9 @@ static inline void pmix_obj_construct_tma(pmix_object_t *obj, pmix_tma_t *t)
547562 } while (0)
548563
549564
550- #define PMIX_CONSTRUCT_TMA (object , type , t ) \
551- do { \
552- PMIX_CONSTRUCT_INTERNAL_TMA((object), PMIX_CLASS(type), t ); \
565+ #define PMIX_CONSTRUCT_TMA (object , type , t ) \
566+ do { \
567+ PMIX_CONSTRUCT_INTERNAL_TMA((object), PMIX_CLASS(type), (t) ); \
553568 } while (0)
554569
555570
@@ -594,7 +609,7 @@ PMIX_CLASS_DECLARATION(pmix_object_t);
594609 *
595610 * @param class Pointer to class descriptor
596611 */
597- PMIX_EXPORT void pmix_class_initialize (pmix_class_t * );
612+ PMIX_EXPORT void pmix_class_initialize (pmix_class_t * cls , pmix_tma_t * tma );
598613
599614/**
600615 * Shut down the class system and release all memory
@@ -668,13 +683,10 @@ static inline pmix_object_t *pmix_obj_new_tma(pmix_class_t *cls, pmix_tma_t *tma
668683 pmix_object_t * object ;
669684 assert (cls -> cls_sizeof >= sizeof (pmix_object_t ));
670685
671- if (NULL == tma ) {
672- object = (pmix_object_t * ) malloc (cls -> cls_sizeof );
673- } else {
674- object = (pmix_object_t * ) pmix_tma_malloc (tma , cls -> cls_sizeof );
675- }
686+ object = (pmix_object_t * ) pmix_tma_malloc (tma , cls -> cls_sizeof );
687+
676688 if (pmix_class_init_epoch != cls -> cls_initialized ) {
677- pmix_class_initialize (cls );
689+ pmix_class_initialize (cls , tma );
678690 }
679691 if (NULL != object ) {
680692#if PMIX_ENABLE_DEBUG
@@ -704,8 +716,8 @@ static inline pmix_object_t *pmix_obj_new_tma(pmix_class_t *cls, pmix_tma_t *tma
704716 object -> obj_tma .tma_calloc = NULL ;
705717 object -> obj_tma .tma_realloc = NULL ;
706718 object -> obj_tma .tma_strdup = NULL ;
719+ object -> obj_tma .tma_free = NULL ;
707720 object -> obj_tma .arena = NULL ;
708- object -> obj_tma .dontfree = false;
709721 } else {
710722 object -> obj_tma = * tma ;
711723 }
@@ -714,11 +726,6 @@ static inline pmix_object_t *pmix_obj_new_tma(pmix_class_t *cls, pmix_tma_t *tma
714726 return object ;
715727}
716728
717- static inline pmix_object_t * pmix_obj_new (pmix_class_t * cls )
718- {
719- return pmix_obj_new_tma (cls , NULL );
720- }
721-
722729/**
723730 * Atomically update the object's reference count by some increment.
724731 *
0 commit comments