comparison Python/errors.c @ 8706:ca1c669bb041 legacy-trunk

PyErr_SetFromErrnoWithFilename(): New function which supports setting an exception from errno, with a supplied filename (primarily used by IOError and OSError). If class exceptions are used then the exception is instantiated with a 3-tuple: (errno, strerror, filename). For backwards compatibility reasons, if string exceptions are used, filename is ignored. PyErr_SetFromErrno(): Implement in terms of PyErr_SetFromErrnoWithFilename().
author Barry Warsaw <barry@python.org>
date Thu, 23 Jul 1998 16:05:56 +0000
parents bb440a2975ab
children c80321c328b5
comparison
equal deleted inserted replaced
8705:8571c1246f09 8706:ca1c669bb041
275 275
276 return NULL; 276 return NULL;
277 } 277 }
278 278
279 PyObject * 279 PyObject *
280 PyErr_SetFromErrno(exc) 280 PyErr_SetFromErrnoWithFilename(exc, filename)
281 PyObject *exc; 281 PyObject *exc;
282 char *filename;
282 { 283 {
283 PyObject *v; 284 PyObject *v;
284 int i = errno; 285 int i = errno;
285 #ifdef EINTR 286 #ifdef EINTR
286 if (i == EINTR && PyErr_CheckSignals()) 287 if (i == EINTR && PyErr_CheckSignals())
287 return NULL; 288 return NULL;
288 #endif 289 #endif
289 v = Py_BuildValue("(is)", i, strerror(i)); 290 if (filename != NULL && Py_UseClassExceptionsFlag)
291 v = Py_BuildValue("(iss)", i, strerror(i), filename);
292 else
293 v = Py_BuildValue("(is)", i, strerror(i));
290 if (v != NULL) { 294 if (v != NULL) {
291 PyErr_SetObject(exc, v); 295 PyErr_SetObject(exc, v);
292 Py_DECREF(v); 296 Py_DECREF(v);
293 } 297 }
294 return NULL; 298 return NULL;
299 }
300
301
302 PyObject *
303 PyErr_SetFromErrno(exc)
304 PyObject *exc;
305 {
306 return PyErr_SetFromErrnoWithFilename(exc, NULL);
295 } 307 }
296 308
297 void 309 void
298 PyErr_BadInternalCall() 310 PyErr_BadInternalCall()
299 { 311 {