Vikrant Ghai
Vikrant Ghai

Reputation: 13

TCL crashing when on including source multiple times

I have one receive.tcl script which contains only single proc which consist of some 1KLOC

puts "DEBUG_1"
proc Receive { arg1 arg2} {
puts "DEBUG_2"
... TCL Code
}
puts "DEBUG_3"

Now i need to use this proc Receive at so many different scripts; Lets say in; 1.tcl 2.tcl 3.tcl and so on and all these 1.tcl 2.tcl are getting called from Master(Master.tcl).

Is it neccessary to include/write source PATH/receive.tcl in every 1.tcl 2.tcl and so on; to use Receive.

OR

I can call "source PATH/receive.tcl" from some Master(Master.tcl)script and it can be used further in any 1.tcl 2.tcl and so on without including anything separately; will TCL interpreter store/remember this proc Receive and can be used in any further scripts?

Problem : When I "source $PATH/receive.tcl in every 1.tcl 2.tcl and so on and not in Master.tcl; Master.tcl contains source $PATH/1.tcl source $PATH/2.tcl and so on; then i am executing Master.tcl.

  1. In First iteration 1.tcl gets successfully executed;
  2. Interpreter will go in receive.tcl; it's printing DEBUG_1 and DEBUG_3 and further proc Receive is used by 1.tcl successfully.
  3. but when interpreter moves to 2.tcl it finds source $PATH/receive.tcl
  4. Interpreter goes to receive.tcl
  5. and TCL gets crashing again and again; means i can see only DEBUG_1 only; segmentation fault after that.

Upvotes: 0

Views: 437

Answers (1)

Johannes Kuhn
Johannes Kuhn

Reputation: 15163

Ok, first a few things: Tcl should not crash (if you don't use any 3rd party dlls). If it does, consider creating a bug report.

1kloc sounds bad to me, maybe something else is better. I think you try to parse some input and invoke different things, if this is the case, take a look at the interp, one of my favorite gems in Tcl.

To answer your question: You can source the file in the master and use it from other files that are later sourced.

In your case (where the only purpose of that file is to be called by other files), you could create a package. The biggest problems when creating a package is to decide where to install it (use TCL_LIBRARY enviroment variable, pick a directory in $auto_path, add the folder to the $auto_path in your code). Look into the Tcl Tutorial for some reference.

Upvotes: 2

Related Questions