Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:18315 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2476 invoked by uid 1010); 23 Aug 2005 18:47:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 2461 invoked from network); 23 Aug 2005 18:47:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Aug 2005 18:47:22 -0000 X-Host-Fingerprint: 69.12.155.130 69-12-155-130.dsl.static.sonic.net Linux 2.4/2.6 Received: from ([69.12.155.130:4133] helo=pigeon.alphaweb.net) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 74/2E-28235-93F6B034 for ; Tue, 23 Aug 2005 14:47:21 -0400 Received: from localhost ([127.0.0.1] helo=peiscg33m) by pigeon.alphaweb.net with smtp (Exim 4.10) id 1E7dAx-0004QY-00 for internals@lists.php.net; Tue, 23 Aug 2005 11:07:07 -0700 Message-ID: <004501c5a813$1691dc30$5c8be5a9@ohr.berkeley.edu> Reply-To: "Sara Golemon" To: Date: Tue, 23 Aug 2005 11:47:15 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Subject: Returning References from Internal Functions From: pollita@php.net ("Sara Golemon") I've got a one-line fix to allow internal functions to return by reference. What happens currently is if (*return_value_ptr)->refcount <= 2 at the end of an internal function, then the _get_zval_ptr_ptr_var delrefs it down to refcount==1 (removing is_ref in the process). With userspace functions ASSIGN_REF can handle this since EX_T(opline->result.u.var).var.fcall_returned_reference is set appropriately in fcall_common_helper. With internal functions, this value is never set. The following one-liner change to Zend/zend_vm_def.h sets this value if the function has declared itself to return reference (based on arg_info data), and the value in return_value_ptr is in fact set to is_ref. Two question: (1) Is it okay for me to just commit this (Andi? Zeev?), (2) Should this fix be applied to 5.1 and 5.0 branches as well? Note: It doesn't directly apply to 4.x branches since they have no return_value_ptr, nor arg_info hinting. I havn't actually looked at the PHP_4_4 branch to see if it has a similar problem. -Sara Index: zend_vm_def.h =================================================================== RCS file: /repository/ZendEngine2/zend_vm_def.h,v retrieving revision 1.68 diff -u -r1.68 zend_vm_def.h --- zend_vm_def.h 19 Aug 2005 13:20:14 -0000 1.68 +++ zend_vm_def.h 23 Aug 2005 18:38:28 -0000 @@ -1883,6 +1883,8 @@ EX_T(opline->result.u.var).var.ptr->refcount = 1; } */ + EX_T(opline->result.u.var).var.fcall_returned_reference = EX(function_state).function->common.return_reference && EX_T(opline->result.u.var).var.ptr->is_ref; + if (!return_value_used) { zval_ptr_dtor(&EX_T(opline->result.u.var).var.ptr); }