Skip to content

Commit 1b61723

Browse files
author
theller
committed
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. git-svn-id: http://svn.python.org/projects/python/trunk@27814 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 65bf288 commit 1b61723

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

Doc/api/exceptions.tex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ \chapter{Exception Handling \label{exceptionHandling}}
208208
Availability: Windows.
209209
\end{cfuncdesc}
210210

211+
\begin{cfuncdesc}{PyObject*}{PyErr_SetExcFromWindowsErr}{PyObject *type,
212+
int ierr}
213+
Similar to \cfunction{PyErr_SetFromWindowsErr()}, with an additional
214+
parameter specifying the exception type to be raised.
215+
Availability: Windows.
216+
\versionadded{2.3}
217+
\end{cfuncdesc}
218+
211219
\begin{cfuncdesc}{PyObject*}{PyErr_SetFromWindowsErrWithFilename}{int ierr,
212220
char *filename}
213221
Similar to \cfunction{PyErr_SetFromWindowsErr()}, with the
@@ -217,6 +225,14 @@ \chapter{Exception Handling \label{exceptionHandling}}
217225
Availability: Windows.
218226
\end{cfuncdesc}
219227

228+
\begin{cfuncdesc}{PyObject*}{PyErr_SetExcFromWindowsErrWithFilename}
229+
{PyObject *type, int ierr, char *filename}
230+
Similar to \cfunction{PyErr_SetFromWindowsErrWithFilename()}, with
231+
an additional parameter specifying the exception type to be raised.
232+
Availability: Windows.
233+
\versionadded{2.3}
234+
\end{cfuncdesc}
235+
220236
\begin{cfuncdesc}{void}{PyErr_BadInternalCall}{}
221237
This is a shorthand for \samp{PyErr_SetString(PyExc_TypeError,
222238
\var{message})}, where \var{message} indicates that an internal

Include/pyerrors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ extern DL_IMPORT(PyObject *) PyErr_Format(PyObject *, const char *, ...)
8383
#ifdef MS_WINDOWS
8484
extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErrWithFilename(int, const char *);
8585
extern DL_IMPORT(PyObject *) PyErr_SetFromWindowsErr(int);
86+
extern DL_IMPORT(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
87+
PyObject *,int, const char *);
88+
extern DL_IMPORT(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
8689
#endif
8790

8891
/* Export the old function so that the existing API remains available: */

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ Build
380380

381381
C API
382382

383+
- New functions PyErr_SetExcFromWindowsErr() and
384+
PyErr_SetExcFromWindowsErrWithFilename(). Similar to
385+
PyErr_SetFromWindowsErrWithFilename() and
386+
PyErr_SetFromWindowsErr(), but they allow to specify
387+
the exception type to raise. Available on Windows.
388+
383389
- Py_FatalError() is now declared as taking a const char* argument. It
384390
was previously declared without const. This should not affect working
385391
code.

Python/errors.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ PyErr_SetFromErrno(PyObject *exc)
337337

338338
#ifdef MS_WINDOWS
339339
/* Windows specific error code handling */
340-
PyObject *PyErr_SetFromWindowsErrWithFilename(
340+
PyObject *PyErr_SetExcFromWindowsErrWithFilename(
341+
PyObject *exc,
341342
int ierr,
342343
const char *filename)
343344
{
@@ -366,16 +367,29 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
366367
else
367368
v = Py_BuildValue("(is)", err, s);
368369
if (v != NULL) {
369-
PyErr_SetObject(PyExc_WindowsError, v);
370+
PyErr_SetObject(exc, v);
370371
Py_DECREF(v);
371372
}
372373
LocalFree(s);
373374
return NULL;
374375
}
375376

377+
PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr)
378+
{
379+
return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL);
380+
}
381+
376382
PyObject *PyErr_SetFromWindowsErr(int ierr)
377383
{
378-
return PyErr_SetFromWindowsErrWithFilename(ierr, NULL);
384+
return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError,
385+
ierr, NULL);
386+
}
387+
PyObject *PyErr_SetFromWindowsErrWithFilename(
388+
int ierr,
389+
const char *filename)
390+
{
391+
return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError,
392+
ierr, filename);
379393
}
380394
#endif /* MS_WINDOWS */
381395

0 commit comments

Comments
 (0)