TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 2545|回复: 0

[其他代码] def tcaxPy_Init的C语言源码定义【来源:py.c】 [复制链接]

Rank: 4

发表于 2022-3-31 04:19:01 |显示全部楼层
本帖最后由 Seekladoom 于 2022-3-31 04:19 编辑

def tcaxPy_Init的C语言源码定义
  1. 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) {
  2.     PyObject *pyModule;
  3.     char *pyModuleName;
  4.     char *pyModuleDir;
  5.     char *pyFilename;
  6.     char *tokenFilename;
  7.     char *pyModulePath;
  8.     wchar_t *wcsPyModulePath;
  9.     _tcaxpy_fin_user_py_module(pTcaxPy);
  10.     _tcaxpy_get_py_module_name_and_dir(userPyFilename, &pyModuleName, &pyModuleDir);
  11.     if (!pyModuleName) return py_error_null_pointer;
  12.     if (!_tcaxpy_is_py_module_existed(userPyFilename, directory, pyModuleName, &pyFilename)) {
  13.         free(pyModuleName);
  14.         free(pyModuleDir);
  15.         return py_error_file_not_found;
  16.     }
  17.     tcaxpy_convert_file_to_utf8(pyFilename);
  18.     _tcaxpy_make_user_py_module_path(pyModuleDir, directory, &pyModulePath);
  19.     free(pyModuleDir);
  20.     _tcaxpy_sz_ansi_to_unicode(pyModulePath, &wcsPyModulePath);
  21.     free(pyModulePath);
  22.     PySys_SetPath(wcsPyModulePath);
  23.     free(wcsPyModulePath);
  24.     pyModule = PyImport_ImportModuleNoBlock(pyModuleName);
  25.     free(pyModuleName);
  26.     if (!pyModule) {
  27.         PyErr_Print();
  28.         /* PyErr_Clear(); */
  29.         return py_error_init_fail;
  30.     }
  31.     tcaxpy_make_py_token_filename(pyFilename, &tokenFilename);
  32.     if (tcaxpy_is_py_modified(pyFilename, tokenFilename) == py_error_file_modified) {    /* check if we need to reload the module */
  33.         free(pyFilename);
  34.         free(tokenFilename);
  35.         pTcaxPy->pyUserModule = PyImport_ReloadModule(pyModule);  // refresh the module
  36.         Py_CLEAR(pyModule);
  37.         if (!pTcaxPy->pyUserModule) {
  38.             PyErr_Print();
  39.             /* PyErr_Clear(); */
  40.             return py_error_init_fail;
  41.         }
  42.     } else {
  43.         free(pyFilename);
  44.         free(tokenFilename);
  45.         pTcaxPy->pyUserModule = pyModule;
  46.     }
  47.     /* tcaxPy_Init (Alternative) */
  48.     if (use_tcaxpy_init_func) {
  49.         pTcaxPy->pyInitFunc = PyObject_GetAttrString(pTcaxPy->pyUserModule, TCAXPY_PY_FUNC_INIT);
  50.         if (!pTcaxPy->pyInitFunc) {
  51.             _tcaxpy_fin_user_py_module(pTcaxPy);
  52.             PyErr_Print();
  53.             /* PyErr_Clear(); */
  54.             return py_error_init_fail;
  55.         } else if (!PyCallable_Check(pTcaxPy->pyInitFunc)) {
  56.             _tcaxpy_fin_user_py_module(pTcaxPy);
  57.             return py_error_init_fail;
  58.         }
  59.     }
复制代码
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-3-29 18:50

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH