Skip to content

Commit e1fd675

Browse files
committed
gh-128863: Deprecate the private _PyUnicodeWriter API
Deprecate private C API functions: * _PyUnicodeWriter_Init() * _PyUnicodeWriter_Finish() * _PyUnicodeWriter_Dealloc() * _PyUnicodeWriter_WriteChar() * _PyUnicodeWriter_WriteStr() * _PyUnicodeWriter_WriteSubstring() * _PyUnicodeWriter_WriteASCIIString() * _PyUnicodeWriter_WriteLatin1String() These functions are not deprecated in the internal C API (if the Py_BUILD_CORE macro is defined).
1 parent bab8918 commit e1fd675

File tree

4 files changed

+60
-32
lines changed

4 files changed

+60
-32
lines changed

Doc/deprecations/c-api-pending-removal-in-3.18.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Pending removal in Python 3.18
1010
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
1111
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
1212
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
13+
* :c:func:`!_PyUnicodeWriter_Init`: use :c:func:`PyUnicodeWriter_Create`
14+
* :c:func:`!_PyUnicodeWriter_Finish`: use :c:func:`PyUnicodeWriter_Finish`
15+
* :c:func:`!_PyUnicodeWriter_Dealloc`: use :c:func:`PyUnicodeWriter_Discard`
16+
* :c:func:`!_PyUnicodeWriter_WriteChar`: use :c:func:`PyUnicodeWriter_WriteChar`
17+
* :c:func:`!_PyUnicodeWriter_WriteStr`: use :c:func:`PyUnicodeWriter_WriteStr`
18+
* :c:func:`!_PyUnicodeWriter_WriteSubstring`: use :c:func:`PyUnicodeWriter_WriteSubstring`
19+
* :c:func:`!_PyUnicodeWriter_WriteASCIIString`: use :c:func:`PyUnicodeWriter_WriteUTF8`
20+
* :c:func:`!_PyUnicodeWriter_WriteLatin1String`: use :c:func:`PyUnicodeWriter_WriteUTF8`
1321
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
1422
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
1523

Doc/whatsnew/3.14.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,14 @@ Deprecated
13991399
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
14001400
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
14011401
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
1402+
* :c:func:`!_PyUnicodeWriter_Init`: use :c:func:`PyUnicodeWriter_Create`
1403+
* :c:func:`!_PyUnicodeWriter_Finish`: use :c:func:`PyUnicodeWriter_Finish`
1404+
* :c:func:`!_PyUnicodeWriter_Dealloc`: use :c:func:`PyUnicodeWriter_Discard`
1405+
* :c:func:`!_PyUnicodeWriter_WriteChar`: use :c:func:`PyUnicodeWriter_WriteChar`
1406+
* :c:func:`!_PyUnicodeWriter_WriteStr`: use :c:func:`PyUnicodeWriter_WriteStr`
1407+
* :c:func:`!_PyUnicodeWriter_WriteSubstring`: use :c:func:`PyUnicodeWriter_WriteSubstring`
1408+
* :c:func:`!_PyUnicodeWriter_WriteASCIIString`: use :c:func:`PyUnicodeWriter_WriteUTF8`
1409+
* :c:func:`!_PyUnicodeWriter_WriteLatin1String`: use :c:func:`PyUnicodeWriter_WriteUTF8`
14021410
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
14031411
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
14041412

Include/cpython/unicodeobject.h

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,19 @@ typedef struct {
521521
unsigned char readonly;
522522
} _PyUnicodeWriter;
523523

524+
#ifndef Py_BUILD_CORE
525+
# define _Py_PUBLIC_DEPRECATED(version) Py_DEPRECATED(version)
526+
#else
527+
# define _Py_PUBLIC_DEPRECATED(version)
528+
#endif
529+
524530
// Initialize a Unicode writer.
525531
//
526532
// By default, the minimum buffer size is 0 character and overallocation is
527533
// disabled. Set min_length, min_char and overallocate attributes to control
528534
// the allocation of the buffer.
529-
PyAPI_FUNC(void)
530-
_PyUnicodeWriter_Init(_PyUnicodeWriter *writer);
535+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(void) _PyUnicodeWriter_Init(
536+
_PyUnicodeWriter *writer);
531537

532538
/* Prepare the buffer to write 'length' characters
533539
with the specified maximum character.
@@ -543,9 +549,10 @@ _PyUnicodeWriter_Init(_PyUnicodeWriter *writer);
543549

544550
/* Don't call this function directly, use the _PyUnicodeWriter_Prepare() macro
545551
instead. */
546-
PyAPI_FUNC(int)
547-
_PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
548-
Py_ssize_t length, Py_UCS4 maxchar);
552+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_PrepareInternal(
553+
_PyUnicodeWriter *writer,
554+
Py_ssize_t length,
555+
Py_UCS4 maxchar);
549556

550557
/* Prepare the buffer to have at least the kind KIND.
551558
For example, kind=PyUnicode_2BYTE_KIND ensures that the writer will
@@ -559,58 +566,55 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
559566

560567
/* Don't call this function directly, use the _PyUnicodeWriter_PrepareKind()
561568
macro instead. */
562-
PyAPI_FUNC(int)
563-
_PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer,
564-
int kind);
569+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_PrepareKindInternal(
570+
_PyUnicodeWriter *writer,
571+
int kind);
565572

566573
/* Append a Unicode character.
567574
Return 0 on success, raise an exception and return -1 on error. */
568-
PyAPI_FUNC(int)
569-
_PyUnicodeWriter_WriteChar(_PyUnicodeWriter *writer,
570-
Py_UCS4 ch
571-
);
575+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_WriteChar(
576+
_PyUnicodeWriter *writer,
577+
Py_UCS4 ch);
572578

573579
/* Append a Unicode string.
574580
Return 0 on success, raise an exception and return -1 on error. */
575-
PyAPI_FUNC(int)
576-
_PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer,
577-
PyObject *str /* Unicode string */
578-
);
581+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_WriteStr(
582+
_PyUnicodeWriter *writer,
583+
PyObject *str); /* Unicode string */
579584

580585
/* Append a substring of a Unicode string.
581586
Return 0 on success, raise an exception and return -1 on error. */
582-
PyAPI_FUNC(int)
583-
_PyUnicodeWriter_WriteSubstring(_PyUnicodeWriter *writer,
587+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_WriteSubstring(
588+
_PyUnicodeWriter *writer,
584589
PyObject *str, /* Unicode string */
585590
Py_ssize_t start,
586-
Py_ssize_t end
587-
);
591+
Py_ssize_t end);
588592

589593
/* Append an ASCII-encoded byte string.
590594
Return 0 on success, raise an exception and return -1 on error. */
591-
PyAPI_FUNC(int)
592-
_PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
595+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_WriteASCIIString(
596+
_PyUnicodeWriter *writer,
593597
const char *str, /* ASCII-encoded byte string */
594-
Py_ssize_t len /* number of bytes, or -1 if unknown */
595-
);
598+
Py_ssize_t len); /* number of bytes, or -1 if unknown */
596599

597600
/* Append a latin1-encoded byte string.
598601
Return 0 on success, raise an exception and return -1 on error. */
599-
PyAPI_FUNC(int)
600-
_PyUnicodeWriter_WriteLatin1String(_PyUnicodeWriter *writer,
602+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(int) _PyUnicodeWriter_WriteLatin1String(
603+
_PyUnicodeWriter *writer,
601604
const char *str, /* latin1-encoded byte string */
602-
Py_ssize_t len /* length in bytes */
603-
);
605+
Py_ssize_t len); /* length in bytes */
604606

605607
/* Get the value of the writer as a Unicode string. Clear the
606608
buffer of the writer. Raise an exception and return NULL
607609
on error. */
608-
PyAPI_FUNC(PyObject *)
609-
_PyUnicodeWriter_Finish(_PyUnicodeWriter *writer);
610+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyUnicodeWriter_Finish(
611+
_PyUnicodeWriter *writer);
610612

611613
/* Deallocate memory of a writer (clear its internal buffer). */
612-
PyAPI_FUNC(void)
613-
_PyUnicodeWriter_Dealloc(_PyUnicodeWriter *writer);
614+
_Py_PUBLIC_DEPRECATED(3.14) PyAPI_FUNC(void) _PyUnicodeWriter_Dealloc(
615+
_PyUnicodeWriter *writer);
616+
617+
#undef _Py_PUBLIC_DEPRECATED
614618

615619

616620
/* --- Manage the default encoding ---------------------------------------- */

Misc/NEWS.d/next/C_API/2025-01-15-11-42-07.gh-issue-128863.C9MkB_.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Python 3.18:
88
* :c:func:`!_PyLong_New`: use :c:func:`PyLongWriter_Create`.
99
* :c:func:`!_PyThreadState_UncheckedGet`: use :c:func:`PyThreadState_GetUnchecked`.
1010
* :c:func:`!_PyUnicode_AsString`: use :c:func:`PyUnicode_AsUTF8`.
11+
* :c:func:`!_PyUnicodeWriter_Init`: use :c:func:`PyUnicodeWriter_Create`
12+
* :c:func:`!_PyUnicodeWriter_Finish`: use :c:func:`PyUnicodeWriter_Finish`
13+
* :c:func:`!_PyUnicodeWriter_Dealloc`: use :c:func:`PyUnicodeWriter_Discard`
14+
* :c:func:`!_PyUnicodeWriter_WriteChar`: use :c:func:`PyUnicodeWriter_WriteChar`
15+
* :c:func:`!_PyUnicodeWriter_WriteStr`: use :c:func:`PyUnicodeWriter_WriteStr`
16+
* :c:func:`!_PyUnicodeWriter_WriteSubstring`: use :c:func:`PyUnicodeWriter_WriteSubstring`
17+
* :c:func:`!_PyUnicodeWriter_WriteASCIIString`: use :c:func:`PyUnicodeWriter_WriteUTF8`
18+
* :c:func:`!_PyUnicodeWriter_WriteLatin1String`: use :c:func:`PyUnicodeWriter_WriteUTF8`
1119
* :c:func:`!_Py_HashPointer`: use :c:func:`Py_HashPointer`.
1220
* :c:func:`!_Py_fopen_obj`: use :c:func:`Py_fopen`.
1321

0 commit comments

Comments
 (0)