Permalink
Browse files

Fixed bug #38808 ("maybe ref" issue for current() and others)

  • Loading branch information...
1 parent a04b6ed commit c3272ab020f07bff10b44a57c91a30339b52a883 Dmitry Stogov committed Sep 26, 2006
Showing with 39 additions and 39 deletions.
  1. +1 −0 NEWS
  2. +17 −0 Zend/tests/bug38808.phpt
  3. +16 −34 Zend/zend_compile.h
  4. +1 −1 Zend/zend_vm_def.h
  5. +4 −4 Zend/zend_vm_execute.h
View
@@ -13,6 +13,7 @@ PHP NEWS
- Fixed bug #38891 (get_headers() do not work with curl-wrappers). (Ilia)
- Fixed bug #38844 (curl_easy_strerror() is defined only since cURL 7.12.0).
(Tony)
+- Fixed bug #38808 ("maybe ref" issue for current() and others). (Dmitry)
- Fixed bug #38623 (leaks in a tricky code with switch() and exceptions).
(Dmitry)
- Fixed bug #38579 (include_once() may include the same file twice). (Dmitry)
@@ -0,0 +1,17 @@
+--TEST--
+Bug #38808 ("maybe ref" issue for current() and others)
+--FILE--
+<?php
+$current = "current";
+$next = "next";
+
+$b = array(1=>'one', 2=>'two');
+$a =& $b;
+
+echo $current($a)."\n";
+$next($a);
+echo $current($a)."\n";
+?>
+--EXPECT--
+one
+two
View
@@ -663,40 +663,22 @@ int zendlex(znode *zendlval TSRMLS_DC);
#define ZEND_SEND_BY_REF 1
#define ZEND_SEND_PREFER_REF 2
-/* Lost In Stupid Parentheses */
-#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
- ( \
- zf \
- && ((zend_function *) zf)->common.arg_info \
- && \
- ( \
- ( \
- arg_num<=((zend_function *) zf)->common.num_args \
- && ((zend_function *) zf)->common.arg_info[arg_num-1].pass_by_reference == ZEND_SEND_BY_REF \
- ) \
- || ( \
- arg_num>((zend_function *) zf)->common.num_args \
- && ((zend_function *) zf)->common.pass_rest_by_reference == ZEND_SEND_BY_REF \
- ) \
- ) \
- )
-
-#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
- ( \
- zf \
- && ((zend_function *) zf)->common.arg_info \
- && \
- ( \
- ( \
- arg_num<=((zend_function *) zf)->common.num_args \
- && ((zend_function *) zf)->common.arg_info[arg_num-1].pass_by_reference == ZEND_SEND_PREFER_REF \
- ) \
- || ( \
- arg_num>((zend_function *) zf)->common.num_args \
- && ((zend_function *) zf)->common.pass_rest_by_reference == ZEND_SEND_PREFER_REF \
- ) \
- ) \
- )
+#define ARG_SEND_TYPE(zf, arg_num) \
+ ((zf) ? \
+ ((((zend_function*)(zf))->common.arg_info && \
+ arg_num<=((zend_function*)(zf))->common.num_args) ? \
+ ((zend_function *)(zf))->common.arg_info[arg_num-1].pass_by_reference : \
+ ((zend_function *)(zf))->common.pass_rest_by_reference) : \
+ ZEND_SEND_BY_VAL)
+
+#define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
+ (ARG_SEND_TYPE(zf, arg_num) == ZEND_SEND_BY_REF)
+
+#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
+ (ARG_SEND_TYPE(zf, arg_num) & (ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF))
+
+#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
+ (ARG_SEND_TYPE(zf, arg_num) == ZEND_SEND_PREFER_REF)
#define ZEND_RETURN_VAL 0
#define ZEND_RETURN_REF 1
View
@@ -2191,7 +2191,7 @@ ZEND_VM_HANDLER(65, ZEND_SEND_VAL, CONST|TMP|VAR|CV, ANY)
{
zend_op *opline = EX(opline);
if (opline->extended_value==ZEND_DO_FCALL_BY_NAME
- && ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
+ && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num);
}
{
@@ -1794,7 +1794,7 @@ static int ZEND_SEND_VAL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = EX(opline);
if (opline->extended_value==ZEND_DO_FCALL_BY_NAME
- && ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
+ && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num);
}
{
@@ -4320,7 +4320,7 @@ static int ZEND_SEND_VAL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = EX(opline);
if (opline->extended_value==ZEND_DO_FCALL_BY_NAME
- && ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
+ && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num);
}
{
@@ -7338,7 +7338,7 @@ static int ZEND_SEND_VAL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = EX(opline);
if (opline->extended_value==ZEND_DO_FCALL_BY_NAME
- && ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
+ && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num);
}
{
@@ -19377,7 +19377,7 @@ static int ZEND_SEND_VAL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
{
zend_op *opline = EX(opline);
if (opline->extended_value==ZEND_DO_FCALL_BY_NAME
- && ARG_SHOULD_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
+ && ARG_MUST_BE_SENT_BY_REF(EX(fbc), opline->op2.u.opline_num)) {
zend_error_noreturn(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num);
}
{

0 comments on commit c3272ab

Please sign in to comment.