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 への呼び出しで「my_fs」を「ori_fs」に置き換えるとうまくいくようです...これを理解するために、すでに多くの時間を費やしてきました。誰かがこれで私を助けてくれれば幸いです!