Hi there,
I'm writing an extension (it'll be opensource), something inspired in
Python's ctypes (similar to http://pecl.php.net/package/ffi)
In order to make things a bit interesting, I allow to register
resources types from the userland (I don't know if this ok), and its
destructor is a function callback from the userland.
More or less like this,
<?php
use Ctypes\Resource;
use Ctypes\Library;
use CTypes\Type;
// Create new Resource Type
$memory = new Resource("memory");
// load library
$lib = new Library("/lib64/libc.so.6");
// create function proxies
$malloc = $lib->getFunction("malloc", /* return */ $memory, /*
prototype */ array(Type::tInteger));
$free = $lib->getFunction("free", NULL, array($memory));
// tell how to destroy the $memory resouces
$memory->setDestructor($free);
$memory = $malloc(250); /* do the malloc */
unset($memory); // This will call the $free.
?>
Anyways, I'm having issues while I'm destroying the objects. It
usually works, unless the program ends with an exception, then for
some reason, my callback is released before the resources (according
to valgrind, `zend_hash_graceful_reverse_destroy` is destroying my
resources). That's what I think is the issue but it could be another
thing also, I'm just a C wannabe developer :-)
My question is if there is there a way to release (zval *) a RSHUTDOWN
if it wasn't released yet? I could also call to Z_ADDREF_P to the
resources when I create them, but that would mean that all resources
will be destroyed at RSHUTDOWN, that won't be good for cli apps.
Cheers.
--
Cesar D. Rodas
Open source developer
http://cesarrodas.com/
Phone: +595-983-161-124
--
PECL development discussion Mailing List (http://pecl.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php