Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ jobs:
os: 'macos-13'
xdebug: '3.1.2'

- php: '8.0.0'
os: 'ubuntu-20.04'
expect_native: 1
xdebug: '3.1.2'

- php: '7.4.0'
os: 'ubuntu-20.04'
expect_native: 1
xdebug: '3.1.2'

- php: '7.3.0'
os: 'ubuntu-20.04'
expect_native: 1
xdebug: '3.1.2'

runs-on: ${{ matrix.os }}
continue-on-error: ${{ !!matrix.experimental }}
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ install-sh
libtool
ltmain.sh
memprof-*.tgz
memprof_legacy_arginfo.h
missing
mkinstalldirs
modules
Expand Down
68 changes: 21 additions & 47 deletions memprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#endif
#include <assert.h>

#if PHP_VERSION_ID < 80000
#include "memprof_legacy_arginfo.h"
#else
#include "memprof_arginfo.h"
#if PHP_VERSION_ID < 80100
# error "Unsupported PHP version (min supported version: 8.1.0)"
#endif

#include "memprof_arginfo.h"

#define MEMPROF_ENV_PROFILE "MEMPROF_PROFILE"
#define MEMPROF_FLAG_NATIVE "native"
#define MEMPROF_FLAG_DUMP_ON_LIMIT "dump_on_limit"
Expand Down Expand Up @@ -202,24 +202,10 @@ static void (*old_zend_execute)(zend_execute_data *execute_data);
static void (*old_zend_execute_internal)(zend_execute_data *execute_data_ptr, zval *return_value);
#define zend_execute_fn zend_execute_ex

#if PHP_VERSION_ID < 70200 /* PHP 7.1 */
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint error_lineno, const char *format, va_list args
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, format, args
#elif PHP_VERSION_ID < 80000 /* PHP 7.2 - 7.4 */
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, format, args
#elif PHP_VERSION_ID < 80100 /* PHP 8.0 */
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, const char *error_filename, const uint32_t error_lineno, zend_string *message
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, message
#else /* PHP 8.1 */
# define MEMPROF_ZEND_ERROR_CB_ARGS int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message
# define MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU type, error_filename, error_lineno, message
#endif

static void (*old_zend_error_cb)(MEMPROF_ZEND_ERROR_CB_ARGS);
static void (*rinit_zend_error_cb)(MEMPROF_ZEND_ERROR_CB_ARGS);
static void (*old_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
static void (*rinit_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
static zend_bool zend_error_cb_overridden;
static void memprof_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS);
static void memprof_zend_error_cb(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);

static PHP_INI_MH((*origOnChangeMemoryLimit)) = NULL;

Expand Down Expand Up @@ -819,7 +805,7 @@ static void memprof_zend_execute_internal(zend_execute_data *execute_data_ptr, z
}
}

static zend_bool should_autodump(int error_type, const char *message) {
static zend_bool should_autodump(int error_type, zend_string *message) {
if (EXPECTED(error_type != E_ERROR)) {
return 0;
}
Expand All @@ -828,7 +814,7 @@ static zend_bool should_autodump(int error_type, const char *message) {
return 0;
}

if (EXPECTED(strncmp(MEMORY_LIMIT_ERROR_PREFIX, message, strlen(MEMORY_LIMIT_ERROR_PREFIX)) != 0)) {
if (EXPECTED(strncmp(MEMORY_LIMIT_ERROR_PREFIX, ZSTR_VAL(message), strlen(MEMORY_LIMIT_ERROR_PREFIX)) != 0)) {
return 0;
}

Expand All @@ -854,16 +840,12 @@ static char * generate_filename(const char * format) {
return filename;
}

static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)
static void memprof_zend_error_cb_dump(int type, zend_string *error_filename,
const uint32_t error_lineno, zend_string *message)
{
char * filename = NULL;
php_stream * stream;
zend_bool error = 0;
#if PHP_VERSION_ID < 80000
const char * message_chr = format;
#else
const char * message_chr = ZSTR_VAL(message);
#endif
zend_string * new_message = NULL;

zend_mm_set_heap(orig_zheap);
Expand Down Expand Up @@ -893,27 +875,23 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)

if (filename != NULL) {
if (error == 0) {
new_message = strpprintf(0, "%s (memprof dumped to %s)", message_chr, filename);
new_message = strpprintf(0, "%s (memprof dumped to %s)", ZSTR_VAL(message), filename);
} else {
new_message = strpprintf(0, "%s (memprof failed dumping to %s, please check file permissions or disk capacity)", message_chr, filename);
new_message = strpprintf(0, "%s (memprof failed dumping to %s, please check file permissions or disk capacity)", ZSTR_VAL(message), filename);
}
efree(filename);
}

if (new_message != NULL) {
#if PHP_VERSION_ID < 80000
format = ZSTR_VAL(new_message);
#else
message = new_message;
#endif
}
} END_WITHOUT_MALLOC_TRACKING;

zend_mm_set_heap(orig_zheap);
zend_set_memory_limit(PG(memory_limit));
zend_mm_set_heap(zheap);

old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
old_zend_error_cb(type, error_filename, error_lineno, message);

WITHOUT_MALLOC_TRACKING {
if (new_message != NULL) {
Expand All @@ -923,25 +901,21 @@ static void memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS)

}

static void memprof_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS)
static void memprof_zend_error_cb(int type, zend_string *error_filename,
const uint32_t error_lineno, zend_string *message)
{
#if PHP_VERSION_ID < 80000
const char * message_chr = format;
#else
const char * message_chr = ZSTR_VAL(message);
#endif

if (EXPECTED(!MEMPROF_G(profile_flags).enabled)) {
old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
old_zend_error_cb(type, error_filename, error_lineno, message);
return;
}

if (EXPECTED(!should_autodump(type, message_chr))) {
old_zend_error_cb(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
if (EXPECTED(!should_autodump(type, message))) {
old_zend_error_cb(type, error_filename, error_lineno, message);
return;
}

return memprof_zend_error_cb_dump(MEMPROF_ZEND_ERROR_CB_ARGS_PASSTHRU);
return memprof_zend_error_cb_dump(type, error_filename, error_lineno,
message);
}

static PHP_INI_MH(OnChangeMemoryLimit)
Expand Down
44 changes: 0 additions & 44 deletions memprof_legacy_arginfo.h

This file was deleted.

1 change: 0 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<file name="memprof.c" role="src" />
<file name="memprof.stub.php" role="src" />
<file name="memprof_arginfo.h" role="src" />
<file name="memprof_legacy_arginfo.h" role="src" />
<file name="php_memprof.h" role="src" />
<file name="util.c" role="src" />
<file name="util.h" role="src" />
Expand Down
Loading