From 26ee817a0e5a2bed4994fd4efc13e7f5106ca55c Mon Sep 17 00:00:00 2001 From: Ben Fuhrmannek Date: Sat, 7 Aug 2021 22:33:21 +0200 Subject: PHP7 compatibility --- src/config.m4 | 2 +- src/php_snuffleupagus.h | 1 + src/sp_php_compat.c | 22 ++++++++++++++++++++++ src/sp_php_compat.h | 12 ++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/sp_php_compat.c create mode 100644 src/sp_php_compat.h diff --git a/src/config.m4 b/src/config.m4 index 1410565..9778820 100644 --- a/src/config.m4 +++ b/src/config.m4 @@ -7,7 +7,7 @@ sources="$sources sp_disabled_functions.c sp_execute.c sp_upload_validation.c" sources="$sources sp_cookie_encryption.c sp_network_utils.c tweetnacl.c" sources="$sources sp_config_keywords.c sp_var_parser.c sp_var_value.c sp_tree.c" sources="$sources sp_pcre_compat.c sp_crypt.c sp_session.c sp_sloppy.c sp_wrapper.c" -sources="$sources sp_ini.c" +sources="$sources sp_ini.c sp_php_compat.c" PHP_ARG_ENABLE(snuffleupagus, whether to enable snuffleupagus support, [ --enable-snuffleupagus Enable snuffleupagus support]) diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index be4d306..928095d 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h @@ -65,6 +65,7 @@ typedef void (*zif_handler)(INTERNAL_FUNCTION_PARAMETERS); #define SP_CONFIG_INVALID 0 #define SP_CONFIG_NONE -1 +#include "sp_php_compat.h" #include "sp_pcre_compat.h" #include "sp_list.h" #include "sp_tree.h" diff --git a/src/sp_php_compat.c b/src/sp_php_compat.c new file mode 100644 index 0000000..933acd8 --- /dev/null +++ b/src/sp_php_compat.c @@ -0,0 +1,22 @@ +#include "php_snuffleupagus.h" + +#if PHP_VERSION_ID < 80000 + +// zend_string_concat2 taken from PHP 8.0.9 zend_string.c +// TODO: license clarification + +ZEND_API zend_string *zend_string_concat2( + const char *str1, size_t str1_len, + const char *str2, size_t str2_len) +{ + size_t len = str1_len + str2_len; + zend_string *res = zend_string_alloc(len, 0); + + memcpy(ZSTR_VAL(res), str1, str1_len); + memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len); + ZSTR_VAL(res)[len] = '\0'; + + return res; +} + +#endif diff --git a/src/sp_php_compat.h b/src/sp_php_compat.h new file mode 100644 index 0000000..380abe4 --- /dev/null +++ b/src/sp_php_compat.h @@ -0,0 +1,12 @@ +#if PHP_VERSION_ID < 80000 +ZEND_API zend_string *zend_string_concat2( + const char *str1, size_t str1_len, + const char *str2, size_t str2_len); + +#define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \ + ZEND_HASH_REVERSE_FOREACH(ht, 0); \ + _h = _p->h; \ + _key = _p->key; \ + _ptr = Z_PTR_P(_z); + +#endif \ No newline at end of file -- cgit v1.3