From 39cf30efd2423712dcb3e660c1130e8ad2cd1d82 Mon Sep 17 00:00:00 2001 From: John Boehr Date: Thu, 12 Nov 2020 19:33:49 -0800 Subject: [PATCH] Fixes for latest PHP 8.0 --- .github/workflows/docker.yml | 2 +- .github/workflows/linux.yml | 2 +- .github/workflows/osx.yml | 5 ++++- mustache_ast.cpp | 11 +++++++++-- mustache_class_method_lambda.cpp | 2 +- mustache_exceptions.cpp | 11 +++++++---- mustache_mustache.cpp | 8 ++++++++ mustache_template.cpp | 11 +++++++++-- mustache_zend_closure_lambda.cpp | 6 +++++- 9 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0aef35a..d004069 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,7 +20,7 @@ jobs: - "7.2" - "7.3" - "7.4" - # - "8.0-rc" + - "8.0-rc" DOCKER_NAME: - "alpine" - "debian" diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 6dabc22..1c17e24 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -20,7 +20,7 @@ jobs: - "7.2" - "7.3" - "7.4" - # - "8.0" + - "8.0" COVERAGE: ["true", "false"] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 2c6df12..31156e3 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -16,7 +16,10 @@ jobs: strategy: fail-fast: false matrix: - PHP_VERSION: ["7.2", "7.3", "7.4"] + PHP_VERSION: + - "7.2" + - "7.3" + - "7.4" steps: - uses: actions/checkout@v2 - name: I am tired of writing this shit in YAML and learning a new DSL for every CI service so I'm putting everything in a FSCKING BASH SCRIPT diff --git a/mustache_ast.cpp b/mustache_ast.cpp index 6249600..eb0ba06 100644 --- a/mustache_ast.cpp +++ b/mustache_ast.cpp @@ -255,8 +255,11 @@ PHP_METHOD(MustacheAST, __sleep) int len = 0; mustache_node_to_binary_string(payload->node, &str, &len); if( str != NULL ) { - zend_update_property_stringl(MustacheAST_ce_ptr, _this_zval, - ZEND_STRL("binaryString"), str, len); +#if PHP_VERSION_ID < 80000 + zend_update_property_stringl(MustacheAST_ce_ptr, _this_zval, ZEND_STRL("binaryString"), str, len); +#else + zend_update_property_stringl(MustacheAST_ce_ptr, Z_OBJ_P(_this_zval), ZEND_STRL("binaryString"), str, len); +#endif add_next_index_string(return_value, "binaryString"); efree(str); } @@ -338,7 +341,11 @@ static inline void php_mustache_ast_wakeup(zval * _this_zval, zval * return_valu { zval rv; struct php_obj_MustacheAST * payload = php_mustache_ast_object_fetch_object(_this_zval); +#if PHP_VERSION_ID < 80000 zval * value = zend_read_property(Z_OBJCE_P(_this_zval), _this_zval, "binaryString", sizeof("binaryString")-1, 1, &rv); +#else + zval * value = zend_read_property(Z_OBJCE_P(_this_zval), Z_OBJ_P(_this_zval), "binaryString", sizeof("binaryString")-1, 1, &rv); +#endif if( Z_TYPE_P(value) == IS_STRING && Z_STRLEN_P(value) > 0 ) { mustache_node_from_binary_string(&payload->node, Z_STRVAL_P(value), Z_STRLEN_P(value)); diff --git a/mustache_class_method_lambda.cpp b/mustache_class_method_lambda.cpp index 636923b..071001b 100644 --- a/mustache_class_method_lambda.cpp +++ b/mustache_class_method_lambda.cpp @@ -33,5 +33,5 @@ int ClassMethodLambda::getUserFunctionParamCount() int ClassMethodLambda::invokeUserFunction(zval *retval_ptr, int param_count, zval params[]) { - return call_user_function_ex(EG(function_table), object, &function_name, retval_ptr, param_count, params, 1, NULL); + return call_user_function(NULL, object, &function_name, retval_ptr, param_count, params); } diff --git a/mustache_exceptions.cpp b/mustache_exceptions.cpp index ad15730..bae387c 100644 --- a/mustache_exceptions.cpp +++ b/mustache_exceptions.cpp @@ -57,10 +57,13 @@ void mustache_exception_handler() ZVAL_OBJ(&ex, obj); exception = &ex; - zend_update_property_long(MustacheParserException_ce_ptr, exception, - (char *) "templateLineNo", strlen("templateLineNo"), e.lineNo); - zend_update_property_long(MustacheParserException_ce_ptr, exception, - (char *) "templateCharNo", strlen("templateCharNo"), e.charNo); +#if PHP_VERSION_ID < 80000 + zend_update_property_long(MustacheParserException_ce_ptr, exception, (char *) "templateLineNo", strlen("templateLineNo"), e.lineNo); + zend_update_property_long(MustacheParserException_ce_ptr, exception, (char *) "templateCharNo", strlen("templateCharNo"), e.charNo); +#else + zend_update_property_long(MustacheParserException_ce_ptr, Z_OBJ_P(exception), (char *) "templateLineNo", strlen("templateLineNo"), e.lineNo); + zend_update_property_long(MustacheParserException_ce_ptr, Z_OBJ_P(exception), (char *) "templateCharNo", strlen("templateCharNo"), e.charNo); +#endif } catch( mustache::Exception& e ) { zend_throw_exception_ex(MustacheException_ce_ptr, 0, (char *) e.what(), "MustacheException"); diff --git a/mustache_mustache.cpp b/mustache_mustache.cpp index 7f4110e..89492f3 100644 --- a/mustache_mustache.cpp +++ b/mustache_mustache.cpp @@ -210,7 +210,11 @@ static inline void mustache_parse_partial_param(char * key, zval * data, // String key, object value if( Z_OBJCE_P(data) == MustacheTemplate_ce_ptr ) { zval rv; +#if PHP_VERSION_ID < 80000 zval * value = zend_read_property(Z_OBJCE_P(data), data, "template", sizeof("template")-1, 1, &rv); +#else + zval * value = zend_read_property(Z_OBJCE_P(data), Z_OBJ_P(data), "template", sizeof("template")-1, 1, &rv); +#endif convert_to_string(value); std::string tmpstr(Z_STRVAL_P(value)); ckey.assign(key); @@ -276,7 +280,11 @@ bool mustache_parse_template_param(zval * tmpl, mustache::Mustache * mustache, // Use compiled template if( Z_OBJCE_P(tmpl) == MustacheTemplate_ce_ptr ) { zval rv; +#if PHP_VERSION_ID < 80000 zval * value = zend_read_property(Z_OBJCE_P(tmpl), tmpl, "template", sizeof("template")-1, 1, &rv); +#else + zval * value = zend_read_property(Z_OBJCE_P(tmpl), Z_OBJ_P(tmpl), "template", sizeof("template")-1, 1, &rv); +#endif convert_to_string(value); std::string tmpstr(Z_STRVAL_P(value)); diff --git a/mustache_template.cpp b/mustache_template.cpp index 5b15217..e25ab24 100644 --- a/mustache_template.cpp +++ b/mustache_template.cpp @@ -68,8 +68,11 @@ PHP_METHOD(MustacheTemplate, __construct) // Check if data was null if( template_len > 0 && template_str != NULL ) { - zend_update_property_stringl(MustacheTemplate_ce_ptr, _this_zval, - "template", sizeof("template") - 1, template_str, template_len); +#if PHP_VERSION_ID < 80000 + zend_update_property_stringl(MustacheTemplate_ce_ptr, _this_zval, "template", sizeof("template") - 1, template_str, template_len); +#else + zend_update_property_stringl(MustacheTemplate_ce_ptr, Z_OBJ_P(_this_zval), "template", sizeof("template") - 1, template_str, template_len); +#endif } } catch(...) { @@ -94,7 +97,11 @@ PHP_METHOD(MustacheTemplate, __toString) // Return zval rv; +#if PHP_VERSION_ID < 80000 zval * value = zend_read_property(Z_OBJCE_P(_this_zval), _this_zval, "template", sizeof("template")-1, 1, &rv); +#else + zval * value = zend_read_property(Z_OBJCE_P(_this_zval), Z_OBJ_P(_this_zval), "template", sizeof("template")-1, 1, &rv); +#endif convert_to_string(value); RETURN_ZVAL(value, 1, 0); diff --git a/mustache_zend_closure_lambda.cpp b/mustache_zend_closure_lambda.cpp index a5d9e0c..f0c712f 100644 --- a/mustache_zend_closure_lambda.cpp +++ b/mustache_zend_closure_lambda.cpp @@ -18,11 +18,15 @@ ZendClosureLambda::~ZendClosureLambda() int ZendClosureLambda::getUserFunctionParamCount() { +#if PHP_VERSION_ID < 80000 const zend_function * func = zend_get_closure_method_def(closure); +#else + const zend_function * func = zend_get_closure_method_def(Z_OBJ_P(closure)); +#endif return func->common.num_args; } int ZendClosureLambda::invokeUserFunction(zval *retval_ptr, int param_count, zval params[]) { - return call_user_function_ex(CG(function_table), NULL, closure, retval_ptr, param_count, params, 1, NULL); + return call_user_function(NULL, NULL, closure, retval_ptr, param_count, params); }