Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 44669:9b6d348cec87 legacy-trunk
Applied patch #1816: sys.flags patch
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Mon, 14 Jan 2008 03:42:48 +0000 |
| parents | 599f22a349a2 |
| children | 5dfded9ad8a0 |
comparison
equal
deleted
inserted
replaced
| 44668:7e41e1c46b57 | 44669:9b6d348cec87 |
|---|---|
| 13 - argv: script arguments (list of strings) | 13 - argv: script arguments (list of strings) |
| 14 - ps1, ps2: optional primary and secondary prompts (strings) | 14 - ps1, ps2: optional primary and secondary prompts (strings) |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 #include "Python.h" | 17 #include "Python.h" |
| 18 #include "structseq.h" | |
| 18 #include "code.h" | 19 #include "code.h" |
| 19 #include "frameobject.h" | 20 #include "frameobject.h" |
| 20 #include "eval.h" | 21 #include "eval.h" |
| 21 | 22 |
| 22 #include "osdefs.h" | 23 #include "osdefs.h" |
| 1043 { | 1044 { |
| 1044 svnversion_init(); | 1045 svnversion_init(); |
| 1045 return shortbranch; | 1046 return shortbranch; |
| 1046 } | 1047 } |
| 1047 | 1048 |
| 1049 | |
| 1050 PyDoc_STRVAR(flags__doc__, | |
| 1051 "sys.flags\n\ | |
| 1052 \n\ | |
| 1053 Flags provided through command line arguments or environment vars."); | |
| 1054 | |
| 1055 static PyTypeObject FlagsType; | |
| 1056 | |
| 1057 static PyStructSequence_Field flags_fields[] = { | |
| 1058 {"debug", "-d"}, | |
| 1059 {"py3k_warning", "-3"}, | |
| 1060 {"division_warning", "-Q"}, | |
| 1061 {"division_new", "-Qnew"}, | |
| 1062 {"inspect", "-i"}, | |
| 1063 {"interactive", "-i"}, | |
| 1064 {"optimize", "-O or -OO"}, | |
| 1065 {"dont_write_bytecode", "-B"}, | |
| 1066 /* {"no_user_site", "-s"}, */ | |
| 1067 {"no_site", "-S"}, | |
| 1068 {"ingnore_environment", "-E"}, | |
| 1069 {"tabcheck", "-t or -tt"}, | |
| 1070 {"verbose", "-v"}, | |
| 1071 #ifdef RISCOS | |
| 1072 {"ricos_wimp", "???"}, | |
| 1073 #endif | |
| 1074 /* {"unbuffered", "-u"}, */ | |
| 1075 {"unicode", "-U"}, | |
| 1076 /* {"skip_first", "-x"}, */ | |
| 1077 {0} | |
| 1078 }; | |
| 1079 | |
| 1080 static PyStructSequence_Desc flags_desc = { | |
| 1081 "sys.flags", /* name */ | |
| 1082 flags__doc__, /* doc */ | |
| 1083 flags_fields, /* fields */ | |
| 1084 #ifdef RISCOS | |
| 1085 14 | |
| 1086 #else | |
| 1087 13 | |
| 1088 #endif | |
| 1089 }; | |
| 1090 | |
| 1091 static PyObject* | |
| 1092 make_flags(void) | |
| 1093 { | |
| 1094 int pos = 0; | |
| 1095 PyObject *seq; | |
| 1096 | |
| 1097 seq = PyStructSequence_New(&FlagsType); | |
| 1098 if (seq == NULL) | |
| 1099 return NULL; | |
| 1100 | |
| 1101 #define SetFlag(flag) \ | |
| 1102 PyStructSequence_SET_ITEM(seq, pos++, PyInt_FromLong(flag)) | |
| 1103 | |
| 1104 SetFlag(Py_DebugFlag); | |
| 1105 SetFlag(Py_Py3kWarningFlag); | |
| 1106 SetFlag(Py_DivisionWarningFlag); | |
| 1107 SetFlag(_Py_QnewFlag); | |
| 1108 SetFlag(Py_InspectFlag); | |
| 1109 SetFlag(Py_InteractiveFlag); | |
| 1110 SetFlag(Py_OptimizeFlag); | |
| 1111 SetFlag(Py_DontWriteBytecodeFlag); | |
| 1112 /* SetFlag(Py_NoUserSiteDirectory); */ | |
| 1113 SetFlag(Py_NoSiteFlag); | |
| 1114 SetFlag(Py_IgnoreEnvironmentFlag); | |
| 1115 SetFlag(Py_TabcheckFlag); | |
| 1116 SetFlag(Py_VerboseFlag); | |
| 1117 #ifdef RISCOS | |
| 1118 SetFlag(Py_RISCOSWimpFlag); | |
| 1119 #endif | |
| 1120 /* SetFlag(saw_unbuffered_flag); */ | |
| 1121 SetFlag(Py_UnicodeFlag); | |
| 1122 /* SetFlag(skipfirstline); */ | |
| 1123 #undef SetFlag | |
| 1124 | |
| 1125 if (PyErr_Occurred()) { | |
| 1126 return NULL; | |
| 1127 } | |
| 1128 | |
| 1129 Py_INCREF(seq); | |
| 1130 return seq; | |
| 1131 } | |
| 1132 | |
| 1048 PyObject * | 1133 PyObject * |
| 1049 _PySys_Init(void) | 1134 _PySys_Init(void) |
| 1050 { | 1135 { |
| 1051 PyObject *m, *v, *sysdict; | 1136 PyObject *m, *v, *sysdict; |
| 1052 PyObject *sysin, *sysout, *syserr; | 1137 PyObject *sysin, *sysout, *syserr; |
| 1126 Py_XDECREF(v); | 1211 Py_XDECREF(v); |
| 1127 svnversion_init(); | 1212 svnversion_init(); |
| 1128 v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision); | 1213 v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision); |
| 1129 PyDict_SetItemString(sysdict, "subversion", v); | 1214 PyDict_SetItemString(sysdict, "subversion", v); |
| 1130 Py_XDECREF(v); | 1215 Py_XDECREF(v); |
| 1131 PyDict_SetItemString(sysdict, "dont_write_bytecode", | 1216 PyDict_SetItemString(sysdict, "dont_write_bytecode", |
| 1132 v = PyBool_FromLong(Py_DontWriteBytecodeFlag)); | 1217 v = PyBool_FromLong(Py_DontWriteBytecodeFlag)); |
| 1133 Py_XDECREF(v); | 1218 Py_XDECREF(v); |
| 1134 /* | 1219 /* |
| 1135 * These release level checks are mutually exclusive and cover | 1220 * These release level checks are mutually exclusive and cover |
| 1136 * the field, so don't get too fancy with the pre-processor! | 1221 * the field, so don't get too fancy with the pre-processor! |
| 1137 */ | 1222 */ |
| 1138 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA | 1223 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA |
| 1208 Py_INCREF(warnoptions); | 1293 Py_INCREF(warnoptions); |
| 1209 } | 1294 } |
| 1210 if (warnoptions != NULL) { | 1295 if (warnoptions != NULL) { |
| 1211 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); | 1296 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); |
| 1212 } | 1297 } |
| 1298 | |
| 1299 PyStructSequence_InitType(&FlagsType, &flags_desc); | |
| 1300 PyDict_SetItemString(sysdict, "flags", make_flags()); | |
| 1301 /* prevent user from creating new instances */ | |
| 1302 FlagsType.tp_init = NULL; | |
| 1303 FlagsType.tp_new = NULL; | |
| 1213 | 1304 |
| 1214 if (PyErr_Occurred()) | 1305 if (PyErr_Occurred()) |
| 1215 return NULL; | 1306 return NULL; |
| 1216 return m; | 1307 return m; |
| 1217 } | 1308 } |
