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

Appearance settings

Commit 1ed299a

Browse filesBrowse files
committed
gh-116646: Add PyLong_FileDescriptor_Converter() function
1 parent f8147d0 commit 1ed299a
Copy full SHA for 1ed299a

File tree

Expand file treeCollapse file tree

11 files changed

+61
-53
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+61
-53
lines changed

‎Doc/c-api/long.rst

Copy file name to clipboardExpand all lines: Doc/c-api/long.rst
+7Lines 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

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.13.rst
+4Lines 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.
1650+
(Contributed by Victor Stinner in :gh:`116646`.)
1651+
16481652

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

‎Include/fileutils.h

Copy file name to clipboardExpand all lines: Include/fileutils.h
+6Lines 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

Copy file name to clipboardExpand all lines: Include/internal/pycore_fileutils.h
-3Lines 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

+2Lines 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. Patch by Victor Stinner.

‎Modules/clinic/fcntlmodule.c.h

Copy file name to clipboardExpand all lines: Modules/clinic/fcntlmodule.c.h
+5-6Lines 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

Copy file name to clipboardExpand all lines: Modules/clinic/posixmodule.c.h
+16-17Lines 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

Copy file name to clipboardExpand all lines: Modules/clinic/selectmodule.c.h
+10-11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.