Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 39129:f2031f15d99d legacy-trunk
Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Fri, 21 Jul 2006 05:32:28 +0000 |
| parents | b6fd499e4343 |
| children | 6ba402b60041 |
comparison
equal
deleted
inserted
replaced
| 39128:af4a3a0d47cc | 39129:f2031f15d99d |
|---|---|
| 1135 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA | 1135 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA |
| 1136 s = "candidate"; | 1136 s = "candidate"; |
| 1137 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL | 1137 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL |
| 1138 s = "final"; | 1138 s = "final"; |
| 1139 #endif | 1139 #endif |
| 1140 PyDict_SetItemString(sysdict, "version_info", | 1140 |
| 1141 v = Py_BuildValue("iiisi", PY_MAJOR_VERSION, | 1141 #define SET_SYS_FROM_STRING(key, value) \ |
| 1142 v = value; \ | |
| 1143 if (v != NULL) \ | |
| 1144 PyDict_SetItemString(sysdict, key, v); \ | |
| 1145 Py_XDECREF(v) | |
| 1146 | |
| 1147 SET_SYS_FROM_STRING("version_info", | |
| 1148 Py_BuildValue("iiisi", PY_MAJOR_VERSION, | |
| 1142 PY_MINOR_VERSION, | 1149 PY_MINOR_VERSION, |
| 1143 PY_MICRO_VERSION, s, | 1150 PY_MICRO_VERSION, s, |
| 1144 PY_RELEASE_SERIAL)); | 1151 PY_RELEASE_SERIAL)); |
| 1145 Py_XDECREF(v); | 1152 SET_SYS_FROM_STRING("api_version", |
| 1146 PyDict_SetItemString(sysdict, "api_version", | 1153 PyInt_FromLong(PYTHON_API_VERSION)); |
| 1147 v = PyInt_FromLong(PYTHON_API_VERSION)); | 1154 SET_SYS_FROM_STRING("copyright", |
| 1148 Py_XDECREF(v); | 1155 PyString_FromString(Py_GetCopyright())); |
| 1149 PyDict_SetItemString(sysdict, "copyright", | 1156 SET_SYS_FROM_STRING("platform", |
| 1150 v = PyString_FromString(Py_GetCopyright())); | 1157 PyString_FromString(Py_GetPlatform())); |
| 1151 Py_XDECREF(v); | 1158 SET_SYS_FROM_STRING("executable", |
| 1152 PyDict_SetItemString(sysdict, "platform", | 1159 PyString_FromString(Py_GetProgramFullPath())); |
| 1153 v = PyString_FromString(Py_GetPlatform())); | 1160 SET_SYS_FROM_STRING("prefix", |
| 1154 Py_XDECREF(v); | 1161 PyString_FromString(Py_GetPrefix())); |
| 1155 PyDict_SetItemString(sysdict, "executable", | 1162 SET_SYS_FROM_STRING("exec_prefix", |
| 1156 v = PyString_FromString(Py_GetProgramFullPath())); | 1163 PyString_FromString(Py_GetExecPrefix())); |
| 1157 Py_XDECREF(v); | 1164 SET_SYS_FROM_STRING("maxint", |
| 1158 PyDict_SetItemString(sysdict, "prefix", | 1165 PyInt_FromLong(PyInt_GetMax())); |
| 1159 v = PyString_FromString(Py_GetPrefix())); | |
| 1160 Py_XDECREF(v); | |
| 1161 PyDict_SetItemString(sysdict, "exec_prefix", | |
| 1162 v = PyString_FromString(Py_GetExecPrefix())); | |
| 1163 Py_XDECREF(v); | |
| 1164 PyDict_SetItemString(sysdict, "maxint", | |
| 1165 v = PyInt_FromLong(PyInt_GetMax())); | |
| 1166 Py_XDECREF(v); | |
| 1167 #ifdef Py_USING_UNICODE | 1166 #ifdef Py_USING_UNICODE |
| 1168 PyDict_SetItemString(sysdict, "maxunicode", | 1167 SET_SYS_FROM_STRING("maxunicode", |
| 1169 v = PyInt_FromLong(PyUnicode_GetMax())); | 1168 PyInt_FromLong(PyUnicode_GetMax())); |
| 1170 Py_XDECREF(v); | 1169 #endif |
| 1171 #endif | 1170 SET_SYS_FROM_STRING("builtin_module_names", |
| 1172 PyDict_SetItemString(sysdict, "builtin_module_names", | 1171 list_builtin_module_names()); |
| 1173 v = list_builtin_module_names()); | |
| 1174 Py_XDECREF(v); | |
| 1175 { | 1172 { |
| 1176 /* Assumes that longs are at least 2 bytes long. | 1173 /* Assumes that longs are at least 2 bytes long. |
| 1177 Should be safe! */ | 1174 Should be safe! */ |
| 1178 unsigned long number = 1; | 1175 unsigned long number = 1; |
| 1179 char *value; | 1176 char *value; |
| 1181 s = (char *) &number; | 1178 s = (char *) &number; |
| 1182 if (s[0] == 0) | 1179 if (s[0] == 0) |
| 1183 value = "big"; | 1180 value = "big"; |
| 1184 else | 1181 else |
| 1185 value = "little"; | 1182 value = "little"; |
| 1186 PyDict_SetItemString(sysdict, "byteorder", | 1183 SET_SYS_FROM_STRING("byteorder", |
| 1187 v = PyString_FromString(value)); | 1184 PyString_FromString(value)); |
| 1188 Py_XDECREF(v); | |
| 1189 } | 1185 } |
| 1190 #ifdef MS_COREDLL | 1186 #ifdef MS_COREDLL |
| 1191 PyDict_SetItemString(sysdict, "dllhandle", | 1187 SET_SYS_FROM_STRING("dllhandle", |
| 1192 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); | 1188 PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 1193 Py_XDECREF(v); | 1189 SET_SYS_FROM_STRING("winver", |
| 1194 PyDict_SetItemString(sysdict, "winver", | 1190 PyString_FromString(PyWin_DLLVersionString)); |
| 1195 v = PyString_FromString(PyWin_DLLVersionString)); | 1191 #endif |
| 1196 Py_XDECREF(v); | 1192 #undef SET_SYS_FROM_STRING |
| 1197 #endif | |
| 1198 if (warnoptions == NULL) { | 1193 if (warnoptions == NULL) { |
| 1199 warnoptions = PyList_New(0); | 1194 warnoptions = PyList_New(0); |
| 1200 } | 1195 } |
| 1201 else { | 1196 else { |
| 1202 Py_INCREF(warnoptions); | 1197 Py_INCREF(warnoptions); |
