Issue 1442: pythonstartup addition of minor error checking (original) (raw)

Issue1442

Created on 2007-11-14 04:07 by JosephArmbruster, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pythonstartup.patch JosephArmbruster,2008-01-04 16:55 main.c patch for PYTHONSTARTUP error handling
Messages (7)
msg57482 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2007-11-14 04:07
Trunk revision: 58963 Description: No warning or error is reported it a file pointed to by PYTHONSTARTUP is not readable. Request: To display a warning so that the user may be notified. Note: Errors that may occur in PyRun_SimpleFileExFlags are being cast away, may be worthwhile to report an error for those as well (unless this was avoided for good reason :-) Suggestion: static void RunStartupFile(PyCompilerFlags *cf) { char *startup = Py_GETENV("PYTHONSTARTUP"); if (startup != NULL && startup[0] != '\0') { FILE *fp = fopen(startup, "r"); if (fp != NULL) { (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf); PyErr_Clear(); fclose(fp); } else { fprintf(stderr,"Warning: Could not read startup file %s\n",startup); } } }
msg57489 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-14 15:18
Good idea! Errors in the startup file are already reported by PyRun_*
msg57490 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-14 16:22
I've a far better patch that uses Python's infrastructure to report the error: Index: Modules/main.c =================================================================== --- Modules/main.c (Revision 58966) +++ Modules/main.c (Arbeitskopie) @@ -132,6 +132,16 @@ (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf); PyErr_Clear(); fclose(fp); + } else { + int save_errno; + + save_errno = errno; + PySys_WriteStderr("Could not open PYTHONSTARTUP\n"); + errno = save_errno; + PyErr_SetFromErrnoWithFilename(PyExc_IOError, + startup); + PyErr_Print(); + PyErr_Clear(); } } } $ ./python Python 3.0a1+ (py3k:58966M, Nov 14 2007, 17:17:06) [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Could not open PYTHONSTARTUP IOError: [Errno 2] No such file or directory: '/home/heimes/.python/startup.py' >>> Fixed in r58969 (py3k)
msg57804 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-11-24 13:07
Shall we close this issue?
msg57807 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-24 15:45
I think we should backport it to 2.6 and maybe 2.5.
msg59239 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2008-01-04 16:55
Backport to 2.6a0 and tested with: Python 2.6a0 (trunk:59710M, Jan 4 2008, 11:36:45) [MSC v.1500 32 bit (Intel)] on win32
msg64673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-29 01:51
Backported to 2.6 in r62030 and 2.5 in r62031.
History
Date User Action Args
2022-04-11 14:56:28 admin set github: 45783
2008-03-29 01:51:16 georg.brandl set status: open -> closednosy: + georg.brandlmessages: +
2008-01-04 16:55:26 JosephArmbruster set files: + pythonstartup.patchmessages: +
2007-11-24 15:45:42 christian.heimes set messages: +
2007-11-24 13:07:20 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2007-11-14 16:22:06 christian.heimes set resolution: acceptedmessages: + versions: - Python 3.0
2007-11-14 15🔞14 christian.heimes set priority: lownosy: + christian.heimesmessages: + versions: + Python 3.0
2007-11-14 08:04:55 loewis set keywords: + patch
2007-11-14 04:07:24 JosephArmbruster create