diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-12 21:52:39 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-12 21:52:39 (GMT) |
commit | f0b5015edb59bc92bd67b849ec3681629c0d1955 (patch) | |
tree | 2d6ac3ffb36561fc960ec5557a9bdcfad2e81d3e /Modules/posixmodule.c | |
parent | cd4a5cc339f3d243f255581165351d5c5aea935f (diff) | |
download | cpython-f0b5015edb59bc92bd67b849ec3681629c0d1955.zip cpython-f0b5015edb59bc92bd67b849ec3681629c0d1955.tar.gz cpython-f0b5015edb59bc92bd67b849ec3681629c0d1955.tar.bz2 |
Converted os._getfullpathname() and os._isdir() to Argument Clinic.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 98 |
1 files changed, 39 insertions, 59 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3bed958..ec8c526 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -3748,62 +3748,53 @@ os_listdir_impl(PyModuleDef *module, path_t *path) #ifdef MS_WINDOWS /* A helper function for abspath on win32 */ -/* AC 3.5: probably just convert to using path converter */ +/*[clinic input] +os._getfullpathname + + path: path_t + / + +[clinic start generated code]*/ + static PyObject * -posix__getfullpathname(PyObject *self, PyObject *args) +os__getfullpathname_impl(PyModuleDef *module, path_t *path) +/*[clinic end generated code: output=b90b1f103b08773f input=332ed537c29d0a3e]*/ { - const char *path; - char outbuf[MAX_PATH]; - char *temp; - PyObject *po; - - if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) + if (!path->narrow) { - wchar_t *wpath; wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf; wchar_t *wtemp; DWORD result; PyObject *v; - wpath = PyUnicode_AsUnicode(po); - if (wpath == NULL) - return NULL; - result = GetFullPathNameW(wpath, + result = GetFullPathNameW(path->wide, Py_ARRAY_LENGTH(woutbuf), woutbuf, &wtemp); if (result > Py_ARRAY_LENGTH(woutbuf)) { woutbufp = PyMem_New(wchar_t, result); if (!woutbufp) return PyErr_NoMemory(); - result = GetFullPathNameW(wpath, result, woutbufp, &wtemp); + result = GetFullPathNameW(path->wide, result, woutbufp, &wtemp); } if (result) v = PyUnicode_FromWideChar(woutbufp, wcslen(woutbufp)); else - v = win32_error_object("GetFullPathNameW", po); + v = win32_error_object("GetFullPathNameW", path->object); if (woutbufp != woutbuf) PyMem_Free(woutbufp); return v; } - /* Drop the argument parsing error as narrow strings - are also valid. */ - PyErr_Clear(); + else { + char outbuf[MAX_PATH]; + char *temp; - if (!PyArg_ParseTuple (args, "y:_getfullpathname", - &path)) - return NULL; - if (win32_warn_bytes_api()) - return NULL; - if (!GetFullPathName(path, Py_ARRAY_LENGTH(outbuf), - outbuf, &temp)) { - win32_error("GetFullPathName", path); - return NULL; - } - if (PyUnicode_Check(PyTuple_GetItem(args, 0))) { - return PyUnicode_Decode(outbuf, strlen(outbuf), - Py_FileSystemDefaultEncoding, NULL); + if (!GetFullPathName(path->narrow, Py_ARRAY_LENGTH(outbuf), + outbuf, &temp)) { + win32_error_object("GetFullPathName", path->object); + return NULL; + } + return PyBytes_FromString(outbuf); } - return PyBytes_FromString(outbuf); } @@ -3872,37 +3863,28 @@ os__getfinalpathname_impl(PyModuleDef *module, PyObject *path) PyDoc_STRVAR(posix__isdir__doc__, "Return true if the pathname refers to an existing directory."); -/* AC 3.5: convert using path converter */ +/*[clinic input] +os._isdir + + path: path_t + / + +[clinic start generated code]*/ + static PyObject * -posix__isdir(PyObject *self, PyObject *args) +os__isdir_impl(PyModuleDef *module, path_t *path) +/*[clinic end generated code: output=f17b2d4e1994b0ff input=e794f12faab62a2a]*/ { - const char *path; - PyObject *po; DWORD attributes; - if (PyArg_ParseTuple(args, "U|:_isdir", &po)) { - wchar_t *wpath = PyUnicode_AsUnicode(po); - if (wpath == NULL) - return NULL; - - attributes = GetFileAttributesW(wpath); - if (attributes == INVALID_FILE_ATTRIBUTES) - Py_RETURN_FALSE; - goto check; - } - /* Drop the argument parsing error as narrow strings - are also valid. */ - PyErr_Clear(); + if (!path->narrow) + attributes = GetFileAttributesW(path->wide); + else + attributes = GetFileAttributesA(path->narrow); - if (!PyArg_ParseTuple(args, "y:_isdir", &path)) - return NULL; - if (win32_warn_bytes_api()) - return NULL; - attributes = GetFileAttributesA(path); if (attributes == INVALID_FILE_ATTRIBUTES) Py_RETURN_FALSE; -check: if (attributes & FILE_ATTRIBUTE_DIRECTORY) Py_RETURN_TRUE; else @@ -12351,10 +12333,8 @@ static PyMethodDef posix_methods[] = { OS_FPATHCONF_METHODDEF OS_PATHCONF_METHODDEF OS_ABORT_METHODDEF -#ifdef MS_WINDOWS - {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, - {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, -#endif + OS__GETFULLPATHNAME_METHODDEF + OS__ISDIR_METHODDEF OS__GETDISKUSAGE_METHODDEF OS__GETFINALPATHNAME_METHODDEF OS__GETVOLUMEPATHNAME_METHODDEF |