Commit graph

1917 commits

Author SHA1 Message Date
Nikita Popov
220880ad2d Fixed bug #78598
When performing an RW modification of an array offset, the undefined
offset warning may call an error handler / OB callback, which may
destroy the array we're supposed to change. Detect this by temporarily
incrementing the reference count. If we find that the array has been
modified/destroyed in the meantime, we do nothing -- the execution
model here would be that the modification has happened on the destroyed
version of the array.
2020-07-07 12:13:58 +02:00
Nikita Popov
b48bd671b8 Assert no exception if using NEXT_OPCODE()
When NEXT_OPCODE() is used instead of NEXT_OPCODE_CHECK_EXCEPTION(),
assert that there is indeed no exception.
2020-07-07 11:34:43 +02:00
Nikita Popov
e0743d0f91 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79779
2020-07-07 10:27:53 +02:00
Nikita Popov
6a9d934b2c Fixed bug #79779
ASSIGN_OBJ_REF was not handling in zend_wrong_string_offset.
2020-07-07 10:27:22 +02:00
Nikita Popov
795d2cbd71 Reuse warning function 2020-07-06 10:38:02 +02:00
Dmitry Stogov
a60cdcf084 A helper to trace executed source lines 2020-06-10 00:13:39 +03: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
Dmitry Stogov
91f283a0bf micro-optimization 2020-06-05 14:20:39 +03:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00
Máté Kocsis
fbe30592d6
Improve type error messages when an object is given
From now on, we always display the given object's type instead of just reporting "object".
Additionally, make the format of return type errors match the format of argument errors.

Closes GH-5625
2020-05-26 19:06:19 +02:00
Nikita Popov
2daa89b1e6 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix zend_assign_to_typed_ref() implementation
2020-05-26 14:44:09 +02:00
Nikita Popov
314ab47e55 Fix zend_assign_to_typed_ref() implementation
There was some confusion going on here regarding the original
value vs the copied value.

I've dropped the needs_copy variable, because this code is not
inlined, so it would always be true anyway.

What we need to do is perform a move-assignment of the copied
value (in which case we don't care about performing the assignment
before destroying garbage), and destroying the original value
for the VAR/TMP cases. This is a bit complicated by the fact that
references are passed in via a separate ref variable, so we can't
just ptr_dtor the original variable.
2020-05-26 14:42:27 +02:00
Máté Kocsis
1179686f62
Improve error messages for invalid property access
Closes GH-5446
Co-authored-by:  Nikita Popov <nikita.ppv@gmail.com>
2020-05-18 08:27:00 +02:00
Máté Kocsis
93640db4d5
Improve error message for deprecated methods 2020-05-14 17:23:31 +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
Xinchen Hui
dd9d0a96d1 Fixed false alarm about tmp_name maybe unitialized 2020-05-07 14:16:02 +08:00
Nikita Popov
b3c7ab66fb Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79434
2020-04-02 16:34:21 +02:00
Nikita Popov
cf68bc413b Fixed bug #79434 2020-04-02 16:34:03 +02:00
Máté Kocsis
36935e42ea
Improve undefined variable error messages
Closes GH-5312
2020-03-31 13:02:32 +02:00
Nikita Popov
941a3b6ccd Remove unnecessary uses of CHECK_SILENT
If no error is passed, it is always silent.
2020-03-06 16:36:45 +01:00
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Nikita Popov
d594fba3ac Reorder checks in object ref assignment
First check for IS_INDIRECT and de-indirect it directly there.
Handle the error cases later.
2020-02-25 17:30:54 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Nikita Popov
43443857b7 Add static return type
RFC: https://wiki.php.net/rfc/static_return_type

The "static" type is represented as MAY_BE_STATIC, rather than
a class type like "self" and "parent", as it has special
resolution semantics, and cannot be cached in the runtime cache.

Closes GH-5062.
2020-02-17 11:51:09 +01:00
Nikita Popov
bc6bab6cb4 Basic JIT support for verify return 2020-02-07 12:59:48 +03:00
Dmitry Stogov
b53445422a Merge branch 'PHP-7.4'
* PHP-7.4:
  Make opcodes to return de-refereced values of typed references (in the same was as for non-typed)
2020-02-06 15:57:29 +03:00
Dmitry Stogov
5d0ef4c239 Make opcodes to return de-refereced values of typed references (in the same was as for non-typed) 2020-02-06 15:48:54 +03:00
George Peter Banyard
c343c1bcae Fix some -Wold-style-declaration compiler warnings 2020-02-05 17:39:29 +01:00
Nikita Popov
169805777c Merge branch 'PHP-7.4'
* PHP-7.4:
  Apply tidy formatting
2020-02-03 13:42:08 +01:00
Dmitry Stogov
2b279b428f We don't need "safe" destruction anymore 2020-01-31 16:01:09 +03:00
Dmitry Stogov
7ebf1d44ed Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79094 (Crashing when running recursion function)
2020-01-31 10:34:28 +03:00
Dmitry Stogov
db7193f31e Fixed bug #79094 (Crashing when running recursion function) 2020-01-31 10:34:04 +03:00
Nikita Popov
9ec1ee5976 Add support for deprecating constants
Internal constants can be marked as CONST_DEPRECATED, in which
case accessing them will throw a deprecation warning.

For now this is only supported on global constants, not class
constants. Complain to me if you need to deprecate a class
constant...

Closes GH-5072.
2020-01-17 10:05:06 +01:00
Nikita Popov
bd1977282c Use zend_type inside type lists
Instead of having a completely independent encoding for type list
entries. This is going to use more memory, but I'm not particularly
concerned about that, as type unions that contain multiple classes
should be uncommon. On the other hand, this allows us to treat
top-level types and types inside lists mostly the same.

A new ZEND_TYPE_FOREACH macros allows to transparently treat list
and non-list types the same way. I'm not using it everywhere it could be
used for now, just the places that seemed most obvious.

Of course, this will make any future type system changes much simpler,
as it will not be necessary to duplicate all logic two times.
2020-01-17 09:37:54 +01:00
Nikita Popov
d0d1654a34 Fix #49555: Improve "function must be a string" error message
Be more specific for the individual cases and provide relevant
type information.
2020-01-08 14:32:11 +01:00
George Peter Banyard
bfe3f934a3 Add warning and convert to exception in string offset assignment:
Convert the empty string assignment to an Error as per RFC [1]
Add a warning that only the first byte will be assigned to the offset if provided
a needle that is longer than one byte.

[1] https://wiki.php.net/rfc/engine_warnings
2020-01-07 21:54:42 +01:00
Nikita Popov
d5c886ab7d Merge branch 'PHP-7.4'
* PHP-7.4:
  Properly propagate url_stat exceptions during include
2019-12-30 22:57:07 +01:00
Nikita Popov
f77747b06c Properly propagate url_stat exceptions during include
Make sure we abort operations early, and that we don't emit
additional warnings or errors if an exception has been thrown.
2019-12-30 22:56:42 +01:00
Nikita Popov
e15915d21c Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid signed integer overflow in string offset check
2019-12-19 11:48:20 +01:00
Nikita Popov
527ad1d80c Avoid signed integer overflow in string offset check
Cast to size_t before performing operations instead of afterwards.
2019-12-19 11:47:50 +01:00
Nikita Popov
2a76384b87 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak in assign_ref with function
2019-12-18 17:18:46 +01:00
Nikita Popov
df08d6bffe Fix leak in assign_ref with function
As far as I can see, the retval copying is already done in all
callers of this function, so it should not be duplicated here.
2019-12-18 17:18:10 +01:00
Nikita Popov
8eabaf7efc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix const/cv freeing on failed reference assignment
2019-12-18 09:54:18 +01:00
Nikita Popov
0301ab70b3 Fix const/cv freeing on failed reference assignment 2019-12-18 09:54:10 +01:00
Nikita Popov
7194825c86 Fix leak of dynamic property name in address helper 2019-12-17 16:59:35 +01:00
Dmitry Stogov
b1577f5a57 Merge branch 'PHP-7.4'
* PHP-7.4:
  Export zend_init_func_run_time_cache()
2019-12-09 15:58:19 +03:00
Dmitry Stogov
03d1c788ea Export zend_init_func_run_time_cache() 2019-12-09 15:58:00 +03:00
Nikita Popov
aed2bf7ab3 Remove unused function 2019-12-06 14:18:52 +01:00
Nikita Popov
0bac785477 Optimize return type checking
Split off the fast-path case and avoid redundant checks.
2019-12-06 14:17:03 +01:00
Nikita Popov
999e32b65a Implement union types
According to RFC: https://wiki.php.net/rfc/union_types_v2

The type representation now makes use of both the pointer payload
and the type mask at the same time. Additionall, zend_type_list is
introduced as a new kind of pointer payload, which is used to store
multiple class types. Each of the class types is a tagged pointer,
which may be either a class name or class entry. The latter is only
used for typed properties, while arguments/returns will instead use
cache slots. A type list can contain a mix of both names and CEs at
the same time, as not all classes may be resolvable.

One thing this is missing is support for union types in arginfo
and stubs, which I want to handle separately.

I've also dropped the special object code from the JIT implementation
for now -- I plan to add this back in a different form at a later time.
For now I did not want to include non-trivial JIT changes together
with large functional changes.

Another possible piece of follow-up work is to implement "iterable"
as an internal alias for "array|Traversable". I believe this will
eliminate quite a few special-cases that had to be implemented.

Closes GH-4838.
2019-11-08 15:15:48 +01:00