@@ -2503,6 +2503,17 @@ ZEND_API bool is_zend_ptr(const void *ptr)
2503
2503
2504
2504
#if ZEND_MM_CUSTOM
2505
2505
2506
+ #define HANDLE_OBSERVERS (observer_function , ...) \
2507
+ if (use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED) { \
2508
+ zend_mm_observer *current = heap->observers; \
2509
+ while (current != NULL) { \
2510
+ if (current->observer_function != NULL) { \
2511
+ current->observer_function(__VA_ARGS__ ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); \
2512
+ } \
2513
+ current = current->next; \
2514
+ } \
2515
+ }
2516
+
2506
2517
static ZEND_COLD void * ZEND_FASTCALL _malloc_custom (size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC )
2507
2518
{
2508
2519
void * ptr ;
@@ -2516,15 +2527,7 @@ static ZEND_COLD void* ZEND_FASTCALL _malloc_custom(size_t size ZEND_FILE_LINE_D
2516
2527
// no custom memory manager, only observer present
2517
2528
ptr = zend_mm_alloc_heap (AG (mm_heap ), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2518
2529
}
2519
- if (use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED ) {
2520
- zend_mm_observer * current = heap -> observers ;
2521
- while (current != NULL ) {
2522
- if (current -> malloc != NULL ) {
2523
- current -> malloc (size , ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2524
- }
2525
- current = current -> next ;
2526
- }
2527
- }
2530
+ HANDLE_OBSERVERS (malloc , size , ptr )
2528
2531
return ptr ;
2529
2532
}
2530
2533
@@ -2533,15 +2536,7 @@ static ZEND_COLD void ZEND_FASTCALL _efree_custom(void *ptr ZEND_FILE_LINE_DC ZE
2533
2536
zend_mm_heap * heap = AG (mm_heap );
2534
2537
int use_custom_heap = heap -> use_custom_heap ;
2535
2538
2536
- if (use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED ) {
2537
- zend_mm_observer * current = heap -> observers ;
2538
- while (current != NULL ) {
2539
- if (current -> free != NULL ) {
2540
- current -> free (ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2541
- }
2542
- current = current -> next ;
2543
- }
2544
- }
2539
+ HANDLE_OBSERVERS (free , ptr )
2545
2540
2546
2541
if (ZEND_DEBUG && use_custom_heap & ZEND_MM_CUSTOM_HEAP_DEBUG ) {
2547
2542
heap -> custom_heap .debug ._free (ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
@@ -2566,15 +2561,7 @@ static ZEND_COLD void* ZEND_FASTCALL _realloc_custom(void *ptr, size_t size ZEND
2566
2561
// no custom memory manager, only observer present
2567
2562
new_ptr = zend_mm_realloc_heap (AG (mm_heap ), ptr , size , 0 , size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2568
2563
}
2569
- if (use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED ) {
2570
- zend_mm_observer * current = heap -> observers ;
2571
- while (current != NULL ) {
2572
- if (current -> realloc != NULL ) {
2573
- current -> realloc (ptr , size , new_ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC );
2574
- }
2575
- current = current -> next ;
2576
- }
2577
- }
2564
+ HANDLE_OBSERVERS (realloc , ptr , size , new_ptr )
2578
2565
return new_ptr ;
2579
2566
}
2580
2567
#endif
0 commit comments