Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ircmaxell committed Oct 1, 2014
2 parents d04fd50 + c02afb8 commit 9d2dae7
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions lib/ReckiCT/Compiler/PECL/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ protected function generateCFile($moduleName, array $funcs) {
$code .= "#endif\n";
$code .= "#include \"php.h\"\n";
$code .= "#include \"php_{$moduleName}.h\"\n";

$code .= "typedef struct _reckistring { char *string; int length; } reckistring;\n";

foreach ($funcs as $func) {
$code .= "PHP_FUNCTION({$func->name});\n";
Expand All @@ -127,10 +129,16 @@ protected function generateCFile($moduleName, array $funcs) {
$zppArgs = '';
$callArgs = '';
foreach ($func->params as $param) {
$code .= $param[1] . ' ' . $param[0] . ";\n";
$code .= $this->convertToCType($param[1]) . ' ' . $param[0] . ";\n";
$zppType .= $this->getZppFromType($param[1]);
$zppArgs .= ', &' . $param[0];

$callArgs .= $param[0] . ', ';
if ($zppType == 's') {
$zppArgs .= ', &' . $param[0] . '.string, &' . $param[0] . '.length';
} else {
$zppArgs .= ', &' . $param[0];
}

}
$code .= "if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \"{$zppType}\"{$zppArgs}) == FAILURE) {return;}\n";
if ($func->returnType != 'void') {
Expand Down Expand Up @@ -193,6 +201,8 @@ protected function generateRetvalStatement($type) {
return 'RETURN_DOUBLE(reckiretval);';
case 'zend_bool':
return 'RETURN_BOOL(reckiretval);';
case 'reckistring':
return 'RETURN_STRINGL(reckiretval.string, reckiretval.length, 1);';
}
throw new \RuntimeException('Retval Type Not Implemented: ' . $type);
}
Expand All @@ -201,7 +211,7 @@ protected function getZppFromType($type) {
switch ($type) {
case 'long':
return 'l';
case 'char *':
case 'string':
return 's';
case 'zend_bool':
return 'b';
Expand All @@ -214,7 +224,7 @@ protected function getZppFromType($type) {
protected function generateInternalFuncSignature($func) {
$code = $func->returnType . " recki_if_{$func->name}(";
foreach ($func->params as $param) {
$code .= $param[1] . ' ' . $param[0] . ', ';
$code .= $this->convertToCType($param[1]) . ' ' . $param[0] . ', ';
}
$code .= "int *validReturn)";
return $code;
Expand Down Expand Up @@ -280,6 +290,10 @@ protected function buildFunction(array $func, $obj) {
$code .= "if (*validReturn != SUCCESS) { return; }\n";
break;
case 'functioncall':
if ($func[$i][1] == 'strlen') {
$code .= $scope[$func[$i][count($func[$i]) - 1]] . ' = ' . $scope[$func[$i][2]] . '.length;';
break;
}
$code .= $scope[$func[$i][count($func[$i]) - 1]] . ' = recki_if_' . strtolower($func[$i][1]) . '(';
for ($j = 2; $j < count($func[$i]) - 1; $j++) {
$code .= $scope[$func[$i][$j]] . ', ';
Expand Down Expand Up @@ -322,7 +336,7 @@ protected function convertToCType($what) {
case 'double':
return 'double';
case 'string':
return 'char *';
return 'reckistring';
case 'bool':
return 'zend_bool';
case 'void':
Expand All @@ -349,7 +363,8 @@ protected function printConstant(array $const) {
case 'bool':
return (int) $const[3];
case 'string':
return '\"' . addslashes(base64_decode($const[3])) . '\"';
$val = base64_decode($const[3]);
return '{"' . addslashes($val) . '", ' . strlen($val) . '}';
}
throw new \RuntimeException("Unknown constant type {$const[2]} with value {$const[3]}");
}
Expand Down

0 comments on commit 9d2dae7

Please sign in to comment.