[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Modules termios.c,2.24,2.25

Michael Hudson mwh@python.net
09 May 2001 20:50:34 +0100


"Fred L. Drake" <fdrake@users.sourceforge.net> writes:

> ! 	fd = PyObject_AsFileDescriptor(obj);
> ! 	if (fd == -1) {
> ! 		if (PyInt_Check(obj)) {
                    ^^^^^^^^^^^^^^^^
this is a bit pointless.

I admit

->> termios.tcgetattr(-2)
Traceback (most recent call last):
  File "<input>", line 1, in ?
TypeError: tcgetattr, arg 1: can't extract file descriptor from "int"

is a bit confusing, but I'm not sure 

->> termios.tcgetattr(-2)
Traceback (most recent call last):
  File "<input>", line 1, in ?
error: (9, 'Bad file descriptor')

is any better than:

->> termios.tcgetattr(-2)
Traceback (most recent call last):
  File "<input>", line 1, in ?
ValueError: file descriptor cannot be a negative integer (-2)

which is what you get after applying this patch:

Index: Modules/termios.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/termios.c,v
retrieving revision 2.26
diff -c -r2.26 termios.c
*** Modules/termios.c   2001/05/09 17:53:06     2.26
--- Modules/termios.c   2001/05/09 19:49:52
***************
*** 37,43 ****
        fd = PyObject_AsFileDescriptor(obj);
        if (fd == -1) {
                if (PyInt_Check(obj)) {
!                       fd = PyInt_AS_LONG(obj);
                }
                else {
                        char* tname;
--- 37,43 ----
        fd = PyObject_AsFileDescriptor(obj);
        if (fd == -1) {
                if (PyInt_Check(obj)) {
!                       return 0;
                }
                else {
                        char* tname;

Cheers,
M.