mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Issue #2051 and patch from Alexander Belopolsky:
Permission for pyc and pyo files are inherited from the py file.
This commit is contained in:
parent
f0476e8169
commit
4034685a58
3 changed files with 19 additions and 15 deletions
|
@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #2051: pyc and pyo files are not longer created with permission 644. The
|
||||||
|
mode is now inherited from the py file.
|
||||||
|
|
||||||
- Issue #2067: file.__exit__() now calls subclasses' close() method.
|
- Issue #2067: file.__exit__() now calls subclasses' close() method.
|
||||||
|
|
||||||
- Patch #1759: Backport of PEP 3129 class decorators.
|
- Patch #1759: Backport of PEP 3129 class decorators.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
__version__ 53731.
|
__version__ 60978.
|
||||||
|
|
||||||
This module must be committed separately after each AST grammar change;
|
This module must be committed separately after each AST grammar change;
|
||||||
The __version__ number is set to the revision number of the commit
|
The __version__ number is set to the revision number of the commit
|
||||||
|
@ -2958,7 +2958,7 @@ init_ast(void)
|
||||||
if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
|
if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
|
||||||
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
|
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
|
||||||
return;
|
return;
|
||||||
if (PyModule_AddStringConstant(m, "__version__", "53731") < 0)
|
if (PyModule_AddStringConstant(m, "__version__", "60978") < 0)
|
||||||
return;
|
return;
|
||||||
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
|
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
|
||||||
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
|
if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
|
||||||
|
|
|
@ -829,7 +829,7 @@ parse_source_module(const char *pathname, FILE *fp)
|
||||||
/* Helper to open a bytecode file for writing in exclusive mode */
|
/* Helper to open a bytecode file for writing in exclusive mode */
|
||||||
|
|
||||||
static FILE *
|
static FILE *
|
||||||
open_exclusive(char *filename)
|
open_exclusive(char *filename, mode_t mode)
|
||||||
{
|
{
|
||||||
#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)
|
#if defined(O_EXCL)&&defined(O_CREAT)&&defined(O_WRONLY)&&defined(O_TRUNC)
|
||||||
/* Use O_EXCL to avoid a race condition when another process tries to
|
/* Use O_EXCL to avoid a race condition when another process tries to
|
||||||
|
@ -845,9 +845,9 @@ open_exclusive(char *filename)
|
||||||
|O_BINARY /* necessary for Windows */
|
|O_BINARY /* necessary for Windows */
|
||||||
#endif
|
#endif
|
||||||
#ifdef __VMS
|
#ifdef __VMS
|
||||||
, 0666, "ctxt=bin", "shr=nil"
|
, mode, "ctxt=bin", "shr=nil"
|
||||||
#else
|
#else
|
||||||
, 0666
|
, mode
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -866,11 +866,13 @@ open_exclusive(char *filename)
|
||||||
remove the file. */
|
remove the file. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
|
write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
time_t mtime = srcstat->st_mtime;
|
||||||
|
mode_t mode = srcstat->st_mode;
|
||||||
|
|
||||||
fp = open_exclusive(cpathname);
|
fp = open_exclusive(cpathname, mode);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
if (Py_VerboseFlag)
|
if (Py_VerboseFlag)
|
||||||
PySys_WriteStderr(
|
PySys_WriteStderr(
|
||||||
|
@ -907,17 +909,16 @@ write_compiled_module(PyCodeObject *co, char *cpathname, time_t mtime)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
load_source_module(char *name, char *pathname, FILE *fp)
|
load_source_module(char *name, char *pathname, FILE *fp)
|
||||||
{
|
{
|
||||||
time_t mtime;
|
struct stat st;
|
||||||
FILE *fpc;
|
FILE *fpc;
|
||||||
char buf[MAXPATHLEN+1];
|
char buf[MAXPATHLEN+1];
|
||||||
char *cpathname;
|
char *cpathname;
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
PyObject *m;
|
PyObject *m;
|
||||||
|
|
||||||
mtime = PyOS_GetLastModificationTime(pathname, fp);
|
if (fstat(fileno(fp), &st) != 0) {
|
||||||
if (mtime == (time_t)(-1)) {
|
|
||||||
PyErr_Format(PyExc_RuntimeError,
|
PyErr_Format(PyExc_RuntimeError,
|
||||||
"unable to get modification time from '%s'",
|
"unable to get file status from '%s'",
|
||||||
pathname);
|
pathname);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -926,7 +927,7 @@ load_source_module(char *name, char *pathname, FILE *fp)
|
||||||
in 4 bytes. This will be fine until sometime in the year 2038,
|
in 4 bytes. This will be fine until sometime in the year 2038,
|
||||||
when a 4-byte signed time_t will overflow.
|
when a 4-byte signed time_t will overflow.
|
||||||
*/
|
*/
|
||||||
if (mtime >> 32) {
|
if (st.st_mtime >> 32) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"modification time overflows a 4 byte field");
|
"modification time overflows a 4 byte field");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -935,7 +936,7 @@ load_source_module(char *name, char *pathname, FILE *fp)
|
||||||
cpathname = make_compiled_pathname(pathname, buf,
|
cpathname = make_compiled_pathname(pathname, buf,
|
||||||
(size_t)MAXPATHLEN + 1);
|
(size_t)MAXPATHLEN + 1);
|
||||||
if (cpathname != NULL &&
|
if (cpathname != NULL &&
|
||||||
(fpc = check_compiled_module(pathname, mtime, cpathname))) {
|
(fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) {
|
||||||
co = read_compiled_module(cpathname, fpc);
|
co = read_compiled_module(cpathname, fpc);
|
||||||
fclose(fpc);
|
fclose(fpc);
|
||||||
if (co == NULL)
|
if (co == NULL)
|
||||||
|
@ -955,7 +956,7 @@ load_source_module(char *name, char *pathname, FILE *fp)
|
||||||
if (cpathname) {
|
if (cpathname) {
|
||||||
PyObject *ro = PySys_GetObject("dont_write_bytecode");
|
PyObject *ro = PySys_GetObject("dont_write_bytecode");
|
||||||
if (ro == NULL || !PyObject_IsTrue(ro))
|
if (ro == NULL || !PyObject_IsTrue(ro))
|
||||||
write_compiled_module(co, cpathname, mtime);
|
write_compiled_module(co, cpathname, &st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
|
m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue