我正在尝试使用 Tclapi 为 Tcl 编写一个自定义文件系统(它与工作相关,不会详细介绍),但我一直试图弄清楚为什么这不起作用。
在这个代码段中,我得到了原始/本地 Tcl_Filesystem,将其所有内容(函数指针)复制到 my_fs,然后在 my_fs 上调用 Tcl_FSRegister。很简单,认为它应该工作。
// global scope
const Tcl_Filesystem *ori_fs;
Tcl_Filesystem *my_fs;
...
// in Init
// Get the original Tcl_Filesystem.
Tcl_Obj *root_obj = Tcl_NewStringObj("/", -1);
Tcl_IncrRefCount(root_obj);
ori_fs = Tcl_FSGetFileSystemForPath(root_obj);
Tcl_DecrRefCount(root_obj);
// create a duplicate of the original Tcl_Filesystem struct.
my_fs = malloc(sizeof(Tcl_Filesystem));
memmove(my_fs, ori_fs, ori_fs->structureLength);
int ret = Tcl_FSRegister((ClientData)1, my_fs);
if (ret == TCL_ERROR) {
...
当我跑
load <path to .so>/my_fs[info sharedlibextension]
# sanity check
puts [pwd]
set fp [open test.txt]
但是,我明白了
<my current directory>
while executing
"open test.txt"
invoked from within
"set fp [open test.txt]"
(file "test.tcl" line 3)
注意“puts [pwd]”是如何工作的,但不是“open test.txt”?
在对 Tcl_FSRegister 的调用中用“ori_fs”替换“my_fs”似乎可行……我已经花了太多时间试图弄清楚这一点。如果有人可以帮助我,我将不胜感激!