diff --git a/php_v8js_macros.h b/php_v8js_macros.h index e95ca55..a578057 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -166,6 +166,13 @@ extern struct _v8js_process_globals v8js_process_globals; /* Register builtin methods into passed object */ void v8js_register_methods(v8::Local, v8js_ctx *c); +#ifdef ZEND_HASH_INC_APPLY_COUNT +# define GC_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht) +#endif +#ifdef ZEND_HASH_DEC_APPLY_COUNT +# define GC_UNPROTECT_RECURSION(ht) ZEND_HASH_DEC_APPLY_COUNT(ht) +#endif + #endif /* PHP_V8JS_MACROS_H */ /* diff --git a/v8js_convert.cc b/v8js_convert.cc index 056e31b..da52980 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -70,7 +70,11 @@ static v8::Local v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate v8::Local newarr; /* Prevent recursion */ +#if PHP_VERSION_ID >= 70300 + if (myht && GC_IS_RECURSIVE(myht)) { +#else if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) { +#endif return V8JS_NULL; } @@ -86,13 +90,13 @@ static v8::Local v8js_hash_to_jsarr(zval *value, v8::Isolate *isolate tmp_ht = HASH_OF(data); if (tmp_ht) { - ZEND_HASH_INC_APPLY_COUNT(myht); + GC_PROTECT_RECURSION(myht); } newarr->Set(index++, zval_to_v8js(data, isolate)); if (tmp_ht) { - ZEND_HASH_DEC_APPLY_COUNT(myht); + GC_UNPROTECT_RECURSION(myht); } } ZEND_HASH_FOREACH_END(); } diff --git a/v8js_exceptions.cc b/v8js_exceptions.cc index 42fe7b1..967cae8 100644 --- a/v8js_exceptions.cc +++ b/v8js_exceptions.cc @@ -88,7 +88,11 @@ void v8js_create_script_exception(zval *return_value, v8::Isolate *isolate, v8:: zend_class_entry *exception_ce = zend_exception_get_default(); if (instanceof_function(php_exception->ce, exception_ce)) { +#ifdef GC_ADDREF + GC_ADDREF(php_exception); +#else ++GC_REFCOUNT(php_exception); +#endif zend_exception_set_previous(Z_OBJ_P(return_value), php_exception); } } diff --git a/v8js_object_export.cc b/v8js_object_export.cc index 4d61e76..0092737 100644 --- a/v8js_object_export.cc +++ b/v8js_object_export.cc @@ -137,7 +137,9 @@ static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, v zend_try { /* zend_fcall_info_cache */ +#if PHP_VERSION_ID < 70300 fcc.initialized = 1; +#endif fcc.function_handler = method_ptr; fcc.calling_scope = object->ce; fcc.called_scope = object->ce; @@ -959,14 +961,14 @@ static v8::Local v8js_wrap_array_to_object(v8::Isolate *isolate, zva tmp_ht = HASH_OF(data); if (tmp_ht) { - ZEND_HASH_INC_APPLY_COUNT(tmp_ht); + GC_PROTECT_RECURSION(tmp_ht); } if (key) { if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(value) == IS_OBJECT) { /* Skip protected and private members. */ if (tmp_ht) { - ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); + GC_UNPROTECT_RECURSION(tmp_ht); } continue; } @@ -990,7 +992,7 @@ static v8::Local v8js_wrap_array_to_object(v8::Isolate *isolate, zva } if (tmp_ht) { - ZEND_HASH_DEC_APPLY_COUNT(tmp_ht); + GC_UNPROTECT_RECURSION(tmp_ht); } } ZEND_HASH_FOREACH_END(); } @@ -1013,7 +1015,11 @@ v8::Local v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate) /* {{ } /* Prevent recursion */ +#if PHP_VERSION_ID >= 70300 + if (myht && GC_IS_RECURSIVE(myht)) { +#else if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) { +#endif return V8JS_NULL; } diff --git a/v8js_v8object_class.cc b/v8js_v8object_class.cc index 49669ac..ccf4a1d 100644 --- a/v8js_v8object_class.cc +++ b/v8js_v8object_class.cc @@ -210,7 +210,11 @@ static HashTable *v8js_v8object_get_properties(zval *object) /* {{{ */ v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object); if (obj->properties == NULL) { +#if PHP_VERSION_ID >= 70300 + if (zend_gc_collect_cycles()) { +#else if (GC_G(gc_active)) { +#endif /* the garbage collector is running, don't create more zvals */ return NULL; }