Skip to content

Commit 3f2525a

Browse files
Add PHP 8.1 support to extension (#27)
* PHP 8.1 extension compatibility * Update version numbers * Allow PHP 8.1 in PECL config * Update CHANGLELOG
1 parent 5d999c0 commit 3f2525a

File tree

10 files changed

+52
-25
lines changed

10 files changed

+52
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- 3.1.0
2+
- PHP 8.1 extension compatibility
3+
14
- 3.0.1
25
- Add positive semi-definite typehinting
36

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Andrew DalPino
3+
Copyright (c) 2022 Andrew DalPino
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

build-ext

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ EOT
1616

1717
chdir(__DIR__);
1818

19-
echo 'Reading config.m4 file... ';
19+
echo 'Reading config.m4 file';
2020

2121
$configM4Contents = file_get_contents(CONFIG_M4_PATH);
2222

@@ -25,28 +25,23 @@ if (!$configM4Contents) {
2525

2626
exit(1);
2727
}
28-
echo "done.\n";
2928

30-
echo 'Applying libexec patch...';
29+
echo 'Applying libexec patch';
3130

3231
if (strpos($configM4Contents, EXECINFO_MATCH) === false) {
33-
fwrite(STDERR, "patch entrypoint not found!\n");
32+
fwrite(STDERR, "Patch entrypoint not found!\n");
3433

3534
exit(1);
3635
} elseif (strpos($configM4Contents, trim(EXECINFO_PATCH)) !== false) {
37-
echo "already applied.\n";
36+
echo "Already applied.\n";
3837
} else {
3938
$configM4Contents = str_replace(EXECINFO_MATCH, EXECINFO_MATCH . EXECINFO_PATCH, $configM4Contents);
40-
41-
echo "done.\n";
4239
}
4340

44-
echo 'Saving config.m4 file... ';
41+
echo 'Saving config.m4 file';
4542

4643
if (!file_put_contents(CONFIG_M4_PATH, $configM4Contents)) {
4744
fwrite(STDERR, "Failed to write the config.m4 file\n");
4845

4946
exit(1);
5047
}
51-
52-
echo "done.\n";

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"require-dev": {
3131
"friendsofphp/php-cs-fixer": "^3.0",
32-
"phalcon/zephir": "^0.15",
32+
"phalcon/zephir": "^0.16",
3333
"phpbench/phpbench": "^1.0",
3434
"phpstan/extension-installer": "^1.0",
3535
"phpstan/phpstan": "^1.0",

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"extension-name": "tensor",
55
"description": "A library and extension that provides objects for scientific computing in PHP.",
66
"author": "Andrew DalPino",
7-
"version": "3.0.0",
7+
"version": "3.1.0",
88
"verbose": true,
99
"extra-cflags": "-O3 -ffast-math",
1010
"extra-libs": "-lopenblas -llapacke -lgfortran",

ext/kernel/file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ int zephir_file_exists(zval *filename)
6565
return FAILURE;
6666
}
6767

68+
#if PHP_VERSION_ID >= 80100
69+
zend_string *file = zend_string_init(Z_STRVAL_P(filename), Z_STRLEN_P(filename), 0);
70+
php_stat(file, FS_EXISTS, &return_value);
71+
zval_ptr_dtor(file);
72+
#else
6873
php_stat(Z_STRVAL_P(filename), (php_stat_len) Z_STRLEN_P(filename), FS_EXISTS, &return_value);
74+
#endif
6975

7076
if (Z_TYPE(return_value) != IS_TRUE) {
7177
return FAILURE;
@@ -288,7 +294,13 @@ void zephir_file_put_contents(zval *return_value, zval *filename, zval *data)
288294
void zephir_filemtime(zval *return_value, zval *path)
289295
{
290296
if (EXPECTED(Z_TYPE_P(path) == IS_STRING)) {
297+
#if PHP_VERSION_ID >= 80100
298+
zend_string *file = zend_string_init(Z_STRVAL_P(path), Z_STRLEN_P(path), 0);
299+
php_stat(file, FS_MTIME, return_value);
300+
zval_ptr_dtor(file);
301+
#else
291302
php_stat(Z_STRVAL_P(path), (php_stat_len)(Z_STRLEN_P(path)), FS_MTIME, return_value);
303+
#endif
292304
} else {
293305
ZVAL_FALSE(return_value);
294306
}

ext/kernel/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void zephir_fast_count(zval *result, zval *value)
151151
}
152152
}
153153

154-
if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) {
154+
if (instanceof_function(Z_OBJCE_P(value), zend_ce_countable)) {
155155
#if PHP_VERSION_ID >= 80000
156156
zend_call_method_with_0_params(Z_OBJ_P(value), NULL, NULL, "count", &retval);
157157
#else
@@ -201,7 +201,7 @@ int zephir_fast_count_ev(zval *value)
201201
return (int) count > 0;
202202
}
203203

204-
if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) {
204+
if (instanceof_function(Z_OBJCE_P(value), zend_ce_countable)) {
205205
#if PHP_VERSION_ID >= 80000
206206
zend_call_method_with_0_params(Z_OBJ_P(value), NULL, NULL, "count", &retval);
207207
#else
@@ -249,7 +249,7 @@ int zephir_fast_count_int(zval *value)
249249
return (int) count;
250250
}
251251

252-
if (instanceof_function(Z_OBJCE_P(value), spl_ce_Countable)) {
252+
if (instanceof_function(Z_OBJCE_P(value), zend_ce_countable)) {
253253
#if PHP_VERSION_ID >= 80000
254254
zend_call_method_with_0_params(Z_OBJ_P(value), NULL, NULL, "count", &retval);
255255
#else

ext/kernel/require.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,22 @@ int zephir_require_ret(zval *return_value_ptr, const char *require_path)
4545
}
4646
#endif
4747

48-
ret = php_stream_open_for_zend_ex(require_path, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
48+
#if PHP_VERSION_ID >= 80100
49+
zend_string *zend_string_path = zend_string_init(require_path, strlen(require_path), 0);
50+
51+
zend_stream_init_filename_ex(&file_handle, zend_string_path);
52+
ret = php_stream_open_for_zend_ex(&file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
53+
54+
zval_ptr_dtor(zend_string_path);
55+
#else
56+
ret = php_stream_open_for_zend_ex(require_path, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
57+
#endif
4958
if (ret != SUCCESS) {
5059
return FAILURE;
5160
}
5261

5362
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);
5463
if (new_op_array) {
55-
5664
if (file_handle.handle.stream.handle) {
5765
ZVAL_NULL(&dummy);
5866
if (!file_handle.opened_path) {
@@ -110,7 +118,16 @@ int zephir_require_once_ret(zval *return_value_ptr, const char *require_path)
110118
}
111119
#endif
112120

113-
ret = php_stream_open_for_zend_ex(require_path, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
121+
#if PHP_VERSION_ID >= 80100
122+
zend_string *zend_string_path = zend_string_init(require_path, strlen(require_path), 0);
123+
124+
zend_stream_init_filename_ex(&file_handle, zend_string_path);
125+
ret = php_stream_open_for_zend_ex(&file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
126+
127+
zval_ptr_dtor(zend_string_path);
128+
#else
129+
ret = php_stream_open_for_zend_ex(require_path, &file_handle, USE_PATH|STREAM_OPEN_FOR_INCLUDE);
130+
#endif
114131
if (ret != SUCCESS) {
115132
return FAILURE;
116133
}

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.0"
1515
#define PHP_TENSOR_EXTNAME "tensor"
1616
#define PHP_TENSOR_AUTHOR "Andrew DalPino"
17-
#define PHP_TENSOR_ZEPVERSION "0.15.2-$Id$"
17+
#define PHP_TENSOR_ZEPVERSION "0.16.0-$Id$"
1818
#define PHP_TENSOR_DESCRIPTION "A library and extension that provides objects for scientific computing in PHP."
1919

2020

package.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
<email>[email protected]</email>
1111
<active>yes</active>
1212
</lead>
13-
<date>2021-06-06</date>
13+
<date>2022-04-01</date>
1414
<version>
15-
<release>3.0.00</release>
16-
<api>3.0</api>
15+
<release>3.1.0</release>
16+
<api>3.1</api>
1717
</version>
1818
<stability>
1919
<release>stable</release>
2020
<api>stable</api>
2121
</stability>
2222
<license uri="https://github.com/RubixML/Tensor/blob/master/LICENSE">MIT</license>
2323
<notes>
24-
- No changes
24+
- PHP 8.1 extension compatibilitys
2525
</notes>
2626
<contents>
2727
<dir name="/">
@@ -152,7 +152,7 @@
152152
<required>
153153
<php>
154154
<min>7.4.0</min>
155-
<max>8.0.99</max>
155+
<max>8.1.99</max>
156156
</php>
157157
<pearinstaller>
158158
<min>1.4.0</min>

0 commit comments

Comments
 (0)