Commit Graph

183 Commits

Author SHA1 Message Date
Sammy Kaye Powers
9e29f841ce Update copyright headers to 2017 2017-01-02 09:30:12 -06:00
Nikita Popov
9f92bb80e4 Merge branch 'PHP-7.1' 2016-09-30 22:10:32 +02:00
Nikita Popov
02ba9d71ab Unwrap reference returns in cufa etc 2016-09-30 22:10:01 +02:00
Dmitry Stogov
97628da24a Expose information about calls to "fake" closures (created through ReflectionFunction::getClosure), to allow extra specialization of RETRUN opcode handler. 2016-09-26 17:44:28 +03:00
Nikita Popov
dbe6a23194 Closure::fromCallable(): Getting non-static method statically
As this is new functionality, I'm going directly for a TypeError,
rather than a deprecation warning.
2016-07-05 15:52:03 +02:00
Nikita Popov
ceae9fb540 Closure::fromCallable(): Better LSB handling
The previous fix missed the "late" part of "late static binding" :)
2016-07-05 15:44:17 +02:00
Nikita Popov
e959a9b652 Closure::fromCallable(): Fix late static binding 2016-07-05 15:31:11 +02:00
Nikita Popov
e395b62c51 Closure::fromCallable(): Use fake closures 2016-07-05 15:13:51 +02:00
Nikita Popov
041476f4ae Closure::fromCallable(): Fix stack corruption
So the tests work at least...
2016-07-05 14:54:35 +02:00
Xinchen Hui
11d0101516 Some cleanup:
1. use c89 comments
2. exception should not be swallowd
3. ZVAL_OBJ may have problem if obj is NULL in the feature(who knows)
2016-07-05 15:31:46 +08:00
Danack
fc92eeeadf Added reflection test. Standardised filename for other tests. 2016-06-01 21:53:01 +01:00
Danack
4a7afdaa98 Typo. 2016-05-15 21:08:52 +01:00
Danack
63ca65daef Add Closure::fromCallable().
Add the ability to create closures from callable as part of RFC: https://wiki.php.net/rfc/closurefromcallable
2016-05-15 17:39:47 +01:00
Dmitry Stogov
7b94b958cc Intern some known (and offten used) strings. 2016-05-12 13:47:22 +03:00
Nikita Popov
3dd2df85b3 Drop unnecessary checks in get_closure 2016-04-16 20:23:23 +02:00
Nikita Popov
8c5861e6c6 Don't copy args in Closure::__invoke() 2016-04-16 14:47:27 +02:00
Nikita Popov
fea04a528b Drop dead assignment 2016-04-16 14:34:32 +02:00
Nikita Popov
75af8150f5 Forbid binding methods to incompatible $this
This prohibits binding closures returned by
ReflectionMethod::getClosure() to a $this, which is not an
instance of the method scope. This restriction was already in
place for internal methods, now it is extended to user methods.

ML discussion: http://markmail.org/message/zepnhdyr3kij6di6
2016-04-08 00:38:44 +02:00
Nikita Popov
29bc5a0b0f Merge branch 'PHP-7.0' 2016-03-30 18:32:29 +02:00
Nikita Popov
f95679885f Fix __invoke comparison in closure_get_method
It compared against the wrong variable. Fixed this by getting rid
of lc_name entirely and use equals_literal_ci instead.
2016-03-30 18:32:00 +02:00
Xinchen Hui
563659822d Merge branch 'PHP-7.0' 2016-01-02 17:56:54 +08:00
Xinchen Hui
97a9470d97 bump year which is missed in rev 49493a2 2016-01-02 17:56:11 +08:00
Nikita Popov
65e456f364 Introduce BIND_LEXICAL
This opcodes inserts a local CV into the closure static variable
table. This replaces the previous mechanism of having static
variables marked as LEXICAL, which perform a symtable lookup
during copying.

This means a) functions which contain closures no longer have to
rebuild their symtable (better performance) and b) we can now track
used variables in SSA.
2015-12-29 23:14:53 +01:00
Andrea Faulds
8907da99b8 Set called_scope in Closure::call (fixes bug #70987) 2015-11-27 15:06:13 +00:00
Dmitry Stogov
23b372d358 Forbid "fake" closure rebinding 2015-10-12 20:34:08 +02:00
Nikita Popov
4b821f0fc6 Normalize rebinding failures
Move all rebinding checks into one function to make sure they stay
in sync. Normalize return value to be NULL for all rebinding
failures, instead of returning an improperly bound closure in some
cases.
2015-10-10 13:56:36 +02:00
Nikita Popov
d677b25b1c Merge branch 'PHP-5.6' into PHP-7.0 2015-10-09 23:28:58 +02:00
Nikita Popov
e19423f3cb Improve previous fix
Don't forbid null binding on plain functions.
2015-10-09 23:28:24 +02:00
Nikita Popov
f6ae19f158 Merge branch 'PHP-5.6' into PHP-7.0 2015-10-09 23:06:32 +02:00
Nikita Popov
bbae7ddf29 Fixed bug #70681 2015-10-09 23:01:23 +02:00
Dmitry Stogov
0847681b1a Fixed bug #70630 (Closure::call/bind() crash with ReflectionFunction->getClosure()) 2015-10-09 11:48:13 +03:00
Dmitry Stogov
93748bf9dd Fixed infinity recurion if we create closure on top of other closure. 2015-10-09 02:37:51 +03:00
Dmitry Stogov
05bd331c6a Fixed use after free 2015-10-09 01:09:22 +03:00
Dmitry Stogov
91fb3a7b27 Fixed bug #70674 (ReflectionFunction::getClosure() leaks memory when used for internal functions) 2015-10-09 00:45:02 +03:00
Dmitry Stogov
e0b3b3c752 Revert "Fixed bug #70630 (Closure::call/bind() crash with ReflectionFunction->getClosure())"
This reverts commit 517b553625.
2015-10-06 23:59:36 +03:00
Dmitry Stogov
e193d35c1e Revert "Improve 517b55362 (scope rebinding on method Closures)"
This reverts commit 881c502520.
2015-10-06 23:48:15 +03:00
Dmitry Stogov
524d00e005 Revert "Allow random $this on non-internal Closures again"
This reverts commit 35d0405c47.
2015-10-06 23:48:10 +03:00
Bob Weinand
35d0405c47 Allow random $this on non-internal Closures again
As it turns out, there is actually no reason to prevent this, it even was a bigger BC break than expected...

Also fixes a memory leak (the Closure leaks) when calling internal functions via Closure by moving it out of leave helper onto caller side for TOP_CODE:

$z = new SplStack; $z->push(20);
$x = (new ReflectionMethod("SplStack", "pop"))->getClosure($z);
var_dump($x());
2015-10-05 17:49:32 +02:00
Bob Weinand
881c502520 Improve 517b55362 (scope rebinding on method Closures)
Now it is completely impossible to rebind a scoped method Closure (only the kind you get from ReflectionMethod::getClosure()) to a foreign scope
Adding a lot of tests to ensure this...
Also, properly return NULL in case the Closure could not be created instead of some crippled unbound Closure
2015-10-05 00:56:55 +02:00
Bob Weinand
517b553625 Fixed bug #70630 (Closure::call/bind() crash with ReflectionFunction->getClosure())
This additionally removes support for binding to an unknown (not in parent hierarchy) scope.
Removing support for cross-scope is necessary for certain compile-time assumptions (like class constants) to prevent unexpected results
2015-10-04 01:38:59 +02:00
Bob Weinand
e878dff5d8 Revert accidentally committed closures.c and execute.c 2015-09-19 23:22:07 +02:00
Bob Weinand
08e253cdbc Optimize zend_mm_small_size_to_bin()
It removes a cmov operation and has a much faster branch for small allocations (especially when handling strings) (<= 64 bytes)
2015-09-19 23:07:43 +02:00
Bob Weinand
50d6fd6a03 Fixed bug #70397 (Segmentation fault when using Closure::call and yield) 2015-09-01 18:04:19 +02:00
Dmitry Stogov
71af54e5f6 Mark error and exception functions as "cold" (Matt's idea) 2015-08-19 14:40:56 +03:00
Aaron Piotrowski
5df893ce3c Use NULL where possible for exception class
Matches usage of zend_throw_exception()/zend_throw_exception_ex().
2015-07-07 12:10:55 -05:00
Aaron Piotrowski
22c38b2ef5 Remove need to pass error level 2015-07-03 17:53:41 -05:00
Aaron Piotrowski
5a99c07ecc Enable throwing custom exceptions from errors 2015-07-03 17:53:40 -05:00
Dmitry Stogov
7aa7627172 Use ZSTR_ API to access zend_string elements (this is just renaming without semantick changes). 2015-06-30 13:59:27 +03:00
Rasmus Lerdorf
41774bceff Fix more minor mistakes in the proto comments 2015-06-23 15:47:33 -04:00
Bob Weinand
3c288b12b4 Fix bad run_time_cache with Closure::call()
This also fixes a memory "leak" (memory is allocated on unbounded arena without limits) on each new Closure instantiation.
Closures with same scope now all share the same run_time_cache (as long as it is arena allocated)
2015-06-21 16:39:44 +02:00