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
bd0850b8
Commit
bd0850b8
authored
Dec 18, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import.c now catchs _Py_stat() exceptions
_Py_stat() now returns -2 if an exception was raised.
parent
7bfe8994
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
13 deletions
+37
-13
Modules/zipimport.c
Modules/zipimport.c
+2
-2
Python/fileutils.c
Python/fileutils.c
+4
-4
Python/import.c
Python/import.c
+31
-7
No files found.
Modules/zipimport.c
View file @
bd0850b8
...
...
@@ -102,6 +102,8 @@ zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
int
rv
;
rv
=
_Py_stat
(
filename
,
&
statbuf
);
if
(
rv
==
-
2
)
goto
error
;
if
(
rv
==
0
)
{
/* it exists */
if
(
!
S_ISREG
(
statbuf
.
st_mode
))
...
...
@@ -109,8 +111,6 @@ zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
Py_CLEAR
(
filename
);
break
;
}
else
if
(
PyErr_Occurred
())
goto
error
;
Py_CLEAR
(
filename
);
/* back up one path element */
flen
=
PyUnicode_FindChar
(
path
,
SEP
,
0
,
flen
,
-
1
);
...
...
Python/fileutils.c
View file @
bd0850b8
...
...
@@ -240,8 +240,8 @@ _Py_wstat(const wchar_t* path, struct stat *buf)
/* Call _wstat() on Windows, or encode the path to the filesystem encoding and
call stat() otherwise. Only fill st_mode attribute on Windows.
Return 0 on success, -1 on _wstat() / stat() error
or (if PyErr_Occurred())
unicode error
. */
Return 0 on success, -1 on _wstat() / stat() error
, -2 if an exception was
raised
. */
int
_Py_stat
(
PyObject
*
path
,
struct
stat
*
statbuf
)
...
...
@@ -253,7 +253,7 @@ _Py_stat(PyObject *path, struct stat *statbuf)
wpath
=
PyUnicode_AsUnicode
(
path
);
if
(
wpath
==
NULL
)
return
-
1
;
return
-
2
;
err
=
_wstat
(
wpath
,
&
wstatbuf
);
if
(
!
err
)
statbuf
->
st_mode
=
wstatbuf
.
st_mode
;
...
...
@@ -262,7 +262,7 @@ _Py_stat(PyObject *path, struct stat *statbuf)
int
ret
;
PyObject
*
bytes
=
PyUnicode_EncodeFSDefault
(
path
);
if
(
bytes
==
NULL
)
return
-
1
;
return
-
2
;
ret
=
stat
(
PyBytes_AS_STRING
(
bytes
),
statbuf
);
Py_DECREF
(
bytes
);
return
ret
;
...
...
Python/import.c
View file @
bd0850b8
...
...
@@ -1527,6 +1527,7 @@ get_sourcefile(PyObject *filename)
Py_UCS4
*
fileuni
;
PyObject
*
py
;
struct
stat
statbuf
;
int
err
;
len
=
PyUnicode_GET_LENGTH
(
filename
);
if
(
len
==
0
)
...
...
@@ -1554,7 +1555,10 @@ get_sourcefile(PyObject *filename)
if
(
py
==
NULL
)
goto
error
;
if
(
_Py_stat
(
py
,
&
statbuf
)
==
0
&&
S_ISREG
(
statbuf
.
st_mode
))
{
err
=
_Py_stat
(
py
,
&
statbuf
);
if
(
err
==
-
2
)
goto
error
;
if
(
err
==
0
&&
S_ISREG
(
statbuf
.
st_mode
))
{
PyMem_Free
(
fileuni
);
return
py
;
}
...
...
@@ -1760,7 +1764,7 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
Py_ssize_t
len
,
pos
;
struct
stat
statbuf
;
static
struct
filedescr
fd_package
=
{
""
,
""
,
PKG_DIRECTORY
};
int
result
,
addsep
;
int
err
,
result
,
addsep
;
if
(
PyUnicode_Check
(
path
))
{
Py_INCREF
(
path
);
...
...
@@ -1844,7 +1848,12 @@ find_module_path(PyObject *fullname, PyObject *name, PyObject *path,
/* Check for package import (buf holds a directory name,
and there's an __init__ module in that directory */
#ifdef HAVE_STAT
if
(
_Py_stat
(
filename
,
&
statbuf
)
==
0
&&
/* it exists */
err
=
_Py_stat
(
filename
,
&
statbuf
);
if
(
err
==
-
2
)
{
result
=
-
1
;
goto
out
;
}
if
(
err
==
0
&&
/* it exists */
S_ISDIR
(
statbuf
.
st_mode
))
/* it's a directory */
{
int
match
;
...
...
@@ -1905,6 +1914,7 @@ find_module_path_list(PyObject *fullname, PyObject *name,
FILE
*
fp
=
NULL
;
PyObject
*
prefix
,
*
filename
;
int
match
;
int
err
;
npath
=
PyList_Size
(
search_path_list
);
for
(
i
=
0
;
i
<
npath
;
i
++
)
{
...
...
@@ -1944,8 +1954,13 @@ find_module_path_list(PyObject *fullname, PyObject *name,
if
(
Py_VerboseFlag
>
1
)
PySys_FormatStderr
(
"# trying %R
\n
"
,
filename
);
if
(
_Py_stat
(
filename
,
&
statbuf
)
!=
0
||
S_ISDIR
(
statbuf
.
st_mode
))
{
err
=
_Py_stat
(
filename
,
&
statbuf
);
if
(
err
==
-
2
)
{
Py_DECREF
(
prefix
);
Py_DECREF
(
filename
);
return
NULL
;
}
if
(
err
!=
0
||
S_ISDIR
(
statbuf
.
st_mode
))
{
/* it doesn't exist, or it's a directory */
Py_DECREF
(
filename
);
continue
;
...
...
@@ -2345,11 +2360,15 @@ find_init_module(PyObject *directory)
struct
stat
statbuf
;
PyObject
*
filename
;
int
match
;
int
err
;
filename
=
PyUnicode_FromFormat
(
"%U%c__init__.py"
,
directory
,
SEP
);
if
(
filename
==
NULL
)
return
-
1
;
if
(
_Py_stat
(
filename
,
&
statbuf
)
==
0
)
{
err
=
_Py_stat
(
filename
,
&
statbuf
);
if
(
err
==
-
2
)
return
-
1
;
if
(
err
==
0
)
{
/* 3=len(".py") */
match
=
case_ok
(
filename
,
-
3
,
initstr
);
if
(
match
<
0
)
{
...
...
@@ -2367,7 +2386,12 @@ find_init_module(PyObject *directory)
directory
,
SEP
,
Py_OptimizeFlag
?
'o'
:
'c'
);
if
(
filename
==
NULL
)
return
-
1
;
if
(
_Py_stat
(
filename
,
&
statbuf
)
==
0
)
{
err
=
_Py_stat
(
filename
,
&
statbuf
);
if
(
err
==
-
2
)
{
Py_DECREF
(
filename
);
return
-
1
;
}
if
(
err
==
0
)
{
/* 4=len(".pyc") */
match
=
case_ok
(
filename
,
-
4
,
initstr
);
if
(
match
<
0
)
{
...
...
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