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
732f2346
Commit
732f2346
authored
Dec 16, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10350: Read and save errno before calling a function which might overwrite it.
Original patch by Hallvard B Furuseth.
parent
4e382edc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
12 deletions
+33
-12
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+11
-3
Modules/_multiprocessing/semaphore.c
Modules/_multiprocessing/semaphore.c
+3
-1
Modules/main.c
Modules/main.c
+2
-1
Modules/readline.c
Modules/readline.c
+8
-5
Modules/timemodule.c
Modules/timemodule.c
+3
-1
Parser/myreadline.c
Parser/myreadline.c
+3
-1
No files found.
Misc/NEWS
View file @
732f2346
...
@@ -97,6 +97,9 @@ Core and Builtins
...
@@ -97,6 +97,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10350: Read and save errno before calling a function which might
overwrite it. Original patch by Hallvard B Furuseth.
- Issue #13591: A bug in importlib has been fixed that caused import_module
- Issue #13591: A bug in importlib has been fixed that caused import_module
to load a module twice.
to load a module twice.
...
...
Modules/_io/fileio.c
View file @
732f2346
...
@@ -506,6 +506,7 @@ fileio_readinto(fileio *self, PyObject *args)
...
@@ -506,6 +506,7 @@ fileio_readinto(fileio *self, PyObject *args)
{
{
Py_buffer
pbuf
;
Py_buffer
pbuf
;
Py_ssize_t
n
,
len
;
Py_ssize_t
n
,
len
;
int
err
;
if
(
self
->
fd
<
0
)
if
(
self
->
fd
<
0
)
return
err_closed
();
return
err_closed
();
...
@@ -529,10 +530,12 @@ fileio_readinto(fileio *self, PyObject *args)
...
@@ -529,10 +530,12 @@ fileio_readinto(fileio *self, PyObject *args)
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
}
else
}
else
n
=
-
1
;
n
=
-
1
;
err
=
errno
;
PyBuffer_Release
(
&
pbuf
);
PyBuffer_Release
(
&
pbuf
);
if
(
n
<
0
)
{
if
(
n
<
0
)
{
if
(
err
no
==
EAGAIN
)
if
(
err
==
EAGAIN
)
Py_RETURN_NONE
;
Py_RETURN_NONE
;
errno
=
err
;
PyErr_SetFromErrno
(
PyExc_IOError
);
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
return
NULL
;
}
}
...
@@ -675,9 +678,11 @@ fileio_read(fileio *self, PyObject *args)
...
@@ -675,9 +678,11 @@ fileio_read(fileio *self, PyObject *args)
n
=
-
1
;
n
=
-
1
;
if
(
n
<
0
)
{
if
(
n
<
0
)
{
int
err
=
errno
;
Py_DECREF
(
bytes
);
Py_DECREF
(
bytes
);
if
(
err
no
==
EAGAIN
)
if
(
err
==
EAGAIN
)
Py_RETURN_NONE
;
Py_RETURN_NONE
;
errno
=
err
;
PyErr_SetFromErrno
(
PyExc_IOError
);
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
return
NULL
;
}
}
...
@@ -697,6 +702,7 @@ fileio_write(fileio *self, PyObject *args)
...
@@ -697,6 +702,7 @@ fileio_write(fileio *self, PyObject *args)
{
{
Py_buffer
pbuf
;
Py_buffer
pbuf
;
Py_ssize_t
n
,
len
;
Py_ssize_t
n
,
len
;
int
err
;
if
(
self
->
fd
<
0
)
if
(
self
->
fd
<
0
)
return
err_closed
();
return
err_closed
();
...
@@ -727,12 +733,14 @@ fileio_write(fileio *self, PyObject *args)
...
@@ -727,12 +733,14 @@ fileio_write(fileio *self, PyObject *args)
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
}
else
}
else
n
=
-
1
;
n
=
-
1
;
err
=
errno
;
PyBuffer_Release
(
&
pbuf
);
PyBuffer_Release
(
&
pbuf
);
if
(
n
<
0
)
{
if
(
n
<
0
)
{
if
(
err
no
==
EAGAIN
)
if
(
err
==
EAGAIN
)
Py_RETURN_NONE
;
Py_RETURN_NONE
;
errno
=
err
;
PyErr_SetFromErrno
(
PyExc_IOError
);
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
return
NULL
;
}
}
...
...
Modules/_multiprocessing/semaphore.c
View file @
732f2346
...
@@ -267,7 +267,7 @@ sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
...
@@ -267,7 +267,7 @@ sem_timedwait_save(sem_t *sem, struct timespec *deadline, PyThreadState *_save)
static
PyObject
*
static
PyObject
*
semlock_acquire
(
SemLockObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
semlock_acquire
(
SemLockObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
int
blocking
=
1
,
res
;
int
blocking
=
1
,
res
,
err
=
0
;
double
timeout
;
double
timeout
;
PyObject
*
timeout_obj
=
Py_None
;
PyObject
*
timeout_obj
=
Py_None
;
struct
timespec
deadline
=
{
0
};
struct
timespec
deadline
=
{
0
};
...
@@ -313,11 +313,13 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
...
@@ -313,11 +313,13 @@ semlock_acquire(SemLockObject *self, PyObject *args, PyObject *kwds)
else
else
res
=
sem_timedwait
(
self
->
handle
,
&
deadline
);
res
=
sem_timedwait
(
self
->
handle
,
&
deadline
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
err
=
errno
;
if
(
res
==
MP_EXCEPTION_HAS_BEEN_SET
)
if
(
res
==
MP_EXCEPTION_HAS_BEEN_SET
)
break
;
break
;
}
while
(
res
<
0
&&
errno
==
EINTR
&&
!
PyErr_CheckSignals
());
}
while
(
res
<
0
&&
errno
==
EINTR
&&
!
PyErr_CheckSignals
());
if
(
res
<
0
)
{
if
(
res
<
0
)
{
errno
=
err
;
if
(
errno
==
EAGAIN
||
errno
==
ETIMEDOUT
)
if
(
errno
==
EAGAIN
||
errno
==
ETIMEDOUT
)
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
else
if
(
errno
==
EINTR
)
else
if
(
errno
==
EINTR
)
...
...
Modules/main.c
View file @
732f2346
...
@@ -654,13 +654,14 @@ Py_Main(int argc, wchar_t **argv)
...
@@ -654,13 +654,14 @@ Py_Main(int argc, wchar_t **argv)
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
char
*
cfilename_buffer
;
char
*
cfilename_buffer
;
const
char
*
cfilename
;
const
char
*
cfilename
;
int
err
=
errno
;
cfilename_buffer
=
_Py_wchar2char
(
filename
,
NULL
);
cfilename_buffer
=
_Py_wchar2char
(
filename
,
NULL
);
if
(
cfilename_buffer
!=
NULL
)
if
(
cfilename_buffer
!=
NULL
)
cfilename
=
cfilename_buffer
;
cfilename
=
cfilename_buffer
;
else
else
cfilename
=
"<unprintable file name>"
;
cfilename
=
"<unprintable file name>"
;
fprintf
(
stderr
,
"%ls: can't open file '%s': [Errno %d] %s
\n
"
,
fprintf
(
stderr
,
"%ls: can't open file '%s': [Errno %d] %s
\n
"
,
argv
[
0
],
cfilename
,
err
no
,
strerror
(
errno
));
argv
[
0
],
cfilename
,
err
,
strerror
(
err
));
if
(
cfilename_buffer
)
if
(
cfilename_buffer
)
PyMem_Free
(
cfilename_buffer
);
PyMem_Free
(
cfilename_buffer
);
return
2
;
return
2
;
...
...
Modules/readline.c
View file @
732f2346
...
@@ -154,6 +154,7 @@ write_history_file(PyObject *self, PyObject *args)
...
@@ -154,6 +154,7 @@ write_history_file(PyObject *self, PyObject *args)
{
{
PyObject
*
filename_obj
=
Py_None
,
*
filename_bytes
;
PyObject
*
filename_obj
=
Py_None
,
*
filename_bytes
;
char
*
filename
;
char
*
filename
;
int
err
;
if
(
!
PyArg_ParseTuple
(
args
,
"|O:write_history_file"
,
&
filename_obj
))
if
(
!
PyArg_ParseTuple
(
args
,
"|O:write_history_file"
,
&
filename_obj
))
return
NULL
;
return
NULL
;
if
(
filename_obj
!=
Py_None
)
{
if
(
filename_obj
!=
Py_None
)
{
...
@@ -164,10 +165,11 @@ write_history_file(PyObject *self, PyObject *args)
...
@@ -164,10 +165,11 @@ write_history_file(PyObject *self, PyObject *args)
filename_bytes
=
NULL
;
filename_bytes
=
NULL
;
filename
=
NULL
;
filename
=
NULL
;
}
}
errno
=
write_history
(
filename
);
errno
=
err
=
write_history
(
filename
);
if
(
!
err
no
&&
_history_length
>=
0
)
if
(
!
err
&&
_history_length
>=
0
)
history_truncate_file
(
filename
,
_history_length
);
history_truncate_file
(
filename
,
_history_length
);
Py_XDECREF
(
filename_bytes
);
Py_XDECREF
(
filename_bytes
);
errno
=
err
;
if
(
errno
)
if
(
errno
)
return
PyErr_SetFromErrno
(
PyExc_IOError
);
return
PyErr_SetFromErrno
(
PyExc_IOError
);
Py_RETURN_NONE
;
Py_RETURN_NONE
;
...
@@ -970,7 +972,7 @@ readline_until_enter_or_signal(char *prompt, int *signal)
...
@@ -970,7 +972,7 @@ readline_until_enter_or_signal(char *prompt, int *signal)
completed_input_string
=
not_done_reading
;
completed_input_string
=
not_done_reading
;
while
(
completed_input_string
==
not_done_reading
)
{
while
(
completed_input_string
==
not_done_reading
)
{
int
has_input
=
0
;
int
has_input
=
0
,
err
=
0
;
while
(
!
has_input
)
while
(
!
has_input
)
{
struct
timeval
timeout
=
{
0
,
100000
};
/* 0.1 seconds */
{
struct
timeval
timeout
=
{
0
,
100000
};
/* 0.1 seconds */
...
@@ -984,13 +986,14 @@ readline_until_enter_or_signal(char *prompt, int *signal)
...
@@ -984,13 +986,14 @@ readline_until_enter_or_signal(char *prompt, int *signal)
/* select resets selectset if no input was available */
/* select resets selectset if no input was available */
has_input
=
select
(
fileno
(
rl_instream
)
+
1
,
&
selectset
,
has_input
=
select
(
fileno
(
rl_instream
)
+
1
,
&
selectset
,
NULL
,
NULL
,
timeoutp
);
NULL
,
NULL
,
timeoutp
);
err
=
errno
;
if
(
PyOS_InputHook
)
PyOS_InputHook
();
if
(
PyOS_InputHook
)
PyOS_InputHook
();
}
}
if
(
has_input
>
0
)
{
if
(
has_input
>
0
)
{
rl_callback_read_char
();
rl_callback_read_char
();
}
}
else
if
(
err
no
==
EINTR
)
{
else
if
(
err
==
EINTR
)
{
int
s
;
int
s
;
#ifdef WITH_THREAD
#ifdef WITH_THREAD
PyEval_RestoreThread
(
_PyOS_ReadlineTState
);
PyEval_RestoreThread
(
_PyOS_ReadlineTState
);
...
...
Modules/timemodule.c
View file @
732f2346
...
@@ -527,12 +527,14 @@ time_strftime(PyObject *self, PyObject *args)
...
@@ -527,12 +527,14 @@ time_strftime(PyObject *self, PyObject *args)
* will be ahead of time...
* will be ahead of time...
*/
*/
for
(
i
=
1024
;
;
i
+=
i
)
{
for
(
i
=
1024
;
;
i
+=
i
)
{
int
err
;
outbuf
=
(
time_char
*
)
PyMem_Malloc
(
i
*
sizeof
(
time_char
));
outbuf
=
(
time_char
*
)
PyMem_Malloc
(
i
*
sizeof
(
time_char
));
if
(
outbuf
==
NULL
)
{
if
(
outbuf
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
break
;
break
;
}
}
buflen
=
format_time
(
outbuf
,
i
,
fmt
,
&
buf
);
buflen
=
format_time
(
outbuf
,
i
,
fmt
,
&
buf
);
err
=
errno
;
if
(
buflen
>
0
||
i
>=
256
*
fmtlen
)
{
if
(
buflen
>
0
||
i
>=
256
*
fmtlen
)
{
/* If the buffer is 256 times as long as the format,
/* If the buffer is 256 times as long as the format,
it's probably not failing for lack of room!
it's probably not failing for lack of room!
...
@@ -550,7 +552,7 @@ time_strftime(PyObject *self, PyObject *args)
...
@@ -550,7 +552,7 @@ time_strftime(PyObject *self, PyObject *args)
PyMem_Free
(
outbuf
);
PyMem_Free
(
outbuf
);
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
/* VisualStudio .NET 2005 does this properly */
/* VisualStudio .NET 2005 does this properly */
if
(
buflen
==
0
&&
err
no
==
EINVAL
)
{
if
(
buflen
==
0
&&
err
==
EINVAL
)
{
PyErr_SetString
(
PyExc_ValueError
,
"Invalid format string"
);
PyErr_SetString
(
PyExc_ValueError
,
"Invalid format string"
);
break
;
break
;
}
}
...
...
Parser/myreadline.c
View file @
732f2346
...
@@ -36,6 +36,7 @@ static int
...
@@ -36,6 +36,7 @@ static int
my_fgets
(
char
*
buf
,
int
len
,
FILE
*
fp
)
my_fgets
(
char
*
buf
,
int
len
,
FILE
*
fp
)
{
{
char
*
p
;
char
*
p
;
int
err
;
while
(
1
)
{
while
(
1
)
{
if
(
PyOS_InputHook
!=
NULL
)
if
(
PyOS_InputHook
!=
NULL
)
(
void
)(
PyOS_InputHook
)();
(
void
)(
PyOS_InputHook
)();
...
@@ -44,6 +45,7 @@ my_fgets(char *buf, int len, FILE *fp)
...
@@ -44,6 +45,7 @@ my_fgets(char *buf, int len, FILE *fp)
p
=
fgets
(
buf
,
len
,
fp
);
p
=
fgets
(
buf
,
len
,
fp
);
if
(
p
!=
NULL
)
if
(
p
!=
NULL
)
return
0
;
/* No error */
return
0
;
/* No error */
err
=
errno
;
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
/* In the case of a Ctrl+C or some other external event
/* In the case of a Ctrl+C or some other external event
interrupting the operation:
interrupting the operation:
...
@@ -78,7 +80,7 @@ my_fgets(char *buf, int len, FILE *fp)
...
@@ -78,7 +80,7 @@ my_fgets(char *buf, int len, FILE *fp)
return
-
1
;
/* EOF */
return
-
1
;
/* EOF */
}
}
#ifdef EINTR
#ifdef EINTR
if
(
err
no
==
EINTR
)
{
if
(
err
==
EINTR
)
{
int
s
;
int
s
;
#ifdef WITH_THREAD
#ifdef WITH_THREAD
PyEval_RestoreThread
(
_PyOS_ReadlineTState
);
PyEval_RestoreThread
(
_PyOS_ReadlineTState
);
...
...
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