gh-139353: Add Objects/unicode_format.c file (#139491)

* Move PyUnicode_Format() implementation from unicodeobject.c
  to unicode_format.c.
* Replace unicode_modifiable() with _PyUnicode_IsModifiable()
* Add empty lines to have two empty lines between functions.
This commit is contained in:
Victor Stinner 2025-10-10 12:52:59 +02:00 committed by GitHub
parent 7cafd76a7f
commit 4c119714d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 1047 additions and 973 deletions

View file

@ -11,10 +11,14 @@ extern "C" {
#include "pycore_fileutils.h" // _Py_error_handler
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111).
#define _Py_MAX_UNICODE 0x10ffff
extern int _PyUnicode_IsModifiable(PyObject *unicode);
static inline void
_PyUnicode_Fill(int kind, void *data, Py_UCS4 value,
Py_ssize_t start, Py_ssize_t length)
@ -48,6 +52,28 @@ _PyUnicode_Fill(int kind, void *data, Py_UCS4 value,
}
}
static inline int
_PyUnicode_EnsureUnicode(PyObject *obj)
{
if (!PyUnicode_Check(obj)) {
PyErr_Format(PyExc_TypeError,
"must be str, not %T", obj);
return -1;
}
return 0;
}
static inline int
_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch)
{
assert(ch <= _Py_MAX_UNICODE);
if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0)
return -1;
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch);
writer->pos++;
return 0;
}
/* --- Characters Type APIs ----------------------------------------------- */

View file

@ -557,9 +557,10 @@ OBJECT_OBJS= \
Objects/tupleobject.o \
Objects/typeobject.o \
Objects/typevarobject.o \
Objects/unicode_format.o \
Objects/unicode_formatter.o \
Objects/unicodeobject.o \
Objects/unicodectype.o \
Objects/unicodeobject.o \
Objects/unionobject.o \
Objects/weakrefobject.o \
@PERF_TRAMPOLINE_OBJ@
@ -2105,6 +2106,7 @@ Objects/bytes_methods.o: $(srcdir)/Objects/bytes_methods.c $(BYTESTR_DEPS)
Objects/bytesobject.o: $(srcdir)/Objects/bytesobject.c $(BYTESTR_DEPS)
Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c $(BYTESTR_DEPS)
Objects/unicode_format.o: $(srcdir)/Objects/unicode_format.c $(UNICODE_DEPS)
Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h

1002
Objects/unicode_format.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -164,6 +164,7 @@
<ClCompile Include="..\Objects\tupleobject.c" />
<ClCompile Include="..\Objects\typeobject.c" />
<ClCompile Include="..\Objects\typevarobject.c" />
<ClCompile Include="..\Objects\unicode_format.c" />
<ClCompile Include="..\Objects\unicodectype.c" />
<ClCompile Include="..\Objects\unicode_formatter.c" />
<ClCompile Include="..\Objects\unicodeobject.c" />

View file

@ -481,6 +481,9 @@
<ClCompile Include="..\Objects\typeobject.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Objects\unicode_format.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Objects\unicodectype.c">
<Filter>Source Files</Filter>
</ClCompile>

View file

@ -558,6 +558,7 @@
<ClCompile Include="..\Objects\tupleobject.c" />
<ClCompile Include="..\Objects\typeobject.c" />
<ClCompile Include="..\Objects\typevarobject.c" />
<ClCompile Include="..\Objects\unicode_format.c" />
<ClCompile Include="..\Objects\unicodectype.c" />
<ClCompile Include="..\Objects\unicode_formatter.c" />
<ClCompile Include="..\Objects\unicodeobject.c" />

View file

@ -1271,6 +1271,9 @@
<ClCompile Include="..\Objects\typeobject.c">
<Filter>Objects</Filter>
</ClCompile>
<ClCompile Include="..\Objects\unicode_format.c">
<Filter>Objects</Filter>
</ClCompile>
<ClCompile Include="..\Objects\unicodectype.c">
<Filter>Objects</Filter>
</ClCompile>