2

I am using a commercial tool interfaced with an homebrew tclsh(Synopsys EDA).

In their version, they removed the load command. Thus I cannot use third party libraries (Graphviz library in my case).

I wonder if there is a another way to import binary files (.so files)

Krouitch
  • 596
  • 3
  • 13
  • What do you mean by having "removed the `load` command"? Have they removed (`rename ::load ""`) from the interpreter or are they building on a Tcl library configured with `--disable-load` autoconf flag? – mrcalvin Apr 06 '18 at 13:20
  • What do you mean by "Graphviz library"? [Tcldot](http://wiki.tcl.tk/8634)? So, you want to do `package req tcldot`? – mrcalvin Apr 06 '18 at 13:22
  • I do not know about that, but I guess that they disabled it when building the shell. I naively did `rename ::load load` and it returned me that the command `::load` does not exist – Krouitch Apr 06 '18 at 13:23
  • Yes, that is Tcldot that I want to use, but when I do `package require Tcldot`, it throws me a unknown command error for the `load` used in the associated `pkgIndex.tcl`. In which we can find the `ifneeded Tcldot " load [file join $dir tcldot.so] Tcldot"` – Krouitch Apr 06 '18 at 13:26
  • 1) pls report the output of `set tcl_patchLevel`. – mrcalvin Apr 06 '18 at 13:36
  • 1
    2) can you run: `interp create slave; slave eval {::load}`? – mrcalvin Apr 06 '18 at 13:37
  • The patch level: 8.6.3. I tried the `interp` command and as it spawns a duplicate of the shell the load command is still unknown (I tried your command too and it still is the case) – Krouitch Apr 06 '18 at 13:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/168420/discussion-between-mrcalvin-and-krouitch). – mrcalvin Apr 06 '18 at 16:20

1 Answers1

1

The only command in standard Tcl that brings in a dynamic library is load. (OK, package require can do too, but that's because it can call load inside.) Without that command, you only have options like statically linking your own code in and creating the commands in the Tcl_AppInit function, but that's really unlikely to work if you're already using someone else's code that's already done that sort of thing.

The easiest approach might be to run a normal tclsh as a subprocess via exec tclsh script.tcl (run and wait for termination) or open |tclsh r+ (open pipeline). If they've not turned off those capabilities as well; you might be running in a safe interpreter where all those things are systematically disabled. I don't know of any way to break out of a standard safe interpreter (the mechanism for locking them down errs on the side of caution) so if that's the case, you'll just have to save the data you want to a file somewhere (by any mechanism that works; safe interpreters also can't touch the filesystem at all by default though that is often profiled back in in protected ways) and use a completely separate program to work with it.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • If there is a hole that lets you do what you want, it is going to be application-specific (as safe interps let such holes be created by the controlling application even if they don't make them themselves; it's like how an OS can do things to hardware that user programs can't). That means you need to read the Synopsis EDA documentation very carefully. – Donal Fellows Apr 08 '18 at 07:41
  • Just out of curiosity, if I have a process running on my machine, is there a way to load my own library (through debugging that process, injecting my package into it, and call MyPkg_Init with the Interp* that I somehow discover?) – Johannes Kuhn Apr 08 '18 at 19:35
  • You can load packages into interpreters other than the current one. (It's one of the optional arguments to `load`.) But there isn't a way to instruct a standard tclsh to do load anything that isn't allowed for in the script it is running. If the script uses `comm` or `dde` (or has `send` enabled in Tk) to let you talk to a master interpreter with access to `load`, you can do what you want easily. Otherwise… I guess you could use a C debugger to call `Tcl_Eval`? (`Tcl_FSLoadFile` exists, but doesn't have a pleasant API to use from a debugger.) – Donal Fellows Apr 09 '18 at 07:32