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

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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 #endif /* Py_REF_DEBUG */ 887 #endif /* Py_REF_DEBUG */
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 #ifdef Py_REF_DEBUG
898 static PyObject * 897 static PyObject *
899 sys_getallocatedblocks(PyObject *self) 898 sys_getallocatedblocks(PyObject *self)
900 { 899 {
901 return PyLong_FromSsize_t(_Py_GetAllocedBlocks()); 900 return PyLong_FromSsize_t(_Py_GetAllocedBlocks());
902 } 901 }
903 #endif /* Py_REF_DEBUG */ 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 );
904 909
905 #ifdef COUNT_ALLOCS 910 #ifdef COUNT_ALLOCS
906 static PyObject * 911 static PyObject *
907 sys_getcounts(PyObject *self) 912 sys_getcounts(PyObject *self)
908 { 913 {
909 extern PyObject *get_counts(void); 914 extern PyObject *get_counts(void);
910 915
911 return get_counts(); 916 return get_counts();
912 } 917 }
913 #endif 918 #endif
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 6. PyType calls\n\ 1002 6. PyType calls\n\
998 7. PyCFunction calls\n\ 1003 7. PyCFunction calls\n\
999 8. generator calls\n\ 1004 8. generator calls\n\
1000 9. All other calls\n\ 1005 9. All other calls\n\
1001 10. Number of stack pops performed by call_function()" 1006 10. Number of stack pops performed by call_function()"
1002 ); 1007 );
1003 1008
1004 #ifdef __cplusplus 1009 #ifdef __cplusplus
1005 extern "C" { 1010 extern "C" {
1006 #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 ");
1007 1033
1008 #ifdef Py_TRACE_REFS 1034 #ifdef Py_TRACE_REFS
1009 /* 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 */
1010 extern PyObject *_Py_GetObjects(PyObject *, PyObject *); 1036 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
1011 #endif 1037 #endif
1012 1038
1013 #ifdef DYNAMIC_EXECUTION_PROFILE 1039 #ifdef DYNAMIC_EXECUTION_PROFILE
1014 /* 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 */
1015 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *); 1041 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
1016 #endif 1042 #endif
(...skipping 25 matching lines...) Expand all
1042 {"displayhook", sys_displayhook, METH_O, displayhook_doc}, 1068 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
1043 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc}, 1069 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
1044 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc}, 1070 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
1045 {"exit", sys_exit, METH_VARARGS, exit_doc}, 1071 {"exit", sys_exit, METH_VARARGS, exit_doc},
1046 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding, 1072 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
1047 METH_NOARGS, getdefaultencoding_doc}, 1073 METH_NOARGS, getdefaultencoding_doc},
1048 #ifdef HAVE_DLOPEN 1074 #ifdef HAVE_DLOPEN
1049 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS, 1075 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
1050 getdlopenflags_doc}, 1076 getdlopenflags_doc},
1051 #endif 1077 #endif
1052 #ifdef Py_REF_DEBUG 1078 {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS,
1053 {"getallocatedblocks", (PyCFunction)sys_getallocatedblocks, METH_NOARGS}, 1079 getallocatedblocks_doc},
1054 #endif
1055 #ifdef COUNT_ALLOCS 1080 #ifdef COUNT_ALLOCS
1056 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS}, 1081 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
1057 #endif 1082 #endif
1058 #ifdef DYNAMIC_EXECUTION_PROFILE 1083 #ifdef DYNAMIC_EXECUTION_PROFILE
1059 {"getdxp", _Py_GetDXProfile, METH_VARARGS}, 1084 {"getdxp", _Py_GetDXProfile, METH_VARARGS},
1060 #endif 1085 #endif
1061 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding, 1086 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
1062 METH_NOARGS, getfilesystemencoding_doc}, 1087 METH_NOARGS, getfilesystemencoding_doc},
1063 #ifdef Py_TRACE_REFS 1088 #ifdef Py_TRACE_REFS
1064 {"getobjects", _Py_GetObjects, METH_VARARGS}, 1089 {"getobjects", _Py_GetObjects, METH_VARARGS},
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 {"setprofile", sys_setprofile, METH_O, setprofile_doc}, 1122 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
1098 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc}, 1123 {"getprofile", sys_getprofile, METH_NOARGS, getprofile_doc},
1099 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS, 1124 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
1100 setrecursionlimit_doc}, 1125 setrecursionlimit_doc},
1101 #ifdef WITH_TSC 1126 #ifdef WITH_TSC
1102 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc}, 1127 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
1103 #endif 1128 #endif
1104 {"settrace", sys_settrace, METH_O, settrace_doc}, 1129 {"settrace", sys_settrace, METH_O, settrace_doc},
1105 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc}, 1130 {"gettrace", sys_gettrace, METH_NOARGS, gettrace_doc},
1106 {"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},
1107 {NULL, NULL} /* sentinel */ 1134 {NULL, NULL} /* sentinel */
1108 }; 1135 };
1109 1136
1110 static PyObject * 1137 static PyObject *
1111 list_builtin_module_names(void) 1138 list_builtin_module_names(void)
1112 { 1139 {
1113 PyObject *list = PyList_New(0); 1140 PyObject *list = PyList_New(0);
1114 int i; 1141 int i;
1115 if (list == NULL) 1142 if (list == NULL)
1116 return NULL; 1143 return NULL;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 " 1288 "
1262 ) 1289 )
1263 /* concatenating string here */ 1290 /* concatenating string here */
1264 PyDoc_STR( 1291 PyDoc_STR(
1265 "\n\ 1292 "\n\
1266 Static objects:\n\ 1293 Static objects:\n\
1267 \n\ 1294 \n\
1268 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\
1269 copyright -- copyright notice pertaining to this interpreter\n\ 1296 copyright -- copyright notice pertaining to this interpreter\n\
1270 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\
1271 executable -- pathname of this Python interpreter\n\ 1298 executable -- absolute path of the executable binary of the Python interpreter\n \
1272 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\
1273 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\
1274 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\
1275 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\
1276 maxsize -- the largest supported length of containers.\n\ 1304 maxsize -- the largest supported length of containers.\n\
1277 maxunicode -- the value of the largest Unicode codepoint\n\ 1305 maxunicode -- the value of the largest Unicode codepoint\n\
1278 platform -- platform identifier\n\ 1306 platform -- platform identifier\n\
1279 prefix -- prefix used to find the Python library\n\ 1307 prefix -- prefix used to find the Python library\n\
1280 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\
1281 version -- the version of this interpreter as a string\n\ 1309 version -- the version of this interpreter as a string\n\
1282 version_info -- version information as a named tuple\n\ 1310 version_info -- version information as a named tuple\n\
1283 " 1311 "
1284 ) 1312 )
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 static PyStructSequence_Field flags_fields[] = { 1357 static PyStructSequence_Field flags_fields[] = {
1330 {"debug", "-d"}, 1358 {"debug", "-d"},
1331 {"inspect", "-i"}, 1359 {"inspect", "-i"},
1332 {"interactive", "-i"}, 1360 {"interactive", "-i"},
1333 {"optimize", "-O or -OO"}, 1361 {"optimize", "-O or -OO"},
1334 {"dont_write_bytecode", "-B"}, 1362 {"dont_write_bytecode", "-B"},
1335 {"no_user_site", "-s"}, 1363 {"no_user_site", "-s"},
1336 {"no_site", "-S"}, 1364 {"no_site", "-S"},
1337 {"ignore_environment", "-E"}, 1365 {"ignore_environment", "-E"},
1338 {"verbose", "-v"}, 1366 {"verbose", "-v"},
1339 #ifdef RISCOS
1340 {"riscos_wimp", "???"},
1341 #endif
1342 /* {"unbuffered", "-u"}, */ 1367 /* {"unbuffered", "-u"}, */
1343 /* {"skip_first", "-x"}, */ 1368 /* {"skip_first", "-x"}, */
1344 {"bytes_warning", "-b"}, 1369 {"bytes_warning", "-b"},
1345 {"quiet", "-q"}, 1370 {"quiet", "-q"},
1371 {"hash_randomization", "-R"},
1346 {0} 1372 {0}
1347 }; 1373 };
1348 1374
1349 static PyStructSequence_Desc flags_desc = { 1375 static PyStructSequence_Desc flags_desc = {
1350 "sys.flags", /* name */ 1376 "sys.flags", /* name */
1351 flags__doc__, /* doc */ 1377 flags__doc__, /* doc */
1352 flags_fields, /* fields */ 1378 flags_fields, /* fields */
1353 #ifdef RISCOS
1354 12 1379 12
1355 #else
1356 11
1357 #endif
1358 }; 1380 };
1359 1381
1360 static PyObject* 1382 static PyObject*
1361 make_flags(void) 1383 make_flags(void)
1362 { 1384 {
1363 int pos = 0; 1385 int pos = 0;
1364 PyObject *seq; 1386 PyObject *seq;
1365 1387
1366 seq = PyStructSequence_New(&FlagsType); 1388 seq = PyStructSequence_New(&FlagsType);
1367 if (seq == NULL) 1389 if (seq == NULL)
1368 return NULL; 1390 return NULL;
1369 1391
1370 #define SetFlag(flag) \ 1392 #define SetFlag(flag) \
1371 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag)) 1393 PyStructSequence_SET_ITEM(seq, pos++, PyLong_FromLong(flag))
1372 1394
1373 SetFlag(Py_DebugFlag); 1395 SetFlag(Py_DebugFlag);
1374 SetFlag(Py_InspectFlag); 1396 SetFlag(Py_InspectFlag);
1375 SetFlag(Py_InteractiveFlag); 1397 SetFlag(Py_InteractiveFlag);
1376 SetFlag(Py_OptimizeFlag); 1398 SetFlag(Py_OptimizeFlag);
1377 SetFlag(Py_DontWriteBytecodeFlag); 1399 SetFlag(Py_DontWriteBytecodeFlag);
1378 SetFlag(Py_NoUserSiteDirectory); 1400 SetFlag(Py_NoUserSiteDirectory);
1379 SetFlag(Py_NoSiteFlag); 1401 SetFlag(Py_NoSiteFlag);
1380 SetFlag(Py_IgnoreEnvironmentFlag); 1402 SetFlag(Py_IgnoreEnvironmentFlag);
1381 SetFlag(Py_VerboseFlag); 1403 SetFlag(Py_VerboseFlag);
1382 #ifdef RISCOS
1383 SetFlag(Py_RISCOSWimpFlag);
1384 #endif
1385 /* SetFlag(saw_unbuffered_flag); */ 1404 /* SetFlag(saw_unbuffered_flag); */
1386 /* SetFlag(skipfirstline); */ 1405 /* SetFlag(skipfirstline); */
1387 SetFlag(Py_BytesWarningFlag); 1406 SetFlag(Py_BytesWarningFlag);
1388 SetFlag(Py_QuietFlag); 1407 SetFlag(Py_QuietFlag);
1408 SetFlag(Py_HashRandomizationFlag);
1389 #undef SetFlag 1409 #undef SetFlag
1390 1410
1391 if (PyErr_Occurred()) { 1411 if (PyErr_Occurred()) {
1392 return NULL; 1412 return NULL;
1393 } 1413 }
1394 return seq; 1414 return seq;
1395 } 1415 }
1396 1416
1397 PyDoc_STRVAR(version_info__doc__, 1417 PyDoc_STRVAR(version_info__doc__,
1398 "sys.version_info\n\ 1418 "sys.version_info\n\
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 #undef SetIntItem 1476 #undef SetIntItem
1457 #undef SetStrItem 1477 #undef SetStrItem
1458 1478
1459 if (PyErr_Occurred()) { 1479 if (PyErr_Occurred()) {
1460 Py_CLEAR(version_info); 1480 Py_CLEAR(version_info);
1461 return NULL; 1481 return NULL;
1462 } 1482 }
1463 return version_info; 1483 return version_info;
1464 } 1484 }
1465 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
1466 static struct PyModuleDef sysmodule = { 1553 static struct PyModuleDef sysmodule = {
1467 PyModuleDef_HEAD_INIT, 1554 PyModuleDef_HEAD_INIT,
1468 "sys", 1555 "sys",
1469 sys_doc, 1556 sys_doc,
1470 -1, /* multiple "initialization" just copies the module dict. */ 1557 -1, /* multiple "initialization" just copies the module dict. */
1471 sys_methods, 1558 sys_methods,
1472 NULL, 1559 NULL,
1473 NULL, 1560 NULL,
1474 NULL, 1561 NULL,
1475 NULL 1562 NULL
1476 }; 1563 };
1477 1564
1478 PyObject * 1565 PyObject *
1479 _PySys_Init(void) 1566 _PySys_Init(void)
1480 { 1567 {
1481 PyObject *m, *v, *sysdict; 1568 PyObject *m, *v, *sysdict, *version_info;
1482 char *s;
1483 1569
1484 m = PyModule_Create(&sysmodule); 1570 m = PyModule_Create(&sysmodule);
1485 if (m == NULL) 1571 if (m == NULL)
1486 return NULL; 1572 return NULL;
1487 sysdict = PyModule_GetDict(m); 1573 sysdict = PyModule_GetDict(m);
1488 #define SET_SYS_FROM_STRING(key, value) \ 1574 #define SET_SYS_FROM_STRING(key, value) \
1489 v = value; \ 1575 v = value; \
1490 if (v != NULL) \ 1576 if (v != NULL) \
1491 PyDict_SetItemString(sysdict, key, v); \ 1577 PyDict_SetItemString(sysdict, key, v); \
1492 Py_XDECREF(v) 1578 Py_XDECREF(v)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 PyUnicode_FromString(Py_GetCopyright())); 1616 PyUnicode_FromString(Py_GetCopyright()));
1531 SET_SYS_FROM_STRING("platform", 1617 SET_SYS_FROM_STRING("platform",
1532 PyUnicode_FromString(Py_GetPlatform())); 1618 PyUnicode_FromString(Py_GetPlatform()));
1533 SET_SYS_FROM_STRING("executable", 1619 SET_SYS_FROM_STRING("executable",
1534 PyUnicode_FromWideChar( 1620 PyUnicode_FromWideChar(
1535 Py_GetProgramFullPath(), -1)); 1621 Py_GetProgramFullPath(), -1));
1536 SET_SYS_FROM_STRING("prefix", 1622 SET_SYS_FROM_STRING("prefix",
1537 PyUnicode_FromWideChar(Py_GetPrefix(), -1)); 1623 PyUnicode_FromWideChar(Py_GetPrefix(), -1));
1538 SET_SYS_FROM_STRING("exec_prefix", 1624 SET_SYS_FROM_STRING("exec_prefix",
1539 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));
1540 SET_SYS_FROM_STRING("maxsize", 1630 SET_SYS_FROM_STRING("maxsize",
1541 PyLong_FromSsize_t(PY_SSIZE_T_MAX)); 1631 PyLong_FromSsize_t(PY_SSIZE_T_MAX));
1542 SET_SYS_FROM_STRING("float_info", 1632 SET_SYS_FROM_STRING("float_info",
1543 PyFloat_GetInfo()); 1633 PyFloat_GetInfo());
1544 SET_SYS_FROM_STRING("int_info", 1634 SET_SYS_FROM_STRING("int_info",
1545 PyLong_GetInfo()); 1635 PyLong_GetInfo());
1546 /* initialize hash_info */ 1636 /* initialize hash_info */
1547 if (Hash_InfoType.tp_name == 0) 1637 if (Hash_InfoType.tp_name == 0)
1548 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc); 1638 PyStructSequence_InitType(&Hash_InfoType, &hash_info_desc);
1549 SET_SYS_FROM_STRING("hash_info", 1639 SET_SYS_FROM_STRING("hash_info",
1550 get_hash_info()); 1640 get_hash_info());
1551 SET_SYS_FROM_STRING("maxunicode", 1641 SET_SYS_FROM_STRING("maxunicode",
1552 PyLong_FromLong(0x10FFFF)); 1642 PyLong_FromLong(0x10FFFF));
1553 SET_SYS_FROM_STRING("builtin_module_names", 1643 SET_SYS_FROM_STRING("builtin_module_names",
1554 list_builtin_module_names()); 1644 list_builtin_module_names());
1555 { 1645 #if PY_BIG_ENDIAN
1556 /* Assumes that longs are at least 2 bytes long. 1646 SET_SYS_FROM_STRING("byteorder",
1557 Should be safe! */ 1647 PyUnicode_FromString("big"));
1558 unsigned long number = 1; 1648 #else
1559 char *value; 1649 SET_SYS_FROM_STRING("byteorder",
1560 1650 PyUnicode_FromString("little"));
1561 s = (char *) &number; 1651 #endif
1562 if (s[0] == 0) 1652
1563 value = "big";
1564 else
1565 value = "little";
1566 SET_SYS_FROM_STRING("byteorder",
1567 PyUnicode_FromString(value));
1568 }
1569 #ifdef MS_COREDLL 1653 #ifdef MS_COREDLL
1570 SET_SYS_FROM_STRING("dllhandle", 1654 SET_SYS_FROM_STRING("dllhandle",
1571 PyLong_FromVoidPtr(PyWin_DLLhModule)); 1655 PyLong_FromVoidPtr(PyWin_DLLhModule));
1572 SET_SYS_FROM_STRING("winver", 1656 SET_SYS_FROM_STRING("winver",
1573 PyUnicode_FromString(PyWin_DLLVersionString)); 1657 PyUnicode_FromString(PyWin_DLLVersionString));
1574 #endif 1658 #endif
1575 #ifdef ABIFLAGS 1659 #ifdef ABIFLAGS
1576 SET_SYS_FROM_STRING("abiflags", 1660 SET_SYS_FROM_STRING("abiflags",
1577 PyUnicode_FromString(ABIFLAGS)); 1661 PyUnicode_FromString(ABIFLAGS));
1578 #endif 1662 #endif
1579 if (warnoptions == NULL) { 1663 if (warnoptions == NULL) {
1580 warnoptions = PyList_New(0); 1664 warnoptions = PyList_New(0);
1581 } 1665 }
1582 else { 1666 else {
1583 Py_INCREF(warnoptions); 1667 Py_INCREF(warnoptions);
1584 } 1668 }
1585 if (warnoptions != NULL) { 1669 if (warnoptions != NULL) {
1586 PyDict_SetItemString(sysdict, "warnoptions", warnoptions); 1670 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
1587 } 1671 }
1588 1672
1589 v = get_xoptions(); 1673 v = get_xoptions();
1590 if (v != NULL) { 1674 if (v != NULL) {
1591 PyDict_SetItemString(sysdict, "_xoptions", v); 1675 PyDict_SetItemString(sysdict, "_xoptions", v);
1592 } 1676 }
1593 1677
1594 /* version_info */ 1678 /* version_info */
1595 if (VersionInfoType.tp_name == 0) 1679 if (VersionInfoType.tp_name == 0)
1596 PyStructSequence_InitType(&VersionInfoType, &version_info_desc); 1680 PyStructSequence_InitType(&VersionInfoType, &version_info_desc);
1597 SET_SYS_FROM_STRING("version_info", make_version_info()); 1681 version_info = make_version_info();
1682 SET_SYS_FROM_STRING("version_info", version_info);
1598 /* prevent user from creating new instances */ 1683 /* prevent user from creating new instances */
1599 VersionInfoType.tp_init = NULL; 1684 VersionInfoType.tp_init = NULL;
1600 VersionInfoType.tp_new = NULL; 1685 VersionInfoType.tp_new = NULL;
1686
1687 /* implementation */
1688 SET_SYS_FROM_STRING("implementation", make_impl_info(version_info));
1601 1689
1602 /* flags */ 1690 /* flags */
1603 if (FlagsType.tp_name == 0) 1691 if (FlagsType.tp_name == 0)
1604 PyStructSequence_InitType(&FlagsType, &flags_desc); 1692 PyStructSequence_InitType(&FlagsType, &flags_desc);
1605 SET_SYS_FROM_STRING("flags", make_flags()); 1693 SET_SYS_FROM_STRING("flags", make_flags());
1606 /* prevent user from creating new instances */ 1694 /* prevent user from creating new instances */
1607 FlagsType.tp_init = NULL; 1695 FlagsType.tp_init = NULL;
1608 FlagsType.tp_new = NULL; 1696 FlagsType.tp_new = NULL;
1609 1697
1610 1698
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 2094
2007 void 2095 void
2008 PySys_FormatStderr(const char *format, ...) 2096 PySys_FormatStderr(const char *format, ...)
2009 { 2097 {
2010 va_list va; 2098 va_list va;
2011 2099
2012 va_start(va, format); 2100 va_start(va, format);
2013 sys_format("stderr", stderr, format, va); 2101 sys_format("stderr", stderr, format, va);
2014 va_end(va); 2102 va_end(va);
2015 } 2103 }
LEFTRIGHT

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