diff options
author | Thomas Heller <theller@ctypes.org> | 2002-07-29 14:27:41 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2002-07-29 14:27:41 (GMT) |
commit | 085358a3e208b4825dafa829798cfc125f56a2e4 (patch) | |
tree | ace1ac831a2e29283383fd65071c34805dd23e07 | |
parent | b9e0764d8bc610d90d5aed9d8a97fe7643a2eeec (diff) | |
download | cpython-085358a3e208b4825dafa829798cfc125f56a2e4.zip cpython-085358a3e208b4825dafa829798cfc125f56a2e4.tar.gz cpython-085358a3e208b4825dafa829798cfc125f56a2e4.tar.bz2 |
New functions for extension writers on Windows:
PyErr_SetExcFromWindowsErr(), PyErr_SetExcFromWindowsErrWithFilename().
Similar to PyErr_SetFromWindowsErrWithFilename() and
PyErr_SetFromWindowsErr(), but they allow to specify
the exception type to raise. Available on Windows.
See SF patch #576458.
-rw-r--r-- | Doc/api/exceptions.tex | 16 | ||||
-rw-r--r-- | Include/pyerrors.h | 3 | ||||
-rw-r--r-- | Misc/NEWS | 6 | ||||
-rw-r--r-- | Python/errors.c | 20 |
4 files changed, 42 insertions, 3 deletions
diff --git a/Doc/api/exceptions.tex b/Doc/api/exceptions.tex index 7375dd7..f4e4ef0 100644 --- a/Doc/api/exceptions.tex +++ b/Doc/api/exceptions.tex @@ -208,6 +208,14 @@ for each thread. Availability: Windows. \end{cfuncdesc} +\begin{cfuncdesc}{PyObject*}{PyErr_SetExcFromWindowsErr}{PyObject *type, + int ierr} + Similar to \cfunction{PyErr_SetFromWindowsErr()}, with an additional + parameter specifying the exception type to be raised. + Availability: Windows. + \versionadded{2.3} +\end{cfuncdesc} + \begin{cfuncdesc}{PyObject*}{PyErr_SetFromWindowsErrWithFilename}{int ierr, char *filename} Similar to \cfunction{PyErr_SetFromWindowsErr()}, with the @@ -217,6 +225,14 @@ for each thread. Availability: Windows. \end{cfuncdesc} +\begin{cfuncdesc}{PyObject*}{PyErr_SetExcFromWindowsErrWithFilename} + {PyObject *type, int ierr, char *filename} + Similar to \cfunction{PyErr_SetFromWindowsErrWithFilename()}, with + an additional parameter specifying the exception type to be raised. + Availability: Windows. + \versionadded{2.3} +\end{cfuncdesc} + \begin{cfuncdesc}{void}{PyErr_BadInternalCall}{} This is a shorthand for \samp{PyErr_SetString(PyExc_TypeError, \var{message})}, where \var{message} indicates that an internal diff --git a/Include/pyerrors.h b/Include/pyerrors.h index fa5634a..f06d38c 100644 --- a/Include/pyerrors.h +++ b/Include/pyerrors.h @@ -83,6 +83,9 @@ extern DL_IMPORT(PyObject *) PyErr_Format(PyObject *, const char *, ...) #ifdef MS_WINDOWS extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *); extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErr(int); +extern DL_IMPORT(PyObject *) PyErr_SetExcFromWindowsErrWithFilename( + PyObject *,int, const char *); +extern DL_IMPORT(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int); #endif /* Export the old function so that the existing API remains available: */ @@ -380,6 +380,12 @@ Build C API +- New functions PyErr_SetExcFromWindowsErr() and + PyErr_SetExcFromWindowsErrWithFilename(). Similar to + PyErr_SetFromWindowsErrWithFilename() and + PyErr_SetFromWindowsErr(), but they allow to specify + the exception type to raise. Available on Windows. + - Py_FatalError() is now declared as taking a const char* argument. It was previously declared without const. This should not affect working code. diff --git a/Python/errors.c b/Python/errors.c index f744ad4..61d1df0 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -337,7 +337,8 @@ PyErr_SetFromErrno(PyObject *exc) #ifdef MS_WINDOWS /* Windows specific error code handling */ -PyObject *PyErr_SetFromWindowsErrWithFilename( +PyObject *PyErr_SetExcFromWindowsErrWithFilename( + PyObject *exc, int ierr, const char *filename) { @@ -366,16 +367,29 @@ PyObject *PyErr_SetFromWindowsErrWithFilename( else v = Py_BuildValue("(is)", err, s); if (v != NULL) { - PyErr_SetObject(PyExc_WindowsError, v); + PyErr_SetObject(exc, v); Py_DECREF(v); } LocalFree(s); return NULL; } +PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr) +{ + return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL); +} + PyObject *PyErr_SetFromWindowsErr(int ierr) { - return PyErr_SetFromWindowsErrWithFilename(ierr, NULL); + return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, + ierr, NULL); +} +PyObject *PyErr_SetFromWindowsErrWithFilename( + int ierr, + const char *filename) +{ + return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, + ierr, filename); } #endif /* MS_WINDOWS */ |