[Python-checkins] CVS: python/dist/src/Modules _tkinter.c,1.93,1.94

Guido van Rossum python-dev@python.org
Thu, 30 Mar 2000 19:51:39 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules

Modified Files:
	_tkinter.c 
Log Message:
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
changed from 8.0 to 8.1 and I see no big reason to use objects in 8.0.
At least now it works again with all versions from 8.0 - 8.3.


Index: _tkinter.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.93
retrieving revision 1.94
diff -C2 -r1.93 -r1.94
*** _tkinter.c	2000/03/29 00:19:50	1.93
--- _tkinter.c	2000/03/31 00:51:37	1.94
***************
*** 426,470 ****
  }
  
- static Tcl_Obj*
- AsObj(value)
- 	PyObject *value;
- {
- 	Tcl_Obj *result;
- 
- 	if (PyString_Check(value))
- 		return Tcl_NewStringObj(PyString_AS_STRING(value),
- 					PyString_GET_SIZE(value));
- 	else if (PyInt_Check(value))
- 		return Tcl_NewLongObj(PyInt_AS_LONG(value));
- 	else if (PyFloat_Check(value))
- 		return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
- 	else if (PyTuple_Check(value)) {
- 		Tcl_Obj **argv = (Tcl_Obj**)
- 			ckalloc(PyTuple_Size(value)*sizeof(Tcl_Obj*));
- 		int i;
- 		if(!argv)
- 		  return 0;
- 		for(i=0;i<PyTuple_Size(value);i++)
- 		  argv[i] = AsObj(PyTuple_GetItem(value,i));
- 		result = Tcl_NewListObj(PyTuple_Size(value), argv);
- 		ckfree(FREECAST argv);
- 		return result;
- 	}
- 	else if (PyUnicode_Check(value)) {
- 		PyObject* utf8 = PyUnicode_AsUTF8String (value);
- 		if (!utf8)
- 			return 0;
- 		return Tcl_NewStringObj (PyString_AS_STRING (utf8),
- 					 PyString_GET_SIZE (utf8));
- 	}
- 	else {
- 		PyObject *v = PyObject_Str(value);
- 		if (!v)
- 			return 0;
- 		result = AsObj(v);
- 		Py_DECREF(v);
- 		return result;
- 	}
- }
  
  
--- 426,429 ----
***************
*** 560,563 ****
--- 519,570 ----
  /** Tcl Eval **/
  
+ #if TKMAJORMINOR >= 8001
+ #define USING_OBJECTS
+ #endif
+ 
+ #ifdef USING_OBJECTS
+ 
+ static Tcl_Obj*
+ AsObj(value)
+ 	PyObject *value;
+ {
+ 	Tcl_Obj *result;
+ 
+ 	if (PyString_Check(value))
+ 		return Tcl_NewStringObj(PyString_AS_STRING(value),
+ 					PyString_GET_SIZE(value));
+ 	else if (PyInt_Check(value))
+ 		return Tcl_NewLongObj(PyInt_AS_LONG(value));
+ 	else if (PyFloat_Check(value))
+ 		return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
+ 	else if (PyTuple_Check(value)) {
+ 		Tcl_Obj **argv = (Tcl_Obj**)
+ 			ckalloc(PyTuple_Size(value)*sizeof(Tcl_Obj*));
+ 		int i;
+ 		if(!argv)
+ 		  return 0;
+ 		for(i=0;i<PyTuple_Size(value);i++)
+ 		  argv[i] = AsObj(PyTuple_GetItem(value,i));
+ 		result = Tcl_NewListObj(PyTuple_Size(value), argv);
+ 		ckfree(FREECAST argv);
+ 		return result;
+ 	}
+ 	else if (PyUnicode_Check(value)) {
+ 		PyObject* utf8 = PyUnicode_AsUTF8String (value);
+ 		if (!utf8)
+ 			return 0;
+ 		return Tcl_NewStringObj (PyString_AS_STRING (utf8),
+ 					 PyString_GET_SIZE (utf8));
+ 	}
+ 	else {
+ 		PyObject *v = PyObject_Str(value);
+ 		if (!v)
+ 			return 0;
+ 		result = AsObj(v);
+ 		Py_DECREF(v);
+ 		return result;
+ 	}
+ }
+ 
  static PyObject *
  Tkapp_Call(self, args)
***************
*** 627,630 ****
--- 634,753 ----
  }
  
+ #else /* !USING_OBJECTS */
+ 
+ static PyObject *
+ Tkapp_Call(self, args)
+ 	PyObject *self;
+ 	PyObject *args;
+ {
+ 	/* This is copied from Merge() */
+ 	PyObject *tmp = NULL;
+ 	char *argvStore[ARGSZ];
+ 	char **argv = NULL;
+ 	int fvStore[ARGSZ];
+ 	int *fv = NULL;
+ 	int argc = 0, i;
+ 	PyObject *res = NULL; /* except this has a different type */
+ 	Tcl_CmdInfo info; /* and this is added */
+ 	Tcl_Interp *interp = Tkapp_Interp(self); /* and this too */
+ 
+ 	if (!(tmp = PyList_New(0)))
+ 	    return NULL;
+ 
+ 	argv = argvStore;
+ 	fv = fvStore;
+ 
+ 	if (args == NULL)
+ 		argc = 0;
+ 
+ 	else if (!PyTuple_Check(args)) {
+ 		argc = 1;
+ 		fv[0] = 0;
+ 		argv[0] = AsString(args, tmp);
+ 	}
+ 	else {
+ 		argc = PyTuple_Size(args);
+ 
+ 		if (argc > ARGSZ) {
+ 			argv = (char **)ckalloc(argc * sizeof(char *));
+ 			fv = (int *)ckalloc(argc * sizeof(int));
+ 			if (argv == NULL || fv == NULL) {
+ 				PyErr_NoMemory();
+ 				goto finally;
+ 			}
+ 		}
+ 
+ 		for (i = 0; i < argc; i++) {
+ 			PyObject *v = PyTuple_GetItem(args, i);
+ 			if (PyTuple_Check(v)) {
+ 				fv[i] = 1;
+ 				if (!(argv[i] = Merge(v)))
+ 					goto finally;
+ 			}
+ 			else if (v == Py_None) {
+ 				argc = i;
+ 				break;
+ 			}
+ 			else {
+ 				fv[i] = 0;
+ 				argv[i] = AsString(v, tmp);
+ 			}
+ 		}
+ 	}
+ 	/* End code copied from Merge() */
+ 
+ 	/* All this to avoid a call to Tcl_Merge() and the corresponding call
+ 	   to Tcl_SplitList() inside Tcl_Eval()...  It can save a bundle! */
+ 	if (Py_VerboseFlag >= 2) {
+ 		for (i = 0; i < argc; i++)
+ 			PySys_WriteStderr("%s ", argv[i]);
+ 	}
+ 	ENTER_TCL
+ 	info.proc = NULL;
+ 	if (argc < 1 ||
+ 	    !Tcl_GetCommandInfo(interp, argv[0], &info) ||
+ 	    info.proc == NULL)
+ 	{
+ 		char *cmd;
+ 		cmd = Tcl_Merge(argc, argv);
+ 		i = Tcl_Eval(interp, cmd);
+ 		ckfree(cmd);
+ 	}
+ 	else {
+ 		Tcl_ResetResult(interp);
+ 		i = (*info.proc)(info.clientData, interp, argc, argv);
+ 	}
+ 	ENTER_OVERLAP
+ 	if (info.proc == NULL && Py_VerboseFlag >= 2)
+ 		PySys_WriteStderr("... use TclEval ");
+ 	if (i == TCL_ERROR) {
+ 		if (Py_VerboseFlag >= 2)
+ 			PySys_WriteStderr("... error: '%s'\n",
+ 				interp->result);
+ 		Tkinter_Error(self);
+ 	}
+ 	else {
+ 		if (Py_VerboseFlag >= 2)
+ 			PySys_WriteStderr("-> '%s'\n", interp->result);
+ 		res = PyString_FromString(interp->result);
+ 	}
+ 	LEAVE_OVERLAP_TCL
+ 
+ 	/* Copied from Merge() again */
+   finally:
+ 	for (i = 0; i < argc; i++)
+ 		if (fv[i]) {
+ 			ckfree(argv[i]);
+ 		}
+ 	if (argv != argvStore)
+ 		ckfree(FREECAST argv);
+ 	if (fv != fvStore)
+ 		ckfree(FREECAST fv);
+ 
+ 	Py_DECREF(tmp);
+ 	return res;
+ }
+ 
+ #endif /* !USING_OBJECTS */
  
  static PyObject *