diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2002-10-03 05:10:39 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2002-10-03 05:10:39 (GMT) |
commit | c2e85bd4e20dc3b5bc446a705a46397c799f56c0 (patch) | |
tree | 8db1cdb9fedfe47739b9ace6da4df65389da3567 /Python/errors.c | |
parent | eb287a26621001fb5d945b7b6246ccac77378cc7 (diff) | |
download | cpython-c2e85bd4e20dc3b5bc446a705a46397c799f56c0.zip cpython-c2e85bd4e20dc3b5bc446a705a46397c799f56c0.tar.gz cpython-c2e85bd4e20dc3b5bc446a705a46397c799f56c0.tar.bz2 |
Patch 594001: PEP 277 - Unicode file name support for Windows NT.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 92 |
1 files changed, 82 insertions, 10 deletions
diff --git a/Python/errors.c b/Python/errors.c index 61d1df0..ccc2ae3 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -259,7 +259,7 @@ PyErr_NoMemory(void) } PyObject * -PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename) +PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) { PyObject *v; char *s; @@ -314,8 +314,8 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename) } #endif /* Unix/Windows */ #endif /* PLAN 9*/ - if (filename != NULL) - v = Py_BuildValue("(iss)", i, s, filename); + if (filenameObject != NULL) + v = Py_BuildValue("(isO)", i, s, filenameObject); else v = Py_BuildValue("(is)", i, s); if (v != NULL) { @@ -330,17 +330,39 @@ PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename) PyObject * +PyErr_SetFromErrnoWithFilename(PyObject *exc, char *filename) +{ + PyObject *name = filename ? PyString_FromString(filename) : NULL; + PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name); + Py_DECREF(name); + return result; +} + +#ifdef Py_WIN_WIDE_FILENAMES +PyObject * +PyErr_SetFromErrnoWithUnicodeFilename(PyObject *exc, Py_UNICODE *filename) +{ + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : + NULL; + PyObject *result = PyErr_SetFromErrnoWithFilenameObject(exc, name); + Py_XDECREF(name); + return result; +} +#endif /* Py_WIN_WIDE_FILENAMES */ + +PyObject * PyErr_SetFromErrno(PyObject *exc) { - return PyErr_SetFromErrnoWithFilename(exc, NULL); + return PyErr_SetFromErrnoWithFilenameObject(exc, NULL); } #ifdef MS_WINDOWS /* Windows specific error code handling */ -PyObject *PyErr_SetExcFromWindowsErrWithFilename( +PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject( PyObject *exc, int ierr, - const char *filename) + PyObject *filenameObject) { int len; char *s; @@ -362,8 +384,8 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename( /* remove trailing cr/lf and dots */ while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.')) s[--len] = '\0'; - if (filename != NULL) - v = Py_BuildValue("(iss)", err, s, filename); + if (filenameObject != NULL) + v = Py_BuildValue("(isO)", err, s, filenameObject); else v = Py_BuildValue("(is)", err, s); if (v != NULL) { @@ -374,6 +396,36 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilename( return NULL; } +PyObject *PyErr_SetExcFromWindowsErrWithFilename( + PyObject *exc, + int ierr, + const char *filename) +{ + PyObject *name = filename ? PyString_FromString(filename) : NULL; + PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, + ierr, + name); + Py_XDECREF(name); + return ret; +} + +#ifdef Py_WIN_WIDE_FILENAMES +PyObject *PyErr_SetExcFromWindowsErrWithUnicodeFilename( + PyObject *exc, + int ierr, + const Py_UNICODE *filename) +{ + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : + NULL; + PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObject(exc, + ierr, + name); + Py_XDECREF(name); + return ret; +} +#endif /* Py_WIN_WIDE_FILENAMES */ + PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr) { return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL); @@ -388,9 +440,29 @@ PyObject *PyErr_SetFromWindowsErrWithFilename( int ierr, const char *filename) { - return PyErr_SetExcFromWindowsErrWithFilename(PyExc_WindowsError, - ierr, filename); + PyObject *name = filename ? PyString_FromString(filename) : NULL; + PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( + PyExc_WindowsError, + ierr, name); + Py_XDECREF(result); + return result; +} + +#ifdef Py_WIN_WIDE_FILENAMES +PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( + int ierr, + const Py_UNICODE *filename) +{ + PyObject *name = filename ? + PyUnicode_FromUnicode(filename, wcslen(filename)) : + NULL; + PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObject( + PyExc_WindowsError, + ierr, name); + Py_XDECREF(result); + return result; } +#endif /* Py_WIN_WIDE_FILENAMES */ #endif /* MS_WINDOWS */ void |