comparison Python/sysmodule.c @ 40012:ab13576374b1 2.4

[Backport r50743 | neal.norwitz] Handle allocation failures gracefully. Found with failmalloc. Many (all?) of these could be backported.
author Andrew M. Kuchling <amk@amk.ca>
date Thu, 05 Oct 2006 18:08:58 +0000
parents 6fb46e87d5f9
children 6860ba88d67e
comparison
equal deleted inserted replaced
40011:a9fee1f62f17 40012:ab13576374b1
1015 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA 1015 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
1016 s = "candidate"; 1016 s = "candidate";
1017 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL 1017 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
1018 s = "final"; 1018 s = "final";
1019 #endif 1019 #endif
1020 PyDict_SetItemString(sysdict, "version_info", 1020
1021 v = Py_BuildValue("iiisi", PY_MAJOR_VERSION, 1021 #define SET_SYS_FROM_STRING(key, value) \
1022 v = value; \
1023 if (v != NULL) \
1024 PyDict_SetItemString(sysdict, key, v); \
1025 Py_XDECREF(v)
1026
1027 SET_SYS_FROM_STRING("version_info",
1028 Py_BuildValue("iiisi", PY_MAJOR_VERSION,
1022 PY_MINOR_VERSION, 1029 PY_MINOR_VERSION,
1023 PY_MICRO_VERSION, s, 1030 PY_MICRO_VERSION, s,
1024 PY_RELEASE_SERIAL)); 1031 PY_RELEASE_SERIAL));
1025 Py_XDECREF(v); 1032 SET_SYS_FROM_STRING("api_version",
1026 PyDict_SetItemString(sysdict, "api_version", 1033 PyInt_FromLong(PYTHON_API_VERSION));
1027 v = PyInt_FromLong(PYTHON_API_VERSION)); 1034 SET_SYS_FROM_STRING("copyright",
1028 Py_XDECREF(v); 1035 PyString_FromString(Py_GetCopyright()));
1029 PyDict_SetItemString(sysdict, "copyright", 1036 SET_SYS_FROM_STRING("platform",
1030 v = PyString_FromString(Py_GetCopyright())); 1037 PyString_FromString(Py_GetPlatform()));
1031 Py_XDECREF(v); 1038 SET_SYS_FROM_STRING("executable",
1032 PyDict_SetItemString(sysdict, "platform", 1039 PyString_FromString(Py_GetProgramFullPath()));
1033 v = PyString_FromString(Py_GetPlatform())); 1040 SET_SYS_FROM_STRING("prefix",
1034 Py_XDECREF(v); 1041 PyString_FromString(Py_GetPrefix()));
1035 PyDict_SetItemString(sysdict, "executable", 1042 SET_SYS_FROM_STRING("exec_prefix",
1036 v = PyString_FromString(Py_GetProgramFullPath())); 1043 PyString_FromString(Py_GetExecPrefix()));
1037 Py_XDECREF(v); 1044 SET_SYS_FROM_STRING("maxint",
1038 PyDict_SetItemString(sysdict, "prefix", 1045 PyInt_FromLong(PyInt_GetMax()));
1039 v = PyString_FromString(Py_GetPrefix()));
1040 Py_XDECREF(v);
1041 PyDict_SetItemString(sysdict, "exec_prefix",
1042 v = PyString_FromString(Py_GetExecPrefix()));
1043 Py_XDECREF(v);
1044 PyDict_SetItemString(sysdict, "maxint",
1045 v = PyInt_FromLong(PyInt_GetMax()));
1046 Py_XDECREF(v);
1047 #ifdef Py_USING_UNICODE 1046 #ifdef Py_USING_UNICODE
1048 PyDict_SetItemString(sysdict, "maxunicode", 1047 SET_SYS_FROM_STRING("maxunicode",
1049 v = PyInt_FromLong(PyUnicode_GetMax())); 1048 PyInt_FromLong(PyUnicode_GetMax()));
1050 Py_XDECREF(v); 1049 #endif
1051 #endif 1050 SET_SYS_FROM_STRING("builtin_module_names",
1052 PyDict_SetItemString(sysdict, "builtin_module_names", 1051 list_builtin_module_names());
1053 v = list_builtin_module_names());
1054 Py_XDECREF(v);
1055 { 1052 {
1056 /* Assumes that longs are at least 2 bytes long. 1053 /* Assumes that longs are at least 2 bytes long.
1057 Should be safe! */ 1054 Should be safe! */
1058 unsigned long number = 1; 1055 unsigned long number = 1;
1059 char *value; 1056 char *value;
1061 s = (char *) &number; 1058 s = (char *) &number;
1062 if (s[0] == 0) 1059 if (s[0] == 0)
1063 value = "big"; 1060 value = "big";
1064 else 1061 else
1065 value = "little"; 1062 value = "little";
1066 PyDict_SetItemString(sysdict, "byteorder", 1063 SET_SYS_FROM_STRING("byteorder",
1067 v = PyString_FromString(value)); 1064 PyString_FromString(value));
1068 Py_XDECREF(v);
1069 } 1065 }
1070 #ifdef MS_COREDLL 1066 #ifdef MS_COREDLL
1071 PyDict_SetItemString(sysdict, "dllhandle", 1067 SET_SYS_FROM_STRING("dllhandle",
1072 v = PyLong_FromVoidPtr(PyWin_DLLhModule)); 1068 PyLong_FromVoidPtr(PyWin_DLLhModule));
1073 Py_XDECREF(v); 1069 SET_SYS_FROM_STRING("winver",
1074 PyDict_SetItemString(sysdict, "winver", 1070 PyString_FromString(PyWin_DLLVersionString));
1075 v = PyString_FromString(PyWin_DLLVersionString)); 1071 #endif
1076 Py_XDECREF(v); 1072 #undef SET_SYS_FROM_STRING
1077 #endif
1078 if (warnoptions == NULL) { 1073 if (warnoptions == NULL) {
1079 warnoptions = PyList_New(0); 1074 warnoptions = PyList_New(0);
1080 } 1075 }
1081 else { 1076 else {
1082 Py_INCREF(warnoptions); 1077 Py_INCREF(warnoptions);