Skip to content

Commit 7403d7e

Browse files
committed
Update to Zephir 0.19
1 parent 1967495 commit 7403d7e

16 files changed

Lines changed: 205 additions & 179 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"require-dev": {
2929
"friendsofphp/php-cs-fixer": "^3.0",
30-
"phalcon/zephir": "^0.18",
30+
"phalcon/zephir": "^0.19",
3131
"phpbench/phpbench": "^1.0",
3232
"phpstan/extension-installer": "^1.0",
3333
"phpstan/phpstan": "^1.0",

ext/kernel/array.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ int zephir_array_update_zval(zval *arr, zval *index, zval *value, int flags)
652652

653653
if ((flags & PH_CTOR) == PH_CTOR) {
654654
zval new_zv;
655-
//Z_TRY_DELREF_P(value); //?
656655
ZVAL_DUP(&new_zv, value);
657656
value = &new_zv;
658657
}

ext/kernel/fcall.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,18 @@ int zephir_call_user_func_array_noex(zval *return_value, zval *handler, zval *pa
610610

611611
fci.size = sizeof(fci);
612612
fci.object = fci_cache.object;
613-
ZVAL_COPY_VALUE(&fci.function_name, handler);
613+
/* We have an FCC so no need to copy the callable */
614+
ZVAL_UNDEF(&fci.function_name);
614615
fci.param_count = 0;
615616
fci.params = NULL;
616617
fci.retval = return_value;
617-
fci.named_params = NULL;
618+
if (params) {
619+
fci.named_params = Z_ARRVAL_P(params);
620+
} else {
621+
fci.named_params = NULL;
622+
}
618623

619-
zend_fcall_info_args(&fci, params);
620624
status = zend_call_function(&fci, &fci_cache);
621-
zend_fcall_info_args_clear(&fci, 1);
622625

623626
return status;
624627
}

ext/kernel/math.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include <php.h>
1717
#include <ext/standard/php_string.h>
1818
#include <ext/standard/php_math.h>
19+
#if PHP_VERSION_ID < 80400
1920
#include <ext/standard/php_rand.h>
21+
#endif
2022

2123
#include "php_ext.h"
2224
#include "kernel/main.h"

ext/kernel/object.c

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,77 @@ int zephir_create_closure_ex(zval *return_value, zval *this_ptr, zend_class_entr
12261226
return SUCCESS;
12271227
}
12281228

1229+
/**
1230+
* Copied from php-src source tree for PHP 8.4
1231+
*/
1232+
#if PHP_VERSION_ID < 80400
1233+
static zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params)
1234+
{
1235+
zend_result status = object_and_properties_init(arg, class_type, NULL);
1236+
if (UNEXPECTED(status == FAILURE)) {
1237+
ZVAL_UNDEF(arg);
1238+
return FAILURE;
1239+
}
1240+
zend_object *obj = Z_OBJ_P(arg);
1241+
zend_function *constructor = obj->handlers->get_constructor(obj);
1242+
if (constructor == NULL) {
1243+
/* The constructor can be NULL for 2 different reasons:
1244+
* - It is not defined
1245+
* - We are not allowed to call the constructor (e.g. private, or internal opaque class)
1246+
* and an exception has been thrown
1247+
* in the former case, we are (mostly) done and the object is initialized,
1248+
* in the latter we need to destroy the object as initialization failed
1249+
*/
1250+
if (UNEXPECTED(EG(exception))) {
1251+
zval_ptr_dtor(arg);
1252+
ZVAL_UNDEF(arg);
1253+
return FAILURE;
1254+
}
1255+
1256+
/* Surprisingly, this is the only case where internal classes will allow to pass extra arguments
1257+
* However, if there are named arguments (and it is not empty),
1258+
* an Error must be thrown to be consistent with new ClassName() */
1259+
if (UNEXPECTED(named_params != NULL && zend_hash_num_elements(named_params) != 0)) {
1260+
/* Throw standard Error */
1261+
zend_string *arg_name = NULL;
1262+
zend_hash_get_current_key(named_params, &arg_name, /* num_index */ NULL);
1263+
ZEND_ASSERT(arg_name != NULL);
1264+
zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name));
1265+
/* Do not call destructor, free object, and set arg to IS_UNDEF */
1266+
zend_object_store_ctor_failed(obj);
1267+
zval_ptr_dtor(arg);
1268+
ZVAL_UNDEF(arg);
1269+
return FAILURE;
1270+
} else {
1271+
return SUCCESS;
1272+
}
1273+
}
1274+
/* A constructor should not return a value, however if an exception is thrown
1275+
* zend_call_known_function() will set the retval to IS_UNDEF */
1276+
zval retval;
1277+
zend_call_known_function(
1278+
constructor,
1279+
obj,
1280+
class_type,
1281+
&retval,
1282+
param_count,
1283+
params,
1284+
named_params
1285+
);
1286+
if (Z_TYPE(retval) == IS_UNDEF) {
1287+
/* Do not call destructor, free object, and set arg to IS_UNDEF */
1288+
zend_object_store_ctor_failed(obj);
1289+
zval_ptr_dtor(arg);
1290+
ZVAL_UNDEF(arg);
1291+
return FAILURE;
1292+
} else {
1293+
/* Unlikely, but user constructors may return any value they want */
1294+
zval_ptr_dtor(&retval);
1295+
return SUCCESS;
1296+
}
1297+
}
1298+
#endif
1299+
12291300
/**
12301301
* Creates a new instance dynamically. Call constructor without parameters
12311302
*/
@@ -1244,38 +1315,7 @@ int zephir_create_instance(zval *return_value, const zval *class_name)
12441315
return FAILURE;
12451316
}
12461317

1247-
if(UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) {
1248-
return FAILURE;
1249-
}
1250-
1251-
if (EXPECTED(Z_OBJ_HT_P(return_value)->get_constructor)) {
1252-
zend_object* obj = Z_OBJ_P(return_value);
1253-
zend_function* ctor = Z_OBJ_HT_P(return_value)->get_constructor(obj);
1254-
if (ctor) {
1255-
zend_fcall_info fci;
1256-
zend_fcall_info_cache fcc;
1257-
1258-
zend_class_entry* ce = Z_OBJCE_P(return_value);
1259-
1260-
fci.size = sizeof(fci);
1261-
fci.object = obj;
1262-
fci.retval = 0;
1263-
fci.param_count = 0;
1264-
fci.params = 0;
1265-
fci.named_params = NULL;
1266-
1267-
ZVAL_NULL(&fci.function_name);
1268-
1269-
fcc.object = obj;
1270-
fcc.called_scope = ce;
1271-
fcc.calling_scope = ce;
1272-
fcc.function_handler = ctor;
1273-
1274-
return zend_fcall_info_call(&fci, &fcc, NULL, NULL);
1275-
}
1276-
}
1277-
1278-
return SUCCESS;
1318+
return object_init_with_constructor(return_value, ce, 0, NULL, NULL);
12791319
}
12801320

12811321
/**
@@ -1301,40 +1341,5 @@ int zephir_create_instance_params(zval *return_value, const zval *class_name, zv
13011341
return FAILURE;
13021342
}
13031343

1304-
if(UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) {
1305-
return FAILURE;
1306-
}
1307-
1308-
if (EXPECTED(Z_OBJ_HT_P(return_value)->get_constructor)) {
1309-
zend_object* obj = Z_OBJ_P(return_value);
1310-
zend_function* ctor = Z_OBJ_HT_P(return_value)->get_constructor(obj);
1311-
if (ctor) {
1312-
int status;
1313-
zend_fcall_info fci;
1314-
zend_fcall_info_cache fcc;
1315-
1316-
zend_class_entry* ce = Z_OBJCE_P(return_value);
1317-
1318-
fci.size = sizeof(fci);
1319-
fci.object = obj;
1320-
fci.retval = 0;
1321-
fci.param_count = 0;
1322-
fci.params = 0;
1323-
fci.named_params = NULL;
1324-
1325-
ZVAL_NULL(&fci.function_name);
1326-
1327-
fcc.object = obj;
1328-
fcc.called_scope = ce;
1329-
fcc.calling_scope = ce;
1330-
fcc.function_handler = ctor;
1331-
1332-
zend_fcall_info_args_ex(&fci, fcc.function_handler, params);
1333-
status = zend_fcall_info_call(&fci, &fcc, NULL, NULL);
1334-
zend_fcall_info_args_clear(&fci, 1);
1335-
return status;
1336-
}
1337-
}
1338-
1339-
return SUCCESS;
1344+
return object_init_with_constructor(return_value, ce, 0, NULL, Z_ARRVAL_P(params));
13401345
}

ext/kernel/string.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#include <ext/standard/php_smart_string.h>
2323
#include <ext/standard/php_string.h>
24+
#if PHP_VERSION_ID < 80400
2425
#include <ext/standard/php_rand.h>
2526
#include <ext/standard/php_lcg.h>
27+
#endif
2628
#include <ext/standard/php_http.h>
2729
#include <ext/standard/base64.h>
2830
#include <ext/standard/md5.h>
@@ -107,7 +109,11 @@ void zephir_fast_strtolower(zval *return_value, zval *str)
107109

108110
length = Z_STRLEN_P(str);
109111
lower_str = estrndup(Z_STRVAL_P(str), length);
112+
#if PHP_VERSION_ID < 80400
110113
php_strtolower(lower_str, length);
114+
#else
115+
zend_str_tolower(lower_str, length);
116+
#endif
111117

112118
if (use_copy) {
113119
zval_dtor(str);
@@ -136,7 +142,11 @@ void zephir_fast_strtoupper(zval *return_value, zval *str)
136142

137143
length = Z_STRLEN_P(str);
138144
lower_str = estrndup(Z_STRVAL_P(str), length);
145+
#if PHP_VERSION_ID < 80400
139146
php_strtoupper(lower_str, length);
147+
#else
148+
zend_str_toupper(lower_str, length);
149+
#endif
140150

141151
if (use_copy) {
142152
zval_dtor(str);
@@ -1052,7 +1062,6 @@ void zephir_preg_match(zval *return_value, zval *regex, zval *subject, zval *mat
10521062

10531063
/* Compile regex or get it from cache */
10541064
if ((pce = pcre_get_compiled_regex_cache(Z_STR_P(regex))) == NULL) {
1055-
10561065
if (use_copy) {
10571066
zval_dtor(subject);
10581067
}
@@ -1063,9 +1072,17 @@ void zephir_preg_match(zval *return_value, zval *regex, zval *subject, zval *mat
10631072
ZVAL_UNDEF(&tmp_matches);
10641073

10651074
if (flags != 0 || offset != 0) {
1075+
#if PHP_VERSION_ID < 80400
10661076
php_pcre_match_impl(pce, Z_STR_P(subject), return_value, &tmp_matches, global, 1, flags, offset);
1077+
#else
1078+
php_pcre_match_impl(pce, Z_STR_P(subject), return_value, &tmp_matches, global, flags, offset);
1079+
#endif
10671080
} else {
1081+
#if PHP_VERSION_ID < 80400
10681082
php_pcre_match_impl(pce, Z_STR_P(subject), return_value, &tmp_matches, global, 0, 0, 0);
1083+
#else
1084+
php_pcre_match_impl(pce, Z_STR_P(subject), return_value, &tmp_matches, global, 0, 0);
1085+
#endif
10691086
}
10701087

10711088
if (matches) {
@@ -1223,8 +1240,8 @@ void zephir_crc32(zval *return_value, zval *str)
12231240
int use_copy = 0;
12241241
size_t nr;
12251242
char *p;
1226-
php_uint32 crc;
1227-
php_uint32 crcinit = 0;
1243+
uint32_t crc;
1244+
uint32_t crcinit = 0;
12281245

12291246
if (Z_TYPE_P(str) != IS_STRING) {
12301247
use_copy = zend_make_printable_zval(str, &copy);

ext/php_tensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define PHP_TENSOR_VERSION "3.0.5"
1515
#define PHP_TENSOR_EXTNAME "tensor"
1616
#define PHP_TENSOR_AUTHOR "The Rubix ML Community"
17-
#define PHP_TENSOR_ZEPVERSION "0.18.0-$Id$"
17+
#define PHP_TENSOR_ZEPVERSION "0.19.0-$Id$"
1818
#define PHP_TENSOR_DESCRIPTION "A library and extension that provides objects for scientific computing in PHP."
1919

2020

0 commit comments

Comments
 (0)