Skip to content

Commit 9e146bb

Browse files
authored
gh-80527: Deprecate PEP 623 Unicode functions (#91801)
Deprecate functions: * PyUnicode_AS_DATA() * PyUnicode_AS_UNICODE() * PyUnicode_GET_DATA_SIZE() * PyUnicode_GET_SIZE() Previously, these functions were macros and so it wasn't possible to decorate them with Py_DEPRECATED().
1 parent 82ec638 commit 9e146bb

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Include/cpython/unicodeobject.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static inline Py_ssize_t PyUnicode_WSTR_LENGTH(PyObject *op)
613613
If the Py_UNICODE representation is not available, it will be computed
614614
on request. Use PyUnicode_GET_LENGTH() for the length in code points. */
615615

616-
/* Py_DEPRECATED(3.3) */
616+
Py_DEPRECATED(3.3)
617617
static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
618618
{
619619
_Py_COMP_DIAG_PUSH
@@ -627,10 +627,13 @@ static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
627627
}
628628
#define PyUnicode_GET_SIZE(op) PyUnicode_GET_SIZE(_PyObject_CAST(op))
629629

630-
/* Py_DEPRECATED(3.3) */
631-
static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op)
630+
Py_DEPRECATED(3.3)
631+
static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op)
632632
{
633+
_Py_COMP_DIAG_PUSH
634+
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
633635
return PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE;
636+
_Py_COMP_DIAG_POP
634637
}
635638
#define PyUnicode_GET_DATA_SIZE(op) PyUnicode_GET_DATA_SIZE(_PyObject_CAST(op))
636639

@@ -639,7 +642,7 @@ static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
639642
try to port your code to use the new PyUnicode_*BYTE_DATA() macros or
640643
use PyUnicode_WRITE() and PyUnicode_READ(). */
641644

642-
/* Py_DEPRECATED(3.3) */
645+
Py_DEPRECATED(3.3)
643646
static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op)
644647
{
645648
wchar_t *wstr = _PyASCIIObject_CAST(op)->wstr;
@@ -654,10 +657,13 @@ static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op)
654657
}
655658
#define PyUnicode_AS_UNICODE(op) PyUnicode_AS_UNICODE(_PyObject_CAST(op))
656659

657-
/* Py_DEPRECATED(3.3) */
660+
Py_DEPRECATED(3.3)
658661
static inline const char* PyUnicode_AS_DATA(PyObject *op)
659662
{
663+
_Py_COMP_DIAG_PUSH
664+
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
660665
return (const char *)PyUnicode_AS_UNICODE(op);
666+
_Py_COMP_DIAG_POP
661667
}
662668
#define PyUnicode_AS_DATA(op) PyUnicode_AS_DATA(_PyObject_CAST(op))
663669

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Mark functions as deprecated by :pep:`623`: :c:func:`PyUnicode_AS_DATA`,
2+
:c:func:`PyUnicode_AS_UNICODE`, :c:func:`PyUnicode_GET_DATA_SIZE`,
3+
:c:func:`PyUnicode_GET_SIZE`. Patch by Victor Stinner.

0 commit comments

Comments
 (0)