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
2fc507fe
Commit
2fc507fe
authored
Nov 04, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace tabs by spaces
parent
12be46ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
46 deletions
+46
-46
Objects/unicodeobject.c
Objects/unicodeobject.c
+46
-46
No files found.
Objects/unicodeobject.c
View file @
2fc507fe
...
...
@@ -7267,13 +7267,13 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
BOOL
*
pusedDefaultChar
=
&
usedDefaultChar
;
int
outsize
;
PyObject
*
exc
=
NULL
;
Py_UNICODE
*
p
;
Py_ssize_t
size
;
Py_UNICODE
*
p
;
Py_ssize_t
size
;
const
DWORD
flags
=
encode_code_page_flags
(
code_page
,
NULL
);
char
*
out
;
/* Create a substring so that we can get the UTF-16 representation
of just the slice under consideration. */
PyObject
*
substring
;
/* Create a substring so that we can get the UTF-16 representation
of just the slice under consideration. */
PyObject
*
substring
;
assert
(
len
>
0
);
...
...
@@ -7282,14 +7282,14 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
else
pusedDefaultChar
=
NULL
;
substring
=
PyUnicode_Substring
(
unicode
,
offset
,
offset
+
len
);
if
(
substring
==
NULL
)
return
-
1
;
p
=
PyUnicode_AsUnicodeAndSize
(
substring
,
&
size
);
if
(
p
==
NULL
)
{
Py_DECREF
(
substring
);
return
-
1
;
}
substring
=
PyUnicode_Substring
(
unicode
,
offset
,
offset
+
len
);
if
(
substring
==
NULL
)
return
-
1
;
p
=
PyUnicode_AsUnicodeAndSize
(
substring
,
&
size
);
if
(
p
==
NULL
)
{
Py_DECREF
(
substring
);
return
-
1
;
}
/* First get the size of the result */
outsize
=
WideCharToMultiByte
(
code_page
,
flags
,
...
...
@@ -7299,18 +7299,18 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
if
(
outsize
<=
0
)
goto
error
;
/* If we used a default char, then we failed! */
if
(
pusedDefaultChar
&&
*
pusedDefaultChar
)
{
Py_DECREF
(
substring
);
if
(
pusedDefaultChar
&&
*
pusedDefaultChar
)
{
Py_DECREF
(
substring
);
return
-
2
;
}
}
if
(
*
outbytes
==
NULL
)
{
/* Create string object */
*
outbytes
=
PyBytes_FromStringAndSize
(
NULL
,
outsize
);
if
(
*
outbytes
==
NULL
)
{
Py_DECREF
(
substring
);
if
(
*
outbytes
==
NULL
)
{
Py_DECREF
(
substring
);
return
-
1
;
}
}
out
=
PyBytes_AS_STRING
(
*
outbytes
);
}
else
{
...
...
@@ -7318,13 +7318,13 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
const
Py_ssize_t
n
=
PyBytes_Size
(
*
outbytes
);
if
(
outsize
>
PY_SSIZE_T_MAX
-
n
)
{
PyErr_NoMemory
();
Py_DECREF
(
substring
);
Py_DECREF
(
substring
);
return
-
1
;
}
if
(
_PyBytes_Resize
(
outbytes
,
n
+
outsize
)
<
0
)
{
Py_DECREF
(
substring
);
if
(
_PyBytes_Resize
(
outbytes
,
n
+
outsize
)
<
0
)
{
Py_DECREF
(
substring
);
return
-
1
;
}
}
out
=
PyBytes_AS_STRING
(
*
outbytes
)
+
n
;
}
...
...
@@ -7333,7 +7333,7 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
p
,
size
,
out
,
outsize
,
NULL
,
pusedDefaultChar
);
Py_CLEAR
(
substring
);
Py_CLEAR
(
substring
);
if
(
outsize
<=
0
)
goto
error
;
if
(
pusedDefaultChar
&&
*
pusedDefaultChar
)
...
...
@@ -7341,7 +7341,7 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
return
0
;
error:
Py_XDECREF
(
substring
);
Py_XDECREF
(
substring
);
if
(
GetLastError
()
==
ERROR_NO_UNICODE_TRANSLATION
)
return
-
2
;
PyErr_SetFromWindowsErr
(
0
);
...
...
@@ -7361,8 +7361,8 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
Py_ssize_t
insize
,
const
char
*
errors
)
{
const
DWORD
flags
=
encode_code_page_flags
(
code_page
,
errors
);
Py_ssize_t
pos
=
unicode_offset
;
Py_ssize_t
endin
=
unicode_offset
+
insize
;
Py_ssize_t
pos
=
unicode_offset
;
Py_ssize_t
endin
=
unicode_offset
+
insize
;
/* Ideally, we should get reason from FormatMessage. This is the Windows
2000 English version of the message. */
const
char
*
reason
=
"invalid character"
;
...
...
@@ -7430,20 +7430,20 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
/* Encode the string character per character */
while
(
pos
<
endin
)
{
Py_UCS4
ch
=
PyUnicode_READ_CHAR
(
unicode
,
pos
);
wchar_t
chars
[
2
];
int
charsize
;
if
(
ch
<
0x10000
)
{
chars
[
0
]
=
(
wchar_t
)
ch
;
charsize
=
1
;
}
else
{
ch
-=
0x10000
;
chars
[
0
]
=
0xd800
+
(
ch
>>
10
);
chars
[
1
]
=
0xdc00
+
(
ch
&
0x3ff
);
charsize
=
2
;
}
Py_UCS4
ch
=
PyUnicode_READ_CHAR
(
unicode
,
pos
);
wchar_t
chars
[
2
];
int
charsize
;
if
(
ch
<
0x10000
)
{
chars
[
0
]
=
(
wchar_t
)
ch
;
charsize
=
1
;
}
else
{
ch
-=
0x10000
;
chars
[
0
]
=
0xd800
+
(
ch
>>
10
);
chars
[
1
]
=
0xdc00
+
(
ch
&
0x3ff
);
charsize
=
2
;
}
outsize
=
WideCharToMultiByte
(
code_page
,
flags
,
chars
,
charsize
,
buffer
,
Py_ARRAY_LENGTH
(
buffer
),
...
...
@@ -7547,9 +7547,9 @@ encode_code_page(int code_page,
Py_ssize_t
offset
;
int
chunk_len
,
ret
,
done
;
if
(
PyUnicode_READY
(
unicode
)
<
0
)
return
NULL
;
len
=
PyUnicode_GET_LENGTH
(
unicode
);
if
(
PyUnicode_READY
(
unicode
)
<
0
)
return
NULL
;
len
=
PyUnicode_GET_LENGTH
(
unicode
);
if
(
code_page
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"invalid code page number"
);
...
...
@@ -7563,7 +7563,7 @@ encode_code_page(int code_page,
do
{
#ifdef NEED_RETRY
/* UTF-16 encoding may double the size, so use only INT_MAX/2
/* UTF-16 encoding may double the size, so use only INT_MAX/2
chunks. */
if
(
len
>
INT_MAX
/
2
)
{
chunk_len
=
INT_MAX
/
2
;
...
...
@@ -7575,7 +7575,7 @@ encode_code_page(int code_page,
chunk_len
=
(
int
)
len
;
done
=
1
;
}
ret
=
encode_code_page_strict
(
code_page
,
&
outbytes
,
unicode
,
offset
,
chunk_len
,
errors
);
...
...
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