Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(25394)

Delta Between Two Patch Sets: Python/sysmodule.c

Issue 13390: Hunt memory allocations in addition to reference leaks
Left Patch Set: Created 7 years, 10 months ago
Right Patch Set: Created 6 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Python/pythonrun.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 1
2 /* System module */ 2 /* System module */
3 3
4 /* 4 /*
5 Various bits of information used by the interpreter are collected in 5 Various bits of information used by the interpreter are collected in
6 module 'sys'. 6 module 'sys'.
7 Function member: 7 Function member:
8 - exit(sts): raise SystemExit 8 - exit(sts): raise SystemExit
9 Data members: 9 Data members:
10 - stdin, stdout, stderr: standard file objects 10 - stdin, stdout, stderr: standard file objects
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 mallopt(M_DEBUG, flag); 807 mallopt(M_DEBUG, flag);
808 Py_INCREF(Py_None); 808 Py_INCREF(Py_None);
809 return Py_None; 809 return Py_None;
810 } 810 }
811 #endif /* USE_MALLOPT */ 811 #endif /* USE_MALLOPT */
812 812
813 static PyObject * 813 static PyObject *
814 sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds) 814 sys_getsizeof(PyObject *self, PyObject *args, PyObject *kwds)
815 { 815 {
816 PyObject *res = NULL; 816 PyObject *res = NULL;
817 static PyObject *str__sizeof__ = NULL, *gc_head_size = NULL; 817 static PyObject *gc_head_size = NULL;
818 static char *kwlist[] = {"object", "default", 0}; 818 static char *kwlist[] = {"object", "default", 0};
819 PyObject *o, *dflt = NULL; 819 PyObject *o, *dflt = NULL;
820 PyObject *method; 820 PyObject *method;
821 _Py_IDENTIFIER(__sizeof__);
821 822
822 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof", 823 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:getsizeof",
823 kwlist, &o, &dflt)) 824 kwlist, &o, &dflt))
824 return NULL; 825 return NULL;
825 826
826 /* Initialize static variable for GC head size */ 827 /* Initialize static variable for GC head size */
827 if (gc_head_size == NULL) { 828 if (gc_head_size == NULL) {
828 gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head)); 829 gc_head_size = PyLong_FromSsize_t(sizeof(PyGC_Head));
829 if (gc_head_size == NULL) 830 if (gc_head_size == NULL)
830 return NULL; 831 return NULL;
831 } 832 }
832 833
833 /* Make sure the type is initialized. float gets initialized late */ 834 /* Make sure the type is initialized. float gets initialized late */
834 if (PyType_Ready(Py_TYPE(o)) < 0) 835 if (PyType_Ready(Py_TYPE(o)) < 0)
835 return NULL; 836 return NULL;
836 837
837 method = _PyObject_LookupSpecial(o, "__sizeof__", 838 method = _PyObject_LookupSpecial(o, &PyId___sizeof__);
838 &str__sizeof__);
839 if (method == NULL) { 839 if (method == NULL) {
840 if (!PyErr_Occurred()) 840 if (!PyErr_Occurred())
841 PyErr_Format(PyExc_TypeError, 841 PyErr_Format(PyExc_TypeError,
842 "Type %.100s doesn't define __sizeof__", 842 "Type %.100s doesn't define __sizeof__",
843 Py_TYPE(o)->tp_name); 843 Py_TYPE(o)->tp_name);
844 } 844 }
845 else { 845 else {
846 res = PyObject_CallFunctionObjArgs(method, NULL); 846 res = PyObject_CallFunctionObjArgs(method, NULL);
847 Py_DECREF(method); 847 Py_DECREF(method);
848 } 848 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 888
889 PyDoc_STRVAR(getrefcount_doc, 889 PyDoc_STRVAR(getrefcount_doc,
890 "getrefcount(object) -> integer\n\ 890 "getrefcount(object) -> integer\n\
891 \n\ 891 \n\
892 Return the reference count of object. The count returned is generally\n\ 892 Return the reference count of object. The count returned is generally\n\
893 one higher than you might expect, because it includes the (temporary)\n\ 893 one higher than you might expect, because it includes the (temporary)\n\
894 reference as an argument to getrefcount()." 894 reference as an argument to getrefcount()."
895 ); 895 );
896 896
897 static PyObject * 897 static PyObject *
898 sys_getallocedblocks(PyObject *self) 898 sys_getallocatedblocks(PyObject *self)
899 { 899 {
900 return PyLong_FromSsize_t(_Py_AllocedBlocks); 900 return PyLong_FromSsize_t(_Py_GetAllocedBlocks());
901 } 901 }
902
903 PyDoc_STRVAR(getallocatedblocks_doc,
904 "getallocatedblocks() -> integer\n\
905 \n\
906 Return the number of memory blocks currently allocated, regardless of their\n\
907 size."
908 );
902 909
903 #ifdef COUNT_ALLOCS 910 #ifdef COUNT_ALLOCS
904 static PyObject * 911 static PyObject *
905 sys_getcounts(PyObject *self) 912 sys_getcounts(PyObject *self)
906 { 913 {
907 extern PyObject *get_counts(void); 914 extern PyObject *get_counts(void);
908 915
909 return get_counts(); 916 return get_counts();
910 } 917 }
911 #endif 918 #endif
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 6. PyType calls\n\ 1002 6. PyType calls\n\
996 7. PyCFunction calls\n\ 1003 7. PyCFunction calls\n\
997 8. generator calls\n\ 1004 8. generator calls\n\
998 9. All other calls\n\ 1005 9. All other calls\n\
999 10. Number of stack pops performed by call_function()" 1006 10. Number of stack pops performed by call_function()"
1000 ); 1007 );
1001 1008
1002 #ifdef __cplusplus 1009 #ifdef __cplusplus
1003 extern "C" { 1010 extern "C" {
1004 #endif 1011 #endif
1012
1013 static PyObject *
1014 sys_debugmallocstats(PyObject *self, PyObject *args)
1015 {
1016 #ifdef WITH_PYMALLOC
1017 _PyObject_DebugMallocStats(stderr);
1018 fputc('\n', stderr);
1019 #endif
1020 _PyObject_DebugTypeStats(stderr);
1021
1022 Py_RETURN_NONE;
1023 }
1024 PyDoc_STRVAR(debugmallocstats_doc,
1025 "_debugmallocstats()\n\
1026 \n\
1027 Print summary info to stderr about the state of\n\
1028 pymalloc's structures.\n\
1029 \n\
1030 In Py_DEBUG mode, also perform some expensive internal consistency\n\
1031 checks.\n\
1032 ");
1005 1033
1006 #ifdef Py_TRACE_REFS 1034 #ifdef Py_TRACE_REFS
1007 /* Defined in objects.c because it uses static globals if that file */ 1035 /* Defined in objects.c because it uses static globals if that file */
1008 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); 1036 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
1009 #endif 1037 #endif
1010 1038
1011 #ifdef DYNAMIC_EXECUTION_PROFILE 1039 #ifdef DYNAMIC_EXECUTION_PROFILE
1012 /* Defined in ceval.c because it uses static globals if that file */ 1040 /* Defined in ceval.c because it uses static globals if that file */
1013 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); 1041 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
1014 #endif 1042 #endif
(...skipping 25 matching lines...) Expand all
1040 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 1068 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
1041 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 1069 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
1042 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, 1070 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
1043 {"exit", sys_exit, METH_VARARGS, exit_doc}, 1071 {"exit", sys_exit, METH_VARARGS, exit_doc},
1044 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, 1072 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
1045 METH_NOARGS, getdefaultencoding_doc}, 1073 METH_NOARGS, getdefaultencoding_doc},
1046 #ifdef HAVE_DLOPEN 1074 #ifdef HAVE_DLOPEN
1047 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, 1075 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
1048 getdlopenflags_doc}, 1076 getdlopenflags_doc},
1049 #endif 1077 #endif
1078 {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS,
1079 getallocatedblocks_doc},
1050 #ifdef COUNT_ALLOCS 1080 #ifdef COUNT_ALLOCS
1051 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, 1081 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
1052 #endif 1082 #endif
1053 #ifdef DYNAMIC_EXECUTION_PROFILE 1083 #ifdef DYNAMIC_EXECUTION_PROFILE
1054 {"getdxp", _Py_GetDXProfile, METH_VARARGS}, 1084 {"getdxp", _Py_GetDXProfile, METH_VARARGS},
1055 #endif 1085 #endif
1056 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, 1086 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
1057 METH_NOARGS, getfilesystemencoding_doc}, 1087 METH_NOARGS, getfilesystemencoding_doc},
1058 #ifdef Py_TRACE_REFS 1088 #ifdef Py_TRACE_REFS
1059 {"getobjects", _Py_GetObjects, METH_VARARGS}, 1089 {"getobjects", _Py_GetObjects, METH_VARARGS},
1060 #endif 1090 #endif
1061 #ifdef Py_REF_DEBUG 1091 #ifdef Py_REF_DEBUG
1062 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS}, 1092 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
1063 #endif 1093 #endif
1064 {"getallocedblocks", (PyCFunction)sys_getallocedblocks, METH_NOARGS},
1065 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc}, 1094 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
1066 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS, 1095 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
1067 getrecursionlimit_doc}, 1096 getrecursionlimit_doc},
1068 {"getsizeof", (PyCFunction)sys_getsizeof, 1097 {"getsizeof", (PyCFunction)sys_getsizeof,
1069 METH_VARARGS | METH_KEYWORDS, getsizeof_doc}, 1098 METH_VARARGS | METH_KEYWORDS, getsizeof_doc},
1070 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc}, 1099 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
1071 #ifdef MS_WINDOWS 1100 #ifdef MS_WINDOWS
1072 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS, 1101 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
1073 getwindowsversion_doc}, 1102 getwindowsversion_doc},
1074 #endif /* MS_WINDOWS */ 1103 #endif /* MS_WINDOWS */
(...skipping 18 matching lines...) Expand all
1093 {"setprofile", sys_setprofile, METH_O, setprofile_doc}, 1122 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
1094 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc}, 1123 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc},
1095 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, 1124 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
1096 setrecursionlimit_doc}, 1125 setrecursionlimit_doc},
1097 #ifdef WITH_TSC 1126 #ifdef WITH_TSC
1098 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc}, 1127 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
1099 #endif 1128 #endif
1100 {"settrace", sys_settrace, METH_O, settrace_doc}, 1129 {"settrace", sys_settrace, METH_O, settrace_doc},
1101 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc}, 1130 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
1102 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc}, 1131 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
1132 {"_debugmallocstats", sys_debugmallocstats, METH_VARARGS,
1133 debugmallocstats_doc},
1103 {NULL, NULL} /* sentinel */ 1134 {NULL, NULL} /* sentinel */
1104 }; 1135 };
1105 1136
1106 static PyObject * 1137 static PyObject *
1107 list_builtin_module_names(void) 1138 list_builtin_module_names(void)
1108 { 1139 {
1109 PyObject *list = PyList_New(0); 1140 PyObject *list = PyList_New(0);
1110 int i; 1141 int i;
1111 if (list == NULL) 1142 if (list == NULL)
1112 return NULL; 1143 return NULL;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 " 1288 "
1258 ) 1289 )
1259 /* concatenating string here */ 1290 /* concatenating string here */
1260 PyDoc_STR( 1291 PyDoc_STR(
1261 "\n\ 1292 "\n\
1262 Static objects:\n\ 1293 Static objects:\n\
1263 \n\ 1294 \n\
1264 builtin_module_names -- tuple of module names built into this interpreter\n\ 1295 builtin_module_names -- tuple of module names built into this interpreter\n\
1265 copyright -- copyright notice pertaining to this interpreter\n\ 1296 copyright -- copyright notice pertaining to this interpreter\n\
1266 exec_prefix -- prefix used to find the machine-specific Python library\n\ 1297 exec_prefix -- prefix used to find the machine-specific Python library\n\
1267 executable -- pathname of this Python interpreter\n\ 1298 executable -- absolute path of the executable binary of the Python interpreter\n \
1268 float_info -- a struct sequence with information about the float implementation. \n\ 1299 float_info -- a struct sequence with information about the float implementation. \n\
1269 float_repr_style -- string indicating the style of repr() output for floats\n\ 1300 float_repr_style -- string indicating the style of repr() output for floats\n\
1270 hexversion -- version information encoded as a single integer\n\ 1301 hexversion -- version information encoded as a single integer\n\
1302 implementation -- Python implementation information.\n\
1271 int_info -- a struct sequence with information about the int implementation.\n\ 1303 int_info -- a struct sequence with information about the int implementation.\n\
1272 maxsize -- the largest supported length of containers.\n\ 1304 maxsize -- the largest supported length of containers.\n\
1273 maxunicode -- the value of the largest Unicode codepoint\n\ 1305 maxunicode -- the value of the largest Unicode codepoint\n\
1274 platform -- platform identifier\n\ 1306 platform -- platform identifier\n\
1275 prefix -- prefix used to find the Python library\n\ 1307 prefix -- prefix used to find the Python library\n\
1276 thread_info -- a struct sequence with information about the thread implementatio n.\n\ 1308 thread_info -- a struct sequence with information about the thread implementatio n.\n\
1277 version -- the version of this interpreter as a string\n\ 1309 version -- the version of this interpreter as a string\n\
1278 version_info -- version information as a named tuple\n\ 1310 version_info -- version information as a named tuple\n\
1279 " 1311 "
1280 ) 1312 )
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 static PyStructSequence_Field flags_fields[] = { 1357 static PyStructSequence_Field flags_fields[] = {
1326 {"debug", "-d"}, 1358 {"debug", "-d"},
1327 {"inspect", "-i"}, 1359 {"inspect", "-i"},
1328 {"interactive", "-i"}, 1360 {"interactive", "-i"},
1329 {"optimize", "-O or -OO"}, 1361 {"optimize", "-O or -OO"},
1330 {"dont_write_bytecode", "-B"}, 1362 {"dont_write_bytecode", "-B"},
1331 {"no_user_site", "-s"}, 1363 {"no_user_site", "-s"},
1332 {"no_site", "-S"}, 1364 {"no_site", "-S"},
1333 {"ignore_environment", "-E"}, 1365 {"ignore_environment", "-E"},
1334 {"verbose", "-v"}, 1366 {"verbose", "-v"},
1335 #ifdef RISCOS
1336 {"riscos_wimp", "???"},
1337 #endif
1338 /* {"unbuffered", "-u"}, */ 1367 /* {"unbuffered", "-u"}, */
1339 /* {"skip_first", "-x"}, */ 1368 /* {"skip_first", "-x"}, */
1340 {"bytes_warning", "-b"}, 1369 {"bytes_warning", "-b"},
1341 {"quiet", "-q"}, 1370 {"quiet", "-q"},
1371 {"hash_randomization", "-R"},
1342 {0} 1372 {0}
1343 }; 1373 };
1344 1374
1345 static PyStructSequence_Desc flags_desc = { 1375 static PyStructSequence_Desc flags_desc = {
1346 "sys.flags", /* name */ 1376 "sys.flags", /* name */
1347 flags__doc__, /* doc */ 1377 flags__doc__, /* doc */
1348 flags_fields, /* fields */ 1378 flags_fields, /* fields */
1349 #ifdef RISCOS
1350 12 1379 12
1351 #else
1352 11
1353 #endif
1354 }; 1380 };
1355 1381
1356 static PyObject* 1382 static PyObject*
1357 make_flags(void) 1383 make_flags(void)
1358 { 1384 {
1359 int pos = 0; 1385 int pos = 0;
1360 PyObject *seq; 1386 PyObject *seq;
1361 1387
1362 seq = PyStructSequence_New(&FlagsType); 1388 seq = PyStructSequence_New(&FlagsType);
1363 if (seq == NULL) 1389 if (seq == NULL)
1364 return NULL; 1390 return NULL;
1365 1391
1366 #define SetFlag(flag) \ 1392 #define SetFlag(flag) \
1367 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag)) 1393 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
1368 1394
1369 SetFlag(Py_DebugFlag); 1395 SetFlag(Py_DebugFlag);
1370 SetFlag(Py_InspectFlag); 1396 SetFlag(Py_InspectFlag);
1371 SetFlag(Py_InteractiveFlag); 1397 SetFlag(Py_InteractiveFlag);
1372 SetFlag(Py_OptimizeFlag); 1398 SetFlag(Py_OptimizeFlag);
1373 SetFlag(Py_DontWriteBytecodeFlag); 1399 SetFlag(Py_DontWriteBytecodeFlag);
1374 SetFlag(Py_NoUserSiteDirectory); 1400 SetFlag(Py_NoUserSiteDirectory);
1375 SetFlag(Py_NoSiteFlag); 1401 SetFlag(Py_NoSiteFlag);
1376 SetFlag(Py_IgnoreEnvironmentFlag); 1402 SetFlag(Py_IgnoreEnvironmentFlag);
1377 SetFlag(Py_VerboseFlag); 1403 SetFlag(Py_VerboseFlag);
1378 #ifdef RISCOS
1379 SetFlag(Py_RISCOSWimpFlag);
1380 #endif
1381 /* SetFlag(saw_unbuffered_flag); */ 1404 /* SetFlag(saw_unbuffered_flag); */
1382 /* SetFlag(skipfirstline); */ 1405 /* SetFlag(skipfirstline); */
1383 SetFlag(Py_BytesWarningFlag); 1406 SetFlag(Py_BytesWarningFlag);
1384 SetFlag(Py_QuietFlag); 1407 SetFlag(Py_QuietFlag);
1408 SetFlag(Py_HashRandomizationFlag);
1385 #undef SetFlag 1409 #undef SetFlag
1386 1410
1387 if (PyErr_Occurred()) { 1411 if (PyErr_Occurred()) {
1388 return NULL; 1412 return NULL;
1389 } 1413 }
1390 return seq; 1414 return seq;
1391 } 1415 }
1392 1416
1393 PyDoc_STRVAR(version_info__doc__, 1417 PyDoc_STRVAR(version_info__doc__,
1394 "sys.version_info\n\ 1418 "sys.version_info\n\
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 #undef SetIntItem 1476 #undef SetIntItem
1453 #undef SetStrItem 1477 #undef SetStrItem
1454 1478
1455 if (PyErr_Occurred()) { 1479 if (PyErr_Occurred()) {
1456 Py_CLEAR(version_info); 1480 Py_CLEAR(version_info);
1457 return NULL; 1481 return NULL;
1458 } 1482 }
1459 return version_info; 1483 return version_info;
1460 } 1484 }
1461 1485
1486 /* sys.implementation values */
1487 #define NAME "cpython"
1488 const char *_PySys_ImplName = NAME;
1489 #define QUOTE(arg) #arg
1490 #define STRIFY(name) QUOTE(name)
1491 #define MAJOR STRIFY(PY_MAJOR_VERSION)
1492 #define MINOR STRIFY(PY_MINOR_VERSION)
1493 #define TAG NAME "-" MAJOR MINOR;
1494 const char *_PySys_ImplCacheTag = TAG;
1495 #undef NAME
1496 #undef QUOTE
1497 #undef STRIFY
1498 #undef MAJOR
1499 #undef MINOR
1500 #undef TAG
1501
1502 static PyObject *
1503 make_impl_info(PyObject *version_info)
1504 {
1505 int res;
1506 PyObject *impl_info, *value, *ns;
1507
1508 impl_info = PyDict_New();
1509 if (impl_info == NULL)
1510 return NULL;
1511
1512 /* populate the dict */
1513
1514 value = PyUnicode_FromString(_PySys_ImplName);
1515 if (value == NULL)
1516 goto error;
1517 res = PyDict_SetItemString(impl_info, "name", value);
1518 Py_DECREF(value);
1519 if (res < 0)
1520 goto error;
1521
1522 value = PyUnicode_FromString(_PySys_ImplCacheTag);
1523 if (value == NULL)
1524 goto error;
1525 res = PyDict_SetItemString(impl_info, "cache_tag", value);
1526 Py_DECREF(value);
1527 if (res < 0)
1528 goto error;
1529
1530 res = PyDict_SetItemString(impl_info, "version", version_info);
1531 if (res < 0)
1532 goto error;
1533
1534 value = PyLong_FromLong(PY_VERSION_HEX);
1535 if (value == NULL)
1536 goto error;
1537 res = PyDict_SetItemString(impl_info, "hexversion", value);
1538 Py_DECREF(value);
1539 if (res < 0)
1540 goto error;
1541
1542 /* dict ready */
1543
1544 ns = _PyNamespace_New(impl_info);
1545 Py_DECREF(impl_info);
1546 return ns;
1547
1548 error:
1549 Py_CLEAR(impl_info);
1550 return NULL;
1551 }
1552
1462 static struct PyModuleDef sysmodule = { 1553 static struct PyModuleDef sysmodule = {
1463 PyModuleDef_HEAD_INIT, 1554 PyModuleDef_HEAD_INIT,
1464 "sys", 1555 "sys",
1465 sys_doc, 1556 sys_doc,
1466 -1, /* multiple "initialization" just copies the module dict. */ 1557 -1, /* multiple "initialization" just copies the module dict. */
1467 sys_methods, 1558 sys_methods,
1468 NULL, 1559 NULL,
1469 NULL, 1560 NULL,
1470 NULL, 1561 NULL,
1471 NULL 1562 NULL
1472 }; 1563 };
1473 1564
1474 PyObject * 1565 PyObject *
1475 _PySys_Init(void) 1566 _PySys_Init(void)
1476 { 1567 {
1477 PyObject *m, *v, *sysdict; 1568 PyObject *m, *v, *sysdict, *version_info;
1478 char *s;
1479 1569
1480 m = PyModule_Create(&sysmodule); 1570 m = PyModule_Create(&sysmodule);
1481 if (m == NULL) 1571 if (m == NULL)
1482 return NULL; 1572 return NULL;
1483 sysdict = PyModule_GetDict(m); 1573 sysdict = PyModule_GetDict(m);
1484 #define SET_SYS_FROM_STRING(key, value) \ 1574 #define SET_SYS_FROM_STRING(key, value) \
1485 v = value; \ 1575 v = value; \
1486 if (v != NULL) \ 1576 if (v != NULL) \
1487 PyDict_SetItemString(sysdict, key, v); \ 1577 PyDict_SetItemString(sysdict, key, v); \
1488 Py_XDECREF(v) 1578 Py_XDECREF(v)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 PyUnicode_FromString(Py_GetCopyright())); 1616 PyUnicode_FromString(Py_GetCopyright()));
1527 SET_SYS_FROM_STRING("platform", 1617 SET_SYS_FROM_STRING("platform",
1528 PyUnicode_FromString(Py_GetPlatform())); 1618 PyUnicode_FromString(Py_GetPlatform()));
1529 SET_SYS_FROM_STRING("executable", 1619 SET_SYS_FROM_STRING("executable",
1530 PyUnicode_FromWideChar( 1620 PyUnicode_FromWideChar(
1531 Py_GetProgramFullPath(), -1)); 1621 Py_GetProgramFullPath(), -1));
1532 SET_SYS_FROM_STRING("prefix", 1622 SET_SYS_FROM_STRING("prefix",
1533 PyUnicode_FromWideChar(Py_GetPrefix(), -1)); 1623 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
1534 SET_SYS_FROM_STRING("exec_prefix", 1624 SET_SYS_FROM_STRING("exec_prefix",
1535 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1)); 1625 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
1626 SET_SYS_FROM_STRING("base_prefix",
1627 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
1628 SET_SYS_FROM_STRING("base_exec_prefix",
1629 PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
1536 SET_SYS_FROM_STRING("maxsize", 1630 SET_SYS_FROM_STRING("maxsize",
1537 PyLong_FromSsize_t(PY_SSIZE_T_MAX)); 1631 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
1538 SET_SYS_FROM_STRING("float_info", 1632 SET_SYS_FROM_STRING("float_info",
1539 PyFloat_GetInfo()); 1633 PyFloat_GetInfo());
1540 SET_SYS_FROM_STRING("int_info", 1634 SET_SYS_FROM_STRING("int_info",
1541 PyLong_GetInfo()); 1635 PyLong_GetInfo());
1542 /* initialize hash_info */ 1636 /* initialize hash_info */
1543 if (Hash_InfoType.tp_name == 0) 1637 if (Hash_InfoType.tp_name == 0)
1544 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); 1638 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc);
1545 SET_SYS_FROM_STRING("hash_info", 1639 SET_SYS_FROM_STRING("hash_info",
1546 get_hash_info()); 1640 get_hash_info());
1547 SET_SYS_FROM_STRING("maxunicode", 1641 SET_SYS_FROM_STRING("maxunicode",
1548 PyLong_FromLong(0x10FFFF)); 1642 PyLong_FromLong(0x10FFFF));
1549 SET_SYS_FROM_STRING("builtin_module_names", 1643 SET_SYS_FROM_STRING("builtin_module_names",
1550 list_builtin_module_names()); 1644 list_builtin_module_names());
1551 { 1645 #if PY_BIG_ENDIAN
1552 /* Assumes that longs are at least 2 bytes long. 1646 SET_SYS_FROM_STRING("byteorder",
1553 Should be safe! */ 1647 PyUnicode_FromString("big"));
1554 unsigned long number = 1; 1648 #else
1555 char *value; 1649 SET_SYS_FROM_STRING("byteorder",
1556 1650 PyUnicode_FromString("little"));
1557 s = (char *) &number; 1651 #endif
1558 if (s[0] == 0) 1652
1559 value = "big";
1560 else
1561 value = "little";
1562 SET_SYS_FROM_STRING("byteorder",
1563 PyUnicode_FromString(value));
1564 }
1565 #ifdef MS_COREDLL 1653 #ifdef MS_COREDLL
1566 SET_SYS_FROM_STRING("dllhandle", 1654 SET_SYS_FROM_STRING("dllhandle",
1567 PyLong_FromVoidPtr(PyWin_DLLhModule)); 1655 PyLong_FromVoidPtr(PyWin_DLLhModule));
1568 SET_SYS_FROM_STRING("winver", 1656 SET_SYS_FROM_STRING("winver",
1569 PyUnicode_FromString(PyWin_DLLVersionString)); 1657 PyUnicode_FromString(PyWin_DLLVersionString));
1570 #endif 1658 #endif
1571 #ifdef ABIFLAGS 1659 #ifdef ABIFLAGS
1572 SET_SYS_FROM_STRING("abiflags", 1660 SET_SYS_FROM_STRING("abiflags",
1573 PyUnicode_FromString(ABIFLAGS)); 1661 PyUnicode_FromString(ABIFLAGS));
1574 #endif 1662 #endif
1575 if (warnoptions == NULL) { 1663 if (warnoptions == NULL) {
1576 warnoptions = PyList_New(0); 1664 warnoptions = PyList_New(0);
1577 } 1665 }
1578 else { 1666 else {
1579 Py_INCREF(warnoptions); 1667 Py_INCREF(warnoptions);
1580 } 1668 }
1581 if (warnoptions != NULL) { 1669 if (warnoptions != NULL) {
1582 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); 1670 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
1583 } 1671 }
1584 1672
1585 v = get_xoptions(); 1673 v = get_xoptions();
1586 if (v != NULL) { 1674 if (v != NULL) {
1587 PyDict_SetItemString(sysdict, "_xoptions", v); 1675 PyDict_SetItemString(sysdict, "_xoptions", v);
1588 } 1676 }
1589 1677
1590 /* version_info */ 1678 /* version_info */
1591 if (VersionInfoType.tp_name == 0) 1679 if (VersionInfoType.tp_name == 0)
1592 PyStructSequence_InitType(&VersionInfoType, &version_info_desc); 1680 PyStructSequence_InitType(&VersionInfoType, &version_info_desc);
1593 SET_SYS_FROM_STRING("version_info", make_version_info()); 1681 version_info = make_version_info();
1682 SET_SYS_FROM_STRING("version_info", version_info);
1594 /* prevent user from creating new instances */ 1683 /* prevent user from creating new instances */
1595 VersionInfoType.tp_init = NULL; 1684 VersionInfoType.tp_init = NULL;
1596 VersionInfoType.tp_new = NULL; 1685 VersionInfoType.tp_new = NULL;
1686
1687 /* implementation */
1688 SET_SYS_FROM_STRING("implementation", make_impl_info(version_info));
1597 1689
1598 /* flags */ 1690 /* flags */
1599 if (FlagsType.tp_name == 0) 1691 if (FlagsType.tp_name == 0)
1600 PyStructSequence_InitType(&FlagsType, &flags_desc); 1692 PyStructSequence_InitType(&FlagsType, &flags_desc);
1601 SET_SYS_FROM_STRING("flags", make_flags()); 1693 SET_SYS_FROM_STRING("flags", make_flags());
1602 /* prevent user from creating new instances */ 1694 /* prevent user from creating new instances */
1603 FlagsType.tp_init = NULL; 1695 FlagsType.tp_init = NULL;
1604 FlagsType.tp_new = NULL; 1696 FlagsType.tp_new = NULL;
1605 1697
1606 1698
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 2094
2003 void 2095 void
2004 PySys_FormatStderr(const char *format, ...) 2096 PySys_FormatStderr(const char *format, ...)
2005 { 2097 {
2006 va_list va; 2098 va_list va;
2007 2099
2008 va_start(va, format); 2100 va_start(va, format);
2009 sys_format("stderr", stderr, format, va); 2101 sys_format("stderr", stderr, format, va);
2010 va_end(va); 2102 va_end(va);
2011 } 2103 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+