Skip to content

Commit 4290de3

Browse files
cleanup
1 parent 9f9462f commit 4290de3

3 files changed

Lines changed: 19 additions & 40 deletions

File tree

Zend/zend_alloc.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
* with more specialized routines when the requested size is known.
5151
*/
5252

53-
#include "php.h"
5453
#include "zend.h"
5554
#include "zend_alloc.h"
5655
#include "zend_globals.h"
@@ -240,6 +239,8 @@ struct _zend_mm_observer {
240239
zend_mm_observer *next;
241240
};
242241

242+
static void zend_mm_observers_shutdown(zend_mm_heap *heap);
243+
243244
#define HANDLE_OBSERVERS(observer_function, ...) \
244245
if (use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED) { \
245246
zend_mm_observer *current = heap->observers; \
@@ -2480,7 +2481,6 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
24802481
zend_mm_chunk *p;
24812482
zend_mm_huge_list *list;
24822483

2483-
// Call observer shutdown callbacks before cleaning up
24842484
#if ZEND_MM_CUSTOM
24852485
if (heap->use_custom_heap & ZEND_MM_CUSTOM_HEAP_OBSERVED) {
24862486
zend_mm_observer *current = heap->observers;
@@ -2490,14 +2490,9 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
24902490
}
24912491
current = current->next;
24922492
}
2493-
}
2494-
#endif
2495-
2496-
if (full == false) {
24972493
zend_mm_observers_shutdown(heap);
24982494
}
24992495

2500-
#if ZEND_MM_CUSTOM
25012496
if (heap->use_custom_heap & ~ZEND_MM_CUSTOM_HEAP_OBSERVED) {
25022497
if (heap->custom_heap._malloc == tracked_malloc) {
25032498
if (silent) {
@@ -2842,15 +2837,15 @@ ZEND_API void* ZEND_FASTCALL _emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LI
28422837
if (UNEXPECTED(use_custom_heap)) {
28432838
void *ptr;
28442839

2845-
// Check for actual custom handler (excluding observer bit)
2840+
/* Check for actual custom handler (excluding observer bit) */
28462841
if (use_custom_heap & ~ZEND_MM_CUSTOM_HEAP_OBSERVED) {
28472842
ptr = heap->custom_heap._malloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
28482843
} else {
2849-
// No custom handler, use default heap
2844+
/* No custom handler, use default heap */
28502845
ptr = zend_mm_alloc_heap(heap, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
28512846
}
28522847

2853-
// Call observers if present
2848+
/* Call observers if present */
28542849
HANDLE_OBSERVERS(malloc, size, ptr)
28552850

28562851
return ptr;
@@ -2866,14 +2861,14 @@ ZEND_API void ZEND_FASTCALL _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_OR
28662861
int use_custom_heap = heap->use_custom_heap;
28672862

28682863
if (UNEXPECTED(use_custom_heap)) {
2869-
// Call observers first (before free)
2864+
/* Call observers first (before free) */
28702865
HANDLE_OBSERVERS(free, ptr)
28712866

2872-
// Check for actual custom handler (excluding observer bit)
2867+
/* Check for actual custom handler (excluding observer bit) */
28732868
if (use_custom_heap & ~ZEND_MM_CUSTOM_HEAP_OBSERVED) {
28742869
heap->custom_heap._free(ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
28752870
} else {
2876-
// No custom handler, use default heap
2871+
/* No custom handler, use default heap */
28772872
zend_mm_free_heap(heap, ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
28782873
}
28792874
return;
@@ -2891,15 +2886,15 @@ ZEND_API void* ZEND_FASTCALL _erealloc(void *ptr, size_t size ZEND_FILE_LINE_DC
28912886
if (UNEXPECTED(use_custom_heap)) {
28922887
void *new_ptr;
28932888

2894-
// Check for actual custom handler (excluding observer bit)
2889+
/* Check for actual custom handler (excluding observer bit) */
28952890
if (use_custom_heap & ~ZEND_MM_CUSTOM_HEAP_OBSERVED) {
28962891
new_ptr = heap->custom_heap._realloc(ptr, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
28972892
} else {
2898-
// No custom handler, use default heap
2893+
/* No custom handler, use default heap */
28992894
new_ptr = zend_mm_realloc_heap(heap, ptr, size, 0, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
29002895
}
29012896

2902-
// Call observers if present
2897+
/* Call observers if present */
29032898
HANDLE_OBSERVERS(realloc, ptr, size, new_ptr)
29042899

29052900
return new_ptr;
@@ -2917,15 +2912,15 @@ ZEND_API void* ZEND_FASTCALL _erealloc2(void *ptr, size_t size, size_t copy_size
29172912
if (UNEXPECTED(use_custom_heap)) {
29182913
void *new_ptr;
29192914

2920-
// Check for actual custom handler (excluding observer bit)
2915+
/* Check for actual custom handler (excluding observer bit) */
29212916
if (use_custom_heap & ~ZEND_MM_CUSTOM_HEAP_OBSERVED) {
29222917
new_ptr = heap->custom_heap._realloc(ptr, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
29232918
} else {
2924-
// No custom handler, use default heap
2919+
/* No custom handler, use default heap */
29252920
new_ptr = zend_mm_realloc_heap(heap, ptr, size, 1, copy_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
29262921
}
29272922

2928-
// Call observers if present
2923+
/* Call observers if present */
29292924
HANDLE_OBSERVERS(realloc, ptr, size, new_ptr)
29302925

29312926
return new_ptr;
@@ -3443,7 +3438,6 @@ static void alloc_globals_ctor(zend_alloc_globals *alloc_globals)
34433438
#ifdef ZTS
34443439
static void alloc_globals_dtor(zend_alloc_globals *alloc_globals)
34453440
{
3446-
zend_mm_observers_shutdown(alloc_globals->mm_heap);
34473441
zend_mm_shutdown(alloc_globals->mm_heap, 1, 1);
34483442
}
34493443
#endif
@@ -3645,7 +3639,7 @@ ZEND_API bool zend_mm_observer_unregister(zend_mm_heap *heap, zend_mm_observer *
36453639
}
36463640
pefree(current, 1);
36473641

3648-
// Update flag if no more observers
3642+
/* Update flag if no more observers */
36493643
if (heap->observers == NULL) {
36503644
heap->use_custom_heap &= ~ZEND_MM_CUSTOM_HEAP_OBSERVED;
36513645
}
@@ -3658,16 +3652,9 @@ ZEND_API bool zend_mm_observer_unregister(zend_mm_heap *heap, zend_mm_observer *
36583652
return false;
36593653
}
36603654

3661-
void zend_mm_observers_shutdown(zend_mm_heap *heap)
3655+
static void zend_mm_observers_shutdown(zend_mm_heap *heap)
36623656
{
36633657
#if ZEND_MM_CUSTOM
3664-
if (heap == NULL) {
3665-
heap = AG(mm_heap);
3666-
if (heap == NULL) {
3667-
return;
3668-
}
3669-
}
3670-
36713658
zend_mm_observer *current = heap->observers;
36723659
zend_mm_observer *next = NULL;
36733660

@@ -3681,6 +3668,7 @@ void zend_mm_observers_shutdown(zend_mm_heap *heap)
36813668
heap->use_custom_heap &= ~ZEND_MM_CUSTOM_HEAP_OBSERVED;
36823669
#endif
36833670
}
3671+
36843672
ZEND_API zend_mm_storage *zend_mm_get_storage(zend_mm_heap *heap)
36853673
{
36863674
#if ZEND_MM_STORAGE

Zend/zend_alloc.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ ZEND_API void zend_mm_get_custom_handlers_ex(zend_mm_heap *heap,
297297

298298
typedef struct _zend_mm_observer zend_mm_observer;
299299

300-
// thread local
301300
ZEND_API bool zend_mm_is_observed(zend_mm_heap *heap);
302301
ZEND_API zend_mm_observer* zend_mm_observer_register(
303302
zend_mm_heap *heap,
@@ -308,14 +307,6 @@ ZEND_API zend_mm_observer* zend_mm_observer_register(
308307
void (*shutdown)(bool full, bool silent)
309308
);
310309
ZEND_API bool zend_mm_observer_unregister(zend_mm_heap *heap, zend_mm_observer *observer);
311-
void zend_mm_observers_shutdown(zend_mm_heap *heap);
312-
313-
#if ZEND_DEBUG
314-
ZEND_API void zend_mm_set_custom_debug_handlers(zend_mm_heap *heap,
315-
void* (*_malloc)(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC),
316-
void (*_free)(void* ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC),
317-
void* (*_realloc)(void*, size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC));
318-
#endif
319310

320311
typedef struct _zend_mm_storage zend_mm_storage;
321312

ext/zend_test/zend_mm_observer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ static PHP_INI_MH(OnUpdateZendTestMMObserverEnabled)
7171

7272
int int_value = zend_ini_parse_bool(new_value);
7373

74-
// Only toggle observer during runtime (ini_set during active request)
75-
// RINIT/RSHUTDOWN handle initialization and cleanup
74+
/* Only toggle observer during runtime (ini_set during active request).
75+
* RINIT/RSHUTDOWN handle initialization and cleanup. */
7676
if (stage == PHP_INI_STAGE_RUNTIME) {
7777
if (int_value == 1) {
7878
if (ZT_G(observer) == NULL) {

0 commit comments

Comments
 (0)