PHP 8 compatibility. https://github.com/BitOne/php-meminfo/commit/829e0061b020ec2b9a6a89c1bf381c6038800ef1 --- extension/php7/meminfo.c.orig +++ extension/php7/meminfo.c @@ -16,11 +16,21 @@ #include "SAPI.h" #include "zend_API.h" +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_INFO_EX(arginfo_meminfo_dump, 0, 0, 1) + ZEND_ARG_INFO(0, output_stream) +ZEND_END_ARG_INFO() +const zend_function_entry meminfo_functions[] = { + PHP_FE(meminfo_dump, arginfo_meminfo_dump) + PHP_FE_END +}; +#else const zend_function_entry meminfo_functions[] = { PHP_FE(meminfo_dump, NULL) PHP_FE_END }; +#endif zend_module_entry meminfo_module_entry = { STANDARD_MODULE_HEADER, @@ -48,28 +59,28 @@ PHP_FUNCTION(meminfo_dump) php_stream *stream; HashTable visited_items; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zval_stream) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zval_stream) == FAILURE) { return; } zend_hash_init(&visited_items, 1000, NULL, NULL, 0); php_stream_from_zval(stream, zval_stream); - php_stream_printf(stream TSRMLS_CC, "{\n"); + php_stream_printf(stream, "{\n"); - php_stream_printf(stream TSRMLS_CC, " \"header\" : {\n"); - php_stream_printf(stream TSRMLS_CC, " \"memory_usage\" : %zd,\n", zend_memory_usage(0)); - php_stream_printf(stream TSRMLS_CC, " \"memory_usage_real\" : %zd,\n", zend_memory_usage(1)); - php_stream_printf(stream TSRMLS_CC, " \"peak_memory_usage\" : %zd,\n", zend_memory_peak_usage(0)); - php_stream_printf(stream TSRMLS_CC, " \"peak_memory_usage_real\" : %zd\n", zend_memory_peak_usage(1)); - php_stream_printf(stream TSRMLS_CC, " },\n"); + php_stream_printf(stream, " \"header\" : {\n"); + php_stream_printf(stream, " \"memory_usage\" : %zd,\n", zend_memory_usage(0)); + php_stream_printf(stream, " \"memory_usage_real\" : %zd,\n", zend_memory_usage(1)); + php_stream_printf(stream, " \"peak_memory_usage\" : %zd,\n", zend_memory_peak_usage(0)); + php_stream_printf(stream, " \"peak_memory_usage_real\" : %zd\n", zend_memory_peak_usage(1)); + php_stream_printf(stream, " },\n"); - php_stream_printf(stream TSRMLS_CC, " \"items\": {\n"); + php_stream_printf(stream, " \"items\": {\n"); meminfo_browse_exec_frames(stream, &visited_items, &first_element); meminfo_browse_class_static_members(stream, &visited_items, &first_element); - php_stream_printf(stream TSRMLS_CC, "\n }\n"); - php_stream_printf(stream TSRMLS_CC, "}\n}\n"); + php_stream_printf(stream, "\n }\n"); + php_stream_printf(stream, "}\n}\n"); zend_hash_destroy(&visited_items); } @@ -225,7 +236,7 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H int first_child = 1; - php_stream_printf(stream TSRMLS_CC, " \"children\" : {\n"); + php_stream_printf(stream, " \"children\" : {\n"); zend_hash_internal_pointer_reset_ex(ht, &pos); while ((zval = zend_hash_get_current_data_ex(ht, &pos)) != NULL) { @@ -246,7 +257,7 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H } if (!first_child) { - php_stream_printf(stream TSRMLS_CC, ",\n"); + php_stream_printf(stream, ",\n"); } else { first_child = 0; } @@ -262,7 +273,7 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H escaped_property_name = meminfo_escape_for_json(property_name); - php_stream_printf(stream TSRMLS_CC, " \"%s\":\"%s\"", ZSTR_VAL(escaped_property_name), zval_id); + php_stream_printf(stream, " \"%s\":\"%s\"", ZSTR_VAL(escaped_property_name), zval_id); zend_string_release(escaped_property_name); } else { @@ -270,20 +281,20 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H escaped_key = meminfo_escape_for_json(ZSTR_VAL(key)); - php_stream_printf(stream TSRMLS_CC, " \"%s\":\"%s\"", ZSTR_VAL(escaped_key), zval_id); + php_stream_printf(stream, " \"%s\":\"%s\"", ZSTR_VAL(escaped_key), zval_id); zend_string_release(escaped_key); } break; case HASH_KEY_IS_LONG: - php_stream_printf(stream TSRMLS_CC, " \"%ld\":\"%s\"", num_key, zval_id); + php_stream_printf(stream, " \"%ld\":\"%s\"", num_key, zval_id); break; } zend_hash_move_forward_ex(ht, &pos); } - php_stream_printf(stream TSRMLS_CC, "\n }\n"); + php_stream_printf(stream, "\n }\n"); zend_hash_internal_pointer_reset_ex(ht, &pos); while ((zval = zend_hash_get_current_data_ex(ht, &pos)) != NULL) { @@ -315,14 +326,14 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy } if (! *first_element) { - php_stream_printf(stream TSRMLS_CC, "\n },\n"); + php_stream_printf(stream, "\n },\n"); } else { *first_element = 0; } - php_stream_printf(stream TSRMLS_CC, " \"%s\" : {\n", zval_identifier); - php_stream_printf(stream TSRMLS_CC, " \"type\" : \"%s\",\n", zend_get_type_by_const(Z_TYPE_P(zv))); - php_stream_printf(stream TSRMLS_CC, " \"size\" : \"%ld\",\n", meminfo_get_element_size(zv)); + php_stream_printf(stream, " \"%s\" : {\n", zval_identifier); + php_stream_printf(stream, " \"type\" : \"%s\",\n", zend_get_type_by_const(Z_TYPE_P(zv))); + php_stream_printf(stream, " \"size\" : \"%ld\",\n", meminfo_get_element_size(zv)); if (frame_label) { zend_string * escaped_frame_label; @@ -332,19 +343,19 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy escaped_symbol_name = meminfo_escape_for_json(ZSTR_VAL(symbol_name)); - php_stream_printf(stream TSRMLS_CC, " \"symbol_name\" : \"%s\",\n", ZSTR_VAL(escaped_symbol_name)); + php_stream_printf(stream, " \"symbol_name\" : \"%s\",\n", ZSTR_VAL(escaped_symbol_name)); zend_string_release(escaped_symbol_name); } escaped_frame_label = meminfo_escape_for_json(frame_label); - php_stream_printf(stream TSRMLS_CC, " \"is_root\" : true,\n"); - php_stream_printf(stream TSRMLS_CC, " \"frame\" : \"%s\"\n", ZSTR_VAL(escaped_frame_label)); + php_stream_printf(stream, " \"is_root\" : true,\n"); + php_stream_printf(stream, " \"frame\" : \"%s\"\n", ZSTR_VAL(escaped_frame_label)); zend_string_release(escaped_frame_label); } else { - php_stream_printf(stream TSRMLS_CC, " \"is_root\" : false\n"); + php_stream_printf(stream, " \"is_root\" : false\n"); } if (Z_TYPE_P(zv) == IS_OBJECT) { @@ -355,12 +366,12 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy escaped_class_name = meminfo_escape_for_json(ZSTR_VAL(Z_OBJCE_P(zv)->name)); - php_stream_printf(stream TSRMLS_CC, ",\n"); - php_stream_printf(stream TSRMLS_CC, " \"class\" : \"%s\",\n", ZSTR_VAL(escaped_class_name)); + php_stream_printf(stream, ",\n"); + php_stream_printf(stream, " \"class\" : \"%s\",\n", ZSTR_VAL(escaped_class_name)); zend_string_release(escaped_class_name); - php_stream_printf(stream TSRMLS_CC, " \"object_handle\" : \"%d\",\n", Z_OBJ_HANDLE_P(zv)); + php_stream_printf(stream, " \"object_handle\" : \"%d\",\n", Z_OBJ_HANDLE_P(zv)); #if PHP_VERSION_ID >= 70400 properties = zend_get_properties_for(zv, ZEND_PROP_PURPOSE_DEBUG); @@ -382,10 +393,10 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy #endif } } else if (Z_TYPE_P(zv) == IS_ARRAY) { - php_stream_printf(stream TSRMLS_CC, ",\n"); + php_stream_printf(stream, ",\n"); meminfo_hash_dump(stream, Z_ARRVAL_P(zv), 0, visited_items, first_element); } else { - php_stream_printf(stream TSRMLS_CC, "\n"); + php_stream_printf(stream, "\n"); } } @@ -441,12 +452,21 @@ void meminfo_build_frame_label(char* frame_label, int frame_label_len, zend_exec if (frame->func) { func = frame->func; + +#if PHP_VERSION_ID >= 80000 + if (func->common.function_name) { + function_name = ZSTR_VAL(func->common.function_name); + } else { + function_name = NULL; + } +#else function_name = (func->common.scope && func->common.scope->trait_aliases) ? ZSTR_VAL(zend_resolve_method_name( (object ? object->ce : func->common.scope), func)) : (func->common.function_name ? ZSTR_VAL(func->common.function_name) : NULL); +#endif } else { func = NULL; function_name = NULL;