From e153ff16519eb3266dafd024a2d316d84f93fb96 Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 3 Apr 2020 10:00:27 +0200 Subject: [PATCH] make it compile on PHP 7.3 and 7.4 --- php_v8js_macros.h | 17 +++++++++-------- v8js_class.cc | 8 ++++---- v8js_v8.h | 7 +++++++ v8js_v8object_class.cc | 10 +++++----- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index fa7247c..1e4b966 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -29,16 +29,17 @@ #include #include -#if PHP_VERSION_ID < 70400 && !defined(isnan) -/* php.h requires the isnan() macro, which is removed by c++ header, - * work around: re-define the macro to std::isnan function */ -#define isnan(a) std::isnan(a) - -/* likewise isfinite */ -#define isfinite(a) std::isfinite(a) -#endif extern "C" { +#include "php_config.h" + +/* work around incompatibilities regarding isnan() and isfinite() macros, + * affecting PHP versions before 7.4. */ +#undef HAVE_DECL_ISFINITE +#undef HAVE_DECL_ISNAN +#define HAVE_DECL_ISFINITE 0 +#define HAVE_DECL_ISNAN 0 + #include "php.h" #include "php_v8js.h" } diff --git a/v8js_class.cc b/v8js_class.cc index d36aa6d..4e9be67 100644 --- a/v8js_class.cc +++ b/v8js_class.cc @@ -1307,10 +1307,10 @@ const zend_function_entry v8js_methods[] = { /* {{{ */ /* V8Js object handlers */ -static zval* v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */ +static SINCE74(zval*, void) v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */ { v8js_ctx *c = Z_V8JS_CTX_OBJ_P(object); - V8JS_CTX_PROLOGUE_EX(c, value); + V8JS_CTX_PROLOGUE_EX(c, SINCE74(value,)); /* Check whether member is public, if so, export to V8. */ zend_property_info *property_info = zend_get_property_info(c->std.ce, Z_STR_P(member), 1); @@ -1324,7 +1324,7 @@ static zval* v8js_write_property(zval *object, zval *member, zval *value, void * if (Z_STRLEN_P(member) > std::numeric_limits::max()) { zend_throw_exception(php_ce_v8js_exception, "Property name exceeds maximum supported length", 0); - return value; + return SINCE74(value,); } /* Write value to PHP JS object */ @@ -1333,7 +1333,7 @@ static zval* v8js_write_property(zval *object, zval *member, zval *value, void * } /* Write value to PHP object */ - return std_object_handlers.write_property(object, member, value, NULL); + SINCE74(return,) std_object_handlers.write_property(object, member, value, NULL); } /* }}} */ diff --git a/v8js_v8.h b/v8js_v8.h index 22729f1..7292ac0 100644 --- a/v8js_v8.h +++ b/v8js_v8.h @@ -83,6 +83,13 @@ int v8js_get_properties_hash(v8::Local jsValue, HashTable *retval, in V8JS_CTX_PROLOGUE(ctx); +#if PHP_VERSION_ID < 70400 +#define SINCE74(x,y) y +#else +#define SINCE74(x,y) x +#endif + + #endif /* V8JS_V8_H */ /* diff --git a/v8js_v8object_class.cc b/v8js_v8object_class.cc index fc023ff..de17e26 100644 --- a/v8js_v8object_class.cc +++ b/v8js_v8object_class.cc @@ -167,23 +167,23 @@ static zval *v8js_v8object_get_property_ptr_ptr(zval *object, zval *member, int } /* }}} */ -static zval *v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot ) /* {{{ */ +static SINCE74(zval*, void) v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot ) /* {{{ */ { v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object); if (!obj->ctx) { zend_throw_exception(php_ce_v8js_exception, "Can't access V8Object after V8Js instance is destroyed!", 0); - return value; + return SINCE74(value,); } - V8JS_CTX_PROLOGUE_EX(obj->ctx, value); + V8JS_CTX_PROLOGUE_EX(obj->ctx, SINCE74(value,)); v8::Local v8objHandle = v8::Local::New(isolate, obj->v8obj); if (Z_STRLEN_P(member) > std::numeric_limits::max()) { zend_throw_exception(php_ce_v8js_exception, "Member name length exceeds maximum supported length", 0); - return value; + return SINCE74(value,); } v8::Local v8obj; @@ -191,7 +191,7 @@ static zval *v8js_v8object_write_property(zval *object, zval *member, zval *valu v8obj->CreateDataProperty(v8_context, V8JS_ZSYM(Z_STR_P(member)), zval_to_v8js(value, isolate)); } - return value; + return SINCE74(value,); } /* }}} */