summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-08-07 22:33:21 +0200
committerBen Fuhrmannek2021-08-07 22:33:21 +0200
commit26ee817a0e5a2bed4994fd4efc13e7f5106ca55c (patch)
tree5cb9d274592fa4869c10a25affec977ce8b778a8
parent51c020904f25ac7400e4db2e5174edc8c49fcb43 (diff)
PHP7 compatibility
-rw-r--r--src/config.m42
-rw-r--r--src/php_snuffleupagus.h1
-rw-r--r--src/sp_php_compat.c22
-rw-r--r--src/sp_php_compat.h12
4 files changed, 36 insertions, 1 deletions
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"
7sources="$sources sp_cookie_encryption.c sp_network_utils.c tweetnacl.c" 7sources="$sources sp_cookie_encryption.c sp_network_utils.c tweetnacl.c"
8sources="$sources sp_config_keywords.c sp_var_parser.c sp_var_value.c sp_tree.c" 8sources="$sources sp_config_keywords.c sp_var_parser.c sp_var_value.c sp_tree.c"
9sources="$sources sp_pcre_compat.c sp_crypt.c sp_session.c sp_sloppy.c sp_wrapper.c" 9sources="$sources sp_pcre_compat.c sp_crypt.c sp_session.c sp_sloppy.c sp_wrapper.c"
10sources="$sources sp_ini.c" 10sources="$sources sp_ini.c sp_php_compat.c"
11 11
12PHP_ARG_ENABLE(snuffleupagus, whether to enable snuffleupagus support, 12PHP_ARG_ENABLE(snuffleupagus, whether to enable snuffleupagus support,
13[ --enable-snuffleupagus Enable snuffleupagus support]) 13[ --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);
65#define SP_CONFIG_INVALID 0 65#define SP_CONFIG_INVALID 0
66#define SP_CONFIG_NONE -1 66#define SP_CONFIG_NONE -1
67 67
68#include "sp_php_compat.h"
68#include "sp_pcre_compat.h" 69#include "sp_pcre_compat.h"
69#include "sp_list.h" 70#include "sp_list.h"
70#include "sp_tree.h" 71#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 @@
1#include "php_snuffleupagus.h"
2
3#if PHP_VERSION_ID < 80000
4
5// zend_string_concat2 taken from PHP 8.0.9 zend_string.c
6// TODO: license clarification
7
8ZEND_API zend_string *zend_string_concat2(
9 const char *str1, size_t str1_len,
10 const char *str2, size_t str2_len)
11{
12 size_t len = str1_len + str2_len;
13 zend_string *res = zend_string_alloc(len, 0);
14
15 memcpy(ZSTR_VAL(res), str1, str1_len);
16 memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len);
17 ZSTR_VAL(res)[len] = '\0';
18
19 return res;
20}
21
22#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 @@
1#if PHP_VERSION_ID < 80000
2ZEND_API zend_string *zend_string_concat2(
3 const char *str1, size_t str1_len,
4 const char *str2, size_t str2_len);
5
6#define ZEND_HASH_REVERSE_FOREACH_KEY_PTR(ht, _h, _key, _ptr) \
7 ZEND_HASH_REVERSE_FOREACH(ht, 0); \
8 _h = _p->h; \
9 _key = _p->key; \
10 _ptr = Z_PTR_P(_z);
11
12#endif \ No newline at end of file