Skip to content

Commit

Permalink
gh-106320: Remove private _PyLong_FileDescriptor_Converter() (#108503)
Browse files Browse the repository at this point in the history
Move the private _PyLong converter functions to the internal C API

* _PyLong_FileDescriptor_Converter(): moved to pycore_fileutils.h
* _PyLong_Size_t_Converter(): moved to pycore_long.h

Argument Clinic now emits includes for pycore_fileutils.h and
pycore_long.h when these functions are used.
  • Loading branch information
vstinner authored Aug 26, 2023
1 parent 713afb8 commit 6353c21
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Include/cpython/fileobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ typedef PyObject * (*Py_OpenCodeHookFunction)(PyObject *, void *);
PyAPI_FUNC(PyObject *) PyFile_OpenCode(const char *utf8path);
PyAPI_FUNC(PyObject *) PyFile_OpenCodeObject(PyObject *path);
PyAPI_FUNC(int) PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData);

PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);
2 changes: 0 additions & 2 deletions Include/cpython/longobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# error "this header file must not be included directly"
#endif

PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);

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

/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ 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 *);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 10 additions & 0 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,21 @@ extern char* _PyLong_FormatBytesWriter(
int alternate);

// Argument converters used by Argument Clinic

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

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

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

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

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

/* Long value tag bits:
* 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
Expand Down
3 changes: 2 additions & 1 deletion Modules/clinic/_winapi.c.h

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

3 changes: 2 additions & 1 deletion Modules/clinic/fcntlmodule.c.h

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

3 changes: 2 additions & 1 deletion Modules/clinic/posixmodule.c.h

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

3 changes: 2 additions & 1 deletion Modules/clinic/selectmodule.c.h

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

3 changes: 2 additions & 1 deletion Modules/clinic/termios.c.h

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

4 changes: 4 additions & 0 deletions Modules/fcntlmodule.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* fcntl module */

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif

#include "Python.h"

#ifdef HAVE_SYS_FILE_H
Expand Down
4 changes: 4 additions & 0 deletions Modules/termios.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* termios.c -- POSIX terminal I/O module implementation. */

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif

#include "Python.h"

/* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
Expand Down
5 changes: 4 additions & 1 deletion Tools/c-analyzer/c_parser/preprocessor/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
'multibytecodec.h',
'socketmodule.h',

# Argument Clinic ".c.h" files
# Argument Clinic ".c.h" header files
'_testclinic.c.h',
'_testclinic_depr.c.h',
'_winapi.c.h',
'fcntlmodule.c.h',
'overlapped.c.h',
'posixmodule.c.h',
'selectmodule.c.h',
'sha3module.c.h',
'termios.c.h',
}

TOOL = 'gcc'
Expand Down
8 changes: 8 additions & 0 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,10 @@ class size_t_converter(CConverter):
converter = '_PyLong_Size_t_Converter'
c_ignored_default = "0"

def converter_init(self, *, accept: TypeSet = {int, NoneType}) -> None:
self.add_include('pycore_long.h',
'_PyLong_Size_t_Converter()')

def parse_arg(self, argname: str, displayname: str) -> str | None:
if self.format_unit == 'n':
return """
Expand All @@ -3850,6 +3854,10 @@ class fildes_converter(CConverter):
type = 'int'
converter = '_PyLong_FileDescriptor_Converter'

def converter_init(self, *, accept: TypeSet = {int, NoneType}) -> None:
self.add_include('pycore_fileutils.h',
'_PyLong_FileDescriptor_Converter()')

def _parse_arg(self, argname: str, displayname: str) -> str | None:
return """
{paramname} = PyObject_AsFileDescriptor({argname});
Expand Down

0 comments on commit 6353c21

Please sign in to comment.