Skip to content

Commit c3a63e5

Browse files
committed
gh-116646: Add PyLong_FileDescriptor_Converter() function
1 parent f8147d0 commit c3a63e5

File tree

11 files changed

+61
-53
lines changed

11 files changed

+61
-53
lines changed

Doc/c-api/long.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,10 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
464464
465465
Otherwise, the return value is undefined.
466466
467+
.. c:function:: int PyLong_FileDescriptor_Converter(PyObject *p, void *ptr)
468+
469+
Convert a Python object to a file descript (C ``int`` type).
470+
Set `*ptr` and return ``1`` on success. Set an exception and return ``0`` on error.
471+
472+
It can be used with the ``O&`` format when :ref:`parsing arguments
473+
<arg-parsing>`.

Doc/whatsnew/3.13.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,10 @@ New Features
16451645
between native integer types and Python :class:`int` objects.
16461646
(Contributed by Steve Dower in :gh:`111140`.)
16471647

1648+
* Add :c:func:`PyLong_FileDescriptor_Converter` function: convert a Python
1649+
object to a file descriptor. Function added the limited C API.
1650+
(Contributed by Victor Stinner in :gh:`116646`.)
1651+
16481652

16491653
Porting to Python 3.13
16501654
----------------------

Include/fileutils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
5050
size_t *error_pos);
5151
#endif
5252

53+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
54+
// PyArg converter to convert a Python int objet to a C int.
55+
// Return 1 on success. Set an exception and return 0 on error.
56+
PyAPI_FUNC(int) PyLong_FileDescriptor_Converter(PyObject *, void *);
57+
#endif
58+
5359
#ifndef Py_LIMITED_API
5460
# define Py_CPYTHON_FILEUTILS_H
5561
# include "cpython/fileutils.h"

Include/internal/pycore_fileutils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,6 @@ extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootE
312312
# define _Py_END_SUPPRESS_IPH
313313
#endif /* _MSC_VER >= 1900 */
314314

315-
// Export for 'select' shared extension (Argument Clinic code)
316-
PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);
317-
318315
// Export for test_peg_generator
319316
PyAPI_FUNC(char*) _Py_UniversalNewlineFgetsWithSize(char *, int, FILE*, PyObject *, size_t*);
320317

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add PyLong_FileDescriptor_Converter function: convert a Python object to a
2+
file descriptor. Function added the limited C API. Patch by Victor Stinner.

Modules/clinic/fcntlmodule.c.h

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

Modules/clinic/posixmodule.c.h

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

Modules/clinic/selectmodule.c.h

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

0 commit comments

Comments
 (0)