Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27540 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25239 invoked by uid 1010); 19 Jan 2007 17:14:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 25213 invoked from network); 19 Jan 2007 17:14:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2007 17:14:11 -0000 X-Host-Fingerprint: 85.177.36.139 e177036139.adsl.alicedsl.de Received: from [85.177.36.139] ([85.177.36.139:6608] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/71-03951-16CF0B54 for ; Fri, 19 Jan 2007 12:14:10 -0500 To: internals@lists.php.net,Lars Schultz Message-ID: <45B0FC43.1090708@web.de> Date: Fri, 19 Jan 2007 18:13:39 +0100 User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 References: <45B0E1EE.2030102@widescreen.ch> In-Reply-To: <45B0E1EE.2030102@widescreen.ch> Content-Type: multipart/mixed; boundary="------------050703000807030606060206" X-Posted-By: 85.177.36.139 Subject: Re: PHP Object-Caching and Reference Counting From: akorthaus@web.de (Andreas Korthaus) --------------050703000807030606060206 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi! Lars Schultz wrote: > > As you can see I boldly used the function reference_count(Object) even > though it doesn't exist. This is exactly what I'd need to allow my > concept to work. Some time ago I created a patch to implement a ref_count() function which works the way you suggested. But I'm not sure if it's OK/complete... and I'm not sure if something like that is really needed in the core (and I'm definetly not the person to decide on that ;-)). Anyway, I attatched a simple patch against current 5_2 branch to this mail, perhaps it helps. Best regards Andreas --------------050703000807030606060206 Content-Type: text/plain; name="ref_count_patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ref_count_patch.txt" Index: basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.725.2.31.2.39 diff -u -r1.725.2.31.2.39 basic_functions.c --- basic_functions.c 1 Jan 2007 09:36:08 -0000 1.725.2.31.2.39 +++ basic_functions.c 19 Jan 2007 17:04:39 -0000 @@ -3040,6 +3040,11 @@ /* }}} */ /* {{{ var.c */ static +ZEND_BEGIN_ARG_INFO(arginfo_ref_count, 0) + ZEND_ARG_INFO(0, var) +ZEND_END_ARG_INFO() + +static ZEND_BEGIN_ARG_INFO_EX(arginfo_var_dump, 0, 0, 1) ZEND_ARG_INFO(0, var) ZEND_ARG_INFO(0, ...) @@ -3384,6 +3389,7 @@ PHP_FE(serialize, arginfo_serialize) PHP_FE(unserialize, arginfo_unserialize) + PHP_FE(ref_count, arginfo_ref_count) PHP_FE(var_dump, arginfo_var_dump) PHP_FE(var_export, arginfo_var_export) PHP_FE(debug_zval_dump, arginfo_debug_zval_dump) Index: php_var.h =================================================================== RCS file: /repository/php-src/ext/standard/php_var.h,v retrieving revision 1.30.2.1.2.5 diff -u -r1.30.2.1.2.5 php_var.h --- php_var.h 1 Jan 2007 09:36:08 -0000 1.30.2.1.2.5 +++ php_var.h 19 Jan 2007 17:04:39 -0000 @@ -23,6 +23,7 @@ #include "ext/standard/php_smart_str_public.h" +PHP_FUNCTION(ref_count); PHP_FUNCTION(var_dump); PHP_FUNCTION(var_export); PHP_FUNCTION(debug_zval_dump); Index: var.c =================================================================== RCS file: /repository/php-src/ext/standard/var.c,v retrieving revision 1.203.2.7.2.14 diff -u -r1.203.2.7.2.14 var.c --- var.c 1 Jan 2007 09:36:09 -0000 1.203.2.7.2.14 +++ var.c 19 Jan 2007 17:04:39 -0000 @@ -39,6 +39,21 @@ #define Z_REFCOUNT_PP(a) ((*a)->refcount) /* }}} */ +/* {{{ proto int ref_count(mixed var) + return the number of references pointing to a var */ +PHP_FUNCTION(ref_count) +{ + zval *var; + int cnt = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == FAILURE) { + RETURN_NULL(); + } + + cnt = var->refcount; + RETURN_LONG (cnt); +}; +/* }}} */ /* {{{ php_var_dump */ static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) --------------050703000807030606060206--