comparison Python/sysmodule.c @ 45071:f380d991390e

Merged revisions 60441-60474 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r60441 | christian.heimes | 2008-01-30 12:46:00 +0100 (Wed, 30 Jan 2008) | 1 line Removed unused var ........ r60448 | christian.heimes | 2008-01-30 18:21:22 +0100 (Wed, 30 Jan 2008) | 1 line Fixed some references leaks in sys. ........ r60450 | christian.heimes | 2008-01-30 19:58:29 +0100 (Wed, 30 Jan 2008) | 1 line The previous change was causing a segfault after multiple calls to Py_Initialize() and Py_Finalize(). ........ r60463 | raymond.hettinger | 2008-01-30 23:17:31 +0100 (Wed, 30 Jan 2008) | 1 line Update itertool recipes ........ r60464 | christian.heimes | 2008-01-30 23:54:18 +0100 (Wed, 30 Jan 2008) | 1 line Bug #1234: Fixed semaphore errors on AIX 5.2 ........ r60469 | raymond.hettinger | 2008-01-31 02:38:15 +0100 (Thu, 31 Jan 2008) | 6 lines Fix defect in __ixor__ which would get the wrong answer if the input iterable had a duplicate element (two calls to toggle() reverse each other). Borrow the correct code from sets.py. ........ r60470 | raymond.hettinger | 2008-01-31 02:42:11 +0100 (Thu, 31 Jan 2008) | 1 line Missing return ........ r60471 | jeffrey.yasskin | 2008-01-31 08:44:11 +0100 (Thu, 31 Jan 2008) | 4 lines Added more documentation on how mixed-mode arithmetic should be implemented. I also noticed and fixed a bug in Rational's forward operators (they were claiming all instances of numbers.Rational instead of just the concrete types). ........
author Christian Heimes <christian@cheimes.de>
date Thu, 31 Jan 2008 14:31:45 +0000
parents ebfbaa1051e2
children 3d7b84daa34a
comparison
equal deleted inserted replaced
45067:8930ff230ee9 45071:f380d991390e
1129 #undef SetFlag 1129 #undef SetFlag
1130 1130
1131 if (PyErr_Occurred()) { 1131 if (PyErr_Occurred()) {
1132 return NULL; 1132 return NULL;
1133 } 1133 }
1134
1135 Py_INCREF(seq);
1136 return seq; 1134 return seq;
1137 } 1135 }
1138 1136
1139 PyObject * 1137 PyObject *
1140 _PySys_Init(void) 1138 _PySys_Init(void)
1144 1142
1145 m = Py_InitModule3("sys", sys_methods, sys_doc); 1143 m = Py_InitModule3("sys", sys_methods, sys_doc);
1146 if (m == NULL) 1144 if (m == NULL)
1147 return NULL; 1145 return NULL;
1148 sysdict = PyModule_GetDict(m); 1146 sysdict = PyModule_GetDict(m);
1147 #define SET_SYS_FROM_STRING(key, value) \
1148 v = value; \
1149 if (v != NULL) \
1150 PyDict_SetItemString(sysdict, key, v); \
1151 Py_XDECREF(v)
1149 1152
1150 { 1153 {
1151 /* XXX: does this work on Win/Win64? (see posix_fstat) */ 1154 /* XXX: does this work on Win/Win64? (see posix_fstat) */
1152 struct stat sb; 1155 struct stat sb;
1153 if (fstat(fileno(stdin), &sb) == 0 && 1156 if (fstat(fileno(stdin), &sb) == 0 &&
1163 1166
1164 PyDict_SetItemString(sysdict, "__displayhook__", 1167 PyDict_SetItemString(sysdict, "__displayhook__",
1165 PyDict_GetItemString(sysdict, "displayhook")); 1168 PyDict_GetItemString(sysdict, "displayhook"));
1166 PyDict_SetItemString(sysdict, "__excepthook__", 1169 PyDict_SetItemString(sysdict, "__excepthook__",
1167 PyDict_GetItemString(sysdict, "excepthook")); 1170 PyDict_GetItemString(sysdict, "excepthook"));
1168 PyDict_SetItemString(sysdict, "version", 1171 SET_SYS_FROM_STRING("version",
1169 v = PyUnicode_FromString(Py_GetVersion())); 1172 PyUnicode_FromString(Py_GetVersion()));
1170 Py_XDECREF(v); 1173 SET_SYS_FROM_STRING("hexversion",
1171 PyDict_SetItemString(sysdict, "hexversion", 1174 PyLong_FromLong(PY_VERSION_HEX));
1172 v = PyLong_FromLong(PY_VERSION_HEX));
1173 Py_XDECREF(v);
1174 svnversion_init(); 1175 svnversion_init();
1175 v = Py_BuildValue("(UUU)", "CPython", branch, svn_revision); 1176 SET_SYS_FROM_STRING("subversion",
1176 PyDict_SetItemString(sysdict, "subversion", v); 1177 Py_BuildValue("(UUU)", "CPython", branch,
1177 Py_XDECREF(v); 1178 svn_revision));
1178 PyDict_SetItemString(sysdict, "dont_write_bytecode", 1179 SET_SYS_FROM_STRING("dont_write_bytecode",
1179 v = PyBool_FromLong(Py_DontWriteBytecodeFlag)); 1180 PyBool_FromLong(Py_DontWriteBytecodeFlag));
1180 Py_XDECREF(v);
1181 /* 1181 /*
1182 * These release level checks are mutually exclusive and cover 1182 * These release level checks are mutually exclusive and cover
1183 * the field, so don't get too fancy with the pre-processor! 1183 * the field, so don't get too fancy with the pre-processor!
1184 */ 1184 */
1185 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA 1185 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
1189 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA 1189 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
1190 s = "candidate"; 1190 s = "candidate";
1191 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL 1191 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
1192 s = "final"; 1192 s = "final";
1193 #endif 1193 #endif
1194
1195 #define SET_SYS_FROM_STRING(key, value) \
1196 v = value; \
1197 if (v != NULL) \
1198 PyDict_SetItemString(sysdict, key, v); \
1199 Py_XDECREF(v)
1200 1194
1201 SET_SYS_FROM_STRING("version_info", 1195 SET_SYS_FROM_STRING("version_info",
1202 Py_BuildValue("iiiUi", PY_MAJOR_VERSION, 1196 Py_BuildValue("iiiUi", PY_MAJOR_VERSION,
1203 PY_MINOR_VERSION, 1197 PY_MINOR_VERSION,
1204 PY_MICRO_VERSION, s, 1198 PY_MICRO_VERSION, s,
1242 SET_SYS_FROM_STRING("dllhandle", 1236 SET_SYS_FROM_STRING("dllhandle",
1243 PyLong_FromVoidPtr(PyWin_DLLhModule)); 1237 PyLong_FromVoidPtr(PyWin_DLLhModule));
1244 SET_SYS_FROM_STRING("winver", 1238 SET_SYS_FROM_STRING("winver",
1245 PyUnicode_FromString(PyWin_DLLVersionString)); 1239 PyUnicode_FromString(PyWin_DLLVersionString));
1246 #endif 1240 #endif
1247 #undef SET_SYS_FROM_STRING
1248 if (warnoptions == NULL) { 1241 if (warnoptions == NULL) {
1249 warnoptions = PyList_New(0); 1242 warnoptions = PyList_New(0);
1250 } 1243 }
1251 else { 1244 else {
1252 Py_INCREF(warnoptions); 1245 Py_INCREF(warnoptions);
1253 } 1246 }
1254 if (warnoptions != NULL) { 1247 if (warnoptions != NULL) {
1255 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); 1248 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
1256 } 1249 }
1257 1250
1258 PyStructSequence_InitType(&FlagsType, &flags_desc); 1251 if (FlagsType.tp_name == 0)
1259 PyDict_SetItemString(sysdict, "flags", make_flags()); 1252 PyStructSequence_InitType(&FlagsType, &flags_desc);
1253 SET_SYS_FROM_STRING("flags", make_flags());
1260 /* prevent user from creating new instances */ 1254 /* prevent user from creating new instances */
1261 FlagsType.tp_init = NULL; 1255 FlagsType.tp_init = NULL;
1262 FlagsType.tp_new = NULL; 1256 FlagsType.tp_new = NULL;
1263 1257
1258 #undef SET_SYS_FROM_STRING
1264 if (PyErr_Occurred()) 1259 if (PyErr_Occurred())
1265 return NULL; 1260 return NULL;
1266 return m; 1261 return m;
1267 } 1262 }
1268 1263