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 ----------------------------------------------- */