Skip to content

Commit ac83eae

Browse files
committed
Don't inline "slow" and rarely used functions.
1 parent 6d885e3 commit ac83eae

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

Zend/zend_alloc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,37 @@ ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_handlers *handlers, void
27922792
#endif
27932793
}
27942794

2795+
static ZEND_COLD ZEND_NORETURN void zend_out_of_memory(void)
2796+
{
2797+
fprintf(stderr, "Out of memory\n");
2798+
exit(1);
2799+
}
2800+
2801+
ZEND_API void * __zend_malloc(size_t len)
2802+
{
2803+
void *tmp = malloc(len);
2804+
if (EXPECTED(tmp)) {
2805+
return tmp;
2806+
}
2807+
zend_out_of_memory();
2808+
}
2809+
2810+
ZEND_API void * __zend_calloc(size_t nmemb, size_t len)
2811+
{
2812+
void *tmp = _safe_malloc(nmemb, len, 0);
2813+
memset(tmp, 0, nmemb * len);
2814+
return tmp;
2815+
}
2816+
2817+
ZEND_API void * __zend_realloc(void *p, size_t len)
2818+
{
2819+
p = realloc(p, len);
2820+
if (EXPECTED(p)) {
2821+
return p;
2822+
}
2823+
zend_out_of_memory();
2824+
}
2825+
27952826
/*
27962827
* Local variables:
27972828
* tab-width: 4

Zend/zend_alloc.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,33 +187,9 @@ ZEND_API void ZEND_FASTCALL _efree_huge(void *, size_t size);
187187
#define estrndup_rel(s, length) _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
188188
#define zend_mem_block_size_rel(ptr) _zend_mem_block_size((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
189189

190-
zend_always_inline static void * __zend_malloc(size_t len)
191-
{
192-
void *tmp = malloc(len);
193-
if (tmp) {
194-
return tmp;
195-
}
196-
fprintf(stderr, "Out of memory\n");
197-
exit(1);
198-
}
199-
200-
zend_always_inline static void * __zend_calloc(size_t nmemb, size_t len)
201-
{
202-
void *tmp = _safe_malloc(nmemb, len, 0);
203-
memset(tmp, 0, nmemb * len);
204-
return tmp;
205-
}
206-
207-
zend_always_inline static void * __zend_realloc(void *p, size_t len)
208-
{
209-
p = realloc(p, len);
210-
if (p) {
211-
return p;
212-
}
213-
fprintf(stderr, "Out of memory\n");
214-
exit(1);
215-
}
216-
190+
ZEND_API void * __zend_malloc(size_t len) ZEND_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_ALLOC_SIZE(1);
191+
ZEND_API void * __zend_calloc(size_t nmemb, size_t len) ZEND_ATTRIBUTE_MALLOC ZEND_ATTRIBUTE_ALLOC_SIZE2(1,2);
192+
ZEND_API void * __zend_realloc(void *p, size_t len) ZEND_ATTRIBUTE_ALLOC_SIZE(2);
217193

218194
/* Selective persistent/non persistent allocation macros */
219195
#define pemalloc(size, persistent) ((persistent)?__zend_malloc(size):emalloc(size))

0 commit comments

Comments
 (0)