@@ -231,13 +231,10 @@ typedef struct pmix_tma {
231
231
* Like memmove(), it returns a pointer to the content's destination.
232
232
*/
233
233
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 * );
234
236
/** Pointer inside the memory allocation arena. */
235
237
void * arena ;
236
- /**
237
- * When true free() and realloc() cannot be used,
238
- * and memory allocation functions cannot fail.
239
- */
240
- bool dontfree ;
241
238
} pmix_tma_t ;
242
239
243
240
static 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)
249
246
}
250
247
}
251
248
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
+
252
258
static inline void * pmix_tma_realloc (pmix_tma_t * tma , void * ptr , size_t size )
253
259
{
254
260
if (NULL != tma ) {
@@ -267,6 +273,15 @@ static inline char *pmix_tma_strdup(pmix_tma_t *tma, const char *src)
267
273
}
268
274
}
269
275
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
+
270
285
/**
271
286
* Class descriptor.
272
287
*
@@ -306,8 +321,8 @@ PMIX_EXPORT extern int pmix_class_init_epoch;
306
321
.obj_tma.tma_realloc = NULL, \
307
322
.obj_tma.tma_strdup = NULL, \
308
323
.obj_tma.tma_memmove = NULL, \
324
+ .obj_tma.tma_free = NULL, \
309
325
.obj_tma.arena = NULL, \
310
- .obj_tma.dontfree = false, \
311
326
.cls_init_file_name = __FILE__, \
312
327
.cls_init_lineno = __LINE__ \
313
328
}
@@ -322,8 +337,8 @@ PMIX_EXPORT extern int pmix_class_init_epoch;
322
337
.obj_tma.tma_realloc = NULL, \
323
338
.obj_tma.tma_strdup = NULL, \
324
339
.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 \
327
342
}
328
343
#endif
329
344
@@ -412,12 +427,12 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
412
427
((type *)pmix_obj_new_debug_tma(PMIX_CLASS(type), NULL, __FILE__, __LINE__))
413
428
414
429
#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__))
416
431
417
432
#else
418
433
#define PMIX_NEW_NO_TMA (type ) ((type *)pmix_obj_new_tma(PMIX_CLASS(type), NULL))
419
434
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) ))
421
436
422
437
#endif /* PMIX_ENABLE_DEBUG */
423
438
@@ -486,7 +501,10 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
486
501
PMIX_SET_MAGIC_ID((object), 0); \
487
502
pmix_obj_run_destructors(_obj); \
488
503
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 { \
490
508
free(object); \
491
509
} \
492
510
object = NULL; \
@@ -498,7 +516,10 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
498
516
pmix_object_t *_obj = (pmix_object_t *) object; \
499
517
if (0 == pmix_obj_update(_obj, -1)) { \
500
518
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 { \
502
523
free(object); \
503
524
} \
504
525
object = NULL; \
@@ -512,32 +533,26 @@ static inline pmix_object_t *pmix_obj_new_debug_tma(pmix_class_t *type, pmix_tma
512
533
* @param object Pointer to the object
513
534
* @param type The object type
514
535
*/
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 )
516
537
{
517
- if (NULL == t ) {
538
+ if (NULL == tma ) {
518
539
obj -> obj_tma .tma_malloc = NULL ;
519
540
obj -> obj_tma .tma_calloc = NULL ;
520
541
obj -> obj_tma .tma_realloc = NULL ;
521
542
obj -> obj_tma .tma_strdup = NULL ;
522
543
obj -> obj_tma .tma_memmove = NULL ;
544
+ obj -> obj_tma .tma_free = NULL ;
523
545
obj -> obj_tma .arena = NULL ;
524
- obj -> obj_tma .dontfree = false;
525
546
} 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 ;
533
548
}
534
549
}
535
550
536
551
#define PMIX_CONSTRUCT_INTERNAL_TMA (object , type , t ) \
537
552
do { \
538
553
PMIX_SET_MAGIC_ID((object), PMIX_OBJ_MAGIC_ID); \
539
554
if (pmix_class_init_epoch != (type)->cls_initialized) { \
540
- pmix_class_initialize((type)); \
555
+ pmix_class_initialize((type), (t)); \
541
556
} \
542
557
((pmix_object_t *) (object))->obj_class = (type); \
543
558
((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)
547
562
} while (0)
548
563
549
564
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) ); \
553
568
} while (0)
554
569
555
570
@@ -594,7 +609,7 @@ PMIX_CLASS_DECLARATION(pmix_object_t);
594
609
*
595
610
* @param class Pointer to class descriptor
596
611
*/
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 );
598
613
599
614
/**
600
615
* 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
668
683
pmix_object_t * object ;
669
684
assert (cls -> cls_sizeof >= sizeof (pmix_object_t ));
670
685
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
+
676
688
if (pmix_class_init_epoch != cls -> cls_initialized ) {
677
- pmix_class_initialize (cls );
689
+ pmix_class_initialize (cls , tma );
678
690
}
679
691
if (NULL != object ) {
680
692
#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
704
716
object -> obj_tma .tma_calloc = NULL ;
705
717
object -> obj_tma .tma_realloc = NULL ;
706
718
object -> obj_tma .tma_strdup = NULL ;
719
+ object -> obj_tma .tma_free = NULL ;
707
720
object -> obj_tma .arena = NULL ;
708
- object -> obj_tma .dontfree = false;
709
721
} else {
710
722
object -> obj_tma = * tma ;
711
723
}
@@ -714,11 +726,6 @@ static inline pmix_object_t *pmix_obj_new_tma(pmix_class_t *cls, pmix_tma_t *tma
714
726
return object ;
715
727
}
716
728
717
- static inline pmix_object_t * pmix_obj_new (pmix_class_t * cls )
718
- {
719
- return pmix_obj_new_tma (cls , NULL );
720
- }
721
-
722
729
/**
723
730
* Atomically update the object's reference count by some increment.
724
731
*
0 commit comments