GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-155496: Use the Py_UNICODE converter in the getpath module · serhiy-storchaka/cpython@c7a7b19

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Modules
    • clinic
      • getpath.c.h
    • getpath.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Modules/clinic/getpath.c.h‎

Copy file name to clipboardExpand all lines: Modules/clinic/getpath.c.h
+43-15Lines changed: 43 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎Modules/getpath.c‎

Copy file name to clipboardExpand all lines: Modules/getpath.c
+25-46Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,23 @@ module getpath
7070
/*[clinic input]
7171
getpath.abspath
7272
73-
path as pathobj: unicode
73+
path: Py_UNICODE
7474
/
7575
7676
Return the absolute path.
7777
[clinic start generated code]*/
7878

7979
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]*/
8282
{
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;
9687
}
88+
PyObject *r = PyUnicode_FromWideChar(abs, -1);
89+
PyMem_RawFree((void *)abs);
9790
return r;
9891
}
9992

@@ -143,26 +136,19 @@ getpath_dirname_impl(PyObject *module, PyObject *path)
143136

144137

145138
/*[clinic input]
146-
getpath.isabs
139+
getpath.isabs -> bool
147140
148-
path as pathobj: unicode
141+
path: Py_UNICODE
149142
/
150143
151144
Return True if the path is absolute.
152145
[clinic start generated code]*/
153146

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]*/
157150
{
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);
166152
}
167153

168154

@@ -209,33 +195,26 @@ getpath_hassuffix_impl(PyObject *module, PyObject *pathobj,
209195

210196

211197
/*[clinic input]
212-
getpath.isdir
198+
getpath.isdir -> bool
213199
214-
path as pathobj: unicode
200+
path: Py_UNICODE
215201
/
216202
217203
Return True if the path is a directory.
218204
[clinic start generated code]*/
219205

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]*/
223209
{
224-
PyObject *r = NULL;
225-
const wchar_t *path;
226-
path = PyUnicode_AsWideCharString(pathobj, NULL);
227-
if (path) {
228210
#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);
232214
#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);
235217
#endif
236-
PyMem_Free((void *)path);
237-
}
238-
return Py_XNewRef(r);
239218
}
240219

241220

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.