]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private _PyLong_FileDescriptor_Converter() (#108503)
authorVictor Stinner <vstinner@python.org>
Sat, 26 Aug 2023 01:18:09 +0000 (03:18 +0200)
committerGitHub <noreply@github.com>
Sat, 26 Aug 2023 01:18:09 +0000 (03:18 +0200)
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.

13 files changed:
Include/cpython/fileobject.h
Include/cpython/longobject.h
Include/internal/pycore_fileutils.h
Include/internal/pycore_long.h
Modules/clinic/_winapi.c.h
Modules/clinic/fcntlmodule.c.h
Modules/clinic/posixmodule.c.h
Modules/clinic/selectmodule.c.h
Modules/clinic/termios.c.h
Modules/fcntlmodule.c
Modules/termios.c
Tools/c-analyzer/c_parser/preprocessor/gcc.py
Tools/clinic/clinic.py

index b70ec318986d821580c9c76a6de0ec42fab25256..6fbe69604af40c1fd87683ea835ac7e0b8b6c5c0 100644 (file)
@@ -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 *);
index c7ae1c2cd6bc6b9a26a68dc82676cbf73e39f954..32c40b083b7ab67250de605c8a5f407c30d9ab9e 100644 (file)
@@ -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.
index 90c0878a3ee7d6428f5f17c2912e0edb44331409..f6e625870de9d131eada666bcdd92aaff68a1aab 100644 (file)
@@ -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
index 1dc5b7438c08793699ed9e9c09bd00a076ab7aca..c9d82711862895f2f5165890dea431e3ec806a9f 100644 (file)
@@ -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.
index 35ac053547121c1e726c954f9f5fe8aadab66c20..c648e68be448c65e54acefde6c7a657958673bdd 100644 (file)
@@ -7,6 +7,7 @@ preserve
 #  include "pycore_runtime.h"       // _Py_ID()
 #endif
 
+#include "pycore_long.h"           // _PyLong_Size_t_Converter()
 
 PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
 "GetOverlappedResult($self, wait, /)\n"
@@ -1478,4 +1479,4 @@ exit:
 
     return return_value;
 }
-/*[clinic end generated code: output=ff91ab5cae8961dd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c7e08927e163ef13 input=a9049054013a1b77]*/
index bd978b63e4dd6b53fb1cb115050f758e19493066..c15f345ee6ffe8b5e5bc1d6610008998e2585ef1 100644 (file)
@@ -7,6 +7,7 @@ preserve
 #  include "pycore_runtime.h"       // _Py_ID()
 #endif
 
+#include "pycore_fileutils.h"      // _PyLong_FileDescriptor_Converter()
 
 PyDoc_STRVAR(fcntl_fcntl__doc__,
 "fcntl($module, fd, cmd, arg=0, /)\n"
@@ -249,4 +250,4 @@ skip_optional:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=705976d5f53f2272 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5f096e8731fa38be input=a9049054013a1b77]*/
index ae3c1d60a919c1eb44adaf8f10d2d47776ebaa80..4b85519b532137191f8206dbf19c63bf6f6d214f 100644 (file)
@@ -7,6 +7,7 @@ preserve
 #  include "pycore_runtime.h"       // _Py_ID()
 #endif
 
+#include "pycore_fileutils.h"      // _PyLong_FileDescriptor_Converter()
 #include "pycore_long.h"           // _PyLong_UnsignedInt_Converter()
 
 PyDoc_STRVAR(os_stat__doc__,
@@ -11991,4 +11992,4 @@ exit:
 #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
     #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
 #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=a08a47b52da6da0b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ff0e50316f4ed71a input=a9049054013a1b77]*/
index f6b3ea388108ae45d6bdee29f57d72697188f333..69c0f06789e714b68ed69389998052adccd230d6 100644 (file)
@@ -7,6 +7,7 @@ preserve
 #  include "pycore_runtime.h"       // _Py_ID()
 #endif
 
+#include "pycore_fileutils.h"      // _PyLong_FileDescriptor_Converter()
 #include "pycore_long.h"           // _PyLong_UnsignedShort_Converter()
 
 PyDoc_STRVAR(select_select__doc__,
@@ -1310,4 +1311,4 @@ exit:
 #ifndef SELECT_KQUEUE_CONTROL_METHODDEF
     #define SELECT_KQUEUE_CONTROL_METHODDEF
 #endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
-/*[clinic end generated code: output=a19c29946a931dce input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a215af2157f038c7 input=a9049054013a1b77]*/
index 4e911aa0a5fb9bde56cc037e131642ab24e6c23f..44d4107c378e537945fb668da83267bb72debc5f 100644 (file)
@@ -7,6 +7,7 @@ preserve
 #  include "pycore_runtime.h"       // _Py_ID()
 #endif
 
+#include "pycore_fileutils.h"      // _PyLong_FileDescriptor_Converter()
 
 PyDoc_STRVAR(termios_tcgetattr__doc__,
 "tcgetattr($module, fd, /)\n"
@@ -292,4 +293,4 @@ termios_tcsetwinsize(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=4c79a3bf87370275 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=434df4394b596e92 input=a9049054013a1b77]*/
index e530621fd269a1d70025bbc4cddeec4500125bda..3bf5830b2edca9254e52ed4b79f4df3f4d14eea7 100644 (file)
@@ -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
index 6b254104ed1e2162afd7890c6628892756d3a009..21d3541c177bc3197c8aea75d1f987035439a3e6 100644 (file)
@@ -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
index 62538f53c25a2e6037cd16125e44e4b4fc1bac37..de9a2484de82bbb72c6f40ae45f74d707a5f35c4 100644 (file)
@@ -12,13 +12,16 @@ NEED_BUILD_CORE = {
     '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'
index c4304bb5b1270dd529630671ea92d42538d98b0c..e622d254ee8ccbfc1790f628fc3724a0c357ca1f 100755 (executable)
@@ -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 """
@@ -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});