2003-02-26 10:06:47 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class php_resource extends php_element {
|
2003-04-23 16:19:08 +00:00
|
|
|
|
function php_resource($name, $payload, $alloc, $destruct, $description) {
|
2003-02-26 10:06:47 +00:00
|
|
|
|
$this->name = $name;
|
|
|
|
|
$this->payload = $payload;
|
2003-04-23 16:19:08 +00:00
|
|
|
|
$this->alloc = $alloc;
|
2003-02-26 10:06:47 +00:00
|
|
|
|
$this->destruct = $destruct;
|
|
|
|
|
$this->description = $description;
|
|
|
|
|
|
|
|
|
|
if(empty($this->payload)) {
|
2003-04-23 16:19:08 +00:00
|
|
|
|
$this->payload = "void";
|
2003-02-26 10:06:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function docbook_xml($base) {
|
|
|
|
|
return "
|
|
|
|
|
<section id='$base.resources.{$this->name}'>
|
2003-03-15 22:35:34 +00:00
|
|
|
|
<title><literal>{$this->name}</literal></title>
|
2003-02-26 10:06:47 +00:00
|
|
|
|
<para>
|
|
|
|
|
{$this->description}
|
|
|
|
|
</para>
|
|
|
|
|
</section>
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function minit_code() {
|
|
|
|
|
return "
|
|
|
|
|
le_{$this->name} = zend_register_list_destructors_ex({$this->name}_dtor,
|
|
|
|
|
NULL,
|
|
|
|
|
\"{$this->name}\",
|
|
|
|
|
module_number);
|
|
|
|
|
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function c_code() {
|
2003-04-23 16:19:08 +00:00
|
|
|
|
$dtor = "
|
2003-02-26 10:06:47 +00:00
|
|
|
|
int le_{$this->name};
|
|
|
|
|
|
|
|
|
|
void {$this->name}_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
|
|
|
|
{
|
2003-04-23 16:19:08 +00:00
|
|
|
|
{$this->payload} * resource = ({$this->payload} *)(rsrc->ptr);
|
2003-02-26 10:06:47 +00:00
|
|
|
|
|
|
|
|
|
{$this->destruct}
|
|
|
|
|
";
|
2003-04-23 16:19:08 +00:00
|
|
|
|
|
|
|
|
|
if ($this->alloc === "yes") {
|
|
|
|
|
$dtor .= " efree(resource);\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dtor .= "}\n";
|
|
|
|
|
|
|
|
|
|
return $dtor;
|
2003-02-26 10:06:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function h_code() {
|
|
|
|
|
$upname = strtoupper($this->name);
|
|
|
|
|
|
|
|
|
|
return "
|
2003-04-23 16:19:08 +00:00
|
|
|
|
#define {$upname}_FETCH(r, z) ZEND_FETCH_RESOURCE(r, {$this->payload} *, z, -1, ${$this->name}, le_{$this->name<6D>}); \
|
2003-02-26 10:06:47 +00:00
|
|
|
|
if(!r) { RETURN_FALSE; }
|
|
|
|
|
|
|
|
|
|
#define {$upname}_REGISTER(r) ZEND_REGISTER_RESOURCE(return_value, r, le_{$this->name<6D>});
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|