summaryrefslogtreecommitdiffstats
path: root/Modules/_tkinter.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-05-01 05:47:00 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-05-01 05:47:00 (GMT)
commit1869ec5cb71cd6af1c495d136b1ee5aaaebf9fbb (patch)
tree56d8f9405ad713b0ed76642b5524c55581a411fd /Modules/_tkinter.c
parent9e29625a1b679dfcf2d5bf9957f4efb669602f74 (diff)
downloadcpython-1869ec5cb71cd6af1c495d136b1ee5aaaebf9fbb.zip
cpython-1869ec5cb71cd6af1c495d136b1ee5aaaebf9fbb.tar.gz
cpython-1869ec5cb71cd6af1c495d136b1ee5aaaebf9fbb.tar.bz2
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Diffstat (limited to 'Modules/_tkinter.c')
-rw-r--r--Modules/_tkinter.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index c946f88..e1238d6 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -742,6 +742,12 @@ PyTclObject_str(PyTclObject *self)
return PyString_FromString(Tcl_GetString(self->value));
}
+static char*
+PyTclObject_TclString(PyObject *self)
+{
+ return Tcl_GetString(((PyTclObject*)self)->value);
+}
+
/* Like _str, but create Unicode if necessary. */
PyDoc_STRVAR(PyTclObject_string__doc__,
"the string representation of this object, either as string or Unicode");
@@ -1466,6 +1472,22 @@ typedef struct VarEvent {
Tcl_Condition cond;
} VarEvent;
+static int
+varname_converter(PyObject *in, void *_out)
+{
+ char **out = (char**)_out;
+ if (PyString_Check(in)) {
+ *out = PyString_AsString(in);
+ return 1;
+ }
+ if (PyTclObject_Check(in)) {
+ *out = PyTclObject_TclString(in);
+ return 1;
+ }
+ /* XXX: Should give diagnostics. */
+ return 0;
+}
+
void
var_perform(VarEvent *ev)
{
@@ -1542,7 +1564,8 @@ SetVar(PyObject *self, PyObject *args, int flags)
PyObject *res = NULL;
Tcl_Obj *newval, *ok;
- if (PyArg_ParseTuple(args, "sO:setvar", &name1, &newValue)) {
+ if (PyArg_ParseTuple(args, "O&O:setvar",
+ varname_converter, &name1, &newValue)) {
/* XXX Acquire tcl lock??? */
newval = AsObj(newValue);
if (newval == NULL)
@@ -1604,7 +1627,8 @@ GetVar(PyObject *self, PyObject *args, int flags)
PyObject *res = NULL;
Tcl_Obj *tres;
- if (!PyArg_ParseTuple(args, "s|s:getvar", &name1, &name2))
+ if (!PyArg_ParseTuple(args, "O&|s:getvar",
+ varname_converter, &name1, &name2))
return NULL;
ENTER_TCL