@@ -97,7 +97,7 @@ static inline void mi_free_block_mt(mi_page_t* page, mi_block_t* block, bool was
9797// note: this can be called from `mi_free_generic_mt` where a non-owning thread accesses the
9898// `page_woffset` and `block_size` fields; however these are constant and the page won't be
9999// deallocated (as the block we are freeing keeps it alive) and thus safe to read concurrently.
100- mi_block_t * _mi_page_ptr_unalign (const mi_page_t * page , const void * p ) {
100+ static inline mi_block_t * mi_page_ptr_unalign_ex (const mi_page_t * page , const void * p , size_t * poffset ) {
101101 mi_assert_internal (page != NULL && p != NULL );
102102
103103 const size_t diff = (uint8_t * )p - mi_page_start (page );
@@ -106,9 +106,14 @@ mi_block_t* _mi_page_ptr_unalign(const mi_page_t* page, const void* p) {
106106 if mi_unlikely (!_mi_is_power_of_two (block_size )) {
107107 adjust = diff % block_size ;
108108 }
109+ if (poffset != NULL ) { * poffset = adjust ; }
109110 return (mi_block_t * )((uintptr_t )p - adjust );
110111}
111112
113+ mi_block_t * _mi_page_ptr_unalign (const mi_page_t * page , const void * p ) {
114+ return mi_page_ptr_unalign_ex (page ,p ,NULL );
115+ }
116+
112117static inline mi_block_t * mi_validate_block_from_ptr ( const mi_page_t * page , const void * p ) {
113118 mi_assert (_mi_page_ptr_unalign (page ,p ) == (mi_block_t * )p ); // should never be an interior pointer
114119 #if MI_SECURE > 0
@@ -126,13 +131,13 @@ static inline mi_block_t* mi_page_ptr_block_check(mi_page_t* page, void* p, bool
126131 return mi_validate_block_from_ptr (page ,p );
127132 }
128133 else {
129- mi_block_t * const block = _mi_page_ptr_unalign (page ,p );
134+ size_t offset ;
135+ mi_block_t * const block = mi_page_ptr_unalign_ex (page ,p ,& offset );
130136 #if MI_GUARDED || MI_PROFILE
131- const size_t offset = (uint8_t * )p - (uint8_t * )block ;
132137 if (offset >= sizeof (mi_block_t )) {
133138 #if MI_PROFILE
134139 if (block -> next == MI_BLOCK_TAG_PROFILED ) {
135- _mi_page_profile_free (page ,block ,p );
140+ _mi_page_profile_on_free (page ,block ,p );
136141 }
137142 else
138143 #endif
@@ -141,8 +146,9 @@ static inline mi_block_t* mi_page_ptr_block_check(mi_page_t* page, void* p, bool
141146 _mi_page_block_unguard (page , block , p );
142147 * was_guarded = true;
143148 }
149+ else
144150 #else
145- { }
151+ { /* nothing */ }
146152 #endif
147153 }
148154 #endif
0 commit comments