Skip to content

Commit 506cfdf

Browse files
authored
gh-106320: Remove more private _PyUnicode C API functions (#106382)
Remove more private _PyUnicode C API functions: move them to the internal C API (pycore_unicodeobject.h). No longer export most pycore_unicodeobject.h functions.
1 parent b24479d commit 506cfdf

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

Include/cpython/unicodeobject.h

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,6 @@ static inline int PyUnicode_READY(PyObject* Py_UNUSED(op))
394394
}
395395
#define PyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
396396

397-
/* Get a copy of a Unicode string. */
398-
PyAPI_FUNC(PyObject*) _PyUnicode_Copy(
399-
PyObject *unicode
400-
);
401-
402397
/* Copy character from one unicode object into another, this function performs
403398
character conversion when necessary and falls back to memcpy() if possible.
404399
@@ -425,17 +420,6 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_CopyCharacters(
425420
Py_ssize_t how_many
426421
);
427422

428-
/* Unsafe version of PyUnicode_CopyCharacters(): don't check arguments and so
429-
may crash if parameters are invalid (e.g. if the output string
430-
is too short). */
431-
PyAPI_FUNC(void) _PyUnicode_FastCopyCharacters(
432-
PyObject *to,
433-
Py_ssize_t to_start,
434-
PyObject *from,
435-
Py_ssize_t from_start,
436-
Py_ssize_t how_many
437-
);
438-
439423
/* Fill a string with a character: write fill_char into
440424
unicode[start:start+length].
441425
@@ -451,35 +435,13 @@ PyAPI_FUNC(Py_ssize_t) PyUnicode_Fill(
451435
Py_UCS4 fill_char
452436
);
453437

454-
/* Unsafe version of PyUnicode_Fill(): don't check arguments and so may crash
455-
if parameters are invalid (e.g. if length is longer than the string). */
456-
PyAPI_FUNC(void) _PyUnicode_FastFill(
457-
PyObject *unicode,
458-
Py_ssize_t start,
459-
Py_ssize_t length,
460-
Py_UCS4 fill_char
461-
);
462-
463438
/* Create a new string from a buffer of Py_UCS1, Py_UCS2 or Py_UCS4 characters.
464439
Scan the string to find the maximum character. */
465440
PyAPI_FUNC(PyObject*) PyUnicode_FromKindAndData(
466441
int kind,
467442
const void *buffer,
468443
Py_ssize_t size);
469444

470-
/* Create a new string from a buffer of ASCII characters.
471-
WARNING: Don't check if the string contains any non-ASCII character. */
472-
PyAPI_FUNC(PyObject*) _PyUnicode_FromASCII(
473-
const char *buffer,
474-
Py_ssize_t size);
475-
476-
/* Compute the maximum character of the substring unicode[start:end].
477-
Return 127 for an empty string. */
478-
PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (
479-
PyObject *unicode,
480-
Py_ssize_t start,
481-
Py_ssize_t end);
482-
483445
/* --- Manage the default encoding ---------------------------------------- */
484446

485447
/* Returns a pointer to the default encoding (UTF-8) of the
@@ -618,37 +580,6 @@ PyAPI_FUNC(PyObject*) _PyUnicode_TransformDecimalAndSpaceToASCII(
618580
PyObject *unicode /* Unicode object */
619581
);
620582

621-
/* --- Methods & Slots ---------------------------------------------------- */
622-
623-
PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray(
624-
PyObject *separator,
625-
PyObject *const *items,
626-
Py_ssize_t seqlen
627-
);
628-
629-
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
630-
0 otherwise. The right argument must be ASCII identifier.
631-
Any error occurs inside will be cleared before return. */
632-
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId(
633-
PyObject *left, /* Left string */
634-
_Py_Identifier *right /* Right identifier */
635-
);
636-
637-
/* Test whether a unicode is equal to ASCII string. Return 1 if true,
638-
0 otherwise. The right argument must be ASCII-encoded string.
639-
Any error occurs inside will be cleared before return. */
640-
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString(
641-
PyObject *left,
642-
const char *right /* ASCII-encoded string */
643-
);
644-
645-
/* Externally visible for str.strip(unicode) */
646-
PyAPI_FUNC(PyObject *) _PyUnicode_XStrip(
647-
PyObject *self,
648-
int striptype,
649-
PyObject *sepobj
650-
);
651-
652583
/* === Characters Type APIs =============================================== */
653584

654585
/* These should not be used directly. Use the Py_UNICODE_IS* and

Include/internal/pycore_unicodeobject.h

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,44 @@ extern "C" {
1414
void _PyUnicode_ExactDealloc(PyObject *op);
1515
Py_ssize_t _PyUnicode_InternedSize(void);
1616

17+
/* Get a copy of a Unicode string. */
18+
PyAPI_FUNC(PyObject*) _PyUnicode_Copy(
19+
PyObject *unicode
20+
);
21+
22+
/* Unsafe version of PyUnicode_Fill(): don't check arguments and so may crash
23+
if parameters are invalid (e.g. if length is longer than the string). */
24+
extern void _PyUnicode_FastFill(
25+
PyObject *unicode,
26+
Py_ssize_t start,
27+
Py_ssize_t length,
28+
Py_UCS4 fill_char
29+
);
30+
31+
/* Unsafe version of PyUnicode_CopyCharacters(): don't check arguments and so
32+
may crash if parameters are invalid (e.g. if the output string
33+
is too short). */
34+
extern void _PyUnicode_FastCopyCharacters(
35+
PyObject *to,
36+
Py_ssize_t to_start,
37+
PyObject *from,
38+
Py_ssize_t from_start,
39+
Py_ssize_t how_many
40+
);
41+
42+
/* Create a new string from a buffer of ASCII characters.
43+
WARNING: Don't check if the string contains any non-ASCII character. */
44+
extern PyObject* _PyUnicode_FromASCII(
45+
const char *buffer,
46+
Py_ssize_t size);
47+
48+
/* Compute the maximum character of the substring unicode[start:end].
49+
Return 127 for an empty string. */
50+
extern Py_UCS4 _PyUnicode_FindMaxChar (
51+
PyObject *unicode,
52+
Py_ssize_t start,
53+
Py_ssize_t end);
54+
1755
/* --- _PyUnicodeWriter API ----------------------------------------------- */
1856

1957
typedef struct {
@@ -141,10 +179,40 @@ PyAPI_FUNC(int) _PyUnicode_FormatAdvancedWriter(
141179

142180
/* --- Methods & Slots ---------------------------------------------------- */
143181

182+
extern PyObject* _PyUnicode_JoinArray(
183+
PyObject *separator,
184+
PyObject *const *items,
185+
Py_ssize_t seqlen
186+
);
187+
188+
/* Test whether a unicode is equal to ASCII identifier. Return 1 if true,
189+
0 otherwise. The right argument must be ASCII identifier.
190+
Any error occurs inside will be cleared before return. */
191+
extern int _PyUnicode_EqualToASCIIId(
192+
PyObject *left, /* Left string */
193+
_Py_Identifier *right /* Right identifier */
194+
);
195+
196+
/* Test whether a unicode is equal to ASCII string. Return 1 if true,
197+
0 otherwise. The right argument must be ASCII-encoded string.
198+
Any error occurs inside will be cleared before return. */
199+
PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString(
200+
PyObject *left,
201+
const char *right /* ASCII-encoded string */
202+
);
203+
204+
/* Externally visible for str.strip(unicode) */
205+
extern PyObject* _PyUnicode_XStrip(
206+
PyObject *self,
207+
int striptype,
208+
PyObject *sepobj
209+
);
210+
211+
144212
/* Using explicit passed-in values, insert the thousands grouping
145213
into the string pointed to by buffer. For the argument descriptions,
146214
see Objects/stringlib/localeutil.h */
147-
PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping(
215+
extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
148216
_PyUnicodeWriter *writer,
149217
Py_ssize_t n_buffer,
150218
PyObject *digits,

Python/future.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Python.h"
22
#include "pycore_ast.h" // _PyAST_GetDocString()
3+
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
34

45
#define UNDEFINED_FUTURE_FEATURE "future feature %.100s is not defined"
56

0 commit comments

Comments
 (0)