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
9a953dbb
Commit
9a953dbb
authored
Dec 06, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #28808: PyUnicode_CompareWithASCIIString() now never raises exceptions.
parents
19d24674
419967b8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
5 deletions
+23
-5
Doc/c-api/unicode.rst
Doc/c-api/unicode.rst
+1
-2
Include/unicodeobject.h
Include/unicodeobject.h
+1
-1
Misc/NEWS
Misc/NEWS
+5
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+16
-2
No files found.
Doc/c-api/unicode.rst
View file @
9a953dbb
...
...
@@ -1657,8 +1657,7 @@ They all return *NULL* or ``-1`` if an exception occurs.
ASCII-encoded strings, but the function interprets the input string as
ISO-8859-1 if it contains non-ASCII characters.
This function returns ``-1`` upon failure, so one should call
:c:func:`PyErr_Occurred` to check for errors.
This function does not raise exceptions.
.. c:function:: PyObject* PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
...
...
Include/unicodeobject.h
View file @
9a953dbb
...
...
@@ -2051,7 +2051,7 @@ PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
equal, and greater than, respectively. It is best to pass only
ASCII-encoded strings, but the function interprets the input string as
ISO-8859-1 if it contains non-ASCII characters.
Raise an exception and return -1 on error
. */
This function does not raise exceptions
. */
PyAPI_FUNC
(
int
)
PyUnicode_CompareWithASCIIString
(
PyObject
*
left
,
...
...
Misc/NEWS
View file @
9a953dbb
...
...
@@ -36,6 +36,11 @@ Library
-
Issue
#
28843
:
Fix
asyncio
C
Task
to
handle
exceptions
__traceback__
.
C
API
-----
-
Issue
#
28808
:
PyUnicode_CompareWithASCIIString
()
now
never
raises
exceptions
.
Documentation
-------------
...
...
Objects/unicodeobject.c
View file @
9a953dbb
...
...
@@ -11011,10 +11011,24 @@ PyUnicode_CompareWithASCIIString(PyObject* uni, const char* str)
Py_ssize_t
i
;
int
kind
;
Py_UCS4
chr
;
const
unsigned
char
*
ustr
=
(
const
unsigned
char
*
)
str
;
assert
(
_PyUnicode_CHECK
(
uni
));
if
(
PyUnicode_READY
(
uni
)
==
-
1
)
return
-
1
;
if
(
!
PyUnicode_IS_READY
(
uni
))
{
const
wchar_t
*
ws
=
_PyUnicode_WSTR
(
uni
);
/* Compare Unicode string and source character set string */
for
(
i
=
0
;
(
chr
=
ws
[
i
])
&&
ustr
[
i
];
i
++
)
{
if
(
chr
!=
ustr
[
i
])
return
(
chr
<
ustr
[
i
])
?
-
1
:
1
;
}
/* This check keeps Python strings that end in '\0' from comparing equal
to C strings identical up to that point. */
if
(
_PyUnicode_WSTR_LENGTH
(
uni
)
!=
i
||
chr
)
return
1
;
/* uni is longer */
if
(
ustr
[
i
])
return
-
1
;
/* str is longer */
return
0
;
}
kind
=
PyUnicode_KIND
(
uni
);
if
(
kind
==
PyUnicode_1BYTE_KIND
)
{
const
void
*
data
=
PyUnicode_1BYTE_DATA
(
uni
);
...
...
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