Skip to content

Commit e153ff1

Browse files
committed
make it compile on PHP 7.3 and 7.4
1 parent 83c215d commit e153ff1

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

php_v8js_macros.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
#include <mutex>
3030

3131
#include <cmath>
32-
#if PHP_VERSION_ID < 70400 && !defined(isnan)
33-
/* php.h requires the isnan() macro, which is removed by c++ <cmath> header,
34-
* work around: re-define the macro to std::isnan function */
35-
#define isnan(a) std::isnan(a)
36-
37-
/* likewise isfinite */
38-
#define isfinite(a) std::isfinite(a)
39-
#endif
4032

4133
extern "C" {
34+
#include "php_config.h"
35+
36+
/* work around incompatibilities regarding isnan() and isfinite() macros,
37+
* affecting PHP versions before 7.4. */
38+
#undef HAVE_DECL_ISFINITE
39+
#undef HAVE_DECL_ISNAN
40+
#define HAVE_DECL_ISFINITE 0
41+
#define HAVE_DECL_ISNAN 0
42+
4243
#include "php.h"
4344
#include "php_v8js.h"
4445
}

v8js_class.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,10 +1307,10 @@ const zend_function_entry v8js_methods[] = { /* {{{ */
13071307

13081308
/* V8Js object handlers */
13091309

1310-
static zval* v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
1310+
static SINCE74(zval*, void) v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot) /* {{{ */
13111311
{
13121312
v8js_ctx *c = Z_V8JS_CTX_OBJ_P(object);
1313-
V8JS_CTX_PROLOGUE_EX(c, value);
1313+
V8JS_CTX_PROLOGUE_EX(c, SINCE74(value,));
13141314

13151315
/* Check whether member is public, if so, export to V8. */
13161316
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 *
13241324
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
13251325
zend_throw_exception(php_ce_v8js_exception,
13261326
"Property name exceeds maximum supported length", 0);
1327-
return value;
1327+
return SINCE74(value,);
13281328
}
13291329

13301330
/* Write value to PHP JS object */
@@ -1333,7 +1333,7 @@ static zval* v8js_write_property(zval *object, zval *member, zval *value, void *
13331333
}
13341334

13351335
/* Write value to PHP object */
1336-
return std_object_handlers.write_property(object, member, value, NULL);
1336+
SINCE74(return,) std_object_handlers.write_property(object, member, value, NULL);
13371337
}
13381338
/* }}} */
13391339

v8js_v8.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ int v8js_get_properties_hash(v8::Local<v8::Value> jsValue, HashTable *retval, in
8383
V8JS_CTX_PROLOGUE(ctx);
8484

8585

86+
#if PHP_VERSION_ID < 70400
87+
#define SINCE74(x,y) y
88+
#else
89+
#define SINCE74(x,y) x
90+
#endif
91+
92+
8693
#endif /* V8JS_V8_H */
8794

8895
/*

v8js_v8object_class.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,31 +167,31 @@ static zval *v8js_v8object_get_property_ptr_ptr(zval *object, zval *member, int
167167
}
168168
/* }}} */
169169

170-
static zval *v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot ) /* {{{ */
170+
static SINCE74(zval*, void) v8js_v8object_write_property(zval *object, zval *member, zval *value, void **cache_slot ) /* {{{ */
171171
{
172172
v8js_v8object *obj = Z_V8JS_V8OBJECT_OBJ_P(object);
173173

174174
if (!obj->ctx) {
175175
zend_throw_exception(php_ce_v8js_exception,
176176
"Can't access V8Object after V8Js instance is destroyed!", 0);
177-
return value;
177+
return SINCE74(value,);
178178
}
179179

180-
V8JS_CTX_PROLOGUE_EX(obj->ctx, value);
180+
V8JS_CTX_PROLOGUE_EX(obj->ctx, SINCE74(value,));
181181
v8::Local<v8::Value> v8objHandle = v8::Local<v8::Value>::New(isolate, obj->v8obj);
182182

183183
if (Z_STRLEN_P(member) > std::numeric_limits<int>::max()) {
184184
zend_throw_exception(php_ce_v8js_exception,
185185
"Member name length exceeds maximum supported length", 0);
186-
return value;
186+
return SINCE74(value,);
187187
}
188188

189189
v8::Local<v8::Object> v8obj;
190190
if (v8objHandle->IsObject() && v8objHandle->ToObject(v8_context).ToLocal(&v8obj)) {
191191
v8obj->CreateDataProperty(v8_context, V8JS_ZSYM(Z_STR_P(member)), zval_to_v8js(value, isolate));
192192
}
193193

194-
return value;
194+
return SINCE74(value,);
195195
}
196196
/* }}} */
197197

0 commit comments

Comments
 (0)