diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 51cfa8ce..0b03f07b 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -84,6 +84,7 @@ class CompilerBase extends \PhpAot\Core\Translator 'phpx_func.h', 'php_func_decl.h', 'php_global_var_decl.h', + 'php_aot_helper.h', ]; protected array $localHeaders = []; protected array $nativeFunctions = []; @@ -1395,6 +1396,7 @@ class CompilerBase extends \PhpAot\Core\Translator $list = [ $this->phpxDir . '/include', $this->getBuildDir() . '/include', + $this->rootPath . '/src/cpp', ]; $out = '$(php-config --includes) '; foreach ($list as $li) { diff --git a/src/Php/Translator.php b/src/Php/Translator.php index dcf374dc..7b553775 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -294,12 +294,6 @@ class Translator extends Preprocessor foreach ($this->nativeConstants as $name => $constant) { $code .= 'extern ' . $constant->type . ' ' . $name . ';' . PHP_EOL; } - - $code .= 'extern zend_class_entry *php_get_class(int class_id, const char *class_name);' . PHP_EOL; - $code .= 'extern zend_function *php_get_func(int func_id, const char *func_name);' . PHP_EOL; - $code .= '#define CALL(id, name, args) php::call(php_get_func(id, name), args)' . PHP_EOL; - $code .= '#define CALL_SILENT(id, name, args) php::silentCall(php_get_func(id, name), args)' . PHP_EOL; - $this->writeFile($file, $code); } diff --git a/src/cpp/main.cc b/src/cpp/main.cc index d1da7ac8..61a28720 100644 --- a/src/cpp/main.cc +++ b/src/cpp/main.cc @@ -52,6 +52,7 @@ int main(int cpp_argc, char **cpp_argv) { #endif module->request_shutdown_func(module->type, module->module_number); + module_shutdown(module); php_embed_shutdown(); return rc; diff --git a/src/cpp/php_aot_helper.h b/src/cpp/php_aot_helper.h new file mode 100644 index 00000000..76136713 --- /dev/null +++ b/src/cpp/php_aot_helper.h @@ -0,0 +1,20 @@ +#include + +extern zend_class_entry *php_get_class(int class_id, const char *class_name); +extern zend_function *php_get_func(int func_id, const char *func_name); + +static inline php::Variant CALL(int func_id, const char *func_name, const std::initializer_list &args) { + return php::call(php_get_func(func_id, func_name), args); +} + +static inline php::Variant CALL(int func_id, const char *func_name) { + return php::call(php_get_func(func_id, func_name)); +} + +static inline php::Variant CALL_SILENT(int func_id, const char *func_name, const std::initializer_list &args) { + return php::silentCall(php_get_func(func_id, func_name), args); +} + +static inline php::Variant CALL_SILENT(int func_id, const char *func_name) { + return php::silentCall(php_get_func(func_id, func_name)); +}