- UID
- 2546
- 积分
- 159
- 帖子
- 30
- 主题
- 5
- 论坛币
- 868
- 威望
- 0
- EP值
- 134
- MP值
- 0
- 阅读权限
- 50
- 注册时间
- 2015-5-9
- 在线时间
- 52 小时
- 最后登录
- 2024-10-20
|
本帖最后由 Seekladoom 于 2022-3-31 04:19 编辑
def tcaxPy_Init的C语言源码定义- PY_Error_Code tcaxpy_init_user_py_module(PY_pTcaxPy pTcaxPy, const char *directory, const char *userPyFilename, int use_tcaxpy_init_func, int use_tcaxpy_user_func, int use_tcaxpy_fin_func) {
- PyObject *pyModule;
- char *pyModuleName;
- char *pyModuleDir;
- char *pyFilename;
- char *tokenFilename;
- char *pyModulePath;
- wchar_t *wcsPyModulePath;
- _tcaxpy_fin_user_py_module(pTcaxPy);
- _tcaxpy_get_py_module_name_and_dir(userPyFilename, &pyModuleName, &pyModuleDir);
- if (!pyModuleName) return py_error_null_pointer;
- if (!_tcaxpy_is_py_module_existed(userPyFilename, directory, pyModuleName, &pyFilename)) {
- free(pyModuleName);
- free(pyModuleDir);
- return py_error_file_not_found;
- }
- tcaxpy_convert_file_to_utf8(pyFilename);
- _tcaxpy_make_user_py_module_path(pyModuleDir, directory, &pyModulePath);
- free(pyModuleDir);
- _tcaxpy_sz_ansi_to_unicode(pyModulePath, &wcsPyModulePath);
- free(pyModulePath);
- PySys_SetPath(wcsPyModulePath);
- free(wcsPyModulePath);
- pyModule = PyImport_ImportModuleNoBlock(pyModuleName);
- free(pyModuleName);
- if (!pyModule) {
- PyErr_Print();
- /* PyErr_Clear(); */
- return py_error_init_fail;
- }
- tcaxpy_make_py_token_filename(pyFilename, &tokenFilename);
- if (tcaxpy_is_py_modified(pyFilename, tokenFilename) == py_error_file_modified) { /* check if we need to reload the module */
- free(pyFilename);
- free(tokenFilename);
- pTcaxPy->pyUserModule = PyImport_ReloadModule(pyModule); // refresh the module
- Py_CLEAR(pyModule);
- if (!pTcaxPy->pyUserModule) {
- PyErr_Print();
- /* PyErr_Clear(); */
- return py_error_init_fail;
- }
- } else {
- free(pyFilename);
- free(tokenFilename);
- pTcaxPy->pyUserModule = pyModule;
- }
- /* tcaxPy_Init (Alternative) */
- if (use_tcaxpy_init_func) {
- pTcaxPy->pyInitFunc = PyObject_GetAttrString(pTcaxPy->pyUserModule, TCAXPY_PY_FUNC_INIT);
- if (!pTcaxPy->pyInitFunc) {
- _tcaxpy_fin_user_py_module(pTcaxPy);
- PyErr_Print();
- /* PyErr_Clear(); */
- return py_error_init_fail;
- } else if (!PyCallable_Check(pTcaxPy->pyInitFunc)) {
- _tcaxpy_fin_user_py_module(pTcaxPy);
- return py_error_init_fail;
- }
- }
复制代码 |
|