Commit Graph

1014 Commits

Author SHA1 Message Date
Nikita Popov
f29149b419 Merge branch 'PHP-7.1' 2016-08-05 16:32:25 +02:00
Nikita Popov
1a780e6727 Add assertion to prevent type narrowing
Currently type narrowing is always a bug, make sure we know about
it.
2016-08-05 16:30:57 +02:00
Nikita Popov
fc7c81ff54 Fixed bug #72762 2016-08-05 16:27:55 +02:00
Xinchen Hui
7b4157d2c4 Merge branch 'PHP-7.1'
* PHP-7.1:
  Make the expression more reasonble (by nikic)
2016-08-01 20:20:27 +08:00
Xinchen Hui
f93061471b Make the expression more reasonble (by nikic) 2016-08-01 20:20:01 +08:00
Kalle Sommer Nielsen
59a7da7b49 Fix opcache build 2016-07-30 17:55:20 +02:00
Nikita Popov
42260325a4 Fix optimization of $i = $i++ 2016-07-17 22:47:49 +02:00
Dmitry Stogov
0da7c08e39 Prevent wrong optimization 2016-07-13 15:05:11 +03:00
Keyur
ffa863e800 Merge branch 'PHP-7.0'
* PHP-7.0:
  Add to NEWS
  Fixes #72590: Opcache restart with kill_all_lockers does not work
2016-07-13 03:07:41 +00:00
Keyur
b512f4a956 Fixes #72590: Opcache restart with kill_all_lockers does not work
ACCEL_LOG_ERROR is special and causes a zend_bailout() and the code
never gets to call kill() in the next line after the logging. Change
the log level to WARNING.
2016-07-13 03:01:26 +00:00
Nikita Popov
5f6effed43 Add opcodes to zend_wrong_string_offset() 2016-07-10 15:15:34 +02:00
Aaron Piotrowski
d9a9cf8eca Merge branch 'master' into iterable 2016-07-03 22:42:10 -05:00
Dmitry Stogov
acdafc0a27 Prevent inlining through call_user_func() and call_user_func_array() 2016-07-01 00:16:54 +03:00
Dmitry Stogov
f2e4fc307b Fixed ext/opcache/tests/bug70207.phpt 2016-06-30 21:50:57 +03:00
Dmitry Stogov
1a14533806 Introduce new CHECK_VAR instruction to keep warnings about undefined variables. 2016-06-30 21:40:34 +03:00
Dmitry Stogov
3a45242669 Disable inlining for $this->foo(), because $this may be not in object context 2016-06-30 21:05:48 +03:00
Dmitry Stogov
c3667a5eed Disable inlining for $this->foo(), because $this may be used not in object context 2016-06-30 21:03:08 +03:00
Dmitry Stogov
5ae07dc34a Fixed incorrect constant propagation 2016-06-30 20:48:16 +03:00
Nikita Popov
6f8273e3bf Fix RT_CONSTANT_EX typo 2016-06-30 17:42:57 +02:00
Dmitry Stogov
d898344663 Inline simple constant functions 2016-06-30 17:04:25 +03:00
Dmitry Stogov
871cd76af4 clanup 2016-06-29 17:53:39 +03:00
Nikita Popov
2710ce22a0 Remove assert for now 2016-06-28 18:47:29 +02:00
Nikita Popov
cdd58edf42 More type inferences fixes 2016-06-28 11:49:50 +02:00
Xinchen Hui
de7a6b1232 MFH: Fixed fd leak (the origin commit can not be cherry-picked) 2016-06-28 11:36:27 +08:00
David Carlier
85e985f191 couple of resource leaks fixes and use after free's 2016-06-27 07:44:21 +01:00
Xinchen Hui
3440054ca8 Merge branch 'PHP-7.0'
* PHP-7.0:
  Fixed format

Conflicts:
	ext/opcache/zend_shared_alloc.c
2016-06-24 21:14:02 +08:00
Xinchen Hui
53de1c2830 Fixed format 2016-06-24 21:13:04 +08:00
Dmitry Stogov
1433162083 Fixed compilation warnings 2016-06-21 20:12:29 +03:00
Dmitry Stogov
1616038698 Added ZEND_ATTRIBUTE_FORMAT to some middind functions.
"%p" replaced by ZEND_LONG_FMT to avoid compilation warnings.
Fixed most incorrect use cases of format specifiers.
2016-06-21 16:00:37 +03:00
Dmitry Stogov
8b823235d6 Removed wrong HANDLE_UNBLOCK_INTERRUPTIONS() 2016-06-20 18:50:24 +03:00
Dmitry Stogov
ad55348e66 Protect OPcache from termination during SHM modification. 2016-06-20 16:03:31 +03:00
Anatol Belski
3d3f11ede4 Fixed the UTF-8 and long path support in the streams on Windows.
Since long the default PHP charset is UTF-8, however the Windows part is
out of step with this important point. The current implementation in PHP
doesn't technically permit to handle UTF-8 filepath and several other
things. Till now, only the ANSI compatible APIs are being used. Here is more
about it

https://msdn.microsoft.com/en-us/library/windows/desktop/dd317752%28v=vs.85%29.aspx

The patch fixes not only issues with multibyte filenames under
incompatible codepages, but indirectly also issues with some other multibyte
encodings like BIG5, Shift-JIS, etc. by providing a clean way to access
filenames in UTF-8. Below is a small list of issues from the bug tracker,
that are getting fixed:

https://bugs.php.net/63401
https://bugs.php.net/41199
https://bugs.php.net/50203
https://bugs.php.net/71509
https://bugs.php.net/64699
https://bugs.php.net/64506
https://bugs.php.net/30195
https://bugs.php.net/65358
https://bugs.php.net/61315
https://bugs.php.net/70943
https://bugs.php.net/70903
https://bugs.php.net/63593
https://bugs.php.net/54977
https://bugs.php.net/54028
https://bugs.php.net/43148
https://bugs.php.net/30730
https://bugs.php.net/33350
https://bugs.php.net/35300
https://bugs.php.net/46990
https://bugs.php.net/61309
https://bugs.php.net/69333
https://bugs.php.net/45517
https://bugs.php.net/70551
https://bugs.php.net/50197
https://bugs.php.net/72200
https://bugs.php.net/37672

Yet more related tickets can for sure be found - on bugs.php.net, Stackoverflow
and Github. Some of the bugs are pretty recent, some descend to early
2000th, but  the user comments in there last even till today. Just for example,
bug #30195 was opened in 2004, the latest comment in there was made in 2014. It
is certain, that these bugs descend not only to pure PHP use cases, but get also
redirected from the popular PHP based projects. Given the modern systems (and
those supported by PHP) are always based on NTFS, there is no excuse to keep
these issues unresolved.

The internalization approach on Windows is in many ways different from
UNIX and Linux, while it supports and is based on Unicode. It depends on the
current system code page, APIs used and exact kind how the binary was compiled
The locale doesn't affect the way Unicode or ANSI API work. PHP in particular
is being compiled without _UNICODE defined and this is conditioned by the
way we handle strings. Here is more about it

https://msdn.microsoft.com/en-us/library/tsbaswba.aspx

However, with any system code page ANSI functions automatically convert
paths to UTF-16. Paths in some encodings incompatible with the
current system code page, won't work correctly with ANSI APIs. PHP
till now only uses the ANSI Windows APIs.

For example, on a system with the current code page 1252, the paths
in cp1252 are supported and transparently converted to UTF-16 by the
ANSI functions. Once one wants to handle a filepath encoded with cp932 on
that particular system, an ANSI or a POSIX compatible function used in
PHP will produce an erroneous result. When trying to convert that cp932 path
to UTF-8 and passing to the ANSI functions, an ANSI function would
likely interpret the UTF-8 string as some string in the current code page and
create a filepath that represents every single byte of the UTF-8 string.
These behaviors are not only broken but also disregard the documented
INI settings.

This patch solves the issies with the multibyte paths on Windows by
intelligently enforcing the usage of the Unicode aware APIs. For
functions expect Unicode (fe CreateFileW, FindFirstFileW, etc.), arguments
will be converted to UTF-16 wide chars. For functions returning Unicode
aware data (fe GetCurrentDirectoryW, etc.), resulting wide string is
converted back to char's depending on the current PHP charset settings,
either to the current ANSI codepage (this is the behavior prior to this patch)
or to UTF-8 (the default behavior).

In a particular case, users might have to explicitly set
internal_encoding or default_charset, if filenames in ANSI codepage are
necessary. Current tests show no regressions and witness that this will be an
exotic case, the current default UTF-8 encoding is compatible with any
supported system. The dependency libraries are long switching to Unicode APIs,
so some tests were also added for extensions not directly related to streams.
At large, the patch brings over 150 related tests into the core. Those target
and was run on various environments with European, Asian, etc. codepages.
General PHP frameworks was tested and showed no regressions.

The impact on the current C code base is low, the most places affected
are the Windows only places in the three files tsrm_win32.c, zend_virtual_cwd.c
and plain_wrapper.c. The actual implementation of the most of the wide
char supporting functionality is in win32/ioutil.* and win32/codepage.*,
several  low level functionsare extended in place to avoid reimplementation for
now. No performance impact was sighted. As previously mentioned, the ANSI APIs
used prior the patch perform Unicode conversions internally. Using the
Unicode  APIs directly while doing custom conversions just retains the status
quo. The ways to optimize it are open (fe. by implementing caching for the
strings converted to wide variants).

The long path implementation is user transparent. If a path exceeds the
length of _MAX_PATH, it'll be automatically prefixed with \\?\. The MAXPATHLEN
is set to 2048 bytes.

Appreciation to Pierre Joye, Matt Ficken, @algo13 and others for tips, ideas
and testing.

Thanks.
2016-06-20 12:45:39 +02:00
Nikita Popov
a171522983 Exception safety for direct CV assign of *CALL instrs
Converting T = *CALL; ASSIGN $v, T into $v = *CALL may not be
safe if an exception is thrown after the return value has been
populated -- in this case the value might be destroyed twice.
2016-06-18 00:08:38 +02:00
Nikita Popov
811dfba4bf More type inference fixes 2016-06-16 14:25:48 +02:00
Dmitry Stogov
ff363e2e7c Implemented RFC: Replace "Missing argument" warning with "Too few arguments" exception
Squashed commit of the following:

commit 8b45fa2acb
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jun 16 01:52:50 2016 +0300

    Separate slow path of ZEND_RECV into a cold function.

commit 9e18895ee5
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 23:26:28 2016 +0300

    Required argument can't be IS_UNDEF anymore.

commit 662db66e39
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Tue May 31 17:14:50 2016 +0300

    Replace "Missing argument" warning by "Too few arguments" exception.
2016-06-16 02:32:02 +03:00
Dmitry Stogov
a9512af810 Implemented RFC: Fix inconsistent behavior of $this variable
Squashed commit of the following:

commit bdd3b6895c
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Thu Jun 16 00:19:42 2016 +0300

    Fixed GOTO VM

commit 2f1d7c8b89
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 21:01:57 2016 +0300

    Removed unused variable

commit cf749c42b0
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 19:06:16 2016 +0300

    Protection from $this reassign through mb_parse_str()

commit 59a9a6c83c
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 18:14:50 2016 +0300

    Added type inference rule for FETCH_THIS opcode

commit 73f8d14a85
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Wed Jun 15 18:11:18 2016 +0300

    Restored PHP-7 behavior of isset($this->foo).
    It throws exception if not in object context.
    Removed useless opcode handlers.

commit fa0881381e
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Tue May 31 12:25:47 2016 +0300

    Changed "Notice: Undefined variable: this" into "Exception: Using $this when not in object context".

commit e32cc528c0
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Tue May 24 02:02:43 2016 +0300

    Throw exception on attempt to re-assign $this through extract() and parse_str().

commit 41f1531b52
Author: Dmitry Stogov <dmitry@zend.com>
Date:   Mon May 23 22:18:36 2016 +0300

    Fixed inconsistent $this behavior
2016-06-16 02:30:23 +03:00
Nikita Popov
fba6f90ae3 Fix type inference bugs
* Add proper array_key_any|array_of_any|array_of_ref in some more
  places
* strlen() on objects may be null
* IS fetch on string dim may be null
2016-06-15 22:52:48 +02:00
Dmitry Stogov
d12987256a Fixed mistakes in type inference rules. 2016-06-15 23:04:17 +03:00
Nikita Popov
046889518d Add support for "instanceof" pi nodes 2016-06-13 19:03:59 +02:00
Nikita Popov
9877d8f019 Use union for pi constraints
This will make it easier to extend pi constraints without impacting
structure sizes.
2016-06-13 19:03:57 +02:00
Aaron Piotrowski
0dc772c9b4 Add iterable type to opcache 2016-06-10 19:01:27 -05:00
Nikita Popov
be37de1ff1 Use LCA for object(ce) type joins
For B, C extending A the join of object(B) and object(C) should
be object(instanceof A). For simplicity we only handle the class
hierarchy, as computing the least common unique ancestor for
interfaces would be more involved.

Also ignore phi sources that don't have an object type: The join
of null and object(A) is now null|object(A) rather than
null|object.
2016-06-07 20:42:00 +02:00
Nikita Popov
d8a2370884 Cleanup 2016-06-07 20:42:00 +02:00
Dmitry Stogov
80b39b498a Improve type narrowing (check only SSA definitions). 2016-06-06 14:57:02 +03:00
Nikita Popov
543649bd4c Fix correctness issues with type narrowing
Fixes bug #72335.
2016-06-06 14:56:17 +03:00
Nikita Popov
e6296f0dcc Fix VERIFY_RETURN_TYPE elision
This both fixes incorrect elision and allows elision for cases
where we only have a subset (e.g. true of bool).
2016-06-05 23:44:08 +02:00
Nikita Popov
c5348850df Fix bug71843.phpt
Is Travis not running opcache tests?
2016-06-05 23:05:03 +02:00
Nikita Popov
9fa1ab1b22 Check SKIP_SLOW_TESTS in issue0140.phpt
This test contains two sleeps...
2016-06-05 23:05:00 +02:00
Nikita Popov
7b4618e396 Fix SSA NOP removal
NOPs need to be tracked in the shiftlist as well, as there may be
jumps to NOPs.
2016-06-05 23:00:32 +02:00
Nikita Popov
3be92120ba Fix handling of parse_str() with unpack in optimizer 2016-06-05 22:16:15 +02:00