Skip to content

Commit 713afb8

Browse files
authored
gh-106320: Remove private _PyLong converter functions (#108499)
Move these private functions to the internal C API (pycore_long.h): * _PyLong_UnsignedInt_Converter() * _PyLong_UnsignedLongLong_Converter() * _PyLong_UnsignedLong_Converter() * _PyLong_UnsignedShort_Converter() Argument Clinic now emits #include "pycore_long.h" when these functions are used.
1 parent 86bc9e3 commit 713afb8

File tree

14 files changed

+46
-14
lines changed

14 files changed

+46
-14
lines changed

Include/cpython/longobject.h

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
PyAPI_FUNC(int) _PyLong_UnsignedShort_Converter(PyObject *, void *);
6-
PyAPI_FUNC(int) _PyLong_UnsignedInt_Converter(PyObject *, void *);
7-
PyAPI_FUNC(int) _PyLong_UnsignedLong_Converter(PyObject *, void *);
8-
PyAPI_FUNC(int) _PyLong_UnsignedLongLong_Converter(PyObject *, void *);
95
PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);
106

117
PyAPI_FUNC(PyObject*) PyLong_FromUnicodeObject(PyObject *u, int base);

Include/internal/pycore_long.h

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ extern char* _PyLong_FormatBytesWriter(
186186
int base,
187187
int alternate);
188188

189+
// Argument converters used by Argument Clinic
190+
PyAPI_FUNC(int) _PyLong_UnsignedShort_Converter(PyObject *, void *);
191+
PyAPI_FUNC(int) _PyLong_UnsignedInt_Converter(PyObject *, void *);
192+
PyAPI_FUNC(int) _PyLong_UnsignedLong_Converter(PyObject *, void *);
193+
PyAPI_FUNC(int) _PyLong_UnsignedLongLong_Converter(PyObject *, void *);
194+
195+
189196
/* Long value tag bits:
190197
* 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
191198
* 2: Reserved for immortality bit

Modules/_blake2/clinic/blake2b_impl.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_blake2/clinic/blake2s_impl.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_testclinic.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_testclinic_depr.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/overlapped.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/posixmodule.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/selectmodule.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/sha3module.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/overlapped.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
/* XXX check overflow and DWORD <-> Py_ssize_t conversions
88
Check itemsize */
99

10-
#include "Python.h"
10+
#ifndef Py_BUILD_CORE_BUILTIN
11+
# define Py_BUILD_CORE_MODULE 1
12+
#endif
1113

14+
#include "Python.h"
1215

1316
#define WINDOWS_LEAN_AND_MEAN
1417
#include <winsock2.h>

PC/clinic/winreg.c.h

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/c-analyzer/c_parser/preprocessor/gcc.py

+9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77
# macro. Usually it's defined by the C file which includes it.
88
# Other header files have a similar issue.
99
NEED_BUILD_CORE = {
10+
# Header ".h" files
1011
'cjkcodecs.h',
1112
'multibytecodec.h',
1213
'socketmodule.h',
14+
15+
# Argument Clinic ".c.h" files
16+
'_testclinic.c.h',
17+
'_testclinic_depr.c.h',
18+
'overlapped.c.h',
19+
'posixmodule.c.h',
20+
'selectmodule.c.h',
21+
'sha3module.c.h',
1322
}
1423

1524
TOOL = 'gcc'

Tools/clinic/clinic.py

+8
Original file line numberDiff line numberDiff line change
@@ -3629,6 +3629,8 @@ def converter_init(self, *, bitwise: bool = False) -> None:
36293629
self.format_unit = 'H'
36303630
else:
36313631
self.converter = '_PyLong_UnsignedShort_Converter'
3632+
self.add_include('pycore_long.h',
3633+
'_PyLong_UnsignedShort_Converter()')
36323634

36333635
def parse_arg(self, argname: str, displayname: str) -> str | None:
36343636
if self.format_unit == 'H':
@@ -3690,6 +3692,8 @@ def converter_init(self, *, bitwise: bool = False) -> None:
36903692
self.format_unit = 'I'
36913693
else:
36923694
self.converter = '_PyLong_UnsignedInt_Converter'
3695+
self.add_include('pycore_long.h',
3696+
'_PyLong_UnsignedInt_Converter()')
36933697

36943698
def parse_arg(self, argname: str, displayname: str) -> str | None:
36953699
if self.format_unit == 'I':
@@ -3727,6 +3731,8 @@ def converter_init(self, *, bitwise: bool = False) -> None:
37273731
self.format_unit = 'k'
37283732
else:
37293733
self.converter = '_PyLong_UnsignedLong_Converter'
3734+
self.add_include('pycore_long.h',
3735+
'_PyLong_UnsignedLong_Converter()')
37303736

37313737
def parse_arg(self, argname: str, displayname: str) -> str | None:
37323738
if self.format_unit == 'k':
@@ -3766,6 +3772,8 @@ def converter_init(self, *, bitwise: bool = False) -> None:
37663772
self.format_unit = 'K'
37673773
else:
37683774
self.converter = '_PyLong_UnsignedLongLong_Converter'
3775+
self.add_include('pycore_long.h',
3776+
'_PyLong_UnsignedLongLong_Converter()')
37693777

37703778
def parse_arg(self, argname: str, displayname: str) -> str | None:
37713779
if self.format_unit == 'K':

0 commit comments

Comments
 (0)