projects/aports·blob master · refs

153 lines · 6.2 KiB

1Patch-Source: https://github.com/phpredis/phpredis/commit/78c1c690 (Fix PHP 8.6 builds)
2Patch-Source: https://github.com/phpredis/phpredis/pull/2888 (Fix PHP 8.6 bin2hex build)
3PHP 8.6 removed XtOffsetOf, zval_dtor, zval_is_true, INI_STR/INI_INT/
4INI_BOOL, WRONG_PARAM_COUNT/ZEND_WRONG_PARAM_COUNT and
5EMPTY_SWITCH_DEFAULT_CASE (provided as compat macros in common.h), and
6changed the session module save_path/session_name arguments to
7zend_string* (handled in redis_session.c).
8
9PHP 8.6 also dropped php_hash_bin2hex() from ext/hash in favour of
10zend_bin2hex() in the Zend engine (upstream PR #2888), but the packaged
118.6.0alpha1 predates that php-src change: it still ships the old
12function and lacks the new one, so no PHP_VERSION_ID guard can pick the
13right API. Instead a local redis_bin2hex() helper is added to common.h
14and the two call sites (redis.c, library.c) are switched to it, which
15works with any PHP version.
16--- a/common.h
17+++ b/common.h
18@@ -4,6 +4,39 @@
19 #ifndef REDIS_COMMON_H
20 #define REDIS_COMMON_H
21
22+/* PHP 8.6 removed a number of long-standing compatibility macros. Provide
23+ * replacements so this release keeps building. See upstream commit 78c1c690
24+ * "Fix PHP 8.6 builds" and PR #2888 "Fix PHP 8.6 bin2hex build". */
25+#if PHP_VERSION_ID >= 80600
26+# include <stddef.h>
27+# define XtOffsetOf(type, member) offsetof(type, member)
28+# define zval_dtor(zv) zval_ptr_dtor_nogc(zv)
29+# define zval_is_true(zv) zend_is_true(zv)
30+# define INI_STR(name) ((char *) zend_ini_string((name), strlen(name), 0))
31+# define INI_INT(name) zend_ini_long((name), strlen(name), 0)
32+# define INI_BOOL(name) ((bool) zend_ini_long((name), strlen(name), 0))
33+# define ZEND_WRONG_PARAM_COUNT() do { zend_wrong_param_count(); RETURN_THROWS(); } while (0)
34+# define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
35+# define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_UNREACHABLE(); break;
36+#endif
37+
38+/* PHP 8.6 dropped php_hash_bin2hex() from ext/hash in favour of
39+ * zend_bin2hex() in the Zend engine, but 8.6.0alpha1 predates the
40+ * replacement (it still ships the old function and lacks the new one),
41+ * so no PHP_VERSION_ID guard can pick the right API. Use a local
42+ * implementation instead; call sites are patched to use it. */
43+static zend_always_inline void
44+redis_bin2hex(char *out, const unsigned char *in, size_t in_len)
45+{
46+ static const char hexits[] = "0123456789abcdef";
47+ size_t i;
48+
49+ for (i = 0; i < in_len; i++) {
50+ out[i * 2] = hexits[in[i] >> 4];
51+ out[i * 2 + 1] = hexits[in[i] & 0x0F];
52+ }
53+}
54+
55 #define PHPREDIS_CTX_PTR ((char *)0xDEADC0DE)
56 #define PHPREDIS_NOTUSED(v) ((void)v)
57
58--- a/redis.c
59+++ b/redis.c
60@@ -330,7 +330,7 @@
61
62 /* First try to have PHP generate the bytes */
63 if (php_random_bytes_silent(ZSTR_VAL(s), bytes) == SUCCESS) {
64- php_hash_bin2hex(dst, (unsigned char *)ZSTR_VAL(s), bytes);
65+ redis_bin2hex(dst, (unsigned char *)ZSTR_VAL(s), bytes);
66 zend_string_release(s);
67 return;
68 }
69--- a/library.c
70+++ b/library.c
71@@ -876,7 +876,7 @@
72 efree(ctx);
73
74 hex = zend_string_safe_alloc(ops->digest_size, 2, 0, 0);
75- php_hash_bin2hex(ZSTR_VAL(hex), digest, ops->digest_size);
76+ redis_bin2hex(ZSTR_VAL(hex), digest, ops->digest_size);
77 ZSTR_VAL(hex)[2 * ops->digest_size] = 0;
78
79 efree(digest);
80--- a/redis_session.c
81+++ b/redis_session.c
82@@ -424,16 +424,24 @@
83 zval params, context, *zv;
84 int i, j, path_len;
85
86+#if PHP_VERSION_ID >= 80600
87+ const char *save_path_str = ZSTR_VAL(save_path);
88+ size_t save_path_len = ZSTR_LEN(save_path);
89+#else
90+ const char *save_path_str = save_path;
91+ size_t save_path_len = strlen(save_path);
92+#endif
93+
94 redis_pool *pool = ecalloc(1, sizeof(*pool));
95
96- for (i = 0, j = 0, path_len = strlen(save_path); i < path_len; i = j + 1) {
97+ for (i = 0, j = 0, path_len = save_path_len; i < path_len; i = j + 1) {
98 /* find beginning of url */
99- while ( i< path_len && (isspace(save_path[i]) || save_path[i] == ','))
100+ while ( i< path_len && (isspace(save_path_str[i]) || save_path_str[i] == ','))
101 i++;
102
103 /* find end of url */
104 j = i;
105- while (j<path_len && !isspace(save_path[j]) && save_path[j] != ',')
106+ while (j<path_len && !isspace(save_path_str[j]) && save_path_str[j] != ',')
107 j++;
108
109 if (i < j) {
110@@ -445,18 +453,18 @@
111 zend_string *user = NULL, *pass = NULL;
112
113 /* translate unix: into file: */
114- if (!redis_strncmp(save_path+i, ZEND_STRL("unix:"))) {
115+ if (!redis_strncmp(save_path_str+i, ZEND_STRL("unix:"))) {
116 int len = j-i;
117- char *path = estrndup(save_path+i, len);
118+ char *path = estrndup(save_path_str+i, len);
119 memcpy(path, "file:", sizeof("file:")-1);
120 url = php_url_parse_ex(path, len);
121 efree(path);
122 } else {
123- url = php_url_parse_ex(save_path+i, j-i);
124+ url = php_url_parse_ex(save_path_str+i, j-i);
125 }
126
127 if (!url) {
128- char *path = estrndup(save_path+i, j-i);
129+ char *path = estrndup(save_path_str+i, j-i);
130 php_error_docref(NULL, E_WARNING,
131 "Failed to parse session.save_path (error at offset %d, url was '%s')", i, path);
132 efree(path);
133@@ -498,7 +506,7 @@
134 }
135
136 if ((url->path == NULL && url->host == NULL) || weight <= 0 || timeout <= 0) {
137- char *path = estrndup(save_path+i, j-i);
138+ char *path = estrndup(save_path_str+i, j-i);
139 php_error_docref(NULL, E_WARNING,
140 "Failed to parse session.save_path (error at offset %d, url was '%s')", i, path);
141 efree(path);
142@@ -955,7 +963,11 @@
143
144 /* Parse configuration for session handler */
145 array_init(&z_conf);
146+#if PHP_VERSION_ID >= 80600
147+ sapi_module.treat_data(PARSE_STRING, estrdup(ZSTR_VAL(save_path)), &z_conf);
148+#else
149 sapi_module.treat_data(PARSE_STRING, estrdup(save_path), &z_conf);
150+#endif
151
152 /* We need seeds */
153 zv = REDIS_HASH_STR_FIND_TYPE_STATIC(Z_ARRVAL(z_conf), "seed", IS_ARRAY);