summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'PHP-7.4' into PHP-8.0Nikita Popov2020-10-121-1/+1
|\ | | | | | | | | | | * PHP-7.4: Detect self-addition of array more accurately Deindirect source elements in zend_hash_merge
| * Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2020-10-121-1/+1
| |\ | | | | | | | | | | | | | | | * PHP-7.3: Detect self-addition of array more accurately Deindirect source elements in zend_hash_merge
| | * Detect self-addition of array more accuratelyNikita Popov2020-10-121-1/+1
| | | | | | | | | | | | | | | | | | | | | While the zvals may be different, they may still point to the same array. Fixes oss-fuzz #26245.
* | | Return correct result code for division by zeroNikita Popov2020-10-021-11/+12
| | | | | | | | | | | | | | | | | | | | | Turns out we do need to return FAILURE here on div by zero exception. Use a three-way return value from div_function_base. Fixes oss-fuzz #25975.
* | | Throw warning for failed object to int/float conversionNikita Popov2020-09-211-1/+1
| | | | | | | | | | | | | | | | | | We previously couldn't increase the error level here because it was coupled to comparison handling. This is no longer the case in PHP 8.
* | | Convert Division by 0 warnings to Error per the Engine Warning RFCGeorge Peter Banyard2020-09-141-9/+10
| | | | | | | | | | | | Closes GH-6125
* | | Move custom type checks to ZPPMáté Kocsis2020-09-021-1/+1
| | | | | | | | | | | | Closes GH-6034
* | | Merge branch 'PHP-7.4'Nikita Popov2020-08-311-0/+3
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Fix leak on assign concat of array and empty string
| * | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2020-08-311-0/+3
| |\ \ | | |/ | | | | | | | | | * PHP-7.3: Fix leak on assign concat of array and empty string
| | * Fix leak on assign concat of array and empty stringNikita Popov2020-08-311-0/+3
| | |
* | | Improve type declarations for Zend APIsGeorge Peter Banyard2020-08-281-42/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | Voidification of Zend API which always succeeded Use bool argument types instead of int for boolean arguments Use bool return type for functions which return true/false (1/0) Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics Closes GH-6002
* | | Implement 'Saner Numeric Strings' RFC:George Peter Banyard2020-07-291-31/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | RFC: https://wiki.php.net/rfc/saner-numeric-strings This removes the -1 allow_error mode from is_numeric_string functions and replaces it by a trailing boolean out argument to preserve BC in a couple of places. Most of the changes can be resumed to "numeric" strings which emitted a E_NOTICE now emit a E_WARNING and "numeric" strings which emitted a E_WARNING now throw a TypeError. This mostly affects: - String offsets - Arithmetic operations - Bitwise operations Closes GH-5762
* | | Permit trailing whitespace in numeric stringsAndrea Faulds2020-07-291-4/+11
| | | | | | | | | | | | | | | This is part 1 of the 'Saner Numeric Strings' RFC: https://wiki.php.net/rfc/saner-numeric-strings
* | | Improved number to string comparison semanticsNikita Popov2020-07-221-0/+69
| | | | | | | | | | | | | | | | | | RFC: https://wiki.php.net/rfc/string_to_number_comparison Closes GH-3886.
* | | Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)Christoph M. Becker2020-06-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce `ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)` to mark unreachable code does no longer trigger C4715[1] warnings in debug builds. This may be useful for other compilers as well. [1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
* | | Add helper APIs for maybe-interned string creationtwosee2020-06-081-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add ZVAL_CHAR/RETVAL_CHAR/RETURN_CHAR as a shortcut for using ZVAL_INTERNED_STRING and ZSTR_CHAR. Add zend_string_init_fast() as a helper for the empty string / one char interned string / zend_string_init() pattern. Also add corresponding ZVAL_STRINGL_FAST etc macros. Closes GH-5684.
* | | Use zend_zval_type_name() API where possibleNikita Popov2020-05-131-5/+4
| | | | | | | | | | | | Rather than zend_get_type_by_const(Z_TYPE_P()).
* | | Fix [-Wundef] warning in Zend folderGeorge Peter Banyard2020-05-121-2/+2
| | |
* | | Drop multi_convert_* APIsNikita Popov2020-05-121-48/+0
| | | | | | | | | | | | | | | These are no longer used internally, and I'd rather they weren't used externally either.
* | | Make float to string casts locale-independentMáté Kocsis2020-05-081-17/+3
| | | | | | | | | | | | | | | | | | | | | | | | From now on, float to string casting will always behave locale-independently. RFC: https://wiki.php.net/rfc/locale_independent_float_to_string Closes GH-5224 Co-authored-by: George Peter Banyard <girgias@php.net>
* | | Revert "Move declaration at top of the block"Nikita Popov2020-05-061-17/+15
| | | | | | | | | | | | | | | | | | This reverts commit b56f20385089703de7a3c9d89a9de4f9d14f56a3. We use C99 now, this is not needed anymore.
* | | Move declaration at top of the blockXinchen Hui2020-05-061-15/+17
| | |
* | | Make numeric operations on resources, arrays and objects type errorsNikita Popov2020-05-051-58/+130
| | | | | | | | | | | | | | | | | | RFC: https://wiki.php.net/rfc/arithmetic_operator_type_checks Closes GH-5331.
* | | Perform isupper check using sse2 as wellNikita Popov2020-05-041-11/+42
| | | | | | | | | | | | | | | Rather than just vectorizing the lowering, also vectorize the check for uppercase characters, using the same method.
* | | Folder markXinchen Hui2020-04-281-6/+10
| | |
* | | Also zend_str_tolower_dup_exXinchen Hui2020-04-281-6/+2
| | |
* | | Remove unnecessary register qualifierXinchen Hui2020-04-271-1/+1
| | |
* | | SSE2 str_tolowerXinchen Hui2020-04-271-23/+37
| | |
* | | Avoid control flow warningNikita Popov2020-04-021-0/+5
| | |
* | | Improve "unsupported operands" errorNikita Popov2020-04-011-15/+15
| | | | | | | | | | | | | | | | | | | | | By mentioning the operand types. We can do that now, as the original operand types now remain available. Closes GH-5330.
* | | Remove op_func from TRY_BINARY_OP1 macroNikita Popov2020-04-011-15/+42
| | | | | | | | | | | | | | | And move the operator overloading helpers into zend_operators.c, there's no reason for them to be in the header.
* | | Refactor operator implementationsNikita Popov2020-03-311-296/+288
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of looping, use straight-line code with the following layout: 1. Try to apply the base operation on the dereferenced operands. 2. Try overloaded object operations. 3. Try to convert operands to number, else error out. 4. Apply the base operation on the converted operands. This makes the code easier to reason about and fixes some edge-case bugs: 1. We should only try invoking operator overloading once prior to type conversion. Previously it was invoked both before and after type conversion. 2. We should not modify any values if an exception is thrown. Previously we sometimes modified the LHS of a compound assignment operator. 3. If conversion of the first operand fails, we no longer try to convert the second operand. I think the previous behavior here was fine as well, but this still seems a more typical. This will also make some followup changes I have in mind simpler.
* | | Remove unused argument form convert_object_to_type()Nikita Popov2020-03-311-8/+8
| | |
* | | Clean up silent/noisy flag in convert_to_numberNikita Popov2020-03-311-22/+22
| | |
* | | Make cast_object handler requiredNikita Popov2020-03-311-25/+15
| | | | | | | | | | | | | | | | | | | | | | | | Avoid subtle differences in behavior depending on whether the handler is absent or returns FAILURE. If you previously set cast_object to NULL, create a handler that always returns FAILURE instead.
* | | Report object cast failures internallyNikita Popov2020-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make cast_object return FAILURE for casts to int/float, rather than throwing a notice and returning SUCCESS. Instead move the emission of the notice to the code invoking cast_object. This will allow us to customize the behavior per call-site. This change is written to be NFC, and the code in zend_std_compare_objects() should illustrate the current behavior doesn't make a lot of sense.
* | | Throw "Unsupported operand types" error when using ** on arraysNikita Popov2019-10-291-27/+12
| | |
* | | Optimize instanceof_functionNikita Popov2019-10-251-34/+30
| | | | | | | | | | | | | | | | | | | | | | | | Split out the simple equality check into an inline function -- this is one of the common cases. Replace instanceof_function_ex with zend_class_implements_interface. There are a few more places where it may be used.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-10-251-1/+1
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Remove recursive check from instanceof_interface
| * | Remove recursive check from instanceof_interfaceNikita Popov2019-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Parent interfaces are copied into the interface list during inheritance, so there's no need to perform a recursive check. Only exception are instanceof checks performed during inheritance itself. However, we already have unlinked_instanceof for this purpose, it just needs to be taught to handle this case. Closes GH-4857.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-10-241-3/+3
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Optimize instanceof_class/interface
| * | Optimize instanceof_class/interfaceNikita Popov2019-10-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instanceof_class does not need to check for a NULL pointer in the first iteration -- passing NULL to this function is illegal. instanceof_interface does not need to use instanceof_class(), it only has to check whether the CEs match exactly. There is no way for an interface to appear inside "parent", it will always be in "interfaces" only.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-10-241-28/+7
|\ \ \ | |/ / | | | | | | | | | * PHP-7.4: Clean up and clarify instanceof_function_ex()
| * | Clean up and clarify instanceof_function_ex()Nikita Popov2019-10-241-28/+7
| | | | | | | | | | | | | | | | | | | | | | | | The instanceof_interface_only() function was dead code (always returned zero). Clarify that the last parameter indicates whether the passed CE is interface or class and rewrite the code in terms of assertions.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-10-081-0/+3
|\ \ \ | |/ /
| * | Handle "non well formed" exception during ZPPNikita Popov2019-10-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously if the "non well formed" notice was converted into an exception we'd still end up executing the function. Also drop the now unnecessary EG(exception) checks in the engine. Additionally remote a bogus exception in zend_is_callable: It should only be writing to error, but not directly throwing.
* | | Comparison cleanup:Dmitry Stogov2019-10-071-146/+45
| | | | | | | | | | | | | | | - introduce zend_compare() that returns -1,0,1 dirctly (without intermediate zval) - remove compare_objects() object handler, and keep only compare() handler
* | | Convert some notices to warningsNikita Popov2019-10-021-2/+2
| | | | | | | | | | | | Part of https://wiki.php.net/rfc/engine_warnings.
* | | Merge branch 'PHP-7.4'Nikita Popov2019-09-261-0/+9
|\ \ \ | |/ /
| * | Merge branch 'PHP-7.3' into PHP-7.4Nikita Popov2019-09-261-0/+9
| |\ \ | | |/