[Python-checkins] CVS: python/dist/src/Modules _tkinter.c,1.106,1.107 selectmodule.c,2.37,2.38

A.M. Kuchling python-dev@python.org
Thu, 13 Jul 2000 16:59:37 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv29178

Modified Files:
	_tkinter.c selectmodule.c 
Log Message:
Use PyObject_AsFileDescriptor 


Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -C2 -r1.106 -r1.107
*** _tkinter.c	2000/07/12 13:05:33	1.106
--- _tkinter.c	2000/07/13 23:59:35	1.107
***************
*** 1427,1472 ****
  }
  
- static int
- GetFileNo(PyObject *file)
- 	/* Either an int >= 0 or an object with a
- 	 *.fileno() method that returns an int >= 0
- 	 */
- {
- 	PyObject *meth, *args, *res;
- 	int id;
- 	if (PyInt_Check(file)) {
- 		id = PyInt_AsLong(file);
- 		if (id < 0)
- 			PyErr_SetString(PyExc_ValueError, "invalid file id");
- 		return id;
- 	}
- 	args = PyTuple_New(0);
- 	if (args == NULL)
- 		return -1;
- 
- 	meth = PyObject_GetAttrString(file, "fileno");
- 	if (meth == NULL) {
- 		Py_DECREF(args);
- 		return -1;
- 	}
- 
- 	res = PyEval_CallObject(meth, args);
- 	Py_DECREF(args);
- 	Py_DECREF(meth);
- 	if (res == NULL)
- 		return -1;
- 
- 	if (PyInt_Check(res))
- 		id = PyInt_AsLong(res);
- 	else
- 		id = -1;
- 
- 	if (id < 0)
- 		PyErr_SetString(PyExc_ValueError,
- 				"invalid fileno() return value");
- 	Py_DECREF(res);
- 	return id;
- }
- 
  static PyObject *
  Tkapp_CreateFileHandler(PyObject *self, PyObject *args)
--- 1427,1430 ----
***************
*** 1479,1483 ****
  	if (!PyArg_ParseTuple(args, "OiO:createfilehandler", &file, &mask, &func))
  		return NULL;
! 	tfile = GetFileNo(file);
  	if (tfile < 0)
  		return NULL;
--- 1437,1441 ----
  	if (!PyArg_ParseTuple(args, "OiO:createfilehandler", &file, &mask, &func))
  		return NULL;
! 	tfile = PyObject_AsFileDescriptor(file);
  	if (tfile < 0)
  		return NULL;
***************
*** 1507,1511 ****
  	if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file))
  		return NULL;
! 	tfile = GetFileNo(file);
  	if (tfile < 0)
  		return NULL;
--- 1465,1469 ----
  	if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file))
  		return NULL;
! 	tfile = PyObject_AsFileDescriptor(file);
  	if (tfile < 0)
  		return NULL;

Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.37
retrieving revision 2.38
diff -C2 -r2.37 -r2.38
*** selectmodule.c	2000/07/11 21:35:02	2.37
--- selectmodule.c	2000/07/13 23:59:35	2.38
***************
*** 97,125 ****
  
  		Py_INCREF(o);
  
- 		if (PyInt_Check(o)) {
- 			v = PyInt_AsLong(o);
- 		}
- 		else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
- 		{
- 			PyObject *fno = PyEval_CallObject(meth, NULL);
- 			Py_DECREF(meth);
- 			if (fno == NULL)
- 				goto finally;
- 
-                         if (!PyInt_Check(fno)) {
- 				PyErr_SetString(PyExc_TypeError,
-                                        "fileno method returned a non-integer");
- 				Py_DECREF(fno);
- 				goto finally;
-                         }
-                         v = PyInt_AsLong(fno);
- 			Py_DECREF(fno);
- 		}
- 		else {
- 			PyErr_SetString(PyExc_TypeError,
- 			"argument must be an int, or have a fileno() method.");
- 			goto finally;
- 		}
  #if defined(_MSC_VER)
  		max = 0;		     /* not used for Win32 */
--- 97,103 ----
  
  		Py_INCREF(o);
+ 		v = PyObject_AsFileDescriptor( o );
+ 		if (v == -1) goto finally;
  
  #if defined(_MSC_VER)
  		max = 0;		     /* not used for Win32 */