@@ -70,30 +70,23 @@ module getpath |
70 | 70 | /*[clinic input] |
71 | 71 | getpath.abspath |
72 | 72 |
|
73 | | - path as pathobj: unicode |
| 73 | + path: Py_UNICODE |
74 | 74 | / |
75 | 75 |
|
76 | 76 | Return the absolute path. |
77 | 77 | [clinic start generated code]*/ |
78 | 78 |
|
79 | 79 | static PyObject * |
80 | | -getpath_abspath_impl(PyObject *module, PyObject *pathobj) |
81 | | -/*[clinic end generated code: output=a307fc0d5d82eb2e input=2f8179427a1a31a6]*/ |
| 80 | +getpath_abspath_impl(PyObject *module, const wchar_t *path) |
| 81 | +/*[clinic end generated code: output=5009336e32e75b9b input=0fd554ce535744f2]*/ |
82 | 82 | { |
83 | | - PyObject *r = NULL; |
84 | | - wchar_t *path; |
85 | | - Py_ssize_t len; |
86 | | - path = PyUnicode_AsWideCharString(pathobj, &len); |
87 | | - if (path) { |
88 | | - wchar_t *abs; |
89 | | - if (_Py_abspath((const wchar_t *)_Py_normpath(path, -1), &abs) == 0 && abs) { |
90 | | - r = PyUnicode_FromWideChar(abs, -1); |
91 | | - PyMem_RawFree((void *)abs); |
92 | | - } else { |
93 | | - PyErr_SetString(PyExc_OSError, "failed to make path absolute"); |
94 | | - } |
95 | | - PyMem_Free((void *)path); |
| 83 | + wchar_t *abs; |
| 84 | + if (_Py_abspath(_Py_normpath((wchar_t *)path, -1), &abs) < 0 || abs == NULL) { |
| 85 | + PyErr_SetString(PyExc_OSError, "failed to make path absolute"); |
| 86 | + return NULL; |
96 | 87 | } |
| 88 | + PyObject *r = PyUnicode_FromWideChar(abs, -1); |
| 89 | + PyMem_RawFree((void *)abs); |
97 | 90 | return r; |
98 | 91 | } |
99 | 92 |
|
@@ -143,26 +136,19 @@ getpath_dirname_impl(PyObject *module, PyObject *path) |
143 | 136 |
|
144 | 137 |
|
145 | 138 | /*[clinic input] |
146 | | -getpath.isabs |
| 139 | +getpath.isabs -> bool |
147 | 140 |
|
148 | | - path as pathobj: unicode |
| 141 | + path: Py_UNICODE |
149 | 142 | / |
150 | 143 |
|
151 | 144 | Return True if the path is absolute. |
152 | 145 | [clinic start generated code]*/ |
153 | 146 |
|
154 | | -static PyObject * |
155 | | -getpath_isabs_impl(PyObject *module, PyObject *pathobj) |
156 | | -/*[clinic end generated code: output=7f5c62037d0b2c86 input=e49d90a186348140]*/ |
| 147 | +static int |
| 148 | +getpath_isabs_impl(PyObject *module, const wchar_t *path) |
| 149 | +/*[clinic end generated code: output=4659b9e6f088c2ca input=04931a206cdd77f6]*/ |
157 | 150 | { |
158 | | - PyObject *r = NULL; |
159 | | - const wchar_t *path; |
160 | | - path = PyUnicode_AsWideCharString(pathobj, NULL); |
161 | | - if (path) { |
162 | | - r = _Py_isabs(path) ? Py_True : Py_False; |
163 | | - PyMem_Free((void *)path); |
164 | | - } |
165 | | - return Py_XNewRef(r); |
| 151 | + return _Py_isabs(path); |
166 | 152 | } |
167 | 153 |
|
168 | 154 |
|
@@ -209,33 +195,26 @@ getpath_hassuffix_impl(PyObject *module, PyObject *pathobj, |
209 | 195 |
|
210 | 196 |
|
211 | 197 | /*[clinic input] |
212 | | -getpath.isdir |
| 198 | +getpath.isdir -> bool |
213 | 199 |
|
214 | | - path as pathobj: unicode |
| 200 | + path: Py_UNICODE |
215 | 201 | / |
216 | 202 |
|
217 | 203 | Return True if the path is a directory. |
218 | 204 | [clinic start generated code]*/ |
219 | 205 |
|
220 | | -static PyObject * |
221 | | -getpath_isdir_impl(PyObject *module, PyObject *pathobj) |
222 | | -/*[clinic end generated code: output=5af217f29e968e1b input=d1d4c4d74d2e37f1]*/ |
| 206 | +static int |
| 207 | +getpath_isdir_impl(PyObject *module, const wchar_t *path) |
| 208 | +/*[clinic end generated code: output=467820dd83daa7a6 input=0ddd588cd5357a9a]*/ |
223 | 209 | { |
224 | | - PyObject *r = NULL; |
225 | | - const wchar_t *path; |
226 | | - path = PyUnicode_AsWideCharString(pathobj, NULL); |
227 | | - if (path) { |
228 | 210 | #ifdef MS_WINDOWS |
229 | | - DWORD attr = GetFileAttributesW(path); |
230 | | - r = (attr != INVALID_FILE_ATTRIBUTES) && |
231 | | - (attr & FILE_ATTRIBUTE_DIRECTORY) ? Py_True : Py_False; |
| 211 | + DWORD attr = GetFileAttributesW(path); |
| 212 | + return (attr != INVALID_FILE_ATTRIBUTES) |
| 213 | + && (attr & FILE_ATTRIBUTE_DIRECTORY); |
232 | 214 | #else |
233 | | - struct stat st; |
234 | | - r = (_Py_wstat(path, &st) == 0) && S_ISDIR(st.st_mode) ? Py_True : Py_False; |
| 215 | + struct stat st; |
| 216 | + return (_Py_wstat(path, &st) == 0) && S_ISDIR(st.st_mode); |
235 | 217 | #endif |
236 | | - PyMem_Free((void *)path); |
237 | | - } |
238 | | - return Py_XNewRef(r); |
239 | 218 | } |
240 | 219 |
|
241 | 220 |
|
|