Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 236d8b7

Browse files
committed
Cosmetic changes to MvL's change to unichr():
- the correct range for the error message is range(0x110000); - put the 4-byte Unicode-size code inside the same else branch as the 2-byte code, rather generating unreachable code in the 2-byte case. - Don't hide the 'else' behine the '}'. (I would prefer that in 4-byte mode, any value should be accepted, but reasonable people can argue about that, so I'll put that off.)
1 parent 9b14ab3 commit 236d8b7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Python/bltinmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,27 @@ builtin_unichr(PyObject *self, PyObject *args)
315315

316316
if (x < 0 || x > 0x10ffff) {
317317
PyErr_SetString(PyExc_ValueError,
318-
"unichr() arg not in range(0x10ffff)");
318+
"unichr() arg not in range(0x110000)");
319319
return NULL;
320320
}
321321

322322
if (x <= 0xffff) {
323323
/* UCS-2 character */
324324
s[0] = (Py_UNICODE) x;
325325
return PyUnicode_FromUnicode(s, 1);
326-
} else {
326+
}
327+
else {
327328
#if Py_UNICODE_SIZE == 2
328329
/* UCS-4 character. store as two surrogate characters */
329330
x -= 0x10000L;
330331
s[0] = 0xD800 + (Py_UNICODE) (x >> 10);
331332
s[1] = 0xDC00 + (Py_UNICODE) (x & 0x03FF);
332333
return PyUnicode_FromUnicode(s, 2);
334+
#else
335+
s[0] = (Py_UNICODE)x;
336+
return PyUnicode_FromUnicode(s, 1);
333337
#endif
334338
}
335-
s[0] = (Py_UNICODE)x;
336-
return PyUnicode_FromUnicode(s, 1);
337339
}
338340

339341
static char unichr_doc[] =

0 commit comments

Comments
 (0)