TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua
标题:
def tcaxPy_Init的C语言源码定义【来源:py.c】
[打印本页]
作者:
Seekladoom
时间:
2022-3-31 04:19:01
标题:
def tcaxPy_Init的C语言源码定义【来源:py.c】
本帖最后由 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;
}
}
复制代码
欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/)
Powered by Discuz! X2