10BC0 gh-139353: Add Objects/unicode_format.c file (#139491) · python/cpython@4c11971 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c11971

Browse files
authored
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.
1 parent 7cafd76 commit 4c11971

File tree

8 files changed

+1047
-973
lines changed

8 files changed

+1047
-973
lines changed

Include/internal/pycore_unicodeobject.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ extern "C" {
1111
#include "pycore_fileutils.h" // _Py_error_handler
1212
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1313

14+
1415
// Maximum code point of Unicode 6.0: 0x10ffff (1,114,111).
1516
#define _Py_MAX_UNICODE 0x10ffff
1617

1718

19+
extern int _PyUnicode_IsModifiable(PyObject *unicode);
20+
21+
1822
static inline void
1923
_PyUnicode_Fill(int kind, void *data, Py_UCS4 value,
2024
Py_ssize_t start, Py_ssize_t length)
@@ -48,6 +52,28 @@ _PyUnicode_Fill(int kind, void *data, Py_UCS4 value,
4852
}
4953
}
5054

55+
static inline int
56+
_PyUnicode_EnsureUnicode(PyObject *obj)
57+
{
58+
if (!PyUnicode_Check(obj)) {
59+
PyErr_Format(PyExc_TypeError,
60+
"must be str, not %T", obj);
61+
return -1;
62+
}
63+
return 0;
64+
}
65+
66+
static inline int
67+
_PyUnicodeWriter_WriteCharInline(_PyUnicodeWriter *writer, Py_UCS4 ch)
68+
{
69+
assert(ch <= _Py_MAX_UNICODE);
70+
if (_PyUnicodeWriter_Prepare(writer, 1, ch) < 0)
71+
return -1;
72+
PyUnicode_WRITE(writer->kind, writer->data, writer->pos, ch);
73+
writer->pos++;
74+
return 0;
75+
}
76+
5177

5278
/* --- Characters Type APIs ----------------------------------------------- */
5379

Makefile.pre.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,10 @@ OBJECT_OBJS= \
557557
Objects/tupleobject.o \
558558
Objects/typeobject.o \
559559
Objects/typevarobject.o \
560+
Objects/unicode_format.o \
560561
Objects/unicode_formatter.o \
561-
Objects/unicodeobject.o \
562562
Objects/unicodectype.o \
563+
Objects/unicodeobject.o \
563564
Objects/unionobject.o \
564565
Objects/weakrefobject.o \
565566
@PERF_TRAMPOLINE_OBJ@
@@ -2105,6 +2106,7 @@ Objects/bytes_methods.o: $(srcdir)/Objects/bytes_methods.c $(BYTESTR_DEPS)
21052106
Objects/bytesobject.o: $(srcdir)/Objects/bytesobject.c $(BYTESTR_DEPS)
21062107
Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c $(BYTESTR_DEPS)
21072108

2109+
Objects/unicode_format.o: $(srcdir)/Objects/unicode_format.c $(UNICODE_DEPS)
21082110
Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
21092111

21102112
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h

0 commit comments

Comments
 (0)
0