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

Commit6e63c47

Browse files
authored
gh-119182: Use public PyUnicodeWriter in _json.c (#129249)
Replace the private _PyUnicodeWriter API with the publicPyUnicodeWriter API.
1 parentc005ea4 commit6e63c47

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

‎Modules/_json.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx) {
353353
returntpl;
354354
}
355355

356+
staticinlineint
357+
_PyUnicodeWriter_IsEmpty(PyUnicodeWriter*writer_pub)
358+
{
359+
_PyUnicodeWriter*writer= (_PyUnicodeWriter*)writer_pub;
360+
return (writer->pos==0);
361+
}
362+
356363
staticPyObject*
357364
scanstring_unicode(PyObject*pystr,Py_ssize_tend,intstrict,Py_ssize_t*next_end_ptr)
358365
{
@@ -371,9 +378,10 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
371378
constvoid*buf;
372379
intkind;
373380

374-
_PyUnicodeWriterwriter;
375-
_PyUnicodeWriter_Init(&writer);
376-
writer.overallocate=1;
381+
PyUnicodeWriter*writer=PyUnicodeWriter_Create(0);
382+
if (writer==NULL) {
383+
gotobail;
384+
}
377385

378386
len=PyUnicode_GET_LENGTH(pystr);
379387
buf=PyUnicode_DATA(pystr);
@@ -404,7 +412,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
404412

405413
if (c=='"') {
406414
// Fast path for simple case.
407-
if (writer.buffer==NULL) {
415+
if (_PyUnicodeWriter_IsEmpty(writer)) {
408416
PyObject*ret=PyUnicode_Substring(pystr,end,next);
409417
if (ret==NULL) {
410418
gotobail;
@@ -420,7 +428,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
420428

421429
/* Pick up this chunk if it's not zero length */
422430
if (next!=end) {
423-
if (_PyUnicodeWriter_WriteSubstring(&writer,pystr,end,next)<0) {
431+
if (PyUnicodeWriter_WriteSubstring(writer,pystr,end,next)<0) {
424432
gotobail;
425433
}
426434
}
@@ -511,18 +519,18 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
511519
end-=6;
512520
}
513521
}
514-
if (_PyUnicodeWriter_WriteChar(&writer,c)<0) {
522+
if (PyUnicodeWriter_WriteChar(writer,c)<0) {
515523
gotobail;
516524
}
517525
}
518526

519-
rval=_PyUnicodeWriter_Finish(&writer);
527+
rval=PyUnicodeWriter_Finish(writer);
520528
*next_end_ptr=end;
521529
returnrval;
522530

523531
bail:
524532
*next_end_ptr=-1;
525-
_PyUnicodeWriter_Dealloc(&writer);
533+
PyUnicodeWriter_Discard(writer);
526534
returnNULL;
527535
}
528536

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp