| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a555cfc commit e42ccd2
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2941,11 +2941,9 @@ load_dh_params(PySSLContext *self, PyObject *filepath) | |||
| 2941 | 2941 | DH *dh; | |
| 2942 | 2942 | ||
| 2943 | 2943 | f = _Py_fopen_obj(filepath, "rb"); | |
| 2944 | - if (f == NULL) { | ||
| 2945 | - if (!PyErr_Occurred()) | ||
| 2946 | - PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, filepath); | ||
| 2944 | + if (f == NULL) | ||
| 2947 | 2945 | return NULL; | |
| 2948 | - } | ||
| 2946 | + | ||
| 2949 | 2947 | errno = 0; | |
| 2950 | 2948 | PySSL_BEGIN_ALLOW_THREADS | |
| 2951 | 2949 | dh = PEM_read_DHparams(f, NULL, NULL, NULL); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -875,7 +875,7 @@ read_directory(PyObject *archive) | |||
| 875 | 875 | ||
| 876 | 876 | fp = _Py_fopen_obj(archive, "rb"); | |
| 877 | 877 | if (fp == NULL) { | |
| 878 | - if (!PyErr_Occurred()) | ||
| 878 | + if (PyErr_ExceptionMatches(PyExc_OSError)) | ||
| 879 | 879 | PyErr_Format(ZipImportError, "can't open Zip file: %R", archive); | |
| 880 | 880 | return NULL; | |
| 881 | 881 | } | |
@@ -1073,12 +1073,8 @@ get_data(PyObject *archive, PyObject *toc_entry) | |||
| 1073 | 1073 | } | |
| 1074 | 1074 | ||
| 1075 | 1075 | fp = _Py_fopen_obj(archive, "rb"); | |
| 1076 | - if (!fp) { | ||
| 1077 | - if (!PyErr_Occurred()) | ||
| 1078 | - PyErr_Format(PyExc_IOError, | ||
| 1079 | - "zipimport: can not open file %U", archive); | ||
| 1076 | + if (!fp) | ||
| 1080 | 1077 | return NULL; | |
| 1081 | - } | ||
| 1082 | 1078 | ||
| 1083 | 1079 | /* Check to make sure the local file header is correct */ | |
| 1084 | 1080 | if (fseek(fp, file_offset, 0) == -1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1126,6 +1126,10 @@ PyErr_ProgramTextObject(PyObject *filename, int lineno) | |||
| 1126 | 1126 | if (filename == NULL || lineno <= 0) | |
| 1127 | 1127 | return NULL; | |
| 1128 | 1128 | fp = _Py_fopen_obj(filename, "r" PY_STDIOTEXTMODE); | |
| 1129 | + if (fp == NULL) { | ||
| 1130 | + PyErr_Clear(); | ||
| 1131 | + return NULL; | ||
| 1132 | + } | ||
| 1129 | 1133 | return err_programtext(fp, lineno); | |
| 1130 | 1134 | } | |
| 1131 | 1135 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -957,7 +957,7 @@ _Py_open_impl(const char *pathname, int flags, int gil_held) | |||
| 957 | 957 | ||
| 958 | 958 | The file descriptor is created non-inheritable. | |
| 959 | 959 | ||
| 960 | - The GIL must be held. Use _Py_open_noraise() if the GIL cannot be held. */ | ||
| 960 | + The GIL must be held. */ | ||
| 961 | 961 | int | |
| 962 | 962 | _Py_open(const char *pathname, int flags) | |
| 963 | 963 | { | |
@@ -977,8 +977,9 @@ _Py_open_noraise(const char *pathname, int flags) | |||
| 977 | 977 | } | |
| 978 | 978 | ||
| 979 | 979 | /* Open a file. Use _wfopen() on Windows, encode the path to the locale | |
| 980 | - encoding and use fopen() otherwise. The file descriptor is created | ||
| 981 | - non-inheritable. */ | ||
| 980 | + encoding and use fopen() otherwise. | ||
| 981 | + | ||
| 982 | + The file descriptor is created non-inheritable). */ | ||
| 982 | 983 | FILE * | |
| 983 | 984 | _Py_wfopen(const wchar_t *path, const wchar_t *mode) | |
| 984 | 985 | { | |
@@ -1009,7 +1010,9 @@ _Py_wfopen(const wchar_t *path, const wchar_t *mode) | |||
| 1009 | 1010 | return f; | |
| 1010 | 1011 | } | |
| 1011 | 1012 | ||
| 1012 | - /* Wrapper to fopen(). The file descriptor is created non-inheritable. */ | ||
| 1013 | + /* Wrapper to fopen(). | ||
| 1014 | + | ||
| 1015 | + The file descriptor is created non-inheritable). */ | ||
| 1013 | 1016 | FILE* | |
| 1014 | 1017 | _Py_fopen(const char *pathname, const char *mode) | |
| 1015 | 1018 | { | |
@@ -1024,11 +1027,14 @@ _Py_fopen(const char *pathname, const char *mode) | |||
| 1024 | 1027 | } | |
| 1025 | 1028 | ||
| 1026 | 1029 | /* Open a file. Call _wfopen() on Windows, or encode the path to the filesystem | |
| 1027 | - encoding and call fopen() otherwise. The file descriptor is created | ||
| 1028 | - non-inheritable. | ||
| 1030 | + encoding and call fopen() otherwise. | ||
| 1031 | + | ||
| 1032 | + Return the new file object on success. Raise an exception and return NULL | ||
| 1033 | + on error. | ||
| 1029 | 1034 | ||
| 1030 | - Return the new file object on success, or NULL if the file cannot be open or | ||
| 1031 | - (if PyErr_Occurred()) on unicode error. */ | ||
| 1035 | + The file descriptor is created non-inheritable. | ||
| 1036 | + | ||
| 1037 | + The GIL must be held. */ | ||
| 1032 | 1038 | FILE* | |
| 1033 | 1039 | _Py_fopen_obj(PyObject *path, const char *mode) | |
| 1034 | 1040 | { | |
@@ -1038,6 +1044,8 @@ _Py_fopen_obj(PyObject *path, const char *mode) | |||
| 1038 | 1044 | wchar_t wmode[10]; | |
| 1039 | 1045 | int usize; | |
| 1040 | 1046 | ||
| 1047 | + assert(PyGILState_Check()); | ||
| 1048 | + | ||
| 1041 | 1049 | if (!PyUnicode_Check(path)) { | |
| 1042 | 1050 | PyErr_Format(PyExc_TypeError, | |
| 1043 | 1051 | "str file path expected under Windows, got %R", | |
@@ -1049,20 +1057,36 @@ _Py_fopen_obj(PyObject *path, const char *mode) | |||
| 1049 | 1057 | return NULL; | |
| 1050 | 1058 | ||
| 1051 | 1059 | usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode)); | |
| 1052 | - if (usize == 0) | ||
| 1060 | + if (usize == 0) { | ||
| 1061 | + PyErr_SetFromWindowsErr(0); | ||
| 1053 | 1062 | return NULL; | |
| 1063 | + } | ||
| 1054 | 1064 | ||
| 1065 | + Py_BEGIN_ALLOW_THREADS | ||
| 1055 | 1066 | f = _wfopen(wpath, wmode); | |
| 1067 | + Py_END_ALLOW_THREADS | ||
| 1056 | 1068 | #else | |
| 1057 | 1069 | PyObject *bytes; | |
| 1070 | + char *path_bytes; | ||
| 1071 | + | ||
| 1072 | + assert(PyGILState_Check()); | ||
| 1073 | + | ||
| 1058 | 1074 | if (!PyUnicode_FSConverter(path, &bytes)) | |
| 1059 | 1075 | return NULL; | |
| 1060 | - f = fopen(PyBytes_AS_STRING(bytes), mode); | ||
| 1076 | + path_bytes = PyBytes_AS_STRING(bytes); | ||
| 1077 | + | ||
| 1078 | + Py_BEGIN_ALLOW_THREADS | ||
| 1079 | + f = fopen(path_bytes, mode); | ||
| 1080 | + Py_END_ALLOW_THREADS | ||
| 1081 | + | ||
| 1061 | 1082 | Py_DECREF(bytes); | |
| 1062 | 1083 | #endif | |
| 1063 | - if (f == NULL) | ||
| 1084 | + if (f == NULL) { | ||
| 1085 | + PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path); | ||
| 1064 | 1086 | return NULL; | |
| 1065 | - if (make_non_inheritable(fileno(f)) < 0) { | ||
| 1087 | + } | ||
| 1088 | + | ||
| 1089 | + if (set_inheritable(fileno(f), 0, 1, NULL) < 0) { | ||
| 1066 | 1090 | fclose(f); | |
| 1067 | 1091 | return NULL; | |
| 1068 | 1092 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1945,8 +1945,6 @@ _imp_load_dynamic_impl(PyModuleDef *module, PyObject *name, PyObject *path, PyOb | |||
| 1945 | 1945 | fp = _Py_fopen_obj(path, "r"); | |
| 1946 | 1946 | if (fp == NULL) { | |
| 1947 | 1947 | Py_DECREF(path); | |
| 1948 | - if (!PyErr_Occurred()) | ||
| 1949 | - PyErr_SetFromErrno(PyExc_IOError); | ||
| 1950 | 1948 | return NULL; | |
| 1951 | 1949 | } | |
| 1952 | 1950 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments