Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7fd73e

Browse files
[3.13]gh-60462: Fix locale.strxfrm() on Solaris (GH-138242) (GH-138449)
It should interpret the result of wcsxfrm() as a sequence of abstractintegers, not a sequence of Unicode code points or using other encodingscheme that does not preserve ordering.(cherry picked from commit482fd0c)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent50048aa commita7fd73e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix:func:`locale.strxfrm` on Solaris (and possibly other platforms).

‎Modules/_localemodule.c‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,54 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
472472
gotoexit;
473473
}
474474
}
475-
result=PyUnicode_FromWideChar(buf,n2);
475+
/* The result is just a sequence of integers, they are not necessary
476+
Unicode code points, so PyUnicode_FromWideChar() cannot be used
477+
here. For example, 0xD83D 0xDC0D should not be larger than 0xFF41.
478+
*/
479+
#ifSIZEOF_WCHAR_T==4
480+
{
481+
/* Some codes can exceed the range of Unicode code points
482+
(0 - 0x10FFFF), so they cannot be directly used in
483+
PyUnicode_FromKindAndData(). They should be first encoded in
484+
a way that preserves the lexicographical order.
485+
486+
Codes in the range 0-0xFFFF represent themself.
487+
Codes larger than 0xFFFF are encoded as a pair:
488+
* 0x1xxxx -- the highest 16 bits
489+
* 0x0xxxx -- the lowest 16 bits
490+
*/
491+
size_tn3=0;
492+
for (size_ti=0;i<n2;i++) {
493+
if ((Py_UCS4)buf[i]>0x10000u) {
494+
n3++;
495+
}
496+
}
497+
if (n3) {
498+
n3+=n2;// no integer overflow
499+
Py_UCS4*buf2=PyMem_New(Py_UCS4,n3);
500+
if (buf2==NULL) {
501+
PyErr_NoMemory();
502+
gotoexit;
503+
}
504+
size_tj=0;
505+
for (size_ti=0;i<n2;i++) {
506+
Py_UCS4c= (Py_UCS4)buf[i];
507+
if (c>0x10000u) {
508+
buf2[j++]= (c >>16) |0x10000u;
509+
buf2[j++]=c&0xFFFFu;
510+
}
511+
else {
512+
buf2[j++]=c;
513+
}
514+
}
515+
assert(j==n3);
516+
result=PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND,buf2,n3);
517+
PyMem_Free(buf2);
518+
gotoexit;
519+
}
520+
}
521+
#endif
522+
result=PyUnicode_FromKindAndData(sizeof(wchar_t),buf,n2);
476523
exit:
477524
PyMem_Free(buf);
478525
PyMem_Free(s);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp