Subject: [dtn-users] oasys and tcl 8.6 support

From: Lana Black <[email-masked]>
Date: Sun, 17 Feb 2013 22:53:26 +0000

Hi,

The patch attached adds support for the newer Tcl version. Tcl 8.6 drops
direct access to several Tcl_Interp fields in favor of API functions.
Also, since some pre 8.6 installations don't have Tcl_GetErrorLine() function,
we have to check its presence and build our implementation in case of absence.

Tested on Tcl versions 8.5 and 8.6. Don't forget to run
build-configure.sh script after applying the patch.
diff -r 4cf51fd37f22 aclocal/tcl.ac
--- a/aclocal/tcl.ac	Tue Jul 24 16:09:54 2012 +0100
+++ b/aclocal/tcl.ac	Sun Feb 17 22:42:26 2013 +0000
@@ -22,7 +22,7 @@
 dnl Main macro for finding a usable tcl installation 
 dnl
 AC_DEFUN(AC_CONFIG_TCL, [
-    ac_tclvers='8.5 8.4 8.3'
+    ac_tclvers='8.6 8.5 8.4 8.3'
     ac_tcldir='system'
 
     AC_ARG_WITH(tcl,
@@ -83,6 +83,12 @@
 
     EXTLIB_LDFLAGS="$EXTLIB_LDFLAGS $TCL_LDFLAGS"
     AC_SUBST(TCL_LDFLAGS)
+
+    dnl
+    dnl Check for some APIs
+    dnl
+    AC_SEARCH_LIBS(Tcl_GetErrorLine, tcl,
+            [AC_DEFINE([HAVE_TCL_GETERRORLINE], [1], [Define if Tcl has Tcl_GetErrorLine function.])])
 ])
 
 dnl
diff -r 4cf51fd37f22 tclcmd/TclCommand.cc
--- a/tclcmd/TclCommand.cc	Tue Jul 24 16:09:54 2012 +0100
+++ b/tclcmd/TclCommand.cc	Sun Feb 17 22:42:26 2013 +0000
@@ -70,7 +70,7 @@
     if (Tcl_Init(interp_) != TCL_OK) {
         StringBuffer err("initialization problem calling Tcl_Init: %s\n"
                          "(this is not a fatal error, continuing initialization...)\n\n",
-                         interp_->result);
+                         Tcl_GetStringResult(interp_));
         log_multiline(LOG_WARN, err.c_str());
     }
 
@@ -99,7 +99,7 @@
     // overwrite the string value)
     char* cmd = strdup(INIT_COMMAND);
     if (Tcl_Eval(interp_, cmd) != TCL_OK) {
-        log_err("error in init commands: \"%s\"", interp_->result);
+        log_err("error in init commands: \"%s\"", Tcl_GetStringResult(interp_));
         return TCL_ERROR;
     }
     free(cmd);
@@ -163,7 +163,7 @@
     
     if (err != TCL_OK) {
         logf(LOG_ERR, "error: line %d: '%s':\n%s",
-             interp_->errorLine, Tcl_GetStringResult(interp_),
+             Tcl_GetErrorLine(interp_), Tcl_GetStringResult(interp_),
              Tcl_GetVar(interp_, "errorInfo", TCL_GLOBAL_ONLY));
     }
     
@@ -193,7 +193,7 @@
     
     if (err != TCL_OK) {
         logf(LOG_ERR, "error: line %d: '%s':\n%s",
-             interp_->errorLine, Tcl_GetStringResult(interp_),
+             Tcl_GetErrorLine(interp_), Tcl_GetStringResult(interp_),
              Tcl_GetVar(interp_, "errorInfo", TCL_GLOBAL_ONLY));
     }
     
@@ -211,7 +211,7 @@
     
     if (err != TCL_OK) {
         logf(LOG_ERR, "error: line %d: '%s':\n%s",
-             interp_->errorLine, Tcl_GetStringResult(interp_),
+             Tcl_GetErrorLine(interp_), Tcl_GetStringResult(interp_),
              Tcl_GetVar(interp_, "errorInfo", TCL_GLOBAL_ONLY));
     }
     
@@ -225,7 +225,7 @@
     StringBuffer cmd("set command_logpath %s", logpath());
     if (Tcl_Eval(interp_, const_cast<char*>(cmd.c_str())) != TCL_OK) {
         log_err("tcl error setting command_logpath: \"%s\"",
-                interp_->result);
+                Tcl_GetStringResult(interp_));
     }
 }
 
@@ -240,7 +240,7 @@
     
     if (Tcl_Eval(interp_, const_cast<char*>(cmd.c_str())) != TCL_OK) {
         log_err("tcl error starting command_server: \"%s\"",
-                interp_->result);
+                Tcl_GetStringResult(interp_));
     }
 }
 
@@ -256,7 +256,7 @@
 #endif
     
     if (Tcl_Eval(interp_, const_cast<char*>(cmd.c_str())) != TCL_OK) {
-        log_err("tcl error in command_loop: \"%s\"", interp_->result);
+        log_err("tcl error in command_loop: \"%s\"", Tcl_GetStringResult(interp_));
     }
 }
 
@@ -266,7 +266,7 @@
 {
     set_command_logpath();
     if (Tcl_Eval(interp_, "event_loop") != TCL_OK) {
-        log_err("tcl error in event_loop: \"%s\"", interp_->result);
+        log_err("tcl error in event_loop: \"%s\"", Tcl_GetStringResult(interp_));
     }
 }
 
@@ -275,7 +275,7 @@
 TclCommandInterp::exit_event_loop()
 {
     if (Tcl_Eval(interp_, "exit_event_loop") != TCL_OK) {
-        log_err("tcl error in event_loop: \"%s\"", interp_->result);
+        log_err("tcl error in event_loop: \"%s\"", Tcl_GetStringResult(interp_));
     }
 }
 
diff -r 4cf51fd37f22 tclcmd/TclCommand.h
--- a/tclcmd/TclCommand.h	Tue Jul 24 16:09:54 2012 +0100
+++ b/tclcmd/TclCommand.h	Sun Feb 17 22:42:26 2013 +0000
@@ -32,6 +32,16 @@
 #include "../util/Singleton.h"
 #include "../util/StringBuffer.h"
 
+/**
+ * Workaround for older tcl versions
+ */
+#ifndef HAVE_TCL_GETERRORLINE
+static inline int Tcl_GetErrorLine(Tcl_Interp *interp)
+{
+    return interp->errorLine;
+}
+#endif
+
 namespace oasys {
 
 // forward decls