1 Star 0 Fork 345

衣小白 / swoole-src

forked from swoole / swoole-src 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
php_swoole_cxx.cc 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
twosee 提交于 2019-09-17 15:25 . Fix compilation
#include "php_swoole_cxx.h"
bool zend::include(std::string file)
{
zend_file_handle file_handle;
int ret = php_stream_open_for_zend_ex(file.c_str(), &file_handle, USE_PATH | STREAM_OPEN_FOR_INCLUDE);
if (ret != SUCCESS)
{
return false;
}
zend_string *opened_path;
if (!file_handle.opened_path)
{
file_handle.opened_path = zend_string_init(file.c_str(), file.length(), 0);
}
opened_path = zend_string_copy(file_handle.opened_path);
zval dummy;
zval retval;
zend_op_array *new_op_array;
ZVAL_NULL(&dummy);
if (zend_hash_add(&EG(included_files), opened_path, &dummy))
{
new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE);
zend_destroy_file_handle(&file_handle);
}
else
{
new_op_array = NULL;
zend_file_handle_dtor(&file_handle);
}
zend_string_release(opened_path);
if (!new_op_array)
{
return false;
}
zend_execute(new_op_array, &retval);
destroy_op_array(new_op_array);
efree(new_op_array);
return Z_TYPE(retval) == IS_TRUE;
}
//for compatibly with dis_eval
zend_op_array* (*old_compile_string)(zval *source_string, ZEND_STR_CONST char *filename);
zend_op_array* zend::swoole_compile_string(zval *source_string, ZEND_STR_CONST char *filename)
{
zend_op_array *opa = old_compile_string(source_string, filename);
opa->type = ZEND_USER_FUNCTION;
return opa;
}
bool zend::eval(std::string code, std::string filename)
{
old_compile_string = zend_compile_string;
//overwrite
zend_compile_string = swoole_compile_string;
int ret = (zend_eval_stringl((char*) code.c_str(), code.length(), nullptr, (char *) filename.c_str()) == SUCCESS);
//recover
zend_compile_string = old_compile_string;
return ret;
}
C
1
https://gitee.com/yihaibin/swoole.git
git@gitee.com:yihaibin/swoole.git
yihaibin
swoole
swoole-src
master

搜索帮助