From 421d62e474eff176dd87da6f793faba6c5e742dc Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Fri, 18 Mar 2022 21:28:41 +0000 Subject: [PATCH 1/2] PHP 8.0: define TSRMLS* macros as no-op The TSRM* macros are no-op since PHP 7.0. PHP 8.0 drops them at all. Define them as no-op in our code when building against PHP 8 and newer to overcome a build fail. See [1] and [2] (1.c) for details. Those macros could be removed from the code entirely (both definitions and usages), since we support PHP 7.0+. It is to be done later. [1]: https://wiki.php.net/rfc/native-tls [2]: https://github.com/php/php-src/blob/php-8.0.18RC1/UPGRADING.INTERNALS Part of #171 --- src/php_tarantool.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/php_tarantool.h b/src/php_tarantool.h index db46137..acc39bc 100644 --- a/src/php_tarantool.h +++ b/src/php_tarantool.h @@ -29,6 +29,13 @@ # define smart_string_free_ex(...) smart_str_free_ex(__VA_ARGS__) #endif +#if PHP_VERSION_ID >= 80000 +/* These macroses were removed in PHP 8. */ +# define TSRMLS_CC +# define TSRMLS_DC +# define TSRMLS_FETCH() +#endif /* PHP_VERSION_ID >= 80000 */ + #if PHP_VERSION_ID < 70300 # define GC_SET_REFCOUNT(p, rc) do { \ GC_REFCOUNT((p)) = (rc); \ From 26ea492b705e548a8014144630f353afbbefff7a Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Fri, 18 Mar 2022 21:29:54 +0000 Subject: [PATCH 2/2] PHP 8.0: fix array-list detection The `nNextFreeElement` field is initialized with `ZEND_LONG_MIN` instead of zero since PHP 8.0. Adjust our `php_mp_is_hash()` check accordingly. See [1] and [2] for details. NB: PHP 8.1 introduces `zend_array_is_list()`, which may be used here. See [3] and [4] for details. [1]: https://wiki.php.net/rfc/negative_array_index [2]: https://github.com/php/php-src/pull/3772 [3]: https://wiki.php.net/rfc/is_list [4]: https://github.com/php/php-src/pull/6070 Since I don't observe any other problems on PHP 8.1, closing the relevant issue. Fixes #171 --- src/tarantool_msgpack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tarantool_msgpack.c b/src/tarantool_msgpack.c index 39f904e..4d95de4 100644 --- a/src/tarantool_msgpack.c +++ b/src/tarantool_msgpack.c @@ -96,7 +96,10 @@ void php_mp_pack_array(smart_string *str, size_t len) { int php_mp_is_hash(zval *val) { HashTable *ht = Z_ARRVAL_P(val); int count = zend_hash_num_elements(ht); - if (count != ht->nNextFreeElement) { + if (count == 0) { + /* An empty array is considered as a list. */ + return 0; + } else if (count != ht->nNextFreeElement) { return 1; } else { HashPosition pos = {0};