Commit Graph

643 Commits

Author SHA1 Message Date
Andrea Faulds
f759936591 Permit trailing whitespace in numeric strings
This is part 1 of the 'Saner Numeric Strings' RFC:
https://wiki.php.net/rfc/saner-numeric-strings
2020-07-29 02:22:38 +01:00
Nikita Popov
acbf7802af Improved number to string comparison semantics
RFC: https://wiki.php.net/rfc/string_to_number_comparison

Closes GH-3886.
2020-07-22 12:23:49 +02:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
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>
2020-06-16 18:39:09 +02:00
twosee
83a77015ad Add helper APIs for maybe-interned string creation
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.
2020-06-08 15:31:52 +02:00
Nikita Popov
c6a6ca078b Use zend_zval_type_name() API where possible
Rather than zend_get_type_by_const(Z_TYPE_P()).
2020-05-13 14:56:05 +02:00
George Peter Banyard
25acc4a6b4 Fix [-Wundef] warning in Zend folder 2020-05-12 22:01:51 +02:00
Nikita Popov
53f5cfd99e Drop multi_convert_* APIs
These are no longer used internally, and I'd rather they weren't
used externally either.
2020-05-12 17:10:06 +02:00
Máté Kocsis
4a816584a4
Make float to string casts locale-independent
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>
2020-05-08 10:52:23 +02:00
Nikita Popov
e41f764b5c Revert "Move declaration at top of the block"
This reverts commit b56f203850.

We use C99 now, this is not needed anymore.
2020-05-06 09:42:58 +02:00
Xinchen Hui
b56f203850 Move declaration at top of the block 2020-05-06 14:01:56 +08:00
Nikita Popov
5bc1e224db Make numeric operations on resources, arrays and objects type errors
RFC: https://wiki.php.net/rfc/arithmetic_operator_type_checks

Closes GH-5331.
2020-05-05 16:11:13 +02:00
Nikita Popov
8ffbd4653e Perform isupper check using sse2 as well
Rather than just vectorizing the lowering, also vectorize the
check for uppercase characters, using the same method.
2020-05-04 19:19:54 +02:00
Xinchen Hui
d2c6bf203a Folder mark 2020-04-28 13:47:04 +08:00
Xinchen Hui
11491b63f8 Also zend_str_tolower_dup_ex 2020-04-28 11:04:20 +08:00
Xinchen Hui
58005d7b42 Remove unnecessary register qualifier 2020-04-27 20:31:06 +08:00
Xinchen Hui
6a500cb249 SSE2 str_tolower 2020-04-27 16:35:06 +08:00
Nikita Popov
5430a466ff Avoid control flow warning 2020-04-02 10:54:32 +02:00
Nikita Popov
cdaf35033d Improve "unsupported operands" error
By mentioning the operand types. We can do that now, as the
original operand types now remain available.

Closes GH-5330.
2020-04-01 11:26:43 +02:00
Nikita Popov
9c0afc859c Remove op_func from TRY_BINARY_OP1 macro
And move the operator overloading helpers into zend_operators.c,
there's no reason for them to be in the header.
2020-04-01 10:15:03 +02:00
Nikita Popov
f182309e87 Refactor operator implementations
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.
2020-03-31 20:49:39 +02:00
Nikita Popov
944b10e3d3 Remove unused argument form convert_object_to_type() 2020-03-31 17:31:35 +02:00
Nikita Popov
0509a1e066 Clean up silent/noisy flag in convert_to_number 2020-03-31 16:53:03 +02:00
Nikita Popov
8fd7f02ea4 Make cast_object handler required
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.
2020-03-31 14:37:49 +02:00
Nikita Popov
bef4b2e4e9 Report object cast failures internally
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.
2020-03-31 12:07:25 +02:00
Nikita Popov
26327bcd3b Throw "Unsupported operand types" error when using ** on arrays 2019-10-29 13:05:02 +01:00
Nikita Popov
c858d17f06 Optimize instanceof_function
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.
2019-10-25 10:51:17 +02:00
Nikita Popov
296269cfe8 Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove recursive check from instanceof_interface
2019-10-25 10:20:19 +02:00
Nikita Popov
184ba0c91c Remove recursive check from instanceof_interface
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.
2019-10-25 10:19:42 +02:00
Nikita Popov
374cbfe568 Merge branch 'PHP-7.4'
* PHP-7.4:
  Optimize instanceof_class/interface
2019-10-24 17:50:53 +02:00
Nikita Popov
c63a0e005a Optimize instanceof_class/interface
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.
2019-10-24 17:47:35 +02:00
Nikita Popov
19bea48c9a Merge branch 'PHP-7.4'
* PHP-7.4:
  Clean up and clarify instanceof_function_ex()
2019-10-24 17:42:04 +02:00
Nikita Popov
435f269108 Clean up and clarify instanceof_function_ex()
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.
2019-10-24 17:40:25 +02:00
Nikita Popov
7c1bc91e52 Merge branch 'PHP-7.4' 2019-10-08 17:19:52 +02:00
Nikita Popov
21148679d1 Handle "non well formed" exception during ZPP
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.
2019-10-08 17:17:49 +02:00
Dmitry Stogov
b02b81299c Comparison cleanup:
- introduce zend_compare() that returns -1,0,1 dirctly (without intermediate zval)
- remove compare_objects() object handler, and keep only compare() handler
2019-10-07 17:57:49 +03:00
Nikita Popov
2f92957fd3 Convert some notices to warnings
Part of https://wiki.php.net/rfc/engine_warnings.
2019-10-02 10:34:08 +02:00
Nikita Popov
8686a3d30b Merge branch 'PHP-7.4' 2019-09-26 13:50:02 +02:00
Nikita Popov
d71f859a56 Merge branch 'PHP-7.3' into PHP-7.4 2019-09-26 13:47:41 +02:00
Nikita Popov
91c4abcfcc Merge branch 'PHP-7.2' into PHP-7.3 2019-09-26 13:47:19 +02:00
Nikita Popov
ab938d7bbc Fix memory leak with ** on array operands 2019-09-26 13:45:45 +02:00
Peter Kokot
7f994990ea Merge branch 'PHP-7.4'
* PHP-7.4:
  Remove HAVE_STRCOLL check
2019-06-28 00:13:25 +02:00
Peter Kokot
638c21765c Remove HAVE_STRCOLL check
The strcoll function is defined in the C89 standard and should be
on today's systems always available via the <string.h> header.

https://port70.net/~nsz/c/c89/c89-draft.html#4.11.4.3

- Remove also SKIPIF strcoll check in test
2019-06-28 00:05:55 +02:00
Nikita Popov
6aaab9adf7 Merge branch 'PHP-7.4' 2019-06-20 16:24:31 +02:00
Nikita Popov
a59e0cfce5 Disable float division by zero sanitizer for div_function
We intentionally divide by zero here and want to get IEEE-754
semantics.
2019-06-20 16:21:47 +02:00
Nikita Popov
3645292235 Merge branch 'PHP-7.4' 2019-06-19 15:09:39 +02:00
Nikita Popov
ed2a242317 Fix signed shift UB 2019-06-19 15:09:00 +02:00
Nikita Popov
82a34e71c5 Avoid overflow UB in is_numeric_string
We intentionally overflow the signed space here, so make this an
unsigned variable and only cast to signed at the end.
2019-06-19 15:09:00 +02:00
Nikita Popov
e4fae9c061 Merge branch 'PHP-7.4' 2019-06-11 13:16:38 +02:00
Nikita Popov
8f8fcbbd39 Support full variance if autoloading is used
Keep track of delayed variance obligations and check them after
linking a class is otherwise finished. Obligations may either be
unresolved method compatibility (because the necessecary classes
aren't available yet) or open parent/interface dependencies. The
latter occur because we allow the use of not fully linked classes
as parents/interfaces now.

An important aspect of the implementation is we do not require
classes involved in variance checks to be fully linked in order for
the class to be fully linked. Because the involved types do have to
exist in the class table (as partially linked classes) and we do
check these for correct variance, we have the guarantee that either
those classes will successfully link lateron or generate an error,
but there is no way to actually use them until that point and as
such no possibility of violating the variance contract. This is
important because it ensures that a class declaration always either
errors or will produce an immediately usable class afterwards --
there are no cases where the finalization of the class declaration
has to be delayed until a later time, as earlier variants of this
patch did.

Because variance checks deal with classes in various stages of
linking, we need to use a special instanceof implementation that
supports this, and also introduce finer-grained flags that tell us
which parts have been linked already and which haven't.

Class autoloading for variance checks is delayed into a separate
stage after the class is otherwise linked and before delayed
variance obligations are processed. This separation is needed to
handle cases like A extends B extends C, where B is the autoload
root, but C is required to check variance. This could end up
loading C while the class structure of B is in an inconsistent
state.
2019-06-11 13:09:33 +02:00
Dmitry Stogov
dbd1ecd09f Merge branch 'PHP-7.4'
* PHP-7.4:
  Support for exceptions thrown during "Array to string conversion" error processing
  Reduce over-specialization for quite seldom instructions
2019-06-06 14:10:23 +03:00