quick API question re refcounts in c-modules.
| From: | Thies C. Arntzen | Date: | Thu, 09 Dec 1999 20:23:14 +0000 |
| Subject: | quick API question re refcounts in c-modules. | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-7736@lists.php.net to get a copy of this message | ||
i've just impleneted xml_set_object(&$this) to make the xml-module use
methods of $this for it's callbacks.
i tried to do some fancy refcount stuff in xml.c but had big problems with
it - so i took it out again (see xml.c) - problem is;
<?
call xml
{ var $parser;
function xml()
{ $this->parser = xml_parser_create();
xml_set_object(&$this);
}
}
$myo = new xml();
?>
the initial idea was to zval_add_ref for $this when calling
xml_set_object() and zval_del_ref it when the $parser resource gets
destructed.
now $this->parser is going to be destructed when $myo gets destructed, and
doing another zval_del_ref in the xml_parser_dtor causes real trouble.
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).
here's a test-script:
?
class xml {
var $parser;
function xml()
{ $this->parser = xml_parser_create();
xml_set_object($this->parser,&$this);
xml_set_element_handler($this->parser,"tag_open","tag_close");
xml_set_character_data_handler($this->parser,"cdata");
}
function parse($data)
{ xml_parse($this->parser,$data);
}
function tag_open($parser,$tag,$attributes) { var_dump($parser,$tag,$attributes); }
function cdata($parser,$cdata) { var_dump($parser,$cdata); }
function tag_close($parser,$tag) { var_dump($parser,$tag); }
}
$xml_parser = new xml();
$xml_parser->parse("<A ID=\"hallo\"> a </A>");
?>
un-comment the add_ref and del_ref stuff in xml.c and you'll see what i mean.
regards,
tc