[Python-checkins] CVS: python/dist/src/Python pythonrun.c,2.147,2.148

Guido van Rossum gvanrossum@users.sourceforge.net
2001年8月31日 10:40:17 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv8024/Python
Modified Files:
	pythonrun.c 
Log Message:
Add warning mode for classic division, almost exactly as specified in
PEP 238. Changes:
- add a new flag variable Py_DivisionWarningFlag, declared in
 pydebug.h, defined in object.c, set in main.c, and used in
 {int,long,float,complex}object.c. When this flag is set, the
 classic division operator issues a DeprecationWarning message.
- add a new API PyRun_SimpleStringFlags() to match
 PyRun_SimpleString(). The main() function calls this so that
 commands run with -c can also benefit from -Dnew.
- While I was at it, I changed the usage message in main() somewhat:
 alphabetized the options, split it in *four* parts to fit in under
 512 bytes (not that I still believe this is necessary -- doc strings
 elsewhere are much longer), and perhaps most visibly, don't display
 the full list of options on each command line error. Instead, the
 full list is only displayed when -h is used, and otherwise a brief
 reminder of -h is displayed. When -h is used, write to stdout so
 that you can do `python -h | more'.
Notes:
- I don't want to use the -W option to control whether the classic
 division warning is issued or not, because the machinery to decide
 whether to display the warning or not is very expensive (it involves
 calling into the warnings.py module). You can use -Werror to turn
 the warnings into exceptions though.
- The -Dnew option doesn't select future division for all of the
 program -- only for the __main__ module. I don't know if I'll ever
 change this -- it would require changes to the .pyc file magic
 number to do it right, and a more global notion of compiler flags.
- You can usefully combine -Dwarn and -Dnew: this gives the __main__
 module new division, and warns about classic division everywhere
 else.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.147
retrieving revision 2.148
diff -C2 -d -r2.147 -r2.148
*** pythonrun.c	2001年08月17日 18:39:25	2.147
--- pythonrun.c	2001年08月31日 17:40:15	2.148
***************
*** 688,691 ****
--- 688,697 ----
 PyRun_SimpleString(char *command)
 {
+ 	return PyRun_SimpleStringFlags(command, NULL);
+ }
+ 
+ int
+ PyRun_SimpleStringFlags(char *command, PyCompilerFlags *flags)
+ {
 	PyObject *m, *d, *v;
 	m = PyImport_AddModule("__main__");
***************
*** 693,697 ****
 		return -1;
 	d = PyModule_GetDict(m);
! 	v = PyRun_String(command, Py_file_input, d, d);
 	if (v == NULL) {
 		PyErr_Print();
--- 699,703 ----
 		return -1;
 	d = PyModule_GetDict(m);
! 	v = PyRun_StringFlags(command, Py_file_input, d, d, flags);
 	if (v == NULL) {
 		PyErr_Print();

AltStyle によって変換されたページ (->オリジナル) /