Skip to content

Commit 33d6a8e

Browse files
committed
Drop support for unsupported PHP versions
Drop support for PHP < 8.1
1 parent 846d71a commit 33d6a8e

File tree

4 files changed

+25
-117
lines changed

4 files changed

+25
-117
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,6 @@ jobs:
3939
os: 'macos-13'
4040
xdebug: '3.1.2'
4141

42-
- php: '8.0.0'
43-
os: 'ubuntu-20.04'
44-
expect_native: 1
45-
xdebug: '3.1.2'
46-
47-
- php: '7.4.0'
48-
os: 'ubuntu-20.04'
49-
expect_native: 1
50-
xdebug: '3.1.2'
51-
52-
- php: '7.3.0'
53-
os: 'ubuntu-20.04'
54-
expect_native: 1
55-
xdebug: '3.1.2'
56-
5742
runs-on: ${{ matrix.os }}
5843
continue-on-error: ${{ !!matrix.experimental }}
5944
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ install-sh
3131
libtool
3232
ltmain.sh
3333
memprof-*.tgz
34+
memprof_legacy_arginfo.h
3435
missing
3536
mkinstalldirs
3637
modules

memprof.c

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
#endif
3333
#include <assert.h>
3434

35-
#if PHP_VERSION_ID < 80000
36-
#include "memprof_legacy_arginfo.h"
37-
#else
38-
#include "memprof_arginfo.h"
35+
#if PHP_VERSION_ID < 80100
36+
# error "Unsupported PHP version (min supported version: 8.1.0)"
3937
#endif
4038

39+
#include "memprof_arginfo.h"
40+
4141
#define MEMPROF_ENV_PROFILE "MEMPROF_PROFILE"
4242
#define MEMPROF_FLAG_NATIVE "native"
4343
#define MEMPROF_FLAG_DUMP_ON_LIMIT "dump_on_limit"
@@ -202,24 +202,10 @@ static void (*old_zend_execute)(zend_execute_data *execute_data);
202202
static void (*old_zend_execute_internal)(zend_execute_data *execute_data_ptr, zval *return_value);
203203
#define zend_execute_fn zend_execute_ex
204204

205-
#if PHP_VERSION_ID < 70200 /* PHP 7.1 */
206-
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint error_lineno, const char *format, va_list args
207-
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, format, args
208-
#elif PHP_VERSION_ID < 80000 /* PHP 7.2 - 7.4 */
209-
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args
210-
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, format, args
211-
#elif PHP_VERSION_ID < 80100 /* PHP 8.0 */
212-
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint32_t error_lineno, zend_string *message
213-
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, message
214-
#else /* PHP 8.1 */
215-
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message
216-
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, message
217-
#endif
218-
219-
static void (*old_zend_error_cb)(MEMPROF_ZEND_ERROR_CB_ARGS);
220-
static void (*rinit_zend_error_cb)(MEMPROF_ZEND_ERROR_CB_ARGS);
205+
static void (*old_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
206+
static void (*rinit_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
221207
static zend_bool zend_error_cb_overridden;
222-
static void memprof_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS);
208+
static void memprof_zend_error_cb(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
223209

224210
static PHP_INI_MH((*origOnChangeMemoryLimit)) = NULL;
225211

@@ -648,15 +634,7 @@ static void * memalign_hook(size_t alignment, size_t size, const void *caller)
648634
track_mallocs = ___old_track_mallocs; \
649635
} while (0)
650636

651-
#if PHP_VERSION_ID >= 80400
652-
# define MM_HANDLER_FILE_LINE_DC ZEND_FILE_LINE_DC
653-
# define MM_HANDLER_FILE_LINE_ORIG_DC ZEND_FILE_LINE_ORIG_DC
654-
#else
655-
# define MM_HANDLER_FILE_LINE_DC
656-
# define MM_HANDLER_FILE_LINE_ORIG_DC
657-
#endif
658-
659-
static void * zend_malloc_handler(size_t size MM_HANDLER_FILE_LINE_DC MM_HANDLER_FILE_LINE_ORIG_DC)
637+
static void * zend_malloc_handler(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
660638
{
661639
void *result;
662640

@@ -679,7 +657,7 @@ static void * zend_malloc_handler(size_t size MM_HANDLER_FILE_LINE_DC MM_HANDLER
679657
return result;
680658
}
681659

682-
static void zend_free_handler(void * ptr MM_HANDLER_FILE_LINE_DC MM_HANDLER_FILE_LINE_ORIG_DC)
660+
static void zend_free_handler(void * ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
683661
{
684662
assert(MEMPROF_G(profile_flags).enabled);
685663

@@ -701,7 +679,7 @@ static void zend_free_handler(void * ptr MM_HANDLER_FILE_LINE_DC MM_HANDLER_FILE
701679
} END_WITHOUT_MALLOC_HOOKS;
702680
}
703681

704-
static void * zend_realloc_handler(void * ptr, size_t size MM_HANDLER_FILE_LINE_DC MM_HANDLER_FILE_LINE_ORIG_DC)
682+
static void * zend_realloc_handler(void * ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
705683
{
706684
void *result;
707685
alloc *a;
@@ -819,7 +797,7 @@ static void memprof_zend_execute_internal(zend_execute_data *execute_data_ptr, z
819797
}
820798
}
821799

822-
static zend_bool should_autodump(int error_type, const char *message) {
800+
static zend_bool should_autodump(int error_type, zend_string *message) {
823801
if (EXPECTED(error_type != E_ERROR)) {
824802
return 0;
825803
}
@@ -828,7 +806,7 @@ static zend_bool should_autodump(int error_type, const char *message) {
828806
return 0;
829807
}
830808

831-
if (EXPECTED(strncmp(MEMORY_LIMIT_ERROR_PREFIX, message, strlen(MEMORY_LIMIT_ERROR_PREFIX)) != 0)) {
809+
if (EXPECTED(strncmp(MEMORY_LIMIT_ERROR_PREFIX, ZSTR_VAL(message), strlen(MEMORY_LIMIT_ERROR_PREFIX)) != 0)) {
832810
return 0;
833811
}
834812

@@ -854,16 +832,12 @@ static char * generate_filename(const char * format) {
854832
return filename;
855833
}
856834

857-
static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
835+
static void memprof_zend_error_cb_dump(int type, zend_string *error_filename,
836+
const uint32_t error_lineno, zend_string *message)
858837
{
859838
char * filename = NULL;
860839
php_stream * stream;
861840
zend_bool error = 0;
862-
#if PHP_VERSION_ID < 80000
863-
const char * message_chr = format;
864-
#else
865-
const char * message_chr = ZSTR_VAL(message);
866-
#endif
867841
zend_string * new_message = NULL;
868842

869843
zend_mm_set_heap(orig_zheap);
@@ -893,27 +867,23 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
893867

894868
if (filename != NULL) {
895869
if (error == 0) {
896-
new_message = strpprintf(0, "%s (memprof dumped to %s)", message_chr, filename);
870+
new_message = strpprintf(0, "%s (memprof dumped to %s)", ZSTR_VAL(message), filename);
897871
} else {
898-
new_message = strpprintf(0, "%s (memprof failed dumping to %s, please check file permissions or disk capacity)", message_chr, filename);
872+
new_message = strpprintf(0, "%s (memprof failed dumping to %s, please check file permissions or disk capacity)", ZSTR_VAL(message), filename);
899873
}
900874
efree(filename);
901875
}
902876

903877
if (new_message != NULL) {
904-
#if PHP_VERSION_ID < 80000
905-
format = ZSTR_VAL(new_message);
906-
#else
907878
message = new_message;
908-
#endif
909879
}
910880
} END_WITHOUT_MALLOC_TRACKING;
911881

912882
zend_mm_set_heap(orig_zheap);
913883
zend_set_memory_limit(PG(memory_limit));
914884
zend_mm_set_heap(zheap);
915885

916-
old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
886+
old_zend_error_cb(type, error_filename, error_lineno, message);
917887

918888
WITHOUT_MALLOC_TRACKING {
919889
if (new_message != NULL) {
@@ -923,25 +893,21 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
923893

924894
}
925895

926-
static void memprof_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS)
896+
static void memprof_zend_error_cb(int type, zend_string *error_filename,
897+
const uint32_t error_lineno, zend_string *message)
927898
{
928-
#if PHP_VERSION_ID < 80000
929-
const char * message_chr = format;
930-
#else
931-
const char * message_chr = ZSTR_VAL(message);
932-
#endif
933-
934899
if (EXPECTED(!MEMPROF_G(profile_flags).enabled)) {
935-
old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
900+
old_zend_error_cb(type, error_filename, error_lineno, message);
936901
return;
937902
}
938903

939-
if (EXPECTED(!should_autodump(type, message_chr))) {
940-
old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
904+
if (EXPECTED(!should_autodump(type, message))) {
905+
old_zend_error_cb(type, error_filename, error_lineno, message);
941906
return;
942907
}
943908

944-
return memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
909+
return memprof_zend_error_cb_dump(type, error_filename, error_lineno,
910+
message);
945911
}
946912

947913
static PHP_INI_MH(OnChangeMemoryLimit)

memprof_legacy_arginfo.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)