Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f0b5015e
Commit
f0b5015e
authored
May 13, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted os._getfullpathname() and os._isdir() to Argument Clinic.
parent
cd4a5cc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
60 deletions
+112
-60
Modules/clinic/posixmodule.c.h
Modules/clinic/posixmodule.c.h
+73
-1
Modules/posixmodule.c
Modules/posixmodule.c
+39
-59
No files found.
Modules/clinic/posixmodule.c.h
View file @
f0b5015e
...
...
@@ -890,6 +890,38 @@ exit:
#if defined(MS_WINDOWS)
PyDoc_STRVAR
(
os__getfullpathname__doc__
,
"_getfullpathname($module, path, /)
\n
"
"--
\n
"
"
\n
"
);
#define OS__GETFULLPATHNAME_METHODDEF \
{"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
static
PyObject
*
os__getfullpathname_impl
(
PyModuleDef
*
module
,
path_t
*
path
);
static
PyObject
*
os__getfullpathname
(
PyModuleDef
*
module
,
PyObject
*
arg
)
{
PyObject
*
return_value
=
NULL
;
path_t
path
=
PATH_T_INITIALIZE
(
"_getfullpathname"
,
"path"
,
0
,
0
);
if
(
!
PyArg_Parse
(
arg
,
"O&:_getfullpathname"
,
path_converter
,
&
path
))
goto
exit
;
return_value
=
os__getfullpathname_impl
(
module
,
&
path
);
exit:
/* Cleanup for path */
path_cleanup
(
&
path
);
return
return_value
;
}
#endif
/* defined(MS_WINDOWS) */
#if defined(MS_WINDOWS)
PyDoc_STRVAR
(
os__getfinalpathname__doc__
,
"_getfinalpathname($module, path, /)
\n
"
"--
\n
"
...
...
@@ -920,6 +952,38 @@ exit:
#if defined(MS_WINDOWS)
PyDoc_STRVAR
(
os__isdir__doc__
,
"_isdir($module, path, /)
\n
"
"--
\n
"
"
\n
"
);
#define OS__ISDIR_METHODDEF \
{"_isdir", (PyCFunction)os__isdir, METH_O, os__isdir__doc__},
static
PyObject
*
os__isdir_impl
(
PyModuleDef
*
module
,
path_t
*
path
);
static
PyObject
*
os__isdir
(
PyModuleDef
*
module
,
PyObject
*
arg
)
{
PyObject
*
return_value
=
NULL
;
path_t
path
=
PATH_T_INITIALIZE
(
"_isdir"
,
"path"
,
0
,
0
);
if
(
!
PyArg_Parse
(
arg
,
"O&:_isdir"
,
path_converter
,
&
path
))
goto
exit
;
return_value
=
os__isdir_impl
(
module
,
&
path
);
exit:
/* Cleanup for path */
path_cleanup
(
&
path
);
return
return_value
;
}
#endif
/* defined(MS_WINDOWS) */
#if defined(MS_WINDOWS)
PyDoc_STRVAR
(
os__getvolumepathname__doc__
,
"_getvolumepathname($module, /, path)
\n
"
"--
\n
"
...
...
@@ -5313,10 +5377,18 @@ exit:
#define OS_LINK_METHODDEF
#endif
/* !defined(OS_LINK_METHODDEF) */
#ifndef OS__GETFULLPATHNAME_METHODDEF
#define OS__GETFULLPATHNAME_METHODDEF
#endif
/* !defined(OS__GETFULLPATHNAME_METHODDEF) */
#ifndef OS__GETFINALPATHNAME_METHODDEF
#define OS__GETFINALPATHNAME_METHODDEF
#endif
/* !defined(OS__GETFINALPATHNAME_METHODDEF) */
#ifndef OS__ISDIR_METHODDEF
#define OS__ISDIR_METHODDEF
#endif
/* !defined(OS__ISDIR_METHODDEF) */
#ifndef OS__GETVOLUMEPATHNAME_METHODDEF
#define OS__GETVOLUMEPATHNAME_METHODDEF
#endif
/* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
...
...
@@ -5716,4 +5788,4 @@ exit:
#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
#define OS_SET_HANDLE_INHERITABLE_METHODDEF
#endif
/* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
/*[clinic end generated code: output=
bba73c13a01c09a0
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
f3f92b2d2e2c3fe3
input=a9049054013a1b77]*/
Modules/posixmodule.c
View file @
f0b5015e
...
...
@@ -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"
,
p
o
);
v
=
win32_error_object
(
"GetFullPathNameW"
,
p
ath
->
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment