From dc4a1546eb8b007557471287df00313f7145f0ae Mon Sep 17 00:00:00 2001 From: CismonX Date: Fri, 30 Mar 2018 22:20:58 +0800 Subject: [PATCH] Fix bug in macro. Shorten code. --- src/collections_methods.c | 19 ++++++------------- src/php_collections.h | 5 +++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/collections_methods.c b/src/collections_methods.c index 40090e9..3d59c70 100644 --- a/src/collections_methods.c +++ b/src/collections_methods.c @@ -53,9 +53,9 @@ #define INIT_EQUAL_CHECK_FUNC(val) \ int (*equal_check_func)(zval*, zval*); \ - if (Z_TYPE_P(element) == IS_LONG) \ + if (Z_TYPE_P(val) == IS_LONG) \ equal_check_func = fast_equal_check_long; \ - else if (Z_TYPE_P(element) == IS_STRING) \ + else if (Z_TYPE_P(val) == IS_STRING) \ equal_check_func = fast_equal_check_string; \ else \ equal_check_func = fast_equal_check_function; @@ -568,20 +568,13 @@ PHP_METHOD(Collection, init) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(elements) ZEND_PARSE_PARAMETERS_END(); - NEW_COLLECTION_OBJ(obj); - zval retval; - ZVAL_OBJ(&retval, obj); if (elements) { ELEMENTS_VALIDATE(elements); - COLLECTION_UPDATE(&retval, elements); - } else { - zval collection; - ZVAL_NEW_ARR(&collection); - zend_hash_init(Z_ARRVAL(collection), 0, NULL, ZVAL_PTR_DTOR, 0); - COLLECTION_UPDATE(&retval, &collection); - zval_ptr_dtor(&collection); + GC_ADDREF(Z_ARR_P(elements)); + RETURN_NEW_COLLECTION(Z_ARRVAL_P(elements)); } - RETVAL_OBJ(obj); + ARRAY_NEW(collection, 0); + RETVAL_NEW_COLLECTION(collection); } PHP_METHOD(Collection, intersect) diff --git a/src/php_collections.h b/src/php_collections.h index 6f7968c..ff59362 100644 --- a/src/php_collections.h +++ b/src/php_collections.h @@ -20,6 +20,11 @@ extern zend_module_entry collections_module_entry; #define PHP_COLLECTIONS_API #endif +#if PHP_VERSION_ID < 70300 +#define GC_ADDREF(p) ++GC_REFCOUNT(p) +#define GC_DELREF(p) --GC_REFCOUNT(p) +#endif + extern zend_string* collection_property_name; extern zend_string* pair_first_name; extern zend_string* pair_second_name;