We substitute the construction magic with standard constructors, move
the ZPP checks to the beginning of the ctors, and also let the function
entries be generated from the stubs.
Promote invalid case mode to ValueError in mb_case_converter
Add assertions to check the return value is not NULL as this indicates a bug.
Add identical assertion to mb_strtoupper and mb_strtolower.
This means these functions can't return false anymore, ammend stubs accordingly.
Qianqian Bu [Fri, 3 Apr 2020 07:44:41 +0000 (15:44 +0800)]
Fix incorrect free for last_message
In commit a7305eb539596e175bd6c3ae9a20953358c5d677 the last_message
field of the connection object was changed to be always non-persistent.
But there is a place on change_user path that still treats it
depending on conn->persistent flag. This will cause PHP crash after
com_change_user success when there is last_message set
Promote empty needle warning to ValueError
Convert if branch into an assertion as if mbfl_substr_count fails this now implies a bug
Thus mb_substr_count() can only return int now, fix stubs accordingly
Also add a TODO about documenting this funcion on PHP.net
Convert some checks to assertions as if they don't hold something went wrong during memory allocation
Due to these changes this function cannot return false anymore, fix stubs accordingly
Prevent imap mail tests from borking instead of skipping
As of commit e49593a[1], run-tests.php is rather picky regarding the
output of SKIPIF sections, so we have to suppress warnings for failing
imap_open().
Remove unnecessary check in runtime_compile_time_binary_operands.phpt
Now that operator errors are detected more accurately, we no longer
have any cases where we throw a compile-time error instead of a
run-time exception, so we can drop this check now.
For division (rather than modulus) we should check the double
value, otherwise the result might be zero after integer truncation,
but not zero as a floating point value.
This may produce different behavior if operator overloading is
involved, and may change the error message.
If there's strong interest, this could be done in the DFA pass
with available type information. It does not look particularly
practically useful to me though.
Use php_mb_get_encoding instead of mbfl_name2encoding to get encoding
This reduces the number of places where the error message template is used.
Also promote the mb_check_encoding() warning to ValueError and add a test to cover the behaviour.
Nikita Popov [Tue, 31 Mar 2020 16:03:30 +0000 (18:03 +0200)]
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.
Nikita Popov [Tue, 31 Mar 2020 10:36:48 +0000 (12:36 +0200)]
Add a ZEND_UNCOMPARABLE value
To explicitly indicate that objects are uncomparable. For now
this has no functional difference from the usual 1 return value,
but makes intent clearer.
Nikita Popov [Tue, 31 Mar 2020 10:04:59 +0000 (12:04 +0200)]
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.
Nikita Popov [Tue, 31 Mar 2020 09:06:15 +0000 (11:06 +0200)]
Make sure php_get_internal_encoding() returns non-empty
Even if default_charset is set to "", we should still return
"UTF-8" as the default value here. Setting default_charset to ""
suppresses the header emission, but shouldn't change anything
about our encoding defaults.
Fix #79413: session_create_id() fails for active sessions
The comment on `PS_VALIDATE_SID_FUNC(files)` is very clear that the
function is supposed to return `SUCCESS` if the session already exists.
So to detect a collision, we have to check for `SUCCESS`, not
`FAILURE`.
We also fix the wrong condition in session_regenerate_id() as well.