Skip to content

Commit 42254b3

Browse files
make sure the function name we replace is not for,while and if
1 parent fb4f0ef commit 42254b3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/PHPtoCExt/Converter/CFuntionCallConverter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ public function convert()
9797
//read the c source file content
9898
$cSourceCode = file_get_contents($this->inputDir."/".$cSourceFile);
9999
//prepend file name on each defined c functions
100-
$cSourceCode = preg_replace_callback("|[a-zA-Z0-9_]+\(.*\)([\s]*){|",function($matches) use (&$cSourceFile) {
100+
$cSourceCode = preg_replace_callback("|[a-zA-Z0-9_]+[\s]*\(.*\)([\s]*){|",function($matches) use (&$cSourceFile) {
101101
if (count($matches) > 0 && strlen($matches[0]) > 0) {
102-
return explode(".",$cSourceFile)[0]."_".$matches[0];
102+
//tricky, need to make sure it is not if, for and while
103+
$functionName = trim(substr($matches[0], 0, strpos($matches[0],"(")));
104+
if ( $functionName !== "for" && $functionName !== "while" && $functionName!== "if" ) {
105+
return explode(".",$cSourceFile)[0]."_".$matches[0];
106+
} else {
107+
return $matches[0];
108+
}
103109
}
104110
},$cSourceCode);
105111
$cSourceCodeMap[$classNameCSourceFileKey] = $cSourceCode;

0 commit comments

Comments
 (0)