Re: [PHP4BETA] quick API question re refcounts in c-modules.

From: Date: Thu, 09 Dec 1999 21:08:34 +0000
Subject: Re: [PHP4BETA] quick API question re refcounts in c-modules.
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-7740@lists.php.net to get a copy of this message
At 22:45 09/12/1999 , Thies C. Arntzen wrote:
On Thu, 9 Dec 1999, Zeev Suraski wrote: At 22:23 09/12/1999 , Thies C. Arntzen wrote:
this is by no way really important, but i'd like to understand how we want to handle recursive refs like this ($this->parser is a resource keeping a ref of $this).
I haven't really read your entire letter, I just glanced through this, so there's a (small?) chance that I got it wrong. But as soon as I read the above sentence, the simple answer that came to mind is that you simply can't. The reference mechanism in PHP 4.0 wasn't designed for building fancy data structures such as recursive lists, and its behavior does prevent you from doing that sort of stuff (that is, it's not that it is unstable, it's just that its designed behavior doesn't fit the purposes of recursive data structures). ok, 2nd try (to explain) - a c-module receive a ref to a php-var. - instead of "just-do-and-forget" this function want's to keep that ref for some time (see docs for ocibindbyname) -> so the c-module does an zval_add_ref() for that php-var. - this ref to php-var is kept in a zend-resource (eg an oracle-cursor) - when this resource (eg oracle-resource) gets destructed, it calles zval_del_ref() for the remembered references to php-vars. so far i hop you do agree... (i really do;-) problem is now when i do this inside an object with a reference to the object itself (my xml question from the 1st mail). got me?
Yeah, I think so. At least one problem here would be at destruction; Before you get to destroy the object, its reference count is 2. When you assign something to it, or destroy it otherwise, its reference count goes down to 1. That doesn't trigger anything, since the reference count didn't hit zero. Until the ->parser property is explicitly destroyed, the resource will not be freed. As I said, self referencing is 'not meant to be' the way Zend is implemented (I'm not sure self referencing works too well in a value-reference-counted environment in general; From my experience in PHP and another project, it doesn't, even though in C++ you have more tools to handle the problem). Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.version4 (#7740) next »