Skip to content

Commit 844d82e

Browse files
gh-156261: Move converters used in several files to Argument Clinic
The pid_t, Py_off_t, HANDLE, DWORD and BOOL converters were defined in 9 files. The Py_off_t type and its converter function are now shared too. DWORD in _winapi is used with bitwise=True to keep accepting negative values. The pid_t converter is now used for the pid parameters in the _remote_debugging module, which were declared as int.
1 parent f74cdf8 commit 844d82e

24 files changed

Lines changed: 954 additions & 356 deletions

Include/internal/pycore_fileutils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ extern void _Py_skiproot(const wchar_t *path, Py_ssize_t size, Py_ssize_t *drvsi
302302
// Export for 'select' shared extension (Argument Clinic code)
303303
PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);
304304

305+
#ifdef MS_WINDOWS
306+
/* Windows uses long long for offsets */
307+
typedef long long Py_off_t;
308+
#else
309+
typedef off_t Py_off_t;
310+
#endif
311+
312+
// Export for '_ssl' and 'zlib' shared extensions (Argument Clinic code)
313+
PyAPI_FUNC(int) _Py_Off_t_Converter(PyObject *, void *);
314+
305315
// Export for test_peg_generator
306316
PyAPI_FUNC(char*) _Py_UniversalNewlineFgetsWithSize(char *, int, FILE*, PyObject *, size_t*);
307317

Lib/test/test_clinic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,18 +3561,23 @@ def test_cli_converters(self):
35613561
""")
35623562
expected_converters = (
35633563
"bool",
3564+
"BOOL",
35643565
"byte",
35653566
"char",
35663567
"defining_class",
35673568
"double",
3569+
"DWORD",
35683570
"fildes",
35693571
"float",
3572+
"HANDLE",
35703573
"int",
35713574
"long",
35723575
"long_long",
35733576
"object",
3577+
"pid_t",
35743578
"Py_buffer",
35753579
"Py_complex",
3580+
"Py_off_t",
35763581
"Py_ssize_t",
35773582
"Py_UNICODE",
35783583
"PyByteArrayObject",

Modules/_io/_iomodule.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "exports.h"
66

7+
#include "pycore_fileutils.h" // Py_off_t
78
#include "pycore_moduleobject.h" // _PyModule_GetState()
89
#include "pycore_typeobject.h" // _PyType_GetModuleState()
910
#include "structmember.h"
@@ -94,8 +95,6 @@ extern int _PyIO_trap_eintr(void);
9495

9596
#ifdef MS_WINDOWS
9697

97-
/* Windows uses long long for offsets */
98-
typedef long long Py_off_t;
9998
# define PyLong_AsOff_t PyLong_AsLongLong
10099
# define PyLong_FromOff_t PyLong_FromLongLong
101100
# define PY_OFF_T_MAX LLONG_MAX
@@ -106,7 +105,6 @@ typedef long long Py_off_t;
106105
#else
107106

108107
/* Other platforms use off_t */
109-
typedef off_t Py_off_t;
110108
#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
111109
# define PyLong_AsOff_t PyLong_AsSsize_t
112110
# define PyLong_FromOff_t PyLong_FromSsize_t

Modules/_multiprocessing/multiprocessing.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,6 @@
99

1010
#include "multiprocessing.h"
1111

12-
/*[python input]
13-
class HANDLE_converter(CConverter):
14-
type = "HANDLE"
15-
format_unit = '"F_HANDLE"'
16-
17-
def parse_arg(self, argname, displayname, *, limited_capi):
18-
return self.format_code("""
19-
{paramname} = PyLong_AsVoidPtr({argname});
20-
if (!{paramname} && PyErr_Occurred()) {{{{
21-
goto exit;
22-
}}}}
23-
""",
24-
argname=argname)
25-
26-
[python start generated code]*/
27-
/*[python end generated code: output=da39a3ee5e6b4b0d input=3cf0318efc6a8772]*/
2812

2913
/*[clinic input]
3014
module _multiprocessing

Modules/_posixsubprocess.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,6 @@ module _posixsubprocess
8484
[clinic start generated code]*/
8585
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c62211df27cf7334]*/
8686

87-
/*[python input]
88-
class pid_t_converter(CConverter):
89-
type = 'pid_t'
90-
format_unit = '" _Py_PARSE_PID "'
91-
92-
def parse_arg(self, argname, displayname, *, limited_capi):
93-
return self.format_code("""
94-
{paramname} = PyLong_AsPid({argname});
95-
if ({paramname} == -1 && PyErr_Occurred()) {{{{
96-
goto exit;
97-
}}}}
98-
""",
99-
argname=argname)
100-
[python start generated code]*/
101-
/*[python end generated code: output=da39a3ee5e6b4b0d input=c94349aa1aad151d]*/
102-
10387
#include "clinic/_posixsubprocess.c.h"
10488

10589
/* Convert ASCII to a positive int, no libc call. no overflow. -1 on error. */

Modules/_remote_debugging/clinic/module.c.h

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_remote_debugging/module.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class _remote_debugging.RemoteUnwinder "RemoteUnwinderObject *" "&RemoteUnwinder
281281
/*[clinic input]
282282
@permit_long_summary
283283
_remote_debugging.RemoteUnwinder.__init__
284-
pid: int
284+
pid: pid_t
285285
*
286286
all_threads: bool = False
287287
only_active_thread: bool = False
@@ -334,14 +334,14 @@ other runtime data.
334334

335335
static int
336336
_remote_debugging_RemoteUnwinder___init___impl(RemoteUnwinderObject *self,
337-
int pid, int all_threads,
337+
pid_t pid, int all_threads,
338338
int only_active_thread,
339339
int mode, int debug,
340340
int skip_non_matching_threads,
341341
int native, int gc,
342342
int opcodes, int cache_frames,
343343
int stats)
344-
/*[clinic end generated code: output=0031f743f4b9ad52 input=9d25ae328d62626d]*/
344+
/*[clinic end generated code: output=acfe554c8a92cf6b input=3b5a5ad153709125]*/
345345
{
346346
// Validate that all_threads and only_active_thread are not both True
347347
if (all_threads && only_active_thread) {
@@ -1376,7 +1376,7 @@ cleanup_runtime_offsets(RuntimeOffsets *offsets)
13761376
}
13771377

13781378
static int
1379-
init_runtime_offsets(RuntimeOffsets *offsets, int pid, int debug)
1379+
init_runtime_offsets(RuntimeOffsets *offsets, pid_t pid, int debug)
13801380
{
13811381
offsets->debug = debug;
13821382
if (_Py_RemoteDebug_InitProcHandle(&offsets->handle, pid) < 0) {
@@ -1414,7 +1414,7 @@ class _remote_debugging.GCMonitor "GCMonitorObject *" "&GCMonitor_Type"
14141414
/*[clinic input]
14151415
@permit_long_summary
14161416
_remote_debugging.GCMonitor.__init__
1417-
pid: int
1417+
pid: pid_t
14181418
*
14191419
debug: bool = False
14201420
@@ -1437,9 +1437,9 @@ a running Python process.
14371437
[clinic start generated code]*/
14381438

14391439
static int
1440-
_remote_debugging_GCMonitor___init___impl(GCMonitorObject *self, int pid,
1440+
_remote_debugging_GCMonitor___init___impl(GCMonitorObject *self, pid_t pid,
14411441
int debug)
1442-
/*[clinic end generated code: output=2cdf351c2f6335db input=03da0b2d3282ae1b]*/
1442+
/*[clinic end generated code: output=03b4c92bef0673ad input=dcc6ee2ec5a16fa1]*/
14431443
{
14441444
return init_runtime_offsets(&self->offsets, pid, debug);
14451445
}
@@ -2226,7 +2226,7 @@ _remote_debugging_zstd_available_impl(PyObject *module)
22262226
/*[clinic input]
22272227
_remote_debugging.get_child_pids
22282228
2229-
pid: int
2229+
pid: pid_t
22302230
Process ID of the parent process
22312231
*
22322232
recursive: bool = True
@@ -2248,24 +2248,24 @@ list is returned.
22482248
[clinic start generated code]*/
22492249

22502250
static PyObject *
2251-
_remote_debugging_get_child_pids_impl(PyObject *module, int pid,
2251+
_remote_debugging_get_child_pids_impl(PyObject *module, pid_t pid,
22522252
int recursive)
2253-
/*[clinic end generated code: output=1ae2289c6b953e4b input=c6437b52e2fdd880]*/
2253+
/*[clinic end generated code: output=fa3dfd1b02eed29b input=3325d95e9f39d75d]*/
22542254
{
2255-
return enumerate_child_pids((pid_t)pid, recursive);
2255+
return enumerate_child_pids(pid, recursive);
22562256
}
22572257

22582258
/*[clinic input]
22592259
_remote_debugging.is_python_process
22602260
2261-
pid: int
2261+
pid: pid_t
22622262
22632263
Check if a process is a Python process.
22642264
[clinic start generated code]*/
22652265

22662266
static PyObject *
2267-
_remote_debugging_is_python_process_impl(PyObject *module, int pid)
2268-
/*[clinic end generated code: output=22947dc8afcac362 input=13488e28c7295d84]*/
2267+
_remote_debugging_is_python_process_impl(PyObject *module, pid_t pid)
2268+
/*[clinic end generated code: output=63541478c889e536 input=ff998fef4aeef433]*/
22692269
{
22702270
proc_handle_t handle;
22712271

@@ -2288,7 +2288,7 @@ _remote_debugging_is_python_process_impl(PyObject *module, int pid)
22882288
/*[clinic input]
22892289
_remote_debugging.get_gc_stats
22902290
2291-
pid: int
2291+
pid: pid_t
22922292
*
22932293
all_interpreters: bool = False
22942294
If True, return GC statistics from all interpreters.
@@ -2314,9 +2314,9 @@ Get garbage collector statistics from external Python process.
23142314
[clinic start generated code]*/
23152315

23162316
static PyObject *
2317-
_remote_debugging_get_gc_stats_impl(PyObject *module, int pid,
2317+
_remote_debugging_get_gc_stats_impl(PyObject *module, pid_t pid,
23182318
int all_interpreters)
2319-
/*[clinic end generated code: output=d9dce5f7add149bb input=a2a08a45a8f0b119]*/
2319+
/*[clinic end generated code: output=dd33199ccb6a56e9 input=41399e77788aa369]*/
23202320
{
23212321
RuntimeOffsets offsets;
23222322
if (init_runtime_offsets(&offsets, pid, /*debug=*/1) < 0) {

0 commit comments

Comments
 (0)