Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a73b57

Browse files
authored
gh-106320: Remove _PyUnicode_TransformDecimalAndSpaceToASCII() (#106398)
Remove private _PyUnicode_TransformDecimalAndSpaceToASCII() and otherprivate _PyUnicode C API functions: move them to the internal C API(pycore_unicodeobject.h). No longer most of these functions.Replace _testcapi.unicode_transformdecimalandspacetoascii() with_testinternal._PyUnicode_TransformDecimalAndSpaceToASCII().
1 parentec931fc commit8a73b57

File tree

6 files changed

+56
-50
lines changed

6 files changed

+56
-50
lines changed

‎Include/cpython/unicodeobject.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ typedef struct {
167167
}data;/* Canonical, smallest-form Unicode buffer */
168168
}PyUnicodeObject;
169169

170-
PyAPI_FUNC(int)_PyUnicode_CheckConsistency(
171-
PyObject*op,
172-
intcheck_content);
173-
174170

175171
#define_PyASCIIObject_CAST(op) \
176172
(assert(PyUnicode_Check(op)), \
@@ -461,19 +457,6 @@ PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode);
461457

462458
#define_PyUnicode_AsString PyUnicode_AsUTF8
463459

464-
/* --- Decimal Encoder ---------------------------------------------------- */
465-
466-
/* Coverts a Unicode object holding a decimal value to an ASCII string
467-
for using in int, float and complex parsers.
468-
Transforms code points that have decimal digit property to the
469-
corresponding ASCII digit code points. Transforms spaces to ASCII.
470-
Transforms code points starting from the first non-ASCII code point that
471-
is neither a decimal digit nor a space to the end into '?'. */
472-
473-
PyAPI_FUNC(PyObject*)_PyUnicode_TransformDecimalAndSpaceToASCII(
474-
PyObject*unicode/* Unicode object */
475-
);
476-
477460
/* === Characters Type APIs =============================================== */
478461

479462
/* These should not be used directly. Use the Py_UNICODE_IS* and
@@ -623,23 +606,3 @@ static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
623606
||Py_UNICODE_ISDIGIT(ch)
624607
||Py_UNICODE_ISNUMERIC(ch));
625608
}
626-
627-
628-
/* === Misc functions ===================================================== */
629-
630-
PyAPI_FUNC(PyObject*)_PyUnicode_FormatLong(PyObject*,int,int,int);
631-
632-
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
633-
PyAPI_FUNC(PyObject*)_PyUnicode_FromId(_Py_Identifier*);
634-
635-
/* Fast equality check when the inputs are known to be exact unicode types
636-
and where the hash values are equal (i.e. a very probable match) */
637-
PyAPI_FUNC(int)_PyUnicode_EQ(PyObject*,PyObject*);
638-
639-
/* Equality check. */
640-
PyAPI_FUNC(int)_PyUnicode_Equal(PyObject*,PyObject*);
641-
642-
PyAPI_FUNC(int)_PyUnicode_WideCharString_Converter(PyObject*,void*);
643-
PyAPI_FUNC(int)_PyUnicode_WideCharString_Opt_Converter(PyObject*,void*);
644-
645-
PyAPI_FUNC(Py_ssize_t)_PyUnicode_ScanIdentifier(PyObject*);

‎Include/internal/pycore_unicodeobject.h

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

14-
void_PyUnicode_ExactDealloc(PyObject*op);
15-
Py_ssize_t_PyUnicode_InternedSize(void);
14+
PyAPI_FUNC(int)_PyUnicode_CheckConsistency(
15+
PyObject*op,
16+
intcheck_content);
17+
18+
externvoid_PyUnicode_ExactDealloc(PyObject*op);
19+
externPy_ssize_t_PyUnicode_InternedSize(void);
1620

1721
/* Get a copy of a Unicode string. */
1822
PyAPI_FUNC(PyObject*)_PyUnicode_Copy(
@@ -277,6 +281,18 @@ extern PyObject* _PyUnicode_EncodeCharmap(
277281
PyObject*mapping,/* encoding mapping */
278282
constchar*errors);/* error handling */
279283

284+
/* --- Decimal Encoder ---------------------------------------------------- */
285+
286+
/* Coverts a Unicode object holding a decimal value to an ASCII string
287+
for using in int, float and complex parsers.
288+
Transforms code points that have decimal digit property to the
289+
corresponding ASCII digit code points. Transforms spaces to ASCII.
290+
Transforms code points starting from the first non-ASCII code point that
291+
is neither a decimal digit nor a space to the end into '?'. */
292+
293+
PyAPI_FUNC(PyObject*)_PyUnicode_TransformDecimalAndSpaceToASCII(
294+
PyObject*unicode);/* Unicode object */
295+
280296
/* --- Methods & Slots ---------------------------------------------------- */
281297

282298
externPyObject*_PyUnicode_JoinArray(
@@ -323,6 +339,25 @@ extern Py_ssize_t _PyUnicode_InsertThousandsGrouping(
323339
PyObject*thousands_sep,
324340
Py_UCS4*maxchar);
325341

342+
/* --- Misc functions ----------------------------------------------------- */
343+
344+
externPyObject*_PyUnicode_FormatLong(PyObject*,int,int,int);
345+
346+
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
347+
PyAPI_FUNC(PyObject*)_PyUnicode_FromId(_Py_Identifier*);
348+
349+
/* Fast equality check when the inputs are known to be exact unicode types
350+
and where the hash values are equal (i.e. a very probable match) */
351+
externint_PyUnicode_EQ(PyObject*,PyObject*);
352+
353+
/* Equality check. */
354+
PyAPI_FUNC(int)_PyUnicode_Equal(PyObject*,PyObject*);
355+
356+
externint_PyUnicode_WideCharString_Converter(PyObject*,void*);
357+
externint_PyUnicode_WideCharString_Opt_Converter(PyObject*,void*);
358+
359+
PyAPI_FUNC(Py_ssize_t)_PyUnicode_ScanIdentifier(PyObject*);
360+
326361
/* --- Runtime lifecycle -------------------------------------------------- */
327362

328363
externvoid_PyUnicode_InitState(PyInterpreterState*);

‎Lib/test/test_capi/test_unicode.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import_testcapi
88
exceptImportError:
99
_testcapi=None
10+
try:
11+
import_testinternalcapi
12+
exceptImportError:
13+
_testinternalcapi=None
1014

1115

1216
NULL=None
@@ -913,10 +917,10 @@ def test_getdefaultencoding(self):
913917
self.assertEqual(getdefaultencoding(),b'utf-8')
914918

915919
@support.cpython_only
916-
@unittest.skipIf(_testcapiisNone,'need_testcapi module')
920+
@unittest.skipIf(_testinternalcapiisNone,'need_testinternalcapi module')
917921
deftest_transform_decimal_and_space(self):
918922
"""Test _PyUnicode_TransformDecimalAndSpaceToASCII()"""
919-
from_testcapiimportunicode_transformdecimalandspacetoasciiastransform_decimal
923+
from_testinternalcapiimport_PyUnicode_TransformDecimalAndSpaceToASCIIastransform_decimal
920924

921925
self.assertEqual(transform_decimal('123'),
922926
'123')

‎Modules/_testcapi/unicode.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,6 @@ unicode_getdefaultencoding(PyObject *self, PyObject *Py_UNUSED(ignored))
660660
returnPyBytes_FromString(s);
661661
}
662662

663-
/* Test _PyUnicode_TransformDecimalAndSpaceToASCII() */
664-
staticPyObject*
665-
unicode_transformdecimalandspacetoascii(PyObject*self,PyObject*arg)
666-
{
667-
NULLABLE(arg);
668-
return_PyUnicode_TransformDecimalAndSpaceToASCII(arg);
669-
}
670-
671663
/* Test PyUnicode_DecodeUTF8() */
672664
staticPyObject*
673665
unicode_decodeutf8(PyObject*self,PyObject*args)
@@ -1544,7 +1536,6 @@ static PyMethodDef TestMethods[] = {
15441536
{"unicode_decodeutf8",unicode_decodeutf8,METH_VARARGS},
15451537
{"unicode_decodeutf8stateful",unicode_decodeutf8stateful,METH_VARARGS},
15461538
{"unicode_getdefaultencoding",unicode_getdefaultencoding,METH_NOARGS},
1547-
{"unicode_transformdecimalandspacetoascii",unicode_transformdecimalandspacetoascii,METH_O},
15481539
{"unicode_concat",unicode_concat,METH_VARARGS},
15491540
{"unicode_splitlines",unicode_splitlines,METH_VARARGS},
15501541
{"unicode_split",unicode_split,METH_VARARGS},

‎Modules/_testinternalcapi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,17 @@ test_tstate_capi(PyObject *self, PyObject *Py_UNUSED(args))
12531253
}
12541254

12551255

1256+
/* Test _PyUnicode_TransformDecimalAndSpaceToASCII() */
1257+
staticPyObject*
1258+
unicode_transformdecimalandspacetoascii(PyObject*self,PyObject*arg)
1259+
{
1260+
if (arg==Py_None) {
1261+
arg=NULL;
1262+
}
1263+
return_PyUnicode_TransformDecimalAndSpaceToASCII(arg);
1264+
}
1265+
1266+
12561267
staticPyMethodDefmodule_functions[]= {
12571268
{"get_configs",get_configs,METH_NOARGS},
12581269
{"get_recursion_depth",get_recursion_depth,METH_NOARGS},
@@ -1304,6 +1315,7 @@ static PyMethodDef module_functions[] = {
13041315
{"_PyTime_ObjectToTimeval",test_pytime_object_to_timeval,METH_VARARGS},
13051316
{"_PyTraceMalloc_GetTraceback",tracemalloc_get_traceback,METH_VARARGS},
13061317
{"test_tstate_capi",test_tstate_capi,METH_NOARGS,NULL},
1318+
{"_PyUnicode_TransformDecimalAndSpaceToASCII",unicode_transformdecimalandspacetoascii,METH_O},
13071319
{NULL,NULL}/* sentinel */
13081320
};
13091321

‎Python/pystrhex.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include"Python.h"
44
#include"pycore_strhex.h"// _Py_strhex_with_sep()
5+
#include"pycore_unicodeobject.h"// _PyUnicode_CheckConsistency()
56
#include<stdlib.h>// abs()
67

78
staticPyObject*_Py_strhex_impl(constchar*argbuf,constPy_ssize_targlen,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp