summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2009-11-27 06:33:39 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2009-11-27 06:33:39 (GMT)
commit26dda484fe7ad621e71585270c0a3c914c5fb375 (patch)
treea8cb0e0fd6a6503fbcb3dbd1f10132869fe916b4
parentdc3b82e5c4fef5b8efbdcef11cfc05216d88cc0c (diff)
downloadtcl-26dda484fe7ad621e71585270c0a3c914c5fb375.zip
tcl-26dda484fe7ad621e71585270c0a3c914c5fb375.tar.gz
tcl-26dda484fe7ad621e71585270c0a3c914c5fb375.tar.bz2
[Bug 2903811]: Remove unneeded restrictions on usefully calling the
oo::object->variable method. Leaving it hidden is enough.
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclOOBasic.c14
-rw-r--r--tests/oo.test35
3 files changed, 45 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 0e5bf08..9517277 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-27 Donal K. Fellows <dkf@users.sf.net>
+
+ * generic/tclOOBasic.c (TclOO_Object_LinkVar): [Bug 2903811]: Remove
+ unneeded restrictions on who can usefully call this method.
+
2009-11-26 Donal K. Fellows <dkf@users.sf.net>
* unix/Makefile.in: Add .PHONY rules and documentation to preemptively
diff --git a/generic/tclOOBasic.c b/generic/tclOOBasic.c
index f6e4542..e064928 100644
--- a/generic/tclOOBasic.c
+++ b/generic/tclOOBasic.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclOOBasic.c,v 1.19 2009/10/22 15:39:58 dkf Exp $
+ * RCS: @(#) $Id: tclOOBasic.c,v 1.20 2009/11/27 06:33:40 dkf Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -474,12 +474,12 @@ TclOO_Object_LinkVar(
}
/*
- * Do nothing if we are not called from the body of a method. In this
- * respect, we are like the [global] command.
+ * A sanity check. Shouldn't ever happen. (This is all that remains of a
+ * more complex check inherited from [global] after we have applied the
+ * fix for [Bug 2903811]; note that the fix involved *removing* code.)
*/
- if (iPtr->varFramePtr == NULL ||
- !(iPtr->varFramePtr->isProcCallFrame & FRAME_IS_METHOD)) {
+ if (iPtr->varFramePtr == NULL) {
return TCL_OK;
}
@@ -505,9 +505,7 @@ TclOO_Object_LinkVar(
* would only work if the caller was a method of the object itself,
* which might not be true if the method was exported. This is a bit
* of a hack, but the simplest way to do this (pushing a stack frame
- * would be horribly expensive by comparison). We never have to worry
- * about the case where we're dealing with the global namespace; we've
- * already checked that we are inside a method.
+ * would be horribly expensive by comparison).
*/
savedNsPtr = iPtr->varFramePtr->nsPtr;
diff --git a/tests/oo.test b/tests/oo.test
index 4c289ab..b07b536 100644
--- a/tests/oo.test
+++ b/tests/oo.test
@@ -7,7 +7,7 @@
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: oo.test,v 1.31 2009/11/24 12:00:08 dkf Exp $
+# RCS: @(#) $Id: oo.test,v 1.32 2009/11/27 06:33:40 dkf Exp $
package require TclOO 0.6.1 ;# Must match value in generic/tclOO.h
if {[lsearch [namespace children] ::tcltest] == -1} {
@@ -1815,6 +1815,39 @@ test oo-20.12 {OO: variable method accept zero args (TIP 323)} -setup {
}
foo demo
} -result {}
+test oo-20.13 {OO: variable method use in non-methods [Bug 2903811]} -setup {
+ oo::object create fooObj
+ oo::objdefine fooObj export variable
+} -cleanup {
+ fooObj destroy
+} -body {
+ apply {{} {fooObj variable x; set x ok; return}}
+ apply {{} {fooObj variable x; return $x}}
+} -result ok
+test oo-20.14 {OO: variable method use in non-methods [Bug 2903811]} -setup {
+ oo::object create fooObj
+ oo::objdefine fooObj export variable
+ namespace eval ns1 {}
+ namespace eval ns2 {}
+ set x bad
+} -cleanup {
+ fooObj destroy
+ namespace delete ns1 ns2
+ unset x
+} -body {
+ namespace eval ns1 {fooObj variable x; set x ok; subst ""}
+ set x bad
+ namespace eval ns2 {fooObj variable x; return $x}
+} -result ok
+test oo-20.15 {OO: variable method use in non-methods [Bug 2903811]} -setup {
+ oo::object create fooObj
+ oo::objdefine fooObj export variable varname
+} -cleanup {
+ fooObj destroy
+} -body {
+ apply {{} {fooObj variable x; set x ok; return}}
+ return [set [fooObj varname x]]
+} -result ok
test oo-21.1 {OO: inheritance ordering} -setup {
oo::class create A