]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-32381: Remove unused _Py_fopen() function (GH-23711)
authorVictor Stinner <vstinner@python.org>
Wed, 9 Dec 2020 19:54:31 +0000 (20:54 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Dec 2020 19:54:31 +0000 (20:54 +0100)
Remove the private _Py_fopen() function which is no longer needed.
Use _Py_wfopen() or _Py_fopen_obj() instead.

Include/cpython/fileutils.h
Misc/NEWS.d/next/C API/2020-12-09-00-35-25.bpo-32381.Je08Ny.rst [new file with mode: 0644]
Python/fileutils.c

index e79d03e24f57714eefe1cc20ea907f965715d378..312fd9582847885b1863bb5af11ee2432bab91ba 100644 (file)
@@ -95,10 +95,6 @@ PyAPI_FUNC(FILE *) _Py_wfopen(
     const wchar_t *path,
     const wchar_t *mode);
 
-PyAPI_FUNC(FILE*) _Py_fopen(
-    const char *pathname,
-    const char *mode);
-
 PyAPI_FUNC(FILE*) _Py_fopen_obj(
     PyObject *path,
     const char *mode);
diff --git a/Misc/NEWS.d/next/C API/2020-12-09-00-35-25.bpo-32381.Je08Ny.rst b/Misc/NEWS.d/next/C API/2020-12-09-00-35-25.bpo-32381.Je08Ny.rst
new file mode 100644 (file)
index 0000000..ded75fa
--- /dev/null
@@ -0,0 +1,3 @@
+Remove the private :c:func:`_Py_fopen` function which is no longer needed.
+Use :c:func:`_Py_wfopen` or :c:func:`_Py_fopen_obj` instead. Patch by Victor
+Stinner.
index ac382821174211ddf4ce8c91c9626c9378cb57ef..8dc90fbe2b2e714d17ad773edd6a68439f89be31 100644 (file)
@@ -1455,33 +1455,6 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode)
     return f;
 }
 
-/* Wrapper to fopen().
-
-   The file descriptor is created non-inheritable.
-
-   If interrupted by a signal, fail with EINTR. */
-FILE*
-_Py_fopen(const char *pathname, const char *mode)
-{
-    PyObject *pathname_obj = PyUnicode_DecodeFSDefault(pathname);
-    if (pathname_obj == NULL) {
-        return NULL;
-    }
-    if (PySys_Audit("open", "Osi", pathname_obj, mode, 0) < 0) {
-        Py_DECREF(pathname_obj);
-        return NULL;
-    }
-    Py_DECREF(pathname_obj);
-
-    FILE *f = fopen(pathname, mode);
-    if (f == NULL)
-        return NULL;
-    if (make_non_inheritable(fileno(f)) < 0) {
-        fclose(f);
-        return NULL;
-    }
-    return f;
-}
 
 /* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem
    encoding and call fopen() otherwise.