diff options
author | Fred Drake <fdrake@acm.org> | 2001-05-09 20:14:09 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-05-09 20:14:09 (GMT) |
commit | c99ff60573f00d7fe35cafcc0f2594f24bfe65bd (patch) | |
tree | 951adce48872a8bd357e4a0d58aeeab40b52e0fa /Modules/termios.c | |
parent | 1a97d5f0983e2fb9d1fc7c9690a3e0ddae55fe0f (diff) | |
download | cpython-c99ff60573f00d7fe35cafcc0f2594f24bfe65bd.zip cpython-c99ff60573f00d7fe35cafcc0f2594f24bfe65bd.tar.gz cpython-c99ff60573f00d7fe35cafcc0f2594f24bfe65bd.tar.bz2 |
fdconv(): Do not second guess the error condition returned by
PyObject_AsFileDescriptor() -- it does the same thing everywhere, so
use it the same way everyone else does so that exceptions are
consistent. This means we have less code here, and we do not need to
resort to hackish ways of getting the Python-visible function name to
fdconv().
Diffstat (limited to 'Modules/termios.c')
-rw-r--r-- | Modules/termios.c | 41 |
1 files changed, 4 insertions, 37 deletions
diff --git a/Modules/termios.c b/Modules/termios.c index cedcb0f..f586bb1 100644 --- a/Modules/termios.c +++ b/Modules/termios.c @@ -28,37 +28,16 @@ sys.stdin.fileno(), or a file object, such as sys.stdin itself."; static PyObject *TermiosError; -static char* fname; - static int fdconv(PyObject* obj, void* p) { int fd; fd = PyObject_AsFileDescriptor(obj); - if (fd == -1) { - if (PyInt_Check(obj)) { - fd = PyInt_AS_LONG(obj); - } - else { - char* tname; - - if (PyInstance_Check(obj)) { - tname = PyString_AS_STRING( - ((PyInstanceObject*)obj)->in_class->cl_name); - } - else { - tname = obj->ob_type->tp_name; - } - - PyErr_Format(PyExc_TypeError, - "%s, arg 1: can't extract file descriptor from \"%.500s\"", - fname, tname); - return 0; - } + if (fd >= 0) { + *(int*)p = fd; + return 1; } - - *(int*)p = fd; - return 1; + return 0; } static char termios_tcgetattr__doc__[] = "\ @@ -83,8 +62,6 @@ termios_tcgetattr(PyObject *self, PyObject *args) int i; char ch; - fname = "tcgetattr"; - if (!PyArg_ParseTuple(args, "O&:tcgetattr", fdconv, (void*)&fd)) return NULL; @@ -160,8 +137,6 @@ termios_tcsetattr(PyObject *self, PyObject *args) PyObject *term, *cc, *v; int i; - fname = "tcsetattr"; - if (!PyArg_ParseTuple(args, "O&iO:tcsetattr", fdconv, &fd, &when, &term)) return NULL; @@ -228,8 +203,6 @@ termios_tcsendbreak(PyObject *self, PyObject *args) { int fd, duration; - fname = "tcsendbreak"; - if (!PyArg_ParseTuple(args, "O&i:tcsendbreak", fdconv, &fd, &duration)) return NULL; @@ -250,8 +223,6 @@ termios_tcdrain(PyObject *self, PyObject *args) { int fd; - fname = "tcdrain"; - if (!PyArg_ParseTuple(args, "O&:tcdrain", fdconv, &fd)) return NULL; @@ -275,8 +246,6 @@ termios_tcflush(PyObject *self, PyObject *args) { int fd, queue; - fname = "tcflush"; - if (!PyArg_ParseTuple(args, "O&i:tcflush", fdconv, &fd, &queue)) return NULL; @@ -300,8 +269,6 @@ termios_tcflow(PyObject *self, PyObject *args) { int fd, action; - fname = "tcflow"; - if (!PyArg_ParseTuple(args, "O&i:tcflow", fdconv, &fd, &action)) return NULL; |