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);
202202static 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 );
221207static 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
224210static PHP_INI_MH ((* origOnChangeMemoryLimit )) = NULL ;
225211
@@ -819,7 +805,7 @@ static void memprof_zend_execute_internal(zend_execute_data *execute_data_ptr, z
819805 }
820806}
821807
822- static zend_bool should_autodump (int error_type , const char * message ) {
808+ static zend_bool should_autodump (int error_type , zend_string * message ) {
823809 if (EXPECTED (error_type != E_ERROR )) {
824810 return 0 ;
825811 }
@@ -828,7 +814,7 @@ static zend_bool should_autodump(int error_type, const char *message) {
828814 return 0 ;
829815 }
830816
831- if (EXPECTED (strncmp (MEMORY_LIMIT_ERROR_PREFIX , message , strlen (MEMORY_LIMIT_ERROR_PREFIX )) != 0 )) {
817+ if (EXPECTED (strncmp (MEMORY_LIMIT_ERROR_PREFIX , ZSTR_VAL ( message ) , strlen (MEMORY_LIMIT_ERROR_PREFIX )) != 0 )) {
832818 return 0 ;
833819 }
834820
@@ -854,16 +840,12 @@ static char * generate_filename(const char * format) {
854840 return filename ;
855841}
856842
857- static void memprof_zend_error_cb_dump (MEMPROF_ZEND_ERROR_CB_ARGS )
843+ static void memprof_zend_error_cb_dump (int type , zend_string * error_filename ,
844+ const uint32_t error_lineno , zend_string * message )
858845{
859846 char * filename = NULL ;
860847 php_stream * stream ;
861848 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
867849 zend_string * new_message = NULL ;
868850
869851 zend_mm_set_heap (orig_zheap );
@@ -893,27 +875,23 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
893875
894876 if (filename != NULL ) {
895877 if (error == 0 ) {
896- new_message = strpprintf (0 , "%s (memprof dumped to %s)" , message_chr , filename );
878+ new_message = strpprintf (0 , "%s (memprof dumped to %s)" , ZSTR_VAL ( message ) , filename );
897879 } else {
898- new_message = strpprintf (0 , "%s (memprof failed dumping to %s, please check file permissions or disk capacity)" , message_chr , filename );
880+ new_message = strpprintf (0 , "%s (memprof failed dumping to %s, please check file permissions or disk capacity)" , ZSTR_VAL ( message ) , filename );
899881 }
900882 efree (filename );
901883 }
902884
903885 if (new_message != NULL ) {
904- #if PHP_VERSION_ID < 80000
905- format = ZSTR_VAL (new_message );
906- #else
907886 message = new_message ;
908- #endif
909887 }
910888 } END_WITHOUT_MALLOC_TRACKING ;
911889
912890 zend_mm_set_heap (orig_zheap );
913891 zend_set_memory_limit (PG (memory_limit ));
914892 zend_mm_set_heap (zheap );
915893
916- old_zend_error_cb (MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU );
894+ old_zend_error_cb (type , error_filename , error_lineno , message );
917895
918896 WITHOUT_MALLOC_TRACKING {
919897 if (new_message != NULL ) {
@@ -923,25 +901,21 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
923901
924902}
925903
926- static void memprof_zend_error_cb (MEMPROF_ZEND_ERROR_CB_ARGS )
904+ static void memprof_zend_error_cb (int type , zend_string * error_filename ,
905+ const uint32_t error_lineno , zend_string * message )
927906{
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-
934907 if (EXPECTED (!MEMPROF_G (profile_flags ).enabled )) {
935- old_zend_error_cb (MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU );
908+ old_zend_error_cb (type , error_filename , error_lineno , message );
936909 return ;
937910 }
938911
939- if (EXPECTED (!should_autodump (type , message_chr ))) {
940- old_zend_error_cb (MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU );
912+ if (EXPECTED (!should_autodump (type , message ))) {
913+ old_zend_error_cb (type , error_filename , error_lineno , message );
941914 return ;
942915 }
943916
944- return memprof_zend_error_cb_dump (MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU );
917+ return memprof_zend_error_cb_dump (type , error_filename , error_lineno ,
918+ message );
945919}
946920
947921static PHP_INI_MH (OnChangeMemoryLimit )
0 commit comments