Commit Graph

405 Commits

Author SHA1 Message Date
Xinchen Hui
62059c16ee Fixed bug #63980 (object members get trimmed by zero bytes) 2013-01-14 16:23:22 +08:00
Xinchen Hui
a666285bc2 Happy New Year 2013-01-01 16:37:09 +08:00
Nikita Popov
ffb848b275 Fix bug #63822: Crash when using closures with ArrayAccess
op_array->T was used after the closure's op_array was already freed. This just
swaps the freeing order.
2012-12-21 01:56:37 +01:00
Nikita Popov
d53f1bf8ab Fix leak when generator ignores sent value
When the return value of yield wasn't used it was leaked.

This is fixed by using a TMP_VAR return value instead of VAR. TMP_VARs are
automatically freed when they aren't used.
2012-12-18 21:39:02 +01:00
Xinchen Hui
9fb5cfdeb1 Fixed warning of no return in non-void funciton 2012-12-14 17:21:43 +08:00
Dmitry Stogov
e65b966aac Fixed uninitialized EX(call)->called_scope 2012-12-14 12:10:29 +04:00
Dmitry Stogov
d5c2da5756 Removed unreachable code 2012-12-13 17:51:04 +04:00
Dmitry Stogov
438cd86378 Removed unnecessary checks 2012-12-13 17:29:30 +04:00
Dmitry Stogov
6b0b4bf8eb An exception thrown in try or catch block is disacarded by return statement in finally block. 2012-12-13 02:48:51 +04:00
Dmitry Stogov
9c96fe52d9 Restored proper generators behaviour in conjunction with "finally". (Nikita) 2012-12-12 17:47:55 +04:00
Dmitry Stogov
a9a5f7aca6 - generators API exported for extensions
- improved RETURN sequence to avoid redundant check if op_array is a generator
2012-12-11 17:25:32 +04:00
Dmitry Stogov
e3b2a5cf74 Generatirs are going to be used less than regular functions 2012-12-06 13:14:31 +04:00
Dmitry Stogov
fa30e4754b Slight performance improvement 2012-12-05 13:23:37 +04:00
Dmitry Stogov
61dbf35cfc Moved zend_create_execute_data_from_op_array() implementation from zend_vm_execute.skl to zend_execute.c 2012-12-04 10:42:19 +04:00
Dmitry Stogov
7651d64556 Optimized access to temporary and compiled VM variables 2012-12-04 10:14:39 +04:00
Dmitry Stogov
70f83f35d0 . The VM stacks for passing function arguments and syntaticaly nested calls were merged into a single stack. The stack size needed for op_array execution is calculated at compile time and preallocated at once. As result all the stack push operatins don't require checks for stack overflow any more.
. Generators implementation was improved using the new VM stack. Now it's a bit more clear and faster.
2012-11-30 13:39:23 +04:00
Dmitry Stogov
eb4825b50b Improved "finally" im[plementation 2012-11-22 15:17:05 +04:00
Xinchen Hui
7bcb8780e0 Fixed bug #63428 (The behavior of execute() changed) 2012-11-04 12:48:35 +08:00
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
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