summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--doc/CrtInterp.325
-rw-r--r--generic/tcl.decls11
-rw-r--r--generic/tclBasic.c26
4 files changed, 61 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 10f7d0e..1ed290d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2008-12-05 Donal K. Fellows <dkf@users.sf.net>
+ TIP #335 IMPLEMENTATION
+
+ * generic/tclBasic.c (Tcl_InterpActive): Added function for working
+ * doc/CrtInterp.3: out if an interp is in use.
+
TIP #307 IMPLEMENTATION
* generic/tclResult.c (Tcl_TransferResult): Renamed function from
diff --git a/doc/CrtInterp.3 b/doc/CrtInterp.3
index 14679a6..d751f75 100644
--- a/doc/CrtInterp.3
+++ b/doc/CrtInterp.3
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: CrtInterp.3,v 1.8 2008/07/08 12:34:58 dkf Exp $
+'\" RCS: @(#) $Id: CrtInterp.3,v 1.9 2008/12/05 21:38:47 dkf Exp $
'\"
.so man.macros
.TH Tcl_CreateInterp 3 7.5 Tcl "Tcl Library Procedures"
@@ -23,10 +23,15 @@ Tcl_Interp *
.sp
int
\fBTcl_InterpDeleted\fR(\fIinterp\fR)
+.sp
+.VS 8.6
+int
+\fBTcl_InterpActive\fR(\fIinterp\fR)
+.VE 8.6
.SH ARGUMENTS
.AS Tcl_Interp *interp
.AP Tcl_Interp *interp in
-Token for interpreter to be destroyed.
+Token for interpreter to be destroyed or queried.
.BE
.SH DESCRIPTION
.PP
@@ -65,6 +70,15 @@ between when only the memory the callback is responsible for is being
deleted and when the whole interpreter is being deleted. In the former case
the callback may recreate the data being deleted, but this would lead to an
infinite loop if the interpreter were being deleted.
+.PP
+.VS 8.6
+\fBTcl_InterpActive\fR is useful for determining whether there is any
+execution of scripts ongoing in an interpreter, which is a useful piece of
+information when Tcl is embedded in a garbage-collected environment and it
+becomes necessary to determine whether the interpreter is a candidate for
+deletion. The function returns a true value if the interpreter has at least
+one active execution running inside it, and a false value otherwise.
+.VE 8.6
.SH "INTERPRETERS AND MEMORY MANAGEMENT"
.PP
\fBTcl_DeleteInterp\fR can be called at any time on an interpreter that may
@@ -124,6 +138,13 @@ reused.
All uses of interpreters in Tcl and Tk have already been protected.
Extension writers should ensure that their code also properly protects any
additional interpreters used, as described above.
+.PP
+.VS 8.6
+Note that the protection mechanisms do not work well with conventional garbage
+collection systems. When in such a managed environment, \fBTcl_InterpActive\fR
+should be used to determine when an interpreter is a candidate for deletion
+due to inactivity.
+.VE 8.6
.SH "SEE ALSO"
Tcl_Preserve(3), Tcl_Release(3)
.SH KEYWORDS
diff --git a/generic/tcl.decls b/generic/tcl.decls
index abd9ed7..bdfe02c 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -12,7 +12,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: tcl.decls,v 1.156 2008/12/05 14:27:36 dkf Exp $
+# RCS: @(#) $Id: tcl.decls,v 1.157 2008/12/05 21:38:47 dkf Exp $
library tcl
@@ -2198,7 +2198,7 @@ declare 604 generic {
int *objcPtr, Tcl_Obj *const *objv, Tcl_Obj ***remObjv)
}
-# TIP 335
+# TIP 336 (manipulate the error line)
declare 605 generic {
int Tcl_GetErrorLine(Tcl_Interp *interp)
}
@@ -2206,12 +2206,17 @@ declare 606 generic {
void Tcl_SetErrorLine(Tcl_Interp *interp, int value)
}
-# TIP#307 (expose this function!)
+# TIP#307 (move results between interpreters)
declare 607 generic {
void Tcl_TransferResult(Tcl_Interp *sourceInterp, int result,
Tcl_Interp *targetInterp)
}
+# TIP#335 (detect if interpreter in use)
+declare 608 generic {
+ int Tcl_InterpActive(Tcl_Interp *interp)
+}
+
##############################################################################
# Define the platform specific public Tcl interface. These functions are only
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index dbcaecd..cf618c7 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -16,7 +16,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.374 2008/10/28 23:29:54 nijtmans Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.375 2008/12/05 21:38:47 dkf Exp $
*/
#include "tclInt.h"
@@ -3955,6 +3955,30 @@ Tcl_CancelEval(
/*
*----------------------------------------------------------------------
*
+ * Tcl_InterpActive --
+ *
+ * Returns non-zero if the specified interpreter is in use, i.e. if there
+ * is an evaluation currently active in the interpreter.
+ *
+ * Results:
+ * See above.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Tcl_InterpActive(
+ Tcl_Interp *interp)
+{
+ return ((Interp *) interp)->numLevels > 0;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Tcl_EvalObjv --
*
* This function evaluates a Tcl command that has already been parsed