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
506f5927
Commit
506f5927
authored
Sep 28, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check size of wchar_t using the preprocessor
parent
73f01c65
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
29 deletions
+27
-29
Objects/unicodeobject.c
Objects/unicodeobject.c
+27
-29
No files found.
Objects/unicodeobject.c
View file @
506f5927
...
...
@@ -830,36 +830,34 @@ _PyUnicode_Ready(PyUnicodeObject *unicode)
assert
(
num_surrogates
==
0
&&
"FindMaxCharAndNumSurrogatePairs() messed up"
);
if
(
sizeof
(
wchar_t
)
==
2
)
{
/* We can share representations and are done. */
unicode
->
data
.
any
=
_PyUnicode_WSTR
(
unicode
);
PyUnicode_2BYTE_DATA
(
unicode
)[
_PyUnicode_WSTR_LENGTH
(
unicode
)]
=
'\0'
;
_PyUnicode_LENGTH
(
unicode
)
=
_PyUnicode_WSTR_LENGTH
(
unicode
);
_PyUnicode_STATE
(
unicode
).
kind
=
PyUnicode_2BYTE_KIND
;
unicode
->
_base
.
utf8
=
NULL
;
unicode
->
_base
.
utf8_length
=
0
;
}
else
{
assert
(
sizeof
(
wchar_t
)
==
4
);
unicode
->
data
.
any
=
PyObject_MALLOC
(
2
*
(
_PyUnicode_WSTR_LENGTH
(
unicode
)
+
1
));
if
(
!
unicode
->
data
.
any
)
{
PyErr_NoMemory
();
return
-
1
;
}
_PyUnicode_CONVERT_BYTES
(
wchar_t
,
Py_UCS2
,
_PyUnicode_WSTR
(
unicode
),
end
,
PyUnicode_2BYTE_DATA
(
unicode
));
PyUnicode_2BYTE_DATA
(
unicode
)[
_PyUnicode_WSTR_LENGTH
(
unicode
)]
=
'\0'
;
_PyUnicode_LENGTH
(
unicode
)
=
_PyUnicode_WSTR_LENGTH
(
unicode
);
_PyUnicode_STATE
(
unicode
).
kind
=
PyUnicode_2BYTE_KIND
;
unicode
->
_base
.
utf8
=
NULL
;
unicode
->
_base
.
utf8_length
=
0
;
PyObject_FREE
(
_PyUnicode_WSTR
(
unicode
));
_PyUnicode_WSTR
(
unicode
)
=
NULL
;
_PyUnicode_WSTR_LENGTH
(
unicode
)
=
0
;
#if SIZEOF_WCHAR_T == 2
/* We can share representations and are done. */
unicode
->
data
.
any
=
_PyUnicode_WSTR
(
unicode
);
PyUnicode_2BYTE_DATA
(
unicode
)[
_PyUnicode_WSTR_LENGTH
(
unicode
)]
=
'\0'
;
_PyUnicode_LENGTH
(
unicode
)
=
_PyUnicode_WSTR_LENGTH
(
unicode
);
_PyUnicode_STATE
(
unicode
).
kind
=
PyUnicode_2BYTE_KIND
;
unicode
->
_base
.
utf8
=
NULL
;
unicode
->
_base
.
utf8_length
=
0
;
#else
/* sizeof(wchar_t) == 4 */
unicode
->
data
.
any
=
PyObject_MALLOC
(
2
*
(
_PyUnicode_WSTR_LENGTH
(
unicode
)
+
1
));
if
(
!
unicode
->
data
.
any
)
{
PyErr_NoMemory
();
return
-
1
;
}
_PyUnicode_CONVERT_BYTES
(
wchar_t
,
Py_UCS2
,
_PyUnicode_WSTR
(
unicode
),
end
,
PyUnicode_2BYTE_DATA
(
unicode
));
PyUnicode_2BYTE_DATA
(
unicode
)[
_PyUnicode_WSTR_LENGTH
(
unicode
)]
=
'\0'
;
_PyUnicode_LENGTH
(
unicode
)
=
_PyUnicode_WSTR_LENGTH
(
unicode
);
_PyUnicode_STATE
(
unicode
).
kind
=
PyUnicode_2BYTE_KIND
;
unicode
->
_base
.
utf8
=
NULL
;
unicode
->
_base
.
utf8_length
=
0
;
PyObject_FREE
(
_PyUnicode_WSTR
(
unicode
));
_PyUnicode_WSTR
(
unicode
)
=
NULL
;
_PyUnicode_WSTR_LENGTH
(
unicode
)
=
0
;
#endif
}
/* maxchar exeeds 16 bit, wee need 4 bytes for unicode characters */
else
{
...
...
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