[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns]: ns-2.1b7: "instvar" call in Redhat Linux



You can get around this problem by applying the enclosed patch to
~tclcl/Tcl.cc. (However, doing two instvars of the same variable in the
same frame is not necessary, hence not recommended.)

Thanks for the report.

- Haobo

--- Tcl.cc~     2000/03/24 19:43:07     
+++ Tcl.cc      2000/04/15 01:01:29     
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /usr/src/mash/repository/common/Tcl/Tcl.cc,v 1.60
2000/03/24 19:43:07 haoboy Exp $ (LBL)";
+    "@(#) $Header: /usr/src/mash/repository/common/Tcl/Tcl.cc,v 1.64
2000/04/15 01:01:29 haoboy Exp $ (LBL)";
 #endif
 
 #include <stdio.h>
@@ -343,7 +343,15 @@
        /*
         * XXX can't use tcl.evalf() because it uses Tcl_GlobalEval
         * and we need to run in the context of the method.
+        * 
+        * XXX Should add a check to see if we already have this framevar.
+        * If so, don't do the following set stuff, otherwise it'll change
+        * the correct value to 0.
         */
+       Tcl_Interp* tcl = Tcl::instance().interp();
+       char *v = Tcl_GetVar(tcl, (char*)localName, 0);
+       if (v != 0)
+               return (TCL_OK);
        char wrk[WRK_MEDIUM_SIZE];
        if (-1 == snprintf(wrk, WRK_MEDIUM_SIZE, "set %s 0", localName))
                return TCL_ERROR;

On Tue, 11 Apr 2000, Guo, Liang wrote:

> 
> I came across with a very strange problem. I wanted to trace
> a variable defined in TCP agent, say ndatapack_, so I wrote 
> the following code:
> 
> ...
> set tcp [new Agent/TCP]
> ...
> 
> proc monitor {} {
>    global tcp
> 
>    $tcp instvar ndatapack_
> 
>    puts "ndatapack = $ndatapack_"
> 
>    $tcp instvar ndatapack_
>    puts "ndatapack = $ndatapack_"
> }
> 
> $ns at 1.0 "monitor"
> 
> 
> I.e., I printed it twice in the same function, however, I 
> got two different values for ndatapack_, the first one is
> a reasonable value (some positive number), but the
> second one is always 0.
> 
> So I used tcl-debugger to trace the program, and found
> that after "xxx instvar xxxx", ns automatically
> add a statement "set xxxx 0". (Magic!)
> 
> I don't know why this happens, I'm using Red Hat 6.2, and
> installed ns-2.1b7 on it. I ran exactly the same
> piece of code on my Sun Solaris station, which has
> ns-2.1b6 installed, then the problem disappeared.
> Does anyone have the same experience before? I need help
> from you, thanks.
> 
> 
> Guo, Liang 
> 
> [email protected]                     Dept. of Comp. Sci., Boston Univ.,
> 
>