cvs: pear /CodeGen_PECL/PECL Extension.php /CodeGen_PECL/PECL/Element Function.php Method.php
| From: | Hartmut Holzgraefe | Date: | Mon, 06 Mar 2006 20:38:40 +0000 |
| Subject: | cvs: pear /CodeGen_PECL/PECL Extension.php /CodeGen_PECL/PECL/Element Function.php Method.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38954@lists.php.net to get a copy of this message | ||
hholzgra Mon Mar 6 20:38:40 2006 UTC
Modified files:
/pear/CodeGen_PECL/PECL Extension.php
/pear/CodeGen_PECL/PECL/Element Function.php Method.php
Log:
improved pass-by-reference handling (untested)
http://cvs.php.net/viewcvs.cgi/pear/CodeGen_PECL/PECL/Extension.php?r1=1.41&r2=1.42&diff_format=u
Index: pear/CodeGen_PECL/PECL/Extension.php
diff -u pear/CodeGen_PECL/PECL/Extension.php:1.41 pear/CodeGen_PECL/PECL/Extension.php:1.42
--- pear/CodeGen_PECL/PECL/Extension.php:1.41 Fri Feb 17 19:09:17 2006
+++ pear/CodeGen_PECL/PECL/Extension.php Mon Mar 6 20:38:40 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Extension.php,v 1.41 2006/02/17 19:09:17 hholzgra Exp $
+ * @version CVS: $Id: Extension.php,v 1.42 2006/03/06 20:38:40 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen_PECL
*/
@@ -922,7 +922,7 @@
$code = "/* {{{ {$this->name}_functions[] */\n";
$code .= "function_entry {$this->name}_functions[] = {\n";
foreach ($this->functions as $function) {
- $code .= sprintf(" PHP_FE(%-20s, NULL)\n", $function->getName());
+ $code.= $function->functionEntry();
}
foreach ($this->classes as $class) {
$code.= $class->functionAliasEntries();
http://cvs.php.net/viewcvs.cgi/pear/CodeGen_PECL/PECL/Element/Function.php?r1=1.25&r2=1.26&diff_format=u
Index: pear/CodeGen_PECL/PECL/Element/Function.php
diff -u pear/CodeGen_PECL/PECL/Element/Function.php:1.25
pear/CodeGen_PECL/PECL/Element/Function.php:1.26
--- pear/CodeGen_PECL/PECL/Element/Function.php:1.25 Mon Feb 20 18:22:59 2006
+++ pear/CodeGen_PECL/PECL/Element/Function.php Mon Mar 6 20:38:40 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Function.php,v 1.25 2006/02/20 18:22:59 hholzgra Exp $
+ * @version CVS: $Id: Function.php,v 1.26 2006/03/06 20:38:40 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -240,6 +240,13 @@
protected $optional = 0;
/**
+ * Does this function have by-reference parameters?
+ *
+ * @var bool
+ */
+ protected $hasRefArgs = false;
+
+ /**
* Set parameter and return value information from PHP style prototype
*
* @access public
@@ -454,10 +461,11 @@
}
}
- // return by reference?
+ // pass by reference?
if (count($tokens) && $tokens[0][0] === 'char' &&
$tokens[0][1] === '&') {
list($type, $token) = array_shift($tokens);
$param['byRef'] = true;
+ $this->hasRefArgs = true;
}
// any tokens left?
@@ -1132,7 +1140,7 @@
break;
}
- if (empty($param['byRef']) && $param['type'] !=
'object') {
+ if (empty($param['byRef']) && ($param['type']
== 'mixed' || $param['type'] == 'array')) {
$argString .= "/";
} else if (!$zvalType) {
// TODO: pass by ref for 'simple' types requires further
thinking
@@ -1429,46 +1437,38 @@
/**
- * Code needed ahead of the method table
+ * Code needed ahead of the function table
*
- * Abstract/Interface methods need to define their argument
- * list ahead of the method table
+ * Only required for functions that accept parameters by reference
*
* @returns string
*/
function argInfoCode() {
$code = "";
- if (count($this->params) > 1) {
- $code.= "ZEND_BEGIN_ARG_INFO(".$this->getFullName()."_args,
0)\n";
-
- $params = $this->params;
- array_shift($params);
-
- $useTypeHints = true;
-
- foreach($params as $param) {
- if ($param['type'] != "object" ||
!isset($param['subtype'])) {
- $useTypeHints = false;
- break;
- }
+ // generate refargs mask if needed
+ if ($this->hasRefArgs) {
+ $code.= "ZEND_BEGIN_ARG_INFO({$this->name}_arg_info, 0)\n";
+ foreach ($this->params as $param)
+ {
+ $code.= " ZEND_ARG_PASS_INFO(". (isset($param["byRef"]) ?
1 : 0) .")\n";
}
-
- // TODO optional paramteres?
- foreach($params as $param) {
- $byRef = empty($param["byRef"]) ? 0 : 1;
- if ($useTypeHints) {
- $code.= " ZEND_ARG_OBJ_INFO(0, $param[name], $param[subtype],
0)\n";
- } else {
- $code.= " ZEND_ARG_INFO($byRef, $param[name])\n";
- }
- }
-
$code.= "ZEND_END_ARG_INFO()\n";
}
return $code;
}
+
+ /**
+ * Generate registration entry for extension function table
+ *
+ * @return string
+ */
+ function functionEntry()
+ {
+ $arginfo = $this->hasRefArgs ? "{$this->name}_arg_info" :
"NULL";
+ return sprintf(" PHP_FE(%-20s, %s)\n", $this->name, $arginfo);
+ }
}
?>
http://cvs.php.net/viewcvs.cgi/pear/CodeGen_PECL/PECL/Element/Method.php?r1=1.14&r2=1.15&diff_format=u
Index: pear/CodeGen_PECL/PECL/Element/Method.php
diff -u pear/CodeGen_PECL/PECL/Element/Method.php:1.14
pear/CodeGen_PECL/PECL/Element/Method.php:1.15
--- pear/CodeGen_PECL/PECL/Element/Method.php:1.14 Fri Feb 17 09:58:58 2006
+++ pear/CodeGen_PECL/PECL/Element/Method.php Mon Mar 6 20:38:40 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Method.php,v 1.14 2006/02/17 09:58:58 hholzgra Exp $
+ * @version CVS: $Id: Method.php,v 1.15 2006/03/06 20:38:40 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -425,6 +425,48 @@
return $test;
}
+ /**
+ * Code needed ahead of the method table
+ *
+ * Abstract/Interface methods need to define their argument
+ * list ahead of the method table
+ *
+ * @returns string
+ */
+ function argInfoCode() {
+ $code = "";
+
+ if (count($this->params) > 0) {
+ $code.= "ZEND_BEGIN_ARG_INFO(".$this->getFullName()."_args,
0)\n";
+
+ $params = $this->params;
+ array_shift($params);
+
+ $useTypeHints = true;
+
+ foreach($params as $param) {
+ if ($param['type'] != "object" ||
!isset($param['subtype'])) {
+ $useTypeHints = false;
+ break;
+ }
+ }
+
+ // TODO optional paramteres?
+ foreach($params as $param) {
+ $byRef = empty($param["byRef"]) ? 0 : 1;
+ if ($useTypeHints) {
+ $code.= " ZEND_ARG_OBJ_INFO(0, $param[name], $param[subtype],
0)\n";
+ } else {
+ $code.= " ZEND_ARG_INFO($byRef, $param[name])\n";
+ }
+ }
+
+ $code.= "ZEND_END_ARG_INFO()\n";
+ }
+
+ return $code;
+ }
+
}