-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Proposal: Add final class Vector
to PHP
#7488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a224a89
Proposal: Add `final class Vector` to PHP
TysonAndre 460b1eb
Support `$vector[] = $value;`
TysonAndre ebf2590
Fix strange bug seen with '-O2', '--with-valgrind', and valgrind test
TysonAndre 5431aba
Add Vector::map/filter implementations
TysonAndre b67095c
WIP reduce public api
TysonAndre f3cea21
wip
TysonAndre 1ac4c83
Update API after RFC discussion
TysonAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) | ||
PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h]) | ||
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_vector.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) | ||
PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_vector.h]) | ||
PHP_ADD_EXTENSION_DEP(spl, pcre, true) | ||
PHP_ADD_EXTENSION_DEP(spl, standard, true) | ||
PHP_ADD_EXTENSION_DEP(spl, json) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// vim:ft=javascript | ||
|
||
EXTENSION("spl", "php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); | ||
EXTENSION("spl", "php_spl.c spl_functions.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c spl_vector.c", false /*never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); | ||
PHP_SPL="yes"; | ||
PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h"); | ||
PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h spl_vector.h"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef SPL_UTIL | ||
#define SPL_UTIL | ||
|
||
#include "zend_types.h" | ||
|
||
static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */ | ||
{ | ||
try_again: | ||
switch (Z_TYPE_P(offset)) { | ||
case IS_STRING: { | ||
zend_ulong index; | ||
if (ZEND_HANDLE_NUMERIC(Z_STR_P(offset), index)) { | ||
return (zend_long) index; | ||
} | ||
break; | ||
} | ||
case IS_DOUBLE: | ||
return zend_dval_to_lval_safe(Z_DVAL_P(offset)); | ||
case IS_LONG: | ||
return Z_LVAL_P(offset); | ||
case IS_FALSE: | ||
return 0; | ||
case IS_TRUE: | ||
return 1; | ||
case IS_REFERENCE: | ||
offset = Z_REFVAL_P(offset); | ||
goto try_again; | ||
case IS_RESOURCE: | ||
zend_use_resource_as_offset(offset); | ||
return Z_RES_HANDLE_P(offset); | ||
} | ||
|
||
zend_type_error("Illegal offset type"); | ||
return 0; | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikic FYI - I wonder if you're able to reproduce the test failure in the prior commit (in gcc
9.3.0-17ubuntu1~20.04
) formake test TESTS='ext/spl/tests/Vector/aggregate.phpt -m --show-mem --show-diff
(it segfaults inidx = Z_NEXT(p->val);
when compiling the code and interning the strings, not when running it). It seems almost definitely related to running the code under valgrind with-O2 [-g]
. Even aftergit clean -fdx
and recompiling it's still an issuegcc (Debian 10.2.1-6) 10.2.1 20210110
) don't have this issue.fprintf(stderr
statements, the issue goes away(The segfault doesn't happen with gdb, or even gdb with
USE_ZEND_ALLOC=0
- it's baffling.)redundant loads of ZSTR_LEN(str) from memory into registers if gcc can't infer that the assembly function zend_string_equal_val doesn't modify memory in the assembly block, and needs to scan over multiple buckets(probably not redundant if the hash is the same, hash collision chance is extremely low)Options used to build in linux mint 20.2:
export CFLAGS='-O2 -g'; ./buildconf --force; ./configure --disable-all --with-zlib --with-zip --enable-phar --with-bz2 --enable-opcache --with-readline --enable-tokenizer --prefix=$HOME/php-8.2-unoptimized-nts-vector-install --with-valgrind; make -j8