| 1952 | // gh-127350 added Py_fopen() and Py_fclose() to Python 3.14a4 |
| 1953 | #if PY_VERSION_HEX < 0x030E00A4 |
| 1954 | static inline FILE* Py_fopen(PyObject *path, const char *mode) |
| 1955 | { |
| 1956 | #if 0x030400A2 <= PY_VERSION_HEX && !defined(PYPY_VERSION) |
| 1957 | PyAPI_FUNC(FILE*) _Py_fopen_obj(PyObject *path, const char *mode); |
| 1958 | |
| 1959 | return _Py_fopen_obj(path, mode); |
| 1960 | #else |
| 1961 | FILE *f; |
| 1962 | PyObject *bytes; |
| 1963 | #if PY_VERSION_HEX >= 0x03000000 |
| 1964 | if (!PyUnicode_FSConverter(path, &bytes)) { |
| 1965 | return NULL; |
| 1966 | } |
| 1967 | #else |
| 1968 | if (!PyString_Check(path)) { |
| 1969 | PyErr_SetString(PyExc_TypeError, "except str"); |
| 1970 | return NULL; |
| 1971 | } |
| 1972 | bytes = Py_NewRef(path); |
| 1973 | #endif |
| 1974 | const char *path_bytes = PyBytes_AS_STRING(bytes); |
| 1975 | |
| 1976 | f = fopen(path_bytes, mode); |
| 1977 | Py_DECREF(bytes); |
| 1978 | |
| 1979 | if (f == NULL) { |
| 1980 | PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); |
| 1981 | return NULL; |
| 1982 | } |
| 1983 | return f; |
| 1984 | #endif |
| 1985 | } |
| 1986 | |
| 1987 | static inline int Py_fclose(FILE *file) |
| 1988 | { |
nothing calls this directly
no outgoing calls
no test coverage detected