Commit Graph

452 Commits

Author SHA1 Message Date
Stanislav Malyshev
531e2533dd Use zend_execute_internal always to call internal functions 2012-10-05 08:14:20 +02:00
Nikita Popov
aaabac2473 Merge branch 'PHP-5.4'
Conflicts:
	Zend/zend_vm_def.h
2012-09-27 18:46:27 +02:00
Nikita Popov
592b232e83 Fix bug #63173: Crash when invoking invalid array callback
The code did not check whether the zend_hash_index_find calls succeded,
so PHP crashed when an array callback was called that contains two elements
which don't have the indices 0 and 1.
2012-09-27 18:40:00 +02:00
Xinchen Hui
fd0b3ea663 Fixed bug #61442 (exception threw in __autoload can not be catched) 2012-09-19 19:40:59 +08:00
Nikita Popov
a47c11a13d Fix two op_array -> function cast warnings 2012-09-16 22:01:07 +02:00
Nikita Popov
fb03ce93d3 Fix invalid read / remove useless code
Generators follow a different cleanup path, so the extra check for freeing
the execute_data is unnecessary there. It actually caused problems because
op_array->fn_flags could be in freed memory at that time (in case op_array
came from a closure in an ArrayAccess container).

This fixes the valgrind warning in Zend/tests/bug54367.phpt.
2012-09-16 21:48:57 +02:00
Nikita Popov
dffffdeb3d Fix leak when yielding array as key
The code was copy-pasted and I forgot to change OP1 to OP2 in that one
place.
2012-09-01 20:31:40 +02:00
Nikita Popov
d60e3c6ef5 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
Conflicts:
	Zend/zend_language_parser.y
	Zend/zend_vm_execute.skl
2012-08-26 13:03:55 +02:00
Nikita Popov
bd70d15588 Remove implementation stubs for yield delegation
I decided to leave out yield delegation for an initial proposal, so remove
the stubs for it too.
2012-08-25 19:03:23 +02:00
Nikita Popov
f53225a99e Fix several issues and allow rewind only at/before first yield
* Trying to resume a generator while it is already running now throws a
   fatal error.
 * Trying to use yield in finally while the generator is being force-closed
   (by GC) throws a fatal error.
 * Rewinding after the first yield now throws an Exception
2012-08-25 17:40:08 +02:00
Xinchen Hui
326aa08753 Prefer no finally block for most situations 2012-08-25 21:14:51 +08:00
Nikita Popov
68c1e1cfe9 Add dedicated opcode for returns from a generator
Generators don't have a return value, so it doesn't make sense to have
a shared implementation here.
2012-08-24 13:51:39 +02:00
Nikita Popov
6517ed0215 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
Conflicts:
	Zend/zend_vm_def.h
	Zend/zend_vm_execute.h
2012-08-24 13:29:40 +02:00
Xinchen Hui
60a29791e4 Fixed bug that jmp in try block jmp over finally block
Refactor the implemention,  make codes clear
2012-08-22 18:32:03 +08:00
Xinchen Hui
703a4e390d stash 2012-08-22 13:51:44 +08:00
Nikita Popov
1823b16fa1 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
Merging master to fix Windows build

Conflicts:
	Zend/zend_language_scanner.c
	Zend/zend_language_scanner_defs.h
	Zend/zend_vm_def.h
2012-08-20 13:37:53 +02:00
Xinchen Hui
72b9b8f380 Make the codes clearer, and also check continue statement 2012-08-18 11:44:09 +08:00
Xinchen Hui
c64f4e736c Add functions declarations, use tabs 2012-08-14 08:59:40 +08:00
Anatoliy Belsky
baea290b6c fix windows build 2012-08-13 19:44:45 +02:00
Nikita Popov
ae716939eb Support trivial finally in generators (no yield, no return)
The finally clause is now properly run when an exception is thrown in the
try-block. It is not yet run on `return` and also not run when the generator
is claused within a try block.

I'll add those two things as soon as laruence refactored the finally code.
2012-08-13 17:22:21 +02:00
Nikita Popov
f4ce364628 Merge remote-tracking branch 'php-src/master' into addGeneratorsSupport
This is just an intial merge. It does not yet make generators and finally
work together.

Conflicts:
	Zend/zend_language_scanner.c
	Zend/zend_language_scanner_defs.h
	Zend/zend_vm_def.h
	Zend/zend_vm_execute.h
	Zend/zend_vm_execute.skl
	Zend/zend_vm_opcodes.h
2012-08-13 16:54:53 +02:00
Xinchen Hui
80d5ae3cea Implemented 'finally' keywords for php
RFC: https://wiki.php.net/rfc/finally
FR: https://bugs.php.net/bug.php?id=32100
and I have got some improvment ideas(performance), will implemented
later. thanks
2012-08-13 21:48:39 +08:00
Xinchen Hui
80497ea7df Merge branch 'PHP-5.4' 2012-07-26 13:58:01 +08:00
Xinchen Hui
eae0610042 Fixed bug #62653: (unset($array[$float]) causes a crash)
the reason why jpauli and I can not reproduce is (it's silly):
I typo "USE_ZEND_ALLOC *&&* valgrind" at the first time, then I always ctrl+r
and jpauli copied my command from the pastbin :)

thanks
2012-07-26 13:53:06 +08:00
Nikita Popov
94b2ccae9c Fix throwing of exceptions within a generator
If a generator threw an exception and was iterated using foreach (i.e. not
manually) an infinite loop was triggered. The reason was that the exception
was not properly rethrown using zend_throw_exception_internal.
2012-07-22 17:46:46 +02:00
Nikita Popov
612c2490b7 Move a variable 2012-07-20 17:38:39 +02:00
Nikita Popov
c9709bfbd7 Remove asterix modifier (*) for generators
Generators are now automatically detected by the presence of a `yield`
expression in their body.

This removes the ZEND_SUSPEND_AND_RETURN_GENERATOR opcode. Instead
additional checks for ZEND_ACC_GENERATOR are added to the fcall_common
helper and zend_call_function.

This also adds a new function zend_generator_create_zval, which handles
the actual creation of the generator zval from an op array.

I feel like I should deglobalize the zend_create_execute_data_from_op_array
code a bit. It currently changes EG(current_execute_data) and
EG(opline_ptr) which is somewhat confusing (given the name).
2012-07-20 16:09:06 +02:00
Nikita Popov
85f077cea1 Add support by yielding by-reference 2012-07-17 13:29:56 +02:00
Nikita Popov
14766e1417 Pass zend_generator directly to Zend VM
Previously the zval* of the generator was passed into the VM by misusing
EG(return_value_ptr_ptr). Now the zend_generator* itself is directly passed
in. This saves us from always having to pass the zval* around everywhere.
2012-06-23 14:43:52 +02:00
Nikita Popov
1d3f37dded Fix segfault in method test
A ref has to be added to $this if the generator is called !nested (which
is the case when it is invoked via getIterator).
2012-06-23 00:03:28 +02:00
Nikita Popov
6233408a2a Fix thread safe build 2012-06-20 21:31:23 +02:00
Nikita Popov
d939d2dee5 Add sceleton for yield* expression
This does not yet actually implement any delegation.
2012-06-19 00:37:31 +02:00
Nikita Popov
f169b26dd7 Fix backtraces and func_get_args()
To make the generator function show up in backtraces one has to insert an
additional execute_data into the chain, as prev_execute_data->function_state
is used to determine the called function.

Adding the additional stack frame is also required for func_get_args(), as
the arguments are fetched from there too. The arguments have to be copied
in order to keep them around. Due to the way they are saved doing so is
quite ugly, so I added another function zend_copy_arguments to zend_execute.c
which handles this.
2012-06-09 00:40:47 +02:00
Nikita Popov
ee89e228f6 Allow yielding during function calls
During function calls arguments are pushed onto the stack. Now these are
backed up on yield and restored on resume. This requires memcpy'ing them,
but there doesn't seem to be any better way to do it.

Also this fixes the issue with exceptions thrown during function calls.
2012-05-31 00:00:30 +02:00
Nikita Popov
0033a52521 Allow throwing exceptions from generators
The missing piece is how one can find the next stack frame, which is
required for dtor'ing arguments pushed to the stack. As the generator
execute_data does not live on the stack one can't use it to figure out the
start of the next stack frame. So there must be some other method.
2012-05-30 16:28:33 +02:00
Nikita Popov
8790160235 Add auto-increment keys
When no key is explicitely yielded PHP will used auto-incrementing keys
as a fallback. They behave the same as with arrays, i.e. the key is the
successor of the largest previously used integer key.
2012-05-30 05:05:49 +02:00
Nikita Popov
bc08c2cf94 Add support for yielding keys
Keys are yielded using the

    yield $key => $value

syntax. Currently this is implemented as a statement only and not as an
expression, because conflicts arise considering nesting and use in arrays:

    yield yield $a => $b;
    // could be either
    yield (yield $a) => $b;
    // or
    yield (yield $a => $b);

Once I find some way to resolve these conflicts this should be available
as an expression too.

Also the key yielding code is rather copy-and-past-y for the value yielding
code, so that should be factored out.
2012-05-30 02:44:06 +02:00
Nikita Popov
ad525c288a Allow to use yield without value
If the generator is used as a coroutine it often doesn't make sense to yield
anything. In this case one can simply receive values using

    $value = yield;

The yield here will simply yield NULL.
2012-05-29 17:53:11 +02:00
Nikita Popov
3600914ced Add support for $generator->send()
Yield now is an expression and the return value is the value passed to
$generator->send(). By default (i.e. if ->next() is called) the value is
NULL.

Unlike in Python ->send() can be run without priming the generator with a
->next() call first.
2012-05-29 17:34:33 +02:00
Nikita Popov
b770b221e0 Make the GOTO and SWITCH VMs work again 2012-05-29 02:31:56 +02:00
Nikita Popov
4aab08b64c Properly free resources when generator return value not used
To keep things clean two new functions are introduced:

zend_clean_and_cache_symbol_table(HashTable *symbol_table)
zend_free_compiled_variables(zval ***CVs, int num)
2012-05-28 06:43:18 +02:00
Nikita Popov
9f52c5c226 Fix generator creation when execute_data is not nested
This happens primarily when the generator is invoked from some internal
place like a dynamic function call.
2012-05-27 22:48:21 +02:00
Nikita Popov
64a643a4e3 Free loop variables
If the generator is closed before it has finished running, it may happen
that some FREE or SWITCH_FREE opcodes haven't been executed and memory is
leaked.

This fixes it by walking the brk_cont_array and manually freeing the
variables.
2012-05-27 17:14:20 +02:00
Nikita Popov
247bb737d5 Add support for generator methods 2012-05-27 03:50:31 +02:00
Nikita Popov
d49d3971e6 Close generator on return 2012-05-26 23:59:22 +02:00
Nikita Popov
5bb3a995c2 Implement return for generators
For generators ZEND_RETURN directly calls ZEND_VM_RETURN(), thus passing
execution back to the caller (zend_generator_resume).

This commit also adds a check that only return; is used in generators and
not return $value;.
2012-05-26 23:07:40 +02:00
Nikita Popov
fafce58683 Add YIELD opcode implementation 2012-05-26 22:44:53 +02:00
Nikita Popov
f627be5254 Add support for executing a zend_execute_data
This adds another function execute_ex(), which accepts a zend_execute_data
struct to run (contrary to execute(), which accepts a zend_op_array from
which it initialized the execute_data).

This needs a bit more cleanup.
2012-05-26 17:53:13 +02:00
Nikita Popov
9ce9a7e639 Add initial code for suspending execution
This is just some initial code, which is still quite broken (and needs to be
moved so it can be reused.)
2012-05-23 14:20:25 +02:00
Nikita Popov
5e763d9420 Allocate execute_data using malloc for generators
Generators need to switch the execute_data very often. If the execute_data
is allocated on the VM stack this operation would require to always copy
the structure (which is quite large). That's why the execution context is
allocated on the heap instead (only for generators obviously).
2012-05-22 23:17:59 +02:00
Nikita Popov
46fa26ab85 Make generator functions return a Generator object
Right now generator functions simply immediately return a new Generator
object (no suspension yet).
2012-05-20 14:45:01 +02:00
Nikita Popov
1cec3f12cc Add ZEND_SUSPEND_AND_RETURN_GENERATOR opcode
If the function is a generator this opcode will be invoked right after
receiving the function arguments.

The current implementation is just a dummy.
2012-05-19 23:19:21 +02:00
Stanislav Malyshev
d03900dc92 fix bug #61782 - __clone/__destruct do not match other methods when checking access controls 2012-05-14 11:03:21 -07:00
Stanislav Malyshev
a0dff6fdca fix bug #61782 - __clone/__destruct do not match other methods when checking access controls 2012-05-13 14:40:44 -07:00
Xinchen Hui
565892d4c0 Implement const array/string dereference
RFC:https://wiki.php.net/rfc/constdereference
2012-04-17 10:06:17 +08:00
Xinchen Hui
0876d7bb89 MFH: Fixed bug #61011 (Crash when an exception is thrown by __autoload accessing a static property) 2012-03-02 03:12:15 +00:00
Xinchen Hui
229e55632d Fixed bug #61011 (Crash when an exception is thrown by __autoload accessing a static property) 2012-02-25 13:56:59 +00:00
Dmitry Stogov
3fe072f8a9 Fixed (disabled) inline-caching for ZEND_OVERLOADED_FUNCTION methods 2012-01-30 10:51:02 +00:00
Dmitry Stogov
c95937e902 Fixed (disabled) inline-caching for ZEND_OVERLOADED_FUNCTION methods 2012-01-30 10:51:02 +00:00
Xinchen Hui
3a8a5bc843 WS, merged from trunk cause this issue, sorry 2012-01-26 01:28:37 +00:00
Xinchen Hui
bbd6ab2054 WS, merged from trunk cause this issue, sorry 2012-01-26 01:28:37 +00:00
Xinchen Hui
1207451239 Fixed bug #60825 (Segfault when running symfony 2 tests) 2012-01-26 01:21:35 +00:00
Xinchen Hui
6b1d3b3d10 Re-fixed bug #60825 (Segfault when running symfony 2 tests) 2012-01-24 14:39:45 +00:00
Xinchen Hui
a222954a45 Re-fixed bug #60825 (Segfault when running symfony 2 tests) 2012-01-24 14:39:45 +00:00
Xinchen Hui
cf54cc736b Fixed bug #60825 (Segfault when running symfony 2 tests) 2012-01-21 17:13:53 +00:00
Felipe Pena
e4ca0ed09f - Year++ 2012-01-01 13:15:04 +00:00
Felipe Pena
8775a37559 - Year++ 2012-01-01 13:15:04 +00:00
Felipe Pena
4e19825281 - Year++ 2012-01-01 13:15:04 +00:00
Stanislav Malyshev
327a5828cd Fix warning on non-numeric offsets 2011-12-22 03:22:42 +00:00
Stanislav Malyshev
0610ca459a Fix warning on non-numeric offsets 2011-12-22 03:22:42 +00:00
Stanislav Malyshev
1f4f33afcf implement the solution for isset/string offsets, fix bug #60362 2011-12-19 02:05:03 +00:00
Stanislav Malyshev
622412d8e6 implement the solution for isset/string offsets, fix bug #60362 2011-12-19 02:05:03 +00:00
Dmitry Stogov
cacf363957 Fixed bug #60104 (Segmentation Fault in pdo_sqlite when using sqliteCreateFunction()) 2011-11-08 10:11:25 +00:00
Dmitry Stogov
e86830273b Fixed bug #60104 (Segmentation Fault in pdo_sqlite when using sqliteCreateFunction()) 2011-11-08 10:11:25 +00:00
Xinchen Hui
cae2f1381f Fix bug #60169 Conjunction of ternary and list crashes PHP 2011-11-03 03:59:41 +00:00
Xinchen Hui
a9dbbf6dea Fix bug #60169 Conjunction of ternary and list crashes PHP 2011-11-03 03:59:41 +00:00
Arnaud Le Blanc
ea5a61e39b Improved ternary operator performance when returning arrays 2011-10-18 19:42:42 +00:00
Arnaud Le Blanc
07b7ba8b40 Improved ternary operator performance when returning arrays 2011-10-18 19:42:42 +00:00
Dmitry Stogov
4a25a7740d Fixed ZE specific compile warnings (Bug #55629) 2011-09-13 13:29:35 +00:00
Dmitry Stogov
e43ff1359e Fixed ZE specific compile warnings (Bug #55629) 2011-09-13 13:29:35 +00:00
Dmitry Stogov
5e923d23b4 Fixed bug #55305 (ref lost: 1st ref instantiated in class def, 2nd ref made w/o instantiating) 2011-08-01 15:23:16 +00:00
Dmitry Stogov
d4a80cfa8d Fixed bug #55305 (ref lost: 1st ref instantiated in class def, 2nd ref made w/o instantiating) 2011-08-01 15:23:16 +00:00
Dmitry Stogov
ac1ae51a38 Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) 2011-07-11 10:31:49 +00:00
Dmitry Stogov
a0974f2d59 Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) 2011-07-11 10:31:49 +00:00
Dmitry Stogov
0f3e70fe01 Fixed bug #54305 (Crash in gc_remove_zval_from_buffer) 2011-07-11 10:31:49 +00:00
Felipe Pena
ae40e5f400 - Year++ 2011-07-10 13:05:32 +00:00
Felipe Pena
31a69cd480 - Year++ 2011-07-10 13:05:32 +00:00
Felipe Pena
327a9d45c9 - Year++ 2011-07-10 13:05:32 +00:00
Dmitry Stogov
3931078e7f Fixed bug #55135 (Array keys are no longer type casted in unset()) 2011-07-06 12:04:02 +00:00
Dmitry Stogov
b7e124004f Fixed bug #55135 (Array keys are no longer type casted in unset()) 2011-07-06 12:04:02 +00:00
Felipe Pena
66ac89a00b - Added indirect method call through array variable (FR Bug #47160) 2011-06-06 21:42:05 +00:00
Felipe Pena
be3889456b - Added indirect method call through array variable (FR Bug #47160) 2011-06-06 21:42:05 +00:00
Felipe Pena
32b5f8a1a3 - Added new parameter parsing option (p - for valid path (string without null byte in the middle))
# The tests will be fixed in the next commits
2011-06-06 21:28:16 +00:00
Felipe Pena
4737910b69 - Added new parameter parsing option (p - for valid path (string without null byte in the middle))
# The tests will be fixed in the next commits
2011-06-06 21:28:16 +00:00
Felipe Pena
68ff1463e7 - Restore fix for #39863 (do not accept paths with NULL in them)
# This was removed by regenerating the VM months ago
2011-06-06 02:34:38 +00:00
Dmitry Stogov
c270347c0b MFH: Arithmetic speedup. Inlined most probable code-paths for arithmetic operations directly into executor. 2011-05-31 12:05:25 +00:00
Dmitry Stogov
b7eb3c1c5a Arithmetic speedup. Inlined most probable code-paths for arithmetic operations directly into executor. 2011-05-23 08:05:44 +00:00
Dmitry Stogov
6eedfb9b3a Fixed direct threaded executor (php zend_vm_gen.php --with-vm-kind=GOTO) 2011-05-05 16:02:11 +00:00
Dmitry Stogov
e510daf20b Fixed bug #54585 (track_errors causes segfault) 2011-04-25 07:50:07 +00:00
Dmitry Stogov
9fb4cd1a91 Fixed bug #54585 (track_errors causes segfault) 2011-04-25 07:50:07 +00:00