Commit Graph

2438 Commits

Author SHA1 Message Date
Máté Kocsis
f7fbc6333f
Add more precise type info for stubs
Closes GH-6005
2020-09-01 16:35:56 +02:00
Nikita Popov
f965e20059 Promote ArrayObject modification during sorting to Error exception 2020-08-28 10:42:14 +02:00
Nikita Popov
a3d0d947bd Use zend_dval_to_lval() in spl_offset_convert_to_long()
Avoid fptoi UB and use the standard PHP conversion behavior.
2020-08-27 14:53:56 +02:00
Dmitry Stogov
8c90002201 Fixed bug #79987 (Memory leak in SplFileInfo because of missing zend_restore_error_handling()) 2020-08-18 11:08:04 +03:00
Nikita Popov
07539685b9 Return empty string from SplFileInfo::getPathname()
Instead of false. This is consistent with how other methods like
SplFileInfo::getPath() behave. It's also a requirement before
SplFileInfo::__toString() calls SplFileInfo::getPathname() and
needs to return a string.
2020-08-14 11:09:30 +02:00
Nikita Popov
0a439fa932 Merge branch 'PHP-7.4'
* PHP-7.4:
  Add missing initialization check to RegexIterator::getRegex()
2020-08-14 10:42:14 +02:00
Nikita Popov
a0c231c0f5 Add missing initialization check to RegexIterator::getRegex() 2020-08-14 10:41:36 +02:00
Nikita Popov
f3d6203b0b Use a dedicated method for MultipleIterator::countIterators()
This method has a different signature from
SplObjectStorage::count(), so don't share implementations.
2020-08-13 14:44:03 +02:00
Nikita Popov
f0bf3d4672 Replace fatal error in SplFileInfo with exception
Using RuntimeException here, because the same error condition
uses that in many other places in this file.
2020-08-13 14:43:45 +02:00
Máté Kocsis
7aacc705d0
Add many missing closing PHP tags to tests
Closes GH-5958
2020-08-09 22:03:36 +02:00
Máté Kocsis
046cc5e4c2
Add another round of missing parameter types to stubs
Closes GH-5950
2020-08-07 16:48:45 +02:00
Nikita Popov
7991fc2753 Accept zend_object in zend_read_property 2020-08-07 16:40:27 +02:00
Nikita Popov
c48b745f00 Promote "undefined array key" notice to warning
This implements the last remaining part of the
https://wiki.php.net/rfc/engine_warnings RFC.

Closes GH-5927.
2020-08-03 14:40:50 +02:00
Nikita Popov
7a4b594c6f Convert SPL illegal offset type into TypeError
Make this consistent with the corresponding engine behavior.
Also adjust the messages to match.
2020-08-03 11:17:49 +02:00
Máté Kocsis
6ba24e9615
Improve a few parameter names in ext/spl
Use the same names which are used by zend functions.
2020-08-03 00:45:12 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
From an engine perspective, named parameters mainly add three
concepts:

 * The SEND_* opcodes now accept a CONST op2, which is the
   argument name. For now, it is looked up by linear scan and
   runtime cached.
 * This may leave UNDEF arguments on the stack. To avoid having
   to deal with them in other places, a CHECK_UNDEF_ARGS opcode
   is used to either replace them with defaults, or error.
 * For variadic functions, EX(extra_named_params) are collected
   and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS.

RFC: https://wiki.php.net/rfc/named_params

Closes GH-5357.
2020-07-31 15:53:36 +02:00
Nikita Popov
d65d3f5298 Fix bug #79108
Don't expose references in debug_backtrace() or exception traces.
This is regardless of whether the argument is by-reference or not.

As a side-effect of this change, exception traces may now acquire
the interior value of a reference, which may be unexpected for
some internal functions. This is what necessitated the change in
the spl_array sort implementation.
2020-07-24 12:23:34 +02:00
Nikita Popov
dc30e1d812 Cleanup SPL instantiation code 2020-07-23 16:00:12 +02: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
Nikita Popov
e6ae1bf489 Check dual_it validity in CallbackFilterIterator::accept()
Avoid accessing intern->u.cbfilter null pointer, though it's
harmless here.
2020-07-22 11:31:15 +02:00
Nikita Popov
9d2af91033 Only set DIT type on successful initialization 2020-07-17 16:42:56 +02:00
Nikita Popov
954244b3cb Convert SPL fatal error to Error exception 2020-07-17 16:06:54 +02:00
Nikita Popov
1cba736470 Throw correct exception from ArrayObject sort methods
Let normal zpp throw ArgumentCountErrors.
2020-07-17 10:46:11 +02:00
Rowan Tommins
55a15f32ce Improve output of tokens in Parse Errors
Currently, unexpected tokens in the parser are shown as the text
found, plus the internal token name, including the notorious
"unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM)".

This commit replaces that with a more user-friendly format, with
two main types of token:

* Tokens which always represent the same text are shown like
  'unexpected token "::"' and 'expected "::"'
* Tokens which have variable text are given a user-friendly
  name, and show like 'unexpected identifier "foo"', and
  'expected identifer'.

A few tokens have special cases:

* unexpected token """ -> unexpected double-quote mark
* unexpected quoted string "'foo'" -> unexpected single-quoted
  string "foo"
* unexpected quoted string ""foo"" -> unexpected double-quoted
  string "foo"
* unexpected illegal character "_" -> unexpected character 0xNN
  (where _ is almost certainly a control character, and NN is the
   hexadecimal value of the byte)

The \ token has a special case in the implementation just to stop
bison making a mess of escaping it and it coming out as \\
2020-07-13 11:07:40 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Nikita Popov
df8119d3e1 Don't allow separation in CallbackFilterIterator
As the name might suggest, this is a *filter* iterator. If you want
to have a *map* iterator, write one, or use a generator.
2020-07-07 09:04:20 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Christoph M. Becker
66a5f9fb18 Merge branch 'PHP-7.4'
* PHP-7.4:
  Extract test helper function for SeCreateSymbolicLinkPrivilege check
2020-07-02 12:24:49 +02:00
Christoph M. Becker
c49fb83c38 Extract test helper function for SeCreateSymbolicLinkPrivilege check 2020-07-02 12:23:49 +02:00
Nikita Popov
312201dce4 Add get_gc handle for object iterators
Optional handler with the same semantics as the object handler.
2020-07-01 15:17:22 +02:00
Fabien Villepinte
3190282f09 Fix typos in comments 2020-07-01 09:08:28 +02:00
Ayesh Karunaratne
d114812faf [ci skip] Various typo fixes in stub comments and CHANGES file 2020-06-25 23:32:40 +02:00
Nikita Popov
e12b9df05d Make sorting stable
Make user-exposed sorts stable, by storing the position of elements
in the original array, and using those positions as a fallback
comparison criterion. The base sort is still hybrid q/insert.

The use of true/false comparison functions is deprecated (but still
supported) and should be replaced by -1/0/1 comparison functions,
driven by the <=> operator.

RFC: https://wiki.php.net/rfc/stable_sorting

Closes GH-5236.
2020-06-25 10:49:34 +02:00
Nikita Popov
f37138d2c5 Don't use iterator_funcs_ptr if it is null
This avoids ubsan warnings. Alternatively we could always initialize
iterator_funcs_ptr for aggregates, instead of doing so only for
non-internal ones.
2020-06-25 10:30:40 +02:00
Alex Dowad
47fae8425f Remove useless prototype for spl_heap_get_iterator 2020-06-24 22:29:07 +02:00
Máté Kocsis
b5c7a83dca
Remove unnecessary PHPDoc-alike blocks from tests
Closes GH-5759
2020-06-24 13:13:44 +02:00
Nikita Popov
c9b9f525a9 Include stub hash in generated arginfo files
The hash is used to check whether the arginfo file needs to be
regenerated. PHP-Parser will only be downloaded if this is actually
necessary.

This ensures that release artifacts will never try to regenerate
stubs and thus fetch PHP-Parser, as long as you do not modify any
files.

Closes GH-5739.
2020-06-24 09:55:19 +02:00
Anatol Belski
56aebbec8b Merge branch 'PHP-7.4'
* PHP-7.4:
  SplHeap: Avoid memcpy on overlapping pointer
2020-06-21 22:55:00 +02:00
Anatol Belski
afe14236e3 SplHeap: Avoid memcpy on overlapping pointer
Check if data would overlap and also add an assert. Previous
implementations didn't have this issue, as the direct assignment was
used.

Signed-off-by: Anatol Belski <ab@php.net>
2020-06-21 22:53:46 +02:00
Nikita Popov
b461e6b074 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79710
2020-06-19 10:48:34 +02:00
Nikita Popov
2f56b0018e Merge branch 'PHP-7.3' into PHP-7.4 2020-06-19 10:47:01 +02:00
Nikita Popov
32f377b0b9 Fixed bug #79710
Make sure we don't use zresource after the stream has been destroyed.
2020-06-19 10:46:26 +02:00
Nikita Popov
15846ff115 Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
2020-06-17 16:36:56 +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
Nikita Popov
94df2f697f Fix bug #65006
The "callable name" may be the same for multiple distinct callables.
The code already worked around this for the case of instance methods,
but there are other cases in which callable names clash, such as
the use of self:: reported in the referenced bug.

Rather than trying to generate a unique name for callables, compare
the content of the alfi structures. This is less efficient if there
are many autoload functions, but autoload *registration* does not
need to be particularly efficient.

As a side-effect, this no longer permits unregistering non-callables.
2020-06-10 11:30:32 +02:00
Nikita Popov
034741f6c7 Simplify spl_autoload_perform() implementation
And convert alfi.obj from zval to zend_object*.
2020-06-10 10:33:54 +02:00
Nikita Popov
097043db2a Fix called scope assignment in autoloader
We should use the scope specified in the spl_autoload_register()
call, not whatever LSB scope just so happens to be active at the
time of the autoloader call.
2020-06-10 09:55:50 +02:00
Nikita Popov
e0e4a61847 Remove autoload_running flag
This was only used to decide between a hash clean and a hash
destroyed in spl_autoload_remove(). But now that
spl_autoload_functions() no longer distinguishes between NULL and
an empty array here, there's really no need to try and destroy
the hashtable here.
2020-06-10 09:41:58 +02:00
Nikita Popov
5b59d4915c Cleanup SPL autoload implementation
Replace EG(autoload_func) with a C level zend_autoload hook.
This avoids having to do one indirection through PHP function
calls. The need for EG(autoload_func) was a leftover from the
__autoload() implementation.

Additionally, drop special-casing of spl_autoload(), and instead
register it just like any other autoloading function. This fixes
bug #71236 as a side-effect.

Finally, change spl_autoload_functions() to always return an array.
The distinction between false and an empty array no longer makes
sense here.

Closes GH-5696.
2020-06-10 09:38:47 +02:00