Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5d12abe0
Commit
5d12abe0
authored
Sep 03, 2007
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #1075: Use wide API to format error messages.
parent
c76473d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
32 deletions
+57
-32
Python/errors.c
Python/errors.c
+57
-32
No files found.
Python/errors.c
View file @
5d12abe0
...
...
@@ -10,8 +10,8 @@ extern char *strerror(int);
#endif
#ifdef MS_WINDOWS
#include
"windows.h"
#include
"winbase.h"
#include
<windows.h>
#include
<winbase.h>
#endif
#include <ctype.h>
...
...
@@ -270,30 +270,38 @@ PyErr_NoMemory(void)
PyObject
*
PyErr_SetFromErrnoWithFilenameObject
(
PyObject
*
exc
,
PyObject
*
filenameObject
)
{
PyObject
*
message
;
PyObject
*
v
;
char
*
s
;
int
i
=
errno
;
#ifdef PLAN9
char
errbuf
[
ERRMAX
];
#endif
#ifdef MS_WINDOWS
char
*
s_buf
=
NULL
;
char
s_small_buf
[
28
];
/* Room for "Windows Error 0xFFFFFFFF" */
#endif
#else
#ifndef MS_WINDOWS
char
*
s
;
#else
WCHAR
*
s_buf
=
NULL
;
#endif
/* Unix/Windows */
#endif
/* PLAN 9*/
#ifdef EINTR
if
(
i
==
EINTR
&&
PyErr_CheckSignals
())
return
NULL
;
#endif
#ifdef PLAN9
rerrstr
(
errbuf
,
sizeof
errbuf
);
s
=
errbuf
;
message
=
PyUnicode_DecodeUTF8
(
errbuf
,
strlen
(
errbuf
),
"ignore"
)
;
#else
#ifndef MS_WINDOWS
if
(
i
==
0
)
s
=
"Error"
;
/* Sometimes errno didn't get set */
else
#ifndef MS_WINDOWS
s
=
strerror
(
i
);
message
=
PyUnicode_DecodeUTF8
(
s
,
strlen
(
s
),
"ignore"
);
#else
if
(
i
==
0
)
message
=
PyUnicode_FromString
(
"Error"
);
/* Sometimes errno didn't get set */
else
{
/* Note that the Win32 errors do not lineup with the
errno error. So if the error is in the MSVC error
...
...
@@ -301,10 +309,10 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
a Win32 error code
*/
if
(
i
>
0
&&
i
<
_sys_nerr
)
{
s
=
_sys_errlist
[
i
]
;
message
=
PyUnicode_FromString
(
_sys_errlist
[
i
])
;
}
else
{
int
len
=
FormatMessage
(
int
len
=
FormatMessage
W
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
...
...
@@ -313,29 +321,39 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
/* Default language */
(
LP
T
STR
)
&
s_buf
,
(
LP
W
STR
)
&
s_buf
,
0
,
/* size not used */
NULL
);
/* no args */
if
(
len
==
0
)
{
/* Only ever seen this in out-of-mem
situations */
sprintf
(
s_small_buf
,
"Windows Error 0x%X"
,
i
);
s
=
s_small_buf
;
s_buf
=
NULL
;
message
=
PyUnicode_FromFormat
(
"Windows Error 0x%X"
,
i
);
}
else
{
s
=
s_buf
;
/* remove trailing cr/lf and dots */
while
(
len
>
0
&&
(
s
[
len
-
1
]
<=
' '
||
s
[
len
-
1
]
==
'.'
))
s
[
--
len
]
=
'\0'
;
while
(
len
>
0
&&
(
s_buf
[
len
-
1
]
<=
L' '
||
s_buf
[
len
-
1
]
==
L'.'
))
s_buf
[
--
len
]
=
L'\0'
;
message
=
PyUnicode_FromUnicode
(
s_buf
,
len
);
}
}
}
#endif
/* Unix/Windows */
#endif
/* PLAN 9*/
if
(
message
==
NULL
)
{
#ifdef MS_WINDOWS
LocalFree
(
s_buf
);
#endif
return
NULL
;
}
if
(
filenameObject
!=
NULL
)
v
=
Py_BuildValue
(
"(i
UO)"
,
i
,
s
,
filenameObject
);
v
=
Py_BuildValue
(
"(i
OO)"
,
i
,
message
,
filenameObject
);
else
v
=
Py_BuildValue
(
"(iU)"
,
i
,
s
);
v
=
Py_BuildValue
(
"(iO)"
,
i
,
message
);
Py_DECREF
(
message
);
if
(
v
!=
NULL
)
{
PyErr_SetObject
(
exc
,
v
);
Py_DECREF
(
v
);
...
...
@@ -383,13 +401,12 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject
*
filenameObject
)
{
int
len
;
char
*
s
;
char
*
s_buf
=
NULL
;
/* Free via LocalFree */
char
s_small_buf
[
28
];
/* Room for "Windows Error 0xFFFFFFFF" */
WCHAR
*
s_buf
=
NULL
;
/* Free via LocalFree */
PyObject
*
message
;
PyObject
*
v
;
DWORD
err
=
(
DWORD
)
ierr
;
if
(
err
==
0
)
err
=
GetLastError
();
len
=
FormatMessage
(
len
=
FormatMessage
W
(
/* Error API error */
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
...
...
@@ -398,24 +415,32 @@ PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
err
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
/* Default language */
(
LP
T
STR
)
&
s_buf
,
(
LP
W
STR
)
&
s_buf
,
0
,
/* size not used */
NULL
);
/* no args */
if
(
len
==
0
)
{
/* Only seen this in out of mem situations */
sprintf
(
s_small_buf
,
"Windows Error 0x%X"
,
err
);
s
=
s_small_buf
;
message
=
PyUnicode_FromFormat
(
"Windows Error 0x%X"
,
err
);
s_buf
=
NULL
;
}
else
{
s
=
s_buf
;
/* remove trailing cr/lf and dots */
while
(
len
>
0
&&
(
s
[
len
-
1
]
<=
' '
||
s
[
len
-
1
]
==
'.'
))
s
[
--
len
]
=
'\0'
;
while
(
len
>
0
&&
(
s_buf
[
len
-
1
]
<=
L' '
||
s_buf
[
len
-
1
]
==
L'.'
))
s_buf
[
--
len
]
=
L'\0'
;
message
=
PyUnicode_FromUnicode
(
s_buf
,
len
);
}
if
(
message
==
NULL
)
{
LocalFree
(
s_buf
);
return
NULL
;
}
if
(
filenameObject
!=
NULL
)
v
=
Py_BuildValue
(
"(i
UO)"
,
err
,
s
,
filenameObject
);
v
=
Py_BuildValue
(
"(i
OO)"
,
err
,
message
,
filenameObject
);
else
v
=
Py_BuildValue
(
"(iU)"
,
err
,
s
);
v
=
Py_BuildValue
(
"(iO)"
,
err
,
message
);
Py_DECREF
(
message
);
if
(
v
!=
NULL
)
{
PyErr_SetObject
(
exc
,
v
);
Py_DECREF
(
v
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment