Skip to content

Commit

Permalink
gh-116646: Add PyLong_FileDescriptor_Converter() function
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Mar 12, 2024
1 parent f8147d0 commit c3a63e5
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 53 deletions.
7 changes: 7 additions & 0 deletions Doc/c-api/long.rst
Expand Up @@ -464,3 +464,10 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
Otherwise, the return value is undefined.
.. c:function:: int PyLong_FileDescriptor_Converter(PyObject *p, void *ptr)
Convert a Python object to a file descript (C ``int`` type).
Set `*ptr` and return ``1`` on success. Set an exception and return ``0`` on error.
It can be used with the ``O&`` format when :ref:`parsing arguments
<arg-parsing>`.
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.13.rst
Expand Up @@ -1645,6 +1645,10 @@ New Features
between native integer types and Python :class:`int` objects.
(Contributed by Steve Dower in :gh:`111140`.)

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


Porting to Python 3.13
----------------------
Expand Down
6 changes: 6 additions & 0 deletions Include/fileutils.h
Expand Up @@ -50,6 +50,12 @@ PyAPI_FUNC(char*) Py_EncodeLocale(
size_t *error_pos);
#endif

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
// PyArg converter to convert a Python int objet to a C int.
// Return 1 on success. Set an exception and return 0 on error.
PyAPI_FUNC(int) PyLong_FileDescriptor_Converter(PyObject *, void *);
#endif

#ifndef Py_LIMITED_API
# define Py_CPYTHON_FILEUTILS_H
# include "cpython/fileutils.h"
Expand Down
3 changes: 0 additions & 3 deletions Include/internal/pycore_fileutils.h
Expand Up @@ -312,9 +312,6 @@ extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootE
# define _Py_END_SUPPRESS_IPH
#endif /* _MSC_VER >= 1900 */

// Export for 'select' shared extension (Argument Clinic code)
PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);

// Export for test_peg_generator
PyAPI_FUNC(char*) _Py_UniversalNewlineFgetsWithSize(char *, int, FILE*, PyObject *, size_t*);

Expand Down
@@ -0,0 +1,2 @@
Add PyLong_FileDescriptor_Converter function: convert a Python object to a
file descriptor. Function added the limited C API. Patch by Victor Stinner.
11 changes: 5 additions & 6 deletions Modules/clinic/fcntlmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions Modules/clinic/selectmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3a63e5

Please sign in to comment.