comparison Python/pythonrun.c @ 37879:f731859e9b3b

Merge p3yk branch with the trunk up to revision 45595. This breaks a fair number of tests, all because of the codecs/_multibytecodecs issue described here (it's not a Py3K issue, just something Py3K discovers): http://mail.python.org/pipermail/python-dev/2006-April/064051.html Hye-Shik Chang promised to look for a fix, so no need to fix it here. The tests that are expected to break are: test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp test_codecencodings_kr test_codecencodings_tw test_codecs test_multibytecodec This merge fixes an actual test failure (test_weakref) in this branch, though, so I believe merging is the right thing to do anyway.
author Thomas Wouters <thomas@python.org>
date Fri, 21 Apr 2006 10:40:58 +0000
parents 5aecedc98af6
children 29ae5e0fc348
comparison
equal deleted inserted replaced
37877:6a45f26ea619 37879:f731859e9b3b
28 #undef BYTE 28 #undef BYTE
29 #include "windows.h" 29 #include "windows.h"
30 #endif 30 #endif
31 31
32 #ifndef Py_REF_DEBUG 32 #ifndef Py_REF_DEBUG
33 # define PRINT_TOTAL_REFS() 33 #define PRINT_TOTAL_REFS()
34 #else /* Py_REF_DEBUG */ 34 #else /* Py_REF_DEBUG */
35 # if defined(MS_WIN64) 35 #define PRINT_TOTAL_REFS() fprintf(stderr, \
36 # define PRINT_TOTAL_REFS() fprintf(stderr, "[%Id refs]\n", _Py_RefTotal); 36 "[%" PY_FORMAT_SIZE_T "d refs]\n", \
37 # else /* ! MS_WIN64 */ 37 _Py_GetRefTotal())
38 # define PRINT_TOTAL_REFS() fprintf(stderr, "[%ld refs]\n", \ 38 #endif
39 Py_SAFE_DOWNCAST(_Py_RefTotal, Py_ssize_t, long)); 39
40 # endif /* MS_WIN64 */ 40 #ifdef __cplusplus
41 extern "C" {
41 #endif 42 #endif
42 43
43 extern char *Py_GetPath(void); 44 extern char *Py_GetPath(void);
44 45
45 extern grammar _PyParser_Grammar; /* From graminit.c */ 46 extern grammar _PyParser_Grammar; /* From graminit.c */
278 if (!PyFile_SetEncoding(sys_stream, codeset)) 279 if (!PyFile_SetEncoding(sys_stream, codeset))
279 Py_FatalError("Cannot set codeset of stdout"); 280 Py_FatalError("Cannot set codeset of stdout");
280 } 281 }
281 Py_XDECREF(sys_isatty); 282 Py_XDECREF(sys_isatty);
282 283
284 sys_stream = PySys_GetObject("stderr");
285 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
286 if (!sys_isatty)
287 PyErr_Clear();
288 if(sys_isatty && PyObject_IsTrue(sys_isatty)) {
289 if (!PyFile_SetEncoding(sys_stream, codeset))
290 Py_FatalError("Cannot set codeset of stderr");
291 }
292 Py_XDECREF(sys_isatty);
293
283 if (!Py_FileSystemDefaultEncoding) 294 if (!Py_FileSystemDefaultEncoding)
284 Py_FileSystemDefaultEncoding = codeset; 295 Py_FileSystemDefaultEncoding = codeset;
285 else 296 else
286 free(codeset); 297 free(codeset);
287 } 298 }
294 Py_InitializeEx(1); 305 Py_InitializeEx(1);
295 } 306 }
296 307
297 308
298 #ifdef COUNT_ALLOCS 309 #ifdef COUNT_ALLOCS
299 extern void dump_counts(void); 310 extern void dump_counts(FILE*);
300 #endif 311 #endif
301 312
302 /* Undo the effect of Py_Initialize(). 313 /* Undo the effect of Py_Initialize().
303 314
304 Beware: if multiple interpreter and/or thread states exist, these 315 Beware: if multiple interpreter and/or thread states exist, these
356 * XXX in <function callback at 0x008F5718> ignored 367 * XXX in <function callback at 0x008F5718> ignored
357 * XXX but I'm unclear on exactly how that one happens. In any case, 368 * XXX but I'm unclear on exactly how that one happens. In any case,
358 * XXX I haven't seen a real-life report of either of these. 369 * XXX I haven't seen a real-life report of either of these.
359 */ 370 */
360 PyGC_Collect(); 371 PyGC_Collect();
372 #ifdef COUNT_ALLOCS
373 /* With COUNT_ALLOCS, it helps to run GC multiple times:
374 each collection might release some types from the type
375 list, so they become garbage. */
376 while (PyGC_Collect() > 0)
377 /* nothing */;
378 #endif
361 379
362 /* Destroy all modules */ 380 /* Destroy all modules */
363 PyImport_Cleanup(); 381 PyImport_Cleanup();
364 382
365 /* Collect final garbage. This disposes of cycles created by 383 /* Collect final garbage. This disposes of cycles created by
384 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ 402 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
385 _PyImport_Fini(); 403 _PyImport_Fini();
386 404
387 /* Debugging stuff */ 405 /* Debugging stuff */
388 #ifdef COUNT_ALLOCS 406 #ifdef COUNT_ALLOCS
389 dump_counts(); 407 dump_counts(stdout);
390 #endif 408 #endif
391 409
392 PRINT_TOTAL_REFS() 410 PRINT_TOTAL_REFS();
393 411
394 #ifdef Py_TRACE_REFS 412 #ifdef Py_TRACE_REFS
395 /* Display all objects still alive -- this can invoke arbitrary 413 /* Display all objects still alive -- this can invoke arbitrary
396 * __repr__ overrides, so requires a mostly-intact interpreter. 414 * __repr__ overrides, so requires a mostly-intact interpreter.
397 * Alas, a lot of stuff may still be alive now that will be cleaned 415 * Alas, a lot of stuff may still be alive now that will be cleaned
677 PySys_SetObject("ps2", v = PyString_FromString("... ")); 695 PySys_SetObject("ps2", v = PyString_FromString("... "));
678 Py_XDECREF(v); 696 Py_XDECREF(v);
679 } 697 }
680 for (;;) { 698 for (;;) {
681 ret = PyRun_InteractiveOneFlags(fp, filename, flags); 699 ret = PyRun_InteractiveOneFlags(fp, filename, flags);
682 PRINT_TOTAL_REFS() 700 PRINT_TOTAL_REFS();
683 if (ret == E_EOF) 701 if (ret == E_EOF)
684 return 0; 702 return 0;
685 /* 703 /*
686 if (ret == E_NOMEM) 704 if (ret == E_NOMEM)
687 return -1; 705 return -1;
1449 break; 1467 break;
1450 } 1468 }
1451 v = Py_BuildValue("(ziiz)", err->filename, 1469 v = Py_BuildValue("(ziiz)", err->filename,
1452 err->lineno, err->offset, err->text); 1470 err->lineno, err->offset, err->text);
1453 if (err->text != NULL) { 1471 if (err->text != NULL) {
1454 PyMem_DEL(err->text); 1472 PyObject_FREE(err->text);
1455 err->text = NULL; 1473 err->text = NULL;
1456 } 1474 }
1457 w = NULL; 1475 w = NULL;
1458 if (v != NULL) 1476 if (v != NULL)
1459 w = Py_BuildValue("(sO)", msg, v); 1477 w = Py_BuildValue("(sO)", msg, v);
1664 } 1682 }
1665 1683
1666 /* Deprecated C API functions still provided for binary compatiblity */ 1684 /* Deprecated C API functions still provided for binary compatiblity */
1667 1685
1668 #undef PyParser_SimpleParseFile 1686 #undef PyParser_SimpleParseFile
1687 PyAPI_FUNC(node *)
1688 PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)
1689 {
1690 return PyParser_SimpleParseFileFlags(fp, filename, start, 0);
1691 }
1692
1669 #undef PyParser_SimpleParseString 1693 #undef PyParser_SimpleParseString
1670 1694 PyAPI_FUNC(node *)
1671 node *
1672 PyParser_SimpleParseFile(FILE *fp, const char *filename, int start)
1673 {
1674 return PyParser_SimpleParseFileFlags(fp, filename, start, 0);
1675 }
1676
1677 node *
1678 PyParser_SimpleParseString(const char *str, int start) 1695 PyParser_SimpleParseString(const char *str, int start)
1679 { 1696 {
1680 return PyParser_SimpleParseStringFlags(str, start, 0); 1697 return PyParser_SimpleParseStringFlags(str, start, 0);
1681 } 1698 }
1699
1700 #undef PyRun_AnyFile
1701 PyAPI_FUNC(int)
1702 PyRun_AnyFile(FILE *fp, const char *name)
1703 {
1704 return PyRun_AnyFileExFlags(fp, name, 0, NULL);
1705 }
1706
1707 #undef PyRun_AnyFileEx
1708 PyAPI_FUNC(int)
1709 PyRun_AnyFileEx(FILE *fp, const char *name, int closeit)
1710 {
1711 return PyRun_AnyFileExFlags(fp, name, closeit, NULL);
1712 }
1713
1714 #undef PyRun_AnyFileFlags
1715 PyAPI_FUNC(int)
1716 PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags)
1717 {
1718 return PyRun_AnyFileExFlags(fp, name, 0, flags);
1719 }
1720
1721 #undef PyRun_File
1722 PyAPI_FUNC(PyObject *)
1723 PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l)
1724 {
1725 return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL);
1726 }
1727
1728 #undef PyRun_FileEx
1729 PyAPI_FUNC(PyObject *)
1730 PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c)
1731 {
1732 return PyRun_FileExFlags(fp, p, s, g, l, c, NULL);
1733 }
1734
1735 #undef PyRun_FileFlags
1736 PyAPI_FUNC(PyObject *)
1737 PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l,
1738 PyCompilerFlags *flags)
1739 {
1740 return PyRun_FileExFlags(fp, p, s, g, l, 0, flags);
1741 }
1742
1743 #undef PyRun_SimpleFile
1744 PyAPI_FUNC(int)
1745 PyRun_SimpleFile(FILE *f, const char *p)
1746 {
1747 return PyRun_SimpleFileExFlags(f, p, 0, NULL);
1748 }
1749
1750 #undef PyRun_SimpleFileEx
1751 PyAPI_FUNC(int)
1752 PyRun_SimpleFileEx(FILE *f, const char *p, int c)
1753 {
1754 return PyRun_SimpleFileExFlags(f, p, c, NULL);
1755 }
1756
1757
1758 #undef PyRun_String
1759 PyAPI_FUNC(PyObject *)
1760 PyRun_String(const char *str, int s, PyObject *g, PyObject *l)
1761 {
1762 return PyRun_StringFlags(str, s, g, l, NULL);
1763 }
1764
1765 #undef PyRun_SimpleString
1766 PyAPI_FUNC(int)
1767 PyRun_SimpleString(const char *s)
1768 {
1769 return PyRun_SimpleStringFlags(s, NULL);
1770 }
1771
1772 #undef Py_CompileString
1773 PyAPI_FUNC(PyObject *)
1774 Py_CompileString(const char *str, const char *p, int s)
1775 {
1776 return Py_CompileStringFlags(str, p, s, NULL);
1777 }
1778
1779 #undef PyRun_InteractiveOne
1780 PyAPI_FUNC(int)
1781 PyRun_InteractiveOne(FILE *f, const char *p)
1782 {
1783 return PyRun_InteractiveOneFlags(f, p, NULL);
1784 }
1785
1786 #undef PyRun_InteractiveLoop
1787 PyAPI_FUNC(int)
1788 PyRun_InteractiveLoop(FILE *f, const char *p)
1789 {
1790 return PyRun_InteractiveLoopFlags(f, p, NULL);
1791 }
1792
1793 #ifdef __cplusplus
1794 }
1795 #endif
1796