annotate Python/sysmodule.c @ 38673:a19c20c5e5c7

Merge the rest of the trunk. Merged revisions 46490-46494,46496,46498,46500,46506,46521,46538,46558,46563-46567,46570-46571,46583,46593,46595-46598,46604,46606,46609-46753 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46610 | martin.v.loewis | 2006-06-03 09:42:26 +0200 (Sat, 03 Jun 2006) | 2 lines Updated version (win32-icons2.zip) from #1490384. ........ r46612 | andrew.kuchling | 2006-06-03 20:09:41 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1472084] Fix description of do_tag ........ r46614 | andrew.kuchling | 2006-06-03 20:33:35 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1475554] Strengthen text to say 'must' instead of 'should' ........ r46616 | andrew.kuchling | 2006-06-03 20:41:28 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1441864] Clarify description of 'data' argument ........ r46617 | andrew.kuchling | 2006-06-03 20:43:24 +0200 (Sat, 03 Jun 2006) | 1 line Minor rewording ........ r46619 | andrew.kuchling | 2006-06-03 21:02:35 +0200 (Sat, 03 Jun 2006) | 9 lines [Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler. Fix by renaming the variable. In a different module, Neal fixed it by renaming _self to self. There's already a variable named 'self' here, so I used selfptr. (I'm committing this on a Mac without Tk, but it's a simple search-and-replace. <crosses fingers>, so I'll watch the buildbots and see what happens.) ........ r46621 | fredrik.lundh | 2006-06-03 23:56:05 +0200 (Sat, 03 Jun 2006) | 5 lines "_self" is a said to be a reserved word in Watcom C 10.6. I'm not sure that's really standard compliant behaviour, but I guess we have to fix that anyway... ........ r46622 | andrew.kuchling | 2006-06-04 00:44:42 +0200 (Sun, 04 Jun 2006) | 1 line Update readme ........ r46623 | andrew.kuchling | 2006-06-04 00:59:23 +0200 (Sun, 04 Jun 2006) | 1 line Drop 0 parameter ........ r46624 | andrew.kuchling | 2006-06-04 00:59:59 +0200 (Sun, 04 Jun 2006) | 1 line Some code tidying; use curses.wrapper ........ r46625 | andrew.kuchling | 2006-06-04 01:02:15 +0200 (Sun, 04 Jun 2006) | 1 line Use True; value returned from main is unused ........ r46626 | andrew.kuchling | 2006-06-04 01:07:21 +0200 (Sun, 04 Jun 2006) | 1 line Use true division, and the True value ........ r46627 | andrew.kuchling | 2006-06-04 01:09:58 +0200 (Sun, 04 Jun 2006) | 1 line Docstring fix; use True ........ r46628 | andrew.kuchling | 2006-06-04 01:15:56 +0200 (Sun, 04 Jun 2006) | 1 line Put code in a main() function; loosen up the spacing to match current code style ........ r46629 | andrew.kuchling | 2006-06-04 01:39:07 +0200 (Sun, 04 Jun 2006) | 1 line Use functions; modernize code ........ r46630 | andrew.kuchling | 2006-06-04 01:43:22 +0200 (Sun, 04 Jun 2006) | 1 line This demo requires Medusa (not just asyncore); remove it ........ r46631 | andrew.kuchling | 2006-06-04 01:46:36 +0200 (Sun, 04 Jun 2006) | 2 lines Remove xmlrpc demo -- it duplicates the SimpleXMLRPCServer module. ........ r46632 | andrew.kuchling | 2006-06-04 01:47:22 +0200 (Sun, 04 Jun 2006) | 1 line Remove xmlrpc/ directory ........ r46633 | andrew.kuchling | 2006-06-04 01:51:21 +0200 (Sun, 04 Jun 2006) | 1 line Remove dangling reference ........ r46634 | andrew.kuchling | 2006-06-04 01:59:36 +0200 (Sun, 04 Jun 2006) | 1 line Add more whitespace; use a better socket name ........ r46635 | tim.peters | 2006-06-04 03:22:53 +0200 (Sun, 04 Jun 2006) | 2 lines Whitespace normalization. ........ r46637 | tim.peters | 2006-06-04 05:26:02 +0200 (Sun, 04 Jun 2006) | 16 lines In a PYMALLOC_DEBUG build obmalloc adds extra debugging info to each allocated block. This was using 4 bytes for each such piece of info regardless of platform. This didn't really matter before (proof: no bug reports, and the debug-build obmalloc would have assert-failed if it was ever asked for a chunk of memory >= 2**32 bytes), since container indices were plain ints. But after the Py_ssize_t changes, it's at least theoretically possible to allocate a list or string whose guts exceed 2**32 bytes, and the PYMALLOC_DEBUG routines would fail then (having only 4 bytes to record the originally requested size). Now we use sizeof(size_t) bytes for each of a PYMALLOC_DEBUG build's extra debugging fields. This won't make any difference on 32-bit boxes, but will add 16 bytes to each allocation in a debug build on a 64-bit box. ........ r46638 | tim.peters | 2006-06-04 05:38:04 +0200 (Sun, 04 Jun 2006) | 4 lines _PyObject_DebugMalloc(): The return value should add 2*sizeof(size_t) now, not 8. This probably accounts for current disasters on the 64-bit buildbot slaves. ........ r46639 | neal.norwitz | 2006-06-04 08:19:31 +0200 (Sun, 04 Jun 2006) | 1 line SF #1499797, Fix for memory leak in WindowsError_str ........ r46640 | andrew.macintyre | 2006-06-04 14:31:09 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1454481: Make thread stack size runtime tunable. ........ r46641 | andrew.macintyre | 2006-06-04 14:59:59 +0200 (Sun, 04 Jun 2006) | 2 lines clean up function declarations to conform to PEP-7 style. ........ r46642 | martin.blais | 2006-06-04 15:49:49 +0200 (Sun, 04 Jun 2006) | 15 lines Fixes in struct and socket from merge reviews. - Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t. ........ r46643 | ronald.oussoren | 2006-06-04 16:05:28 +0200 (Sun, 04 Jun 2006) | 3 lines "Import" LDFLAGS in Mac/OSX/Makefile.in to ensure pythonw gets build with the right compiler flags. ........ r46644 | ronald.oussoren | 2006-06-04 16:24:59 +0200 (Sun, 04 Jun 2006) | 2 lines Drop Mac wrappers for the WASTE library. ........ r46645 | tim.peters | 2006-06-04 17:49:07 +0200 (Sun, 04 Jun 2006) | 3 lines s_methods[]: Stop compiler warnings by casting s_unpack_from to PyCFunction. ........ r46646 | george.yoshida | 2006-06-04 19:04:12 +0200 (Sun, 04 Jun 2006) | 2 lines Remove a redundant word ........ r46647 | george.yoshida | 2006-06-04 19:17:25 +0200 (Sun, 04 Jun 2006) | 2 lines Markup fix ........ r46648 | martin.v.loewis | 2006-06-04 21:36:28 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1359618: Speed-up charmap encoder. ........ r46649 | georg.brandl | 2006-06-04 23:46:16 +0200 (Sun, 04 Jun 2006) | 3 lines Repair refleaks in unicodeobject. ........ r46650 | georg.brandl | 2006-06-04 23:56:52 +0200 (Sun, 04 Jun 2006) | 4 lines Patch #1346214: correctly optimize away "if 0"-style stmts (thanks to Neal for review) ........ r46651 | georg.brandl | 2006-06-05 00:15:37 +0200 (Mon, 05 Jun 2006) | 2 lines Bug #1500293: fix memory leaks in _subprocess module. ........ r46654 | tim.peters | 2006-06-05 01:43:53 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46655 | tim.peters | 2006-06-05 01:52:47 +0200 (Mon, 05 Jun 2006) | 16 lines Revert revisions: 46640 Patch #1454481: Make thread stack size runtime tunable. 46647 Markup fix The first is causing many buildbots to fail test runs, and there are multiple causes with seemingly no immediate prospects for repairing them. See python-dev discussion. Note that a branch can (and should) be created for resolving these problems, like svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH followed by merging rev 46647 to the new branch. ........ r46656 | andrew.kuchling | 2006-06-05 02:08:09 +0200 (Mon, 05 Jun 2006) | 1 line Mention second encoding speedup ........ r46657 | gregory.p.smith | 2006-06-05 02:31:01 +0200 (Mon, 05 Jun 2006) | 7 lines bugfix: when log_archive was called with the DB_ARCH_REMOVE flag present in BerkeleyDB >= 4.2 it tried to construct a list out of an uninitialized char **log_list. feature: export the DB_ARCH_REMOVE flag by name in the module on BerkeleyDB >= 4.2. ........ r46658 | gregory.p.smith | 2006-06-05 02:33:35 +0200 (Mon, 05 Jun 2006) | 5 lines fix a bug in the previous commit. don't leak empty list on error return and fix the additional rare (out of memory only) bug that it was supposed to fix of not freeing log_list when the python allocator failed. ........ r46660 | tim.peters | 2006-06-05 02:55:26 +0200 (Mon, 05 Jun 2006) | 9 lines "Flat is better than nested." Move the long-winded, multiply-nested -R support out of runtest() and into some module-level helper functions. This makes runtest() and the -R code easier to follow. That in turn allowed seeing some opportunities for code simplification, and made it obvious that reglog.txt never got closed. ........ r46661 | hyeshik.chang | 2006-06-05 02:59:54 +0200 (Mon, 05 Jun 2006) | 3 lines Fix a potentially invalid memory access of CJKCodecs' shift-jis decoder. (found by Neal Norwitz) ........ r46663 | gregory.p.smith | 2006-06-05 03:39:52 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885] ........ r46664 | tim.peters | 2006-06-05 03:43:03 +0200 (Mon, 05 Jun 2006) | 3 lines Remove doctest.testmod's deprecated (in 2.4) `isprivate` argument. A lot of hair went into supporting that! ........ r46665 | tim.peters | 2006-06-05 03:47:24 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46666 | tim.peters | 2006-06-05 03:48:21 +0200 (Mon, 05 Jun 2006) | 2 lines Make doctest news more accurate. ........ r46667 | gregory.p.smith | 2006-06-05 03:56:15 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.lsn_reset() method on BerkeleyDB >= 4.4 [patch #1494902] ........ r46668 | gregory.p.smith | 2006-06-05 04:02:25 +0200 (Mon, 05 Jun 2006) | 3 lines mention the just committed bsddb changes ........ r46671 | gregory.p.smith | 2006-06-05 19:38:04 +0200 (Mon, 05 Jun 2006) | 3 lines * add support for DBSequence objects [patch #1466734] ........ r46672 | gregory.p.smith | 2006-06-05 20:20:07 +0200 (Mon, 05 Jun 2006) | 3 lines forgot to add this file in previous commit ........ r46673 | tim.peters | 2006-06-05 20:36:12 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46674 | tim.peters | 2006-06-05 20:36:54 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46675 | gregory.p.smith | 2006-06-05 20:48:21 +0200 (Mon, 05 Jun 2006) | 4 lines * fix DBCursor.pget() bug with keyword argument names when no data= is supplied [SF pybsddb bug #1477863] ........ r46676 | andrew.kuchling | 2006-06-05 21:05:32 +0200 (Mon, 05 Jun 2006) | 1 line Remove use of Trove name, which isn't very helpful to users ........ r46677 | andrew.kuchling | 2006-06-05 21:08:25 +0200 (Mon, 05 Jun 2006) | 1 line [Bug #1470026] Include link to list of classifiers ........ r46679 | tim.peters | 2006-06-05 22:48:49 +0200 (Mon, 05 Jun 2006) | 10 lines Access _struct attributes directly instead of mucking with getattr. string_reverse(): Simplify. assertRaises(): Raise TestFailed on failure. test_unpack_from(), test_pack_into(), test_pack_into_fn(): never use `assert` to test for an expected result (it doesn't test anything when Python is run with -O). ........ r46680 | tim.peters | 2006-06-05 22:49:27 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46681 | gregory.p.smith | 2006-06-06 01:38:06 +0200 (Tue, 06 Jun 2006) | 3 lines add depends = ['md5.h'] to the _md5 module extension for correctness sake. ........ r46682 | brett.cannon | 2006-06-06 01:51:55 +0200 (Tue, 06 Jun 2006) | 4 lines Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int. Closes bug #1501223. ........ r46684 | gregory.p.smith | 2006-06-06 01:59:37 +0200 (Tue, 06 Jun 2006) | 5 lines - bsddb: the __len__ method of a DB object has been fixed to return correct results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). ........ r46686 | tim.peters | 2006-06-06 02:25:07 +0200 (Tue, 06 Jun 2006) | 7 lines _PySys_Init(): It's rarely a good idea to size a buffer to the exact maximum size someone guesses is needed. In this case, if we're really worried about extreme integers, then "cp%d" can actually need 14 bytes (2 for "cp" + 1 for \0 at the end + 11 for -(2**31-1)). So reserve 128 bytes instead -- nothing is actually saved by making a stack-local buffer tiny. ........ r46687 | neal.norwitz | 2006-06-06 09:22:08 +0200 (Tue, 06 Jun 2006) | 1 line Remove unused variable (and stop compiler warning) ........ r46688 | neal.norwitz | 2006-06-06 09:23:01 +0200 (Tue, 06 Jun 2006) | 1 line Fix a bunch of parameter strings ........ r46689 | thomas.heller | 2006-06-06 13:34:33 +0200 (Tue, 06 Jun 2006) | 6 lines Convert CFieldObject tp_members to tp_getset, since there is no structmember typecode for Py_ssize_t fields. This should fix some of the errors on the PPC64 debian machine (64-bit, big endian). Assigning to readonly fields now raises AttributeError instead of TypeError, so the testcase has to be changed as well. ........ r46690 | thomas.heller | 2006-06-06 13:54:32 +0200 (Tue, 06 Jun 2006) | 1 line Damn - the sentinel was missing. And fix another silly mistake. ........ r46691 | martin.blais | 2006-06-06 14:46:55 +0200 (Tue, 06 Jun 2006) | 13 lines Normalized a few cases of whitespace in function declarations. Found them using:: find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done (I was doing this all over my own code anyway, because I'd been using spaces in all defs, so I thought I'd make a run on the Python code as well. If you need to do such fixes in your own code, you can use xx-rename or parenregu.el within emacs.) ........ r46693 | thomas.heller | 2006-06-06 17:34:18 +0200 (Tue, 06 Jun 2006) | 1 line Specify argtypes for all test functions. Maybe that helps on strange ;-) architectures ........ r46694 | tim.peters | 2006-06-06 17:50:17 +0200 (Tue, 06 Jun 2006) | 5 lines BSequence_set_range(): Rev 46688 ("Fix a bunch of parameter strings") changed this function's signature seemingly by mistake, which is causing buildbots to fail test_bsddb3. Restored the pre-46688 signature. ........ r46695 | tim.peters | 2006-06-06 17:52:35 +0200 (Tue, 06 Jun 2006) | 4 lines On python-dev Thomas Heller said these were committed by mistake in rev 46693, so reverting this part of rev 46693. ........ r46696 | andrew.kuchling | 2006-06-06 19:10:41 +0200 (Tue, 06 Jun 2006) | 1 line Fix comment typo ........ r46697 | brett.cannon | 2006-06-06 20:08:16 +0200 (Tue, 06 Jun 2006) | 2 lines Fix coding style guide bug. ........ r46698 | thomas.heller | 2006-06-06 20:50:46 +0200 (Tue, 06 Jun 2006) | 2 lines Add a hack so that foreign functions returning float now do work on 64-bit big endian platforms. ........ r46699 | thomas.heller | 2006-06-06 21:25:13 +0200 (Tue, 06 Jun 2006) | 3 lines Use the same big-endian hack as in _ctypes/callproc.c for callback functions. This fixes the callback function tests that return float. ........ r46700 | ronald.oussoren | 2006-06-06 21:50:24 +0200 (Tue, 06 Jun 2006) | 5 lines * Ensure that "make altinstall" works when the tree was configured with --enable-framework * Also for --enable-framework: allow users to use --prefix to specify the location of the compatibility symlinks (such as /usr/local/bin/python) ........ r46701 | ronald.oussoren | 2006-06-06 21:56:00 +0200 (Tue, 06 Jun 2006) | 3 lines A quick hack to ensure the right key-bindings for IDLE on osx: install patched configuration files during a framework install. ........ r46702 | tim.peters | 2006-06-07 03:04:59 +0200 (Wed, 07 Jun 2006) | 4 lines dash_R_cleanup(): Clear filecmp._cache. This accounts for different results across -R runs (at least on Windows) of test_filecmp. ........ r46705 | tim.peters | 2006-06-07 08:57:51 +0200 (Wed, 07 Jun 2006) | 17 lines SF patch 1501987: Remove randomness from test_exceptions, from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code). ........ r46706 | andrew.kuchling | 2006-06-07 15:55:33 +0200 (Wed, 07 Jun 2006) | 1 line Add an SQLite introduction, taken from the 'What's New' text ........ r46708 | andrew.kuchling | 2006-06-07 19:02:52 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46709 | andrew.kuchling | 2006-06-07 19:03:46 +0200 (Wed, 07 Jun 2006) | 1 line Add an item; also, escape % ........ r46710 | andrew.kuchling | 2006-06-07 19:04:01 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46716 | ronald.oussoren | 2006-06-07 20:57:44 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/Tools one level up ........ r46717 | ronald.oussoren | 2006-06-07 20:58:01 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/PythonLauncher one level up ........ r46718 | ronald.oussoren | 2006-06-07 20:58:42 +0200 (Wed, 07 Jun 2006) | 2 lines mv Mac/OSX/BuildScript one level up ........ r46719 | ronald.oussoren | 2006-06-07 21:02:03 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/* one level up ........ r46720 | ronald.oussoren | 2006-06-07 21:06:01 +0200 (Wed, 07 Jun 2006) | 2 lines And the last bit: move IDLE one level up and adjust makefiles ........ r46723 | ronald.oussoren | 2006-06-07 21:38:53 +0200 (Wed, 07 Jun 2006) | 4 lines - Patch the correct version of python in the Info.plists at build time, instead of relying on a maintainer to update them before releases. - Remove the now empty Mac/OSX directory ........ r46727 | ronald.oussoren | 2006-06-07 22:18:44 +0200 (Wed, 07 Jun 2006) | 7 lines * If BuildApplet.py is used as an applet it starts with a version of sys.exutable that isn't usuable on an #!-line. That results in generated applets that don't actually work. Work around this problem by resetting sys.executable. * argvemulator.py didn't work on intel macs. This patch fixes this (bug #1491468) ........ r46728 | tim.peters | 2006-06-07 22:40:06 +0200 (Wed, 07 Jun 2006) | 2 lines Whitespace normalization. ........ r46729 | tim.peters | 2006-06-07 22:40:54 +0200 (Wed, 07 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46730 | thomas.heller | 2006-06-07 22:43:06 +0200 (Wed, 07 Jun 2006) | 7 lines Fix for foreign functions returning small structures on 64-bit big endian machines. Should fix the remaininf failure in the PPC64 Debian buildbot. Thanks to Matthias Klose for providing access to a machine to debug and test this. ........ r46731 | brett.cannon | 2006-06-07 23:48:17 +0200 (Wed, 07 Jun 2006) | 2 lines Clarify documentation for bf_getcharbuffer. ........ r46735 | neal.norwitz | 2006-06-08 07:12:45 +0200 (Thu, 08 Jun 2006) | 1 line Fix a refleak in recvfrom_into ........ r46736 | gregory.p.smith | 2006-06-08 07:17:08 +0200 (Thu, 08 Jun 2006) | 9 lines - bsddb: the bsddb.dbtables Modify method now raises the proper error and aborts the db transaction safely when a modifier callback fails. Fixes SF python patch/bug #1408584. Also cleans up the bsddb.dbtables docstrings since thats the only documentation that exists for that unadvertised module. (people really should really just use sqlite3) ........ r46737 | gregory.p.smith | 2006-06-08 07:38:11 +0200 (Thu, 08 Jun 2006) | 4 lines * Turn the deadlock situation described in SF bug #775414 into a DBDeadLockError exception. * add the test case for my previous dbtables commit. ........ r46738 | gregory.p.smith | 2006-06-08 07:39:54 +0200 (Thu, 08 Jun 2006) | 2 lines pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time. ........ r46739 | armin.rigo | 2006-06-08 12:56:24 +0200 (Thu, 08 Jun 2006) | 6 lines (arre, arigo) SF bug #1350060 Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'. ........ r46740 | andrew.kuchling | 2006-06-08 13:56:44 +0200 (Thu, 08 Jun 2006) | 1 line Typo fix ........ r46741 | georg.brandl | 2006-06-08 14:45:01 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. ........ r46743 | georg.brandl | 2006-06-08 14:54:13 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502728: Correctly link against librt library on HP-UX. ........ r46745 | georg.brandl | 2006-06-08 14:55:47 +0200 (Thu, 08 Jun 2006) | 3 lines Add news for recent bugfix. ........ r46746 | georg.brandl | 2006-06-08 15:31:07 +0200 (Thu, 08 Jun 2006) | 4 lines Argh. "integer" is a very confusing word ;) Actually, checking for INT_MAX and INT_MIN is correct since the format code explicitly handles a C "int". ........ r46748 | nick.coghlan | 2006-06-08 15:54:49 +0200 (Thu, 08 Jun 2006) | 1 line Add functools.update_wrapper() and functools.wraps() as described in PEP 356 ........ r46751 | georg.brandl | 2006-06-08 16:50:21 +0200 (Thu, 08 Jun 2006) | 4 lines Bug #1502805: don't alias file.__exit__ to file.close since the latter can return something that's true. ........ r46752 | georg.brandl | 2006-06-08 16:50:53 +0200 (Thu, 08 Jun 2006) | 3 lines Convert test_file to unittest. ........
author Thomas Wouters <thomas@python.org>
date Thu, 08 Jun 2006 15:35:45 +0000
parents 19fd6141940d
children 654c380cf8b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* System module */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 Various bits of information used by the interpreter are collected in
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 module 'sys'.
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
7 Function member:
2586
ae131b8b4e31 fix comment about exit()
Guido van Rossum <guido@python.org>
parents: 2421
diff changeset
8 - exit(sts): raise SystemExit
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 Data members:
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 - stdin, stdout, stderr: standard file objects
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
11 - modules: the table of modules (dictionary)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 - path: module search path (list of strings)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
13 - argv: script arguments (list of strings)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
14 - ps1, ps2: optional primary and secondary prompts (strings)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
17 #include "Python.h"
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35673
diff changeset
18 #include "code.h"
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
19 #include "frameobject.h"
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
20 #include "eval.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
21
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
22 #include "osdefs.h"
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
23
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
24 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
25 #define WIN32_LEAN_AND_MEAN
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
26 #include "windows.h"
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
27 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
28
4291
1427d61f1307 Rationalized MS ifdefs
Guido van Rossum <guido@python.org>
parents: 4256
diff changeset
29 #ifdef MS_COREDLL
3490
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
30 extern void *PyWin_DLLhModule;
6352
b62a7a59414e Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents: 5955
diff changeset
31 /* A string loaded from the DLL at startup: */
b62a7a59414e Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents: 5955
diff changeset
32 extern const char *PyWin_DLLVersionString;
3490
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
33 #endif
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
34
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
35 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
36 #include <unixlib.h>
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
37 #endif
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
38
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
39 #ifdef MS_WINDOWS
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
40 #include <windows.h>
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
41 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
42
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
43 #ifdef HAVE_LANGINFO_H
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
44 #include <locale.h>
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
45 #include <langinfo.h>
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
46 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
47
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
48 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
49 PySys_GetObject(char *name)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
51 PyThreadState *tstate = PyThreadState_GET();
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
52 PyObject *sd = tstate->interp->sysdict;
11374
66216f32403d In PySys_GetObject(), it's possible that tstate->interp->sysdict is
Guido van Rossum <guido@python.org>
parents: 9964
diff changeset
53 if (sd == NULL)
66216f32403d In PySys_GetObject(), it's possible that tstate->interp->sysdict is
Guido van Rossum <guido@python.org>
parents: 9964
diff changeset
54 return NULL;
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
55 return PyDict_GetItemString(sd, name);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 FILE *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
59 PySys_GetFile(char *name, FILE *def)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 FILE *fp = NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
62 PyObject *v = PySys_GetObject(name);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
63 if (v != NULL && PyFile_Check(v))
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
64 fp = PyFile_AsFile(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 if (fp == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 fp = def;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 return fp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
71 PySys_SetObject(char *name, PyObject *v)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
73 PyThreadState *tstate = PyThreadState_GET();
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
74 PyObject *sd = tstate->interp->sysdict;
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
75 if (v == NULL) {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
76 if (PyDict_GetItemString(sd, name) == NULL)
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
77 return 0;
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
78 else
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
79 return PyDict_DelItemString(sd, name);
631
f5a2bc39e10e sysset(name, NULL) does nothing if sys.name is undefined
Guido van Rossum <guido@python.org>
parents: 596
diff changeset
80 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 else
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
82 return PyDict_SetItemString(sd, name, v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
85 static PyObject *
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
86 sys_displayhook(PyObject *self, PyObject *o)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
87 {
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
88 PyObject *outf;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
89 PyInterpreterState *interp = PyThreadState_GET()->interp;
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
90 PyObject *modules = interp->modules;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
91 PyObject *builtins = PyDict_GetItemString(modules, "__builtin__");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
92
18805
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
93 if (builtins == NULL) {
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
94 PyErr_SetString(PyExc_RuntimeError, "lost __builtin__");
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
95 return NULL;
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
96 }
4462c57f6c94 Patch number #422106 by Greg Ball, to fix segmentation
Moshe Zadka <moshez@math.huji.ac.il>
parents: 18689
diff changeset
97
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
98 /* Print value except if None */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
99 /* After printing, also assign to '_' */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
100 /* Before, set '_' to None to avoid recursion */
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
101 if (o == Py_None) {
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
102 Py_INCREF(Py_None);
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
103 return Py_None;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
104 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
105 if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
106 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
107 if (Py_FlushLine() != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
108 return NULL;
15812
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
109 outf = PySys_GetObject("stdout");
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
110 if (outf == NULL) {
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
111 PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
112 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
113 }
15812
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
114 if (PyFile_WriteObject(o, outf, 0) != 0)
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
115 return NULL;
15812
a563eec46c1a stdout is sometimes a macro; use "outf" instead.
Greg Stein <gstein@lyra.org>
parents: 15811
diff changeset
116 PyFile_SoftSpace(outf, 1);
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
117 if (Py_FlushLine() != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
118 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
119 if (PyObject_SetAttrString(builtins, "_", o) != 0)
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
120 return NULL;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
121 Py_INCREF(Py_None);
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
122 return Py_None;
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
123 }
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
124
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
125 PyDoc_STRVAR(displayhook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
126 "displayhook(object) -> None\n"
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
127 "\n"
36814
7a30dc2af329 Fix minor docstring typo.
Brett Cannon <bcannon@gmail.com>
parents: 36521
diff changeset
128 "Print an object to sys.stdout and also save it in __builtin__.\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
129 );
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
130
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
131 static PyObject *
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
132 sys_excepthook(PyObject* self, PyObject* args)
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
133 {
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
134 PyObject *exc, *value, *tb;
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
135 if (!PyArg_UnpackTuple(args, "excepthook", 3, 3, &exc, &value, &tb))
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
136 return NULL;
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
137 PyErr_Display(exc, value, tb);
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
138 Py_INCREF(Py_None);
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
139 return Py_None;
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
140 }
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
141
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
142 PyDoc_STRVAR(excepthook_doc,
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
143 "excepthook(exctype, value, traceback) -> None\n"
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
144 "\n"
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
145 "Handle an exception by displaying it with a traceback on sys.stderr.\n"
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
146 );
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
147
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
148 static PyObject *
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
149 sys_exc_info(PyObject *self, PyObject *noargs)
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
150 {
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
151 PyThreadState *tstate;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
152 tstate = PyThreadState_GET();
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
153 return Py_BuildValue(
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
154 "(OOO)",
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
155 tstate->exc_type != NULL ? tstate->exc_type : Py_None,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
156 tstate->exc_value != NULL ? tstate->exc_value : Py_None,
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
157 tstate->exc_traceback != NULL ?
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
158 tstate->exc_traceback : Py_None);
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
159 }
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
160
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
161 PyDoc_STRVAR(exc_info_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
162 "exc_info() -> (type, value, traceback)\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
163 \n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
164 Return information about the most recent exception caught by an except\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
165 clause in the current stack frame or in an older stack frame."
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
166 );
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
167
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
168 static PyObject *
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
169 sys_exc_clear(PyObject *self, PyObject *noargs)
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
170 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
171 PyThreadState *tstate = PyThreadState_GET();
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
172 PyObject *tmp_type, *tmp_value, *tmp_tb;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
173 tmp_type = tstate->exc_type;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
174 tmp_value = tstate->exc_value;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
175 tmp_tb = tstate->exc_traceback;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
176 tstate->exc_type = NULL;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
177 tstate->exc_value = NULL;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
178 tstate->exc_traceback = NULL;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
179 Py_XDECREF(tmp_type);
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
180 Py_XDECREF(tmp_value);
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
181 Py_XDECREF(tmp_tb);
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
182 Py_INCREF(Py_None);
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
183 return Py_None;
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
184 }
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
185
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
186 PyDoc_STRVAR(exc_clear_doc,
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
187 "exc_clear() -> None\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
188 \n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
189 Clear global information on the current exception. Subsequent calls to\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
190 exc_info() will return (None,None,None) until another exception is raised\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
191 in the current thread or the execution stack returns to a frame where\n\
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
192 another exception is being handled."
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
193 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
194
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
195 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
196 sys_exit(PyObject *self, PyObject *args)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 {
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
198 PyObject *exit_code = 0;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
199 if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code))
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
200 return NULL;
549
4efff6cea90f Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents: 476
diff changeset
201 /* Raise SystemExit so callers may catch it or clean up. */
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
202 PyErr_SetObject(PyExc_SystemExit, exit_code);
549
4efff6cea90f Raise SystemExit instead of calling goaway().
Guido van Rossum <guido@python.org>
parents: 476
diff changeset
203 return NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
206 PyDoc_STRVAR(exit_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
207 "exit([status])\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
208 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
209 Exit the interpreter by raising SystemExit(status).\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
210 If the status is omitted or None, it defaults to zero (i.e., success).\n\
22531
ef314b37e260 backport nascheme's checkin of
Michael W. Hudson <mwh@python.net>
parents: 22119
diff changeset
211 If the status is numeric, it will be used as the system exit status.\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
212 If it is another kind of object, it will be printed and the system\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
213 exit status will be one (i.e., failure)."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
214 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
215
20943
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
216 #ifdef Py_USING_UNICODE
e4d380f5f297 Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571.
Martin v. Löwis <martin@v.loewis.de>
parents: 20655
diff changeset
217
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
218 static PyObject *
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
219 sys_getdefaultencoding(PyObject *self)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
220 {
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
221 return PyString_FromString(PyUnicode_GetDefaultEncoding());
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
222 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
223
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
224 PyDoc_STRVAR(getdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
225 "getdefaultencoding() -> string\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
226 \n\
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
227 Return the current default string encoding used by the Unicode \n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
228 implementation."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
229 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
230
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
231 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
232 sys_setdefaultencoding(PyObject *self, PyObject *args)
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
233 {
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
234 char *encoding;
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
235 if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
236 return NULL;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
237 if (PyUnicode_SetDefaultEncoding(encoding))
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
238 return NULL;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
239 Py_INCREF(Py_None);
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
240 return Py_None;
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
241 }
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
242
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
243 PyDoc_STRVAR(setdefaultencoding_doc,
12877
78231bbe605d Marc-Andre Lemburg <mal@lemburg.com>:
Marc-André Lemburg <mal@egenix.com>
parents: 12649
diff changeset
244 "setdefaultencoding(encoding)\n\
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
245 \n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
246 Set the current default string encoding used by the Unicode implementation."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
247 );
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
248
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
249 static PyObject *
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
250 sys_getfilesystemencoding(PyObject *self)
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
251 {
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
252 if (Py_FileSystemDefaultEncoding)
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
253 return PyString_FromString(Py_FileSystemDefaultEncoding);
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
254 Py_INCREF(Py_None);
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
255 return Py_None;
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
256 }
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
257
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
258 PyDoc_STRVAR(getfilesystemencoding_doc,
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
259 "getfilesystemencoding() -> string\n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
260 \n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
261 Return the encoding used to convert Unicode filenames in\n\
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
262 operating system filenames."
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
263 );
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
264
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
265 #endif
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
266
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
267 /*
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
268 * Cached interned string objects used for calling the profile and
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
269 * trace functions. Initialized by trace_init().
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
270 */
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
271 static PyObject *whatstrings[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
272
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
273 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
274 trace_init(void)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
275 {
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
276 static char *whatnames[7] = {"call", "exception", "line", "return",
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
277 "c_call", "c_exception", "c_return"};
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
278 PyObject *name;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
279 int i;
31796
1c117dbb2def Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents: 30108
diff changeset
280 for (i = 0; i < 7; ++i) {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
281 if (whatstrings[i] == NULL) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
282 name = PyString_InternFromString(whatnames[i]);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
283 if (name == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
284 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
285 whatstrings[i] = name;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
286 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
287 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
288 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
289 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
290
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
291
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
292 static PyObject *
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
293 call_trampoline(PyThreadState *tstate, PyObject* callback,
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
294 PyFrameObject *frame, int what, PyObject *arg)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
295 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
296 PyObject *args = PyTuple_New(3);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
297 PyObject *whatstr;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
298 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
299
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
300 if (args == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
301 return NULL;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
302 Py_INCREF(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
303 whatstr = whatstrings[what];
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
304 Py_INCREF(whatstr);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
305 if (arg == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
306 arg = Py_None;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
307 Py_INCREF(arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
308 PyTuple_SET_ITEM(args, 0, (PyObject *)frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
309 PyTuple_SET_ITEM(args, 1, whatstr);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
310 PyTuple_SET_ITEM(args, 2, arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
311
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
312 /* call the Python-level function */
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
313 PyFrame_FastToLocals(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
314 result = PyEval_CallObject(callback, args);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
315 PyFrame_LocalsToFast(frame, 1);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
316 if (result == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
317 PyTraceBack_Here(frame);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
318
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
319 /* cleanup */
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
320 Py_DECREF(args);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
321 return result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
322 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
323
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
324 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
325 profile_trampoline(PyObject *self, PyFrameObject *frame,
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
326 int what, PyObject *arg)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
327 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
328 PyThreadState *tstate = frame->f_tstate;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
329 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
330
20247
a4d328d50897 Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents: 19343
diff changeset
331 if (arg == NULL)
a4d328d50897 Rationalize the events passed to the profiler (no changes for the tracer).
Fred Drake <fdrake@acm.org>
parents: 19343
diff changeset
332 arg = Py_None;
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
333 result = call_trampoline(tstate, self, frame, what, arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
334 if (result == NULL) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
335 PyEval_SetProfile(NULL, NULL);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
336 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
337 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
338 Py_DECREF(result);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
339 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
340 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
341
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
342 static int
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
343 trace_trampoline(PyObject *self, PyFrameObject *frame,
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
344 int what, PyObject *arg)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
345 {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
346 PyThreadState *tstate = frame->f_tstate;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
347 PyObject *callback;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
348 PyObject *result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
349
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
350 if (what == PyTrace_CALL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
351 callback = self;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
352 else
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
353 callback = frame->f_trace;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
354 if (callback == NULL)
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
355 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
356 result = call_trampoline(tstate, callback, frame, what, arg);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
357 if (result == NULL) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
358 PyEval_SetTrace(NULL, NULL);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
359 Py_XDECREF(frame->f_trace);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
360 frame->f_trace = NULL;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
361 return -1;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
362 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
363 if (result != Py_None) {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
364 PyObject *temp = frame->f_trace;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
365 frame->f_trace = NULL;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
366 Py_XDECREF(temp);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
367 frame->f_trace = result;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
368 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
369 else {
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
370 Py_DECREF(result);
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
371 }
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
372 return 0;
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
373 }
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
374
12649
c92668766f5d M.-A. Lemburg <mal@lemburg.com>:
Fred Drake <fdrake@acm.org>
parents: 12398
diff changeset
375 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
376 sys_settrace(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
377 {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
378 if (trace_init() == -1)
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
379 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
380 if (args == Py_None)
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
381 PyEval_SetTrace(NULL, NULL);
788
ba4ec13c0f9f Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents: 710
diff changeset
382 else
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
383 PyEval_SetTrace(trace_trampoline, args);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
384 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
385 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
386 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
387
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
388 PyDoc_STRVAR(settrace_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
389 "settrace(function)\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
390 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
391 Set the global debug tracing function. It will be called on each\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
392 function call. See the debugger chapter in the library manual."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
393 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
394
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
395 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
396 sys_setprofile(PyObject *self, PyObject *args)
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
397 {
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
398 if (trace_init() == -1)
18136
4cb34314bd97 Instead of initializing & interning the strings passed to the profile
Fred Drake <fdrake@acm.org>
parents: 17396
diff changeset
399 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
400 if (args == Py_None)
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
401 PyEval_SetProfile(NULL, NULL);
788
ba4ec13c0f9f Fix reference counts of sys_trace and sys_profile
Guido van Rossum <guido@python.org>
parents: 710
diff changeset
402 else
18326
e427afb5637f Revise the interface to the profiling and tracing support for the
Fred Drake <fdrake@acm.org>
parents: 18298
diff changeset
403 PyEval_SetProfile(profile_trampoline, args);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
404 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
405 return Py_None;
710
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
406 }
bc5c77fa8006 Added settrace() and setprofile().
Guido van Rossum <guido@python.org>
parents: 631
diff changeset
407
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
408 PyDoc_STRVAR(setprofile_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
409 "setprofile(function)\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
410 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
411 Set the profiling function. It will be called on each function call\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
412 and return. See the profiler chapter in the library manual."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
413 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
414
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
415 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
416 sys_setcheckinterval(PyObject *self, PyObject *args)
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
417 {
25108
3a26e352f0a6 replace thread state objects' ticker and checkinterval fields with two
Skip Montanaro <skip@pobox.com>
parents: 25099
diff changeset
418 if (!PyArg_ParseTuple(args, "i:setcheckinterval", &_Py_CheckInterval))
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
419 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
420 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
421 return Py_None;
2093
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
422 }
e8cafb2b743a sys.check_interval=x -> sys.setcheckinterval(x)
Guido van Rossum <guido@python.org>
parents: 2062
diff changeset
423
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
424 PyDoc_STRVAR(setcheckinterval_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
425 "setcheckinterval(n)\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
426 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
427 Tell the Python interpreter to check for asynchronous events every\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
428 n instructions. This also affects how often thread switches occur."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
429 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
430
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
431 static PyObject *
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
432 sys_getcheckinterval(PyObject *self, PyObject *args)
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
433 {
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
434 return PyInt_FromLong(_Py_CheckInterval);
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
435 }
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
436
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
437 PyDoc_STRVAR(getcheckinterval_doc,
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
438 "getcheckinterval() -> current check interval; see setcheckinterval()."
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
439 );
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
440
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
441 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
442 static PyObject *
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
443 sys_settscdump(PyObject *self, PyObject *args)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
444 {
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
445 int bool;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
446 PyThreadState *tstate = PyThreadState_Get();
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
447
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
448 if (!PyArg_ParseTuple(args, "i:settscdump", &bool))
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
449 return NULL;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
450 if (bool)
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
451 tstate->interp->tscdump = 1;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
452 else
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
453 tstate->interp->tscdump = 0;
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
454 Py_INCREF(Py_None);
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
455 return Py_None;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
456
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
457 }
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
458
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
459 PyDoc_STRVAR(settscdump_doc,
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
460 "settscdump(bool)\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
461 \n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
462 If true, tell the Python interpreter to dump VM measurements to\n\
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
463 stderr. If false, turn off dump. The measurements are based on the\n\
33104
f455bbe7ea7e This is my patch:
Michael W. Hudson <mwh@python.net>
parents: 32344
diff changeset
464 processor's time-stamp counter."
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
465 );
32344
748129e6e108 Remove compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 32301
diff changeset
466 #endif /* TSC */
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
467
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
468 static PyObject *
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
469 sys_setrecursionlimit(PyObject *self, PyObject *args)
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
470 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
471 int new_limit;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
472 if (!PyArg_ParseTuple(args, "i:setrecursionlimit", &new_limit))
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
473 return NULL;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
474 if (new_limit <= 0) {
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
475 PyErr_SetString(PyExc_ValueError,
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
476 "recursion limit must be positive");
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
477 return NULL;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
478 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
479 Py_SetRecursionLimit(new_limit);
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
480 Py_INCREF(Py_None);
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
481 return Py_None;
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
482 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
483
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
484 PyDoc_STRVAR(setrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
485 "setrecursionlimit(n)\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
486 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
487 Set the maximum depth of the Python interpreter stack to n. This\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
488 limit prevents infinite recursion from causing an overflow of the C\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
489 stack and crashing Python. The highest possible limit is platform-\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
490 dependent."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
491 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
492
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
493 static PyObject *
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
494 sys_getrecursionlimit(PyObject *self)
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
495 {
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
496 return PyInt_FromLong(Py_GetRecursionLimit());
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
497 }
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
498
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
499 PyDoc_STRVAR(getrecursionlimit_doc,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
500 "getrecursionlimit()\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
501 \n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
502 Return the current value of the recursion limit, the maximum depth\n\
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
503 of the Python interpreter stack. This limit prevents infinite\n\
24013
71f13cf4f9e2 Got rid of an extraneous semicolon.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23947
diff changeset
504 recursion from causing an overflow of the C stack and crashing Python."
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
505 );
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
506
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
507 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
508 PyDoc_STRVAR(getwindowsversion_doc,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
509 "getwindowsversion()\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
510 \n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
511 Return information about the running version of Windows.\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
512 The result is a tuple of (major, minor, build, platform, text)\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
513 All elements are numbers, except text which is a string.\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
514 Platform may be 0 for win32s, 1 for Windows 9x/ME, 2 for Windows NT/2000/XP\n\
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
515 "
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
516 );
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
517
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
518 static PyObject *
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
519 sys_getwindowsversion(PyObject *self)
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
520 {
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
521 OSVERSIONINFO ver;
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
522 ver.dwOSVersionInfoSize = sizeof(ver);
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
523 if (!GetVersionEx(&ver))
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
524 return PyErr_SetFromWindowsErr(0);
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
525 return Py_BuildValue("HHHHs",
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
526 ver.dwMajorVersion,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
527 ver.dwMinorVersion,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
528 ver.dwBuildNumber,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
529 ver.dwPlatformId,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
530 ver.szCSDVersion);
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
531 }
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
532
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
533 #endif /* MS_WINDOWS */
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
534
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
535 #ifdef HAVE_DLOPEN
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
536 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
537 sys_setdlopenflags(PyObject *self, PyObject *args)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
538 {
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
539 int new_val;
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
540 PyThreadState *tstate = PyThreadState_GET();
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
541 if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
542 return NULL;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
543 if (!tstate)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
544 return NULL;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
545 tstate->interp->dlopenflags = new_val;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
546 Py_INCREF(Py_None);
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
547 return Py_None;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
548 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
549
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
550 PyDoc_STRVAR(setdlopenflags_doc,
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
551 "setdlopenflags(n) -> None\n\
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
552 \n\
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
553 Set the flags that will be used for dlopen() calls. Among other\n\
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21712
diff changeset
554 things, this will enable a lazy resolving of symbols when importing\n\
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
555 a module, if called as sys.setdlopenflags(0)\n\
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21712
diff changeset
556 To share symbols across extension modules, call as\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
557 sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)"
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
558 );
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
559
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
560 static PyObject *
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
561 sys_getdlopenflags(PyObject *self, PyObject *args)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
562 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
563 PyThreadState *tstate = PyThreadState_GET();
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
564 if (!tstate)
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
565 return NULL;
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
566 return PyInt_FromLong(tstate->interp->dlopenflags);
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
567 }
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
568
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
569 PyDoc_STRVAR(getdlopenflags_doc,
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
570 "getdlopenflags() -> int\n\
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
571 \n\
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
572 Return the current value of the flags that are used for dlopen()\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
573 calls. The flag constants are defined in the dl module."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
574 );
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
575 #endif
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
576
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
577 #ifdef USE_MALLOPT
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
578 /* Link with -lmalloc (or -lmpc) on an SGI */
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
579 #include <malloc.h>
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
580
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
581 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
582 sys_mdebug(PyObject *self, PyObject *args)
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
583 {
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
584 int flag;
12136
9b9abde032b3 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
585 if (!PyArg_ParseTuple(args, "i:mdebug", &flag))
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
586 return NULL;
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
587 mallopt(M_DEBUG, flag);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
588 Py_INCREF(Py_None);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
589 return Py_None;
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
590 }
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
591 #endif /* USE_MALLOPT */
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
592
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
593 static PyObject *
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
594 sys_getrefcount(PyObject *self, PyObject *arg)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
595 {
36866
9eb24f92a784 Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents: 36837
diff changeset
596 return PyInt_FromSsize_t(arg->ob_refcnt);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
597 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
598
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
599 #ifdef Py_REF_DEBUG
12965
04c89d77dfdb Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents: 12877
diff changeset
600 static PyObject *
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
601 sys_gettotalrefcount(PyObject *self)
12965
04c89d77dfdb Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents: 12877
diff changeset
602 {
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
603 return PyInt_FromSsize_t(_Py_GetRefTotal());
12965
04c89d77dfdb Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents: 12877
diff changeset
604 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
605 #endif /* Py_REF_DEBUG */
12965
04c89d77dfdb Added a new debug method sys.gettotalrefcount(), which returns the total number of references on all Python objects. This is only enabled when Py_TRACE_REFS is defined (which includes default debug builds under Windows).
Mark Hammond <mhammond@skippinet.com.au>
parents: 12877
diff changeset
606
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
607 PyDoc_STRVAR(getrefcount_doc,
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
608 "getrefcount(object) -> integer\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
609 \n\
23947
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
610 Return the reference count of object. The count returned is generally\n\
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
611 one higher than you might expect, because it includes the (temporary)\n\
37118b6e5f46 Fix the docstring for sys.getrefcount().
Fred Drake <fdrake@acm.org>
parents: 23746
diff changeset
612 reference as an argument to getrefcount()."
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
613 );
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
614
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
615 #ifdef COUNT_ALLOCS
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
616 static PyObject *
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
617 sys_getcounts(PyObject *self)
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
618 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
619 extern PyObject *get_counts(void);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
620
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
621 return get_counts();
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
622 }
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
623 #endif
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
624
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
625 PyDoc_STRVAR(getframe_doc,
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
626 "_getframe([depth]) -> frameobject\n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
627 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
628 Return a frame object from the call stack. If optional integer depth is\n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
629 given, return the frame object that many calls below the top of the stack.\n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
630 If that is deeper than the call stack, ValueError is raised. The default\n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
631 for depth is zero, returning the frame at the top of the call stack.\n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
632 \n\
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
633 This function should be used for internal and specialized\n\
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
634 purposes only."
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
635 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
636
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
637 static PyObject *
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
638 sys_getframe(PyObject *self, PyObject *args)
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
639 {
31797
846b3ee7e106 Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents: 31796
diff changeset
640 PyFrameObject *f = PyThreadState_GET()->frame;
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
641 int depth = -1;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
642
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
643 if (!PyArg_ParseTuple(args, "|i:_getframe", &depth))
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
644 return NULL;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
645
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
646 while (depth > 0 && f != NULL) {
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
647 f = f->f_back;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
648 --depth;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
649 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
650 if (f == NULL) {
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
651 PyErr_SetString(PyExc_ValueError,
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
652 "call stack is not deep enough");
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
653 return NULL;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
654 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
655 Py_INCREF(f);
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
656 return (PyObject*)f;
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
657 }
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
658
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
659 PyDoc_STRVAR(call_tracing_doc,
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
660 "call_tracing(func, args) -> object\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
661 \n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
662 Call func(*args), while tracing is enabled. The tracing state is\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
663 saved, and restored afterwards. This is intended to be called from\n\
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
664 a debugger from a checkpoint, to recursively debug some other code."
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
665 );
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
666
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
667 static PyObject *
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
668 sys_call_tracing(PyObject *self, PyObject *args)
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
669 {
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
670 PyObject *func, *funcargs;
38669
19fd6141940d Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents: 37879
diff changeset
671 if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs))
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
672 return NULL;
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
673 return _PyEval_CallTracing(func, funcargs);
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
674 }
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
675
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
676 PyDoc_STRVAR(callstats_doc,
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
677 "callstats() -> tuple of integers\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
678 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
679 Return a tuple of function call statistics, if CALL_PROFILE was defined\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
680 when Python was built. Otherwise, return None.\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
681 \n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
682 When enabled, this function returns detailed, implementation-specific\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
683 details about the number of function calls executed. The return value is\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
684 a 11-tuple where the entries in the tuple are counts of:\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
685 0. all function calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
686 1. calls to PyFunction_Type objects\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
687 2. PyFunction calls that do not create an argument tuple\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
688 3. PyFunction calls that do not create an argument tuple\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
689 and bypass PyEval_EvalCodeEx()\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
690 4. PyMethod calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
691 5. PyMethod calls on bound methods\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
692 6. PyType calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
693 7. PyCFunction calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
694 8. generator calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
695 9. All other calls\n\
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
696 10. Number of stack pops performed by call_function()"
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
697 );
15487
f0ca4c67957b _getframe(): New sys module function for getting at the stack frame.
Barry Warsaw <barry@python.org>
parents: 14375
diff changeset
698
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
699 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
700 extern "C" {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
701 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
702
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
703 #ifdef Py_TRACE_REFS
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
704 /* Defined in objects.c because it uses static globals if that file */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
705 extern PyObject *_Py_GetObjects(PyObject *, PyObject *);
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
706 #endif
3609
0b0c4ed1936a rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents: 3585
diff changeset
707
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
708 #ifdef DYNAMIC_EXECUTION_PROFILE
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
709 /* Defined in ceval.c because it uses static globals if that file */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
710 extern PyObject *_Py_GetDXProfile(PyObject *, PyObject *);
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
711 #endif
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
712
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
713 #ifdef __cplusplus
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
714 }
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
715 #endif
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
716
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
717 static PyMethodDef sys_methods[] = {
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
718 /* Might as well keep this in alphabetic order */
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
719 {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
27712
16856c9514e0 Small function call optimization and special build option for call stats.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 27156
diff changeset
720 callstats_doc},
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
721 {"displayhook", sys_displayhook, METH_O, displayhook_doc},
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
722 {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
723 {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
724 {"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
22604
3f4b2f93e8b5 Change sys_exit to use METH_VARARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 22531
diff changeset
725 {"exit", sys_exit, METH_VARARGS, exit_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
726 #ifdef Py_USING_UNICODE
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
727 {"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
728 METH_NOARGS, getdefaultencoding_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
729 #endif
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
730 #ifdef HAVE_DLOPEN
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
731 {"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
732 getdlopenflags_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
733 #endif
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
734 #ifdef COUNT_ALLOCS
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
735 {"getcounts", (PyCFunction)sys_getcounts, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
736 #endif
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
737 #ifdef DYNAMIC_EXECUTION_PROFILE
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
738 {"getdxp", _Py_GetDXProfile, METH_VARARGS},
5047
7a9cac7cb910 Added optional interface for dynamic execution profile (to be gathered
Guido van Rossum <guido@python.org>
parents: 4904
diff changeset
739 #endif
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
740 #ifdef Py_USING_UNICODE
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
741 {"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
742 METH_NOARGS, getfilesystemencoding_doc},
28174
3f90d21debe9 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents: 28119
diff changeset
743 #endif
3585
4ed09a3c3201 TRACE_REFS -> Py_TRACE_REFS
Guido van Rossum <guido@python.org>
parents: 3490
diff changeset
744 #ifdef Py_TRACE_REFS
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
745 {"getobjects", _Py_GetObjects, METH_VARARGS},
24126
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
746 #endif
fdf80e04e4bb Rearranged and added comments to object.h, to clarify many things
Tim Peters <tim.peters@gmail.com>
parents: 24071
diff changeset
747 #ifdef Py_REF_DEBUG
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
748 {"gettotalrefcount", (PyCFunction)sys_gettotalrefcount, METH_NOARGS},
3024
54aa87b1ccee Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents: 2810
diff changeset
749 #endif
20655
7344687bf2c0 Convert getrefcount() to METH_O, and sys_excepthook() to use
Fred Drake <fdrake@acm.org>
parents: 20247
diff changeset
750 {"getrefcount", (PyCFunction)sys_getrefcount, METH_O, getrefcount_doc},
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
751 {"getrecursionlimit", (PyCFunction)sys_getrecursionlimit, METH_NOARGS,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
752 getrecursionlimit_doc},
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
753 {"_getframe", sys_getframe, METH_VARARGS, getframe_doc},
25666
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
754 #ifdef MS_WINDOWS
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
755 {"getwindowsversion", (PyCFunction)sys_getwindowsversion, METH_NOARGS,
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
756 getwindowsversion_doc},
4a825b902310 Add os.path.supports_unicode_filenames for all platforms,
Mark Hammond <mhammond@skippinet.com.au>
parents: 25108
diff changeset
757 #endif /* MS_WINDOWS */
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
758 #ifdef USE_MALLOPT
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
759 {"mdebug", sys_mdebug, METH_VARARGS},
1013
a1ce5a949828 Add an optional interface to turn malloc debugging on and off.
Guido van Rossum <guido@python.org>
parents: 901
diff changeset
760 #endif
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
761 #ifdef Py_USING_UNICODE
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
762 {"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
763 setdefaultencoding_doc},
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
764 #endif
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
765 {"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
766 setcheckinterval_doc},
29765
e9e5832d706f New function sys.getcheckinterval(), to complement setcheckinterval().
Tim Peters <tim.peters@gmail.com>
parents: 29065
diff changeset
767 {"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
768 getcheckinterval_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
769 #ifdef HAVE_DLOPEN
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
770 {"setdlopenflags", sys_setdlopenflags, METH_VARARGS,
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
771 setdlopenflags_doc},
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
772 #endif
22119
0859e764509e SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents: 21833
diff changeset
773 {"setprofile", sys_setprofile, METH_O, setprofile_doc},
19301
b9701538f827 Patch #427190: Implement and use METH_NOARGS and METH_O.
Martin v. Löwis <martin@v.loewis.de>
parents: 18805
diff changeset
774 {"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
775 setrecursionlimit_doc},
32301
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
776 #ifdef WITH_TSC
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
777 {"settscdump", sys_settscdump, METH_VARARGS, settscdump_doc},
41c59d80bbc5 Patch #510695: Add TSC profiling for the VM.
Martin v. Löwis <martin@v.loewis.de>
parents: 31797
diff changeset
778 #endif
22119
0859e764509e SF #506611, fix sys.setprofile(), sys.settrace() core dumps
Neal Norwitz <nnorwitz@gmail.com>
parents: 21833
diff changeset
779 {"settrace", sys_settrace, METH_O, settrace_doc},
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28174
diff changeset
780 {"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
781 {NULL, NULL} /* sentinel */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
782 };
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
783
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
784 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
785 list_builtin_module_names(void)
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
786 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
787 PyObject *list = PyList_New(0);
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
788 int i;
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
789 if (list == NULL)
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
790 return NULL;
6550
f406ec35bfca Get rid of another reference to _PyImport_Inittab (now a static array)
Guido van Rossum <guido@python.org>
parents: 6352
diff changeset
791 for (i = 0; PyImport_Inittab[i].name != NULL; i++) {
5405
b7871ca930ad Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents: 5377
diff changeset
792 PyObject *name = PyString_FromString(
6550
f406ec35bfca Get rid of another reference to _PyImport_Inittab (now a static array)
Guido van Rossum <guido@python.org>
parents: 6352
diff changeset
793 PyImport_Inittab[i].name);
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
794 if (name == NULL)
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
795 break;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
796 PyList_Append(list, name);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
797 Py_DECREF(name);
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
798 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
799 if (PyList_Sort(list) != 0) {
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
800 Py_DECREF(list);
1848
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
801 list = NULL;
b724599401ff Merge back to main trunk
Guido van Rossum <guido@python.org>
parents: 1198
diff changeset
802 }
4904
5dc20a9e0506 Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
803 if (list) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
804 PyObject *v = PyList_AsTuple(list);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
805 Py_DECREF(list);
4904
5dc20a9e0506 Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
806 list = v;
5dc20a9e0506 Make builtin_module_names a tuple instead of a list.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
807 }
1198
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
808 return list;
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
809 }
2937897a7d8b * Added Fixcprt.py: script to fix copyright message.
Guido van Rossum <guido@python.org>
parents: 1073
diff changeset
810
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
811 static PyObject *warnoptions = NULL;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
812
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
813 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
814 PySys_ResetWarnOptions(void)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
815 {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
816 if (warnoptions == NULL || !PyList_Check(warnoptions))
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
817 return;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
818 PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
819 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
820
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
821 void
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
822 PySys_AddWarnOption(char *s)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
823 {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
824 PyObject *str;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
825
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
826 if (warnoptions == NULL || !PyList_Check(warnoptions)) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
827 Py_XDECREF(warnoptions);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
828 warnoptions = PyList_New(0);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
829 if (warnoptions == NULL)
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
830 return;
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
831 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
832 str = PyString_FromString(s);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
833 if (str != NULL) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
834 PyList_Append(warnoptions, str);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
835 Py_DECREF(str);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
836 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
837 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
838
8840
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
839 /* XXX This doc string is too long to be a single string literal in VC++ 5.0.
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
840 Two literals concatenated works just fine. If you have a K&R compiler
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
841 or other abomination that however *does* understand longer strings,
44baef8ab5c8 Gack. The module doc string is too long for VC++ 5.0.
Guido van Rossum <guido@python.org>
parents: 8566
diff changeset
842 get rid of the !!! comment in the middle and the quotes that surround it. */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
843 PyDoc_VAR(sys_doc) =
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
844 PyDoc_STR(
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
845 "This module provides access to some objects used or maintained by the\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
846 interpreter and to functions that interact strongly with the interpreter.\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
847 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
848 Dynamic objects:\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
849 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
850 argv -- command line arguments; argv[0] is the script pathname if known\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
851 path -- module search path; path[0] is the script directory, else ''\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
852 modules -- dictionary of loaded modules\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
853 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
854 displayhook -- called to show results in an interactive session\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
855 excepthook -- called to handle any uncaught exception other than SystemExit\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
856 To customize printing in an interactive session or to install a custom\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
857 top-level exception handler, assign other functions to replace these.\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
858 \n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
859 exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
860 Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
861 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
862 stdin -- standard input file object; used by raw_input() and input()\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
863 stdout -- standard output file object; used by the print statement\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
864 stderr -- standard error object; used for error messages\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
865 By assigning other file objects (or objects that behave like files)\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
866 to these, it is possible to redirect all of the interpreter's I/O.\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
867 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
868 last_type -- type of last uncaught exception\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
869 last_value -- value of last uncaught exception\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
870 last_traceback -- traceback of last uncaught exception\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
871 These three are only available in an interactive session after a\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
872 traceback has been printed.\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
873 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
874 exc_type -- type of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
875 exc_value -- value of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
876 exc_traceback -- traceback of exception currently being handled\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
877 The function exc_info() should be used instead of these three,\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
878 because it is thread-safe.\n\
9885
030ee50bd8d1 Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents: 9746
diff changeset
879 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
880 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
881 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
882 PyDoc_STR(
9885
030ee50bd8d1 Jim Ahlstrom patch: the module doc string is too long for 16-bit VC
Guido van Rossum <guido@python.org>
parents: 9746
diff changeset
883 "\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
884 Static objects:\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
885 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
886 maxint -- the largest supported integer (the smallest is -maxint-1)\n\
18298
982163c4e9d2 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents: 18136
diff changeset
887 maxunicode -- the largest supported character\n\
21833
070d392042e3 Fix spelling mistakes. Bugfix candidates.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21712
diff changeset
888 builtin_module_names -- tuple of module names built into this interpreter\n\
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
889 version -- the version of this interpreter as a string\n\
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
890 version_info -- version information as a tuple\n\
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
891 hexversion -- version information encoded as a single integer\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
892 copyright -- copyright notice pertaining to this interpreter\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
893 platform -- platform identifier\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
894 executable -- pathname of this Python interpreter\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
895 prefix -- prefix used to find the Python library\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
896 exec_prefix -- prefix used to find the machine-specific Python library\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
897 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
898 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
899 #ifdef MS_WINDOWS
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
900 /* concatenating string here */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
901 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
902 "dllhandle -- [Windows only] integer handle of the Python DLL\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
903 winver -- [Windows only] version number of the Python DLL\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
904 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
905 )
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
906 #endif /* MS_WINDOWS */
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
907 PyDoc_STR(
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
908 "__stdin__ -- the original stdin; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
909 __stdout__ -- the original stdout; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
910 __stderr__ -- the original stderr; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
911 __displayhook__ -- the original displayhook; don't touch!\n\
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
912 __excepthook__ -- the original excepthook; don't touch!\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
913 \n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
914 Functions:\n\
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
915 \n\
15811
1a00d21910c8 Implementation of PEP-0217.
Moshe Zadka <moshez@math.huji.ac.il>
parents: 15595
diff changeset
916 displayhook() -- print an object to the screen, and save it in __builtin__._\n\
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
917 excepthook() -- print an exception and its traceback to sys.stderr\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
918 exc_info() -- return thread-safe information about the current exception\n\
28119
869695cba2cd - New function sys.exc_clear() clears the current exception. This is
Guido van Rossum <guido@python.org>
parents: 27977
diff changeset
919 exc_clear() -- clear the exception state for the current thread\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
920 exit() -- exit the interpreter by raising SystemExit\n\
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
921 getdlopenflags() -- returns flags to be used for dlopen() calls\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
922 getrefcount() -- return the reference count for an object (plus one :-)\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
923 getrecursionlimit() -- return the max recursion depth for the interpreter\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
924 setcheckinterval() -- control how often the interpreter checks for events\n\
18689
064de84385ca Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Martin v. Löwis <martin@v.loewis.de>
parents: 18326
diff changeset
925 setdlopenflags() -- set the flags to be used for dlopen() calls\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
926 setprofile() -- set the global profiling function\n\
14308
b8b3f76ffd51 add user-modifiable recursion_limit
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14295
diff changeset
927 setrecursionlimit() -- set the max recursion depth for the interpreter\n\
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
928 settrace() -- set the global debug tracing function\n\
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
929 "
23746
43ddcdcd3c71 Patch #505375: Make doc strings optional.
Martin v. Löwis <martin@v.loewis.de>
parents: 22604
diff changeset
930 )
13971
aa4202702252 The attempt to protect against MS_WIN16 compilers that do not support long
Fred Drake <fdrake@acm.org>
parents: 13968
diff changeset
931 /* end of sys_doc */ ;
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
932
34483
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
933 static int
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
934 _check_and_flush (FILE *stream)
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
935 {
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
936 int prev_fail = ferror (stream);
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
937 return fflush (stream) || prev_fail ? EOF : 0;
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
938 }
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
939
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
940 /* Subversion branch and revision management */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
941 static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
942 static const char headurl[] = "$HeadURL$";
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
943 static int svn_initialized;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
944 static char patchlevel_revision[50]; /* Just the number */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
945 static char branch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
946 static char shortbranch[50];
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
947 static const char *svn_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
948
36212
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
949 static void
cee05980f1fd svnversion_init(): Use standard layout for function defn.
Tim Peters <tim.peters@gmail.com>
parents: 36211
diff changeset
950 svnversion_init(void)
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
951 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
952 const char *python, *br_start, *br_end, *br_end2, *svnversion;
36521
30aef3ce2b26 Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
953 Py_ssize_t len;
30aef3ce2b26 Use Py_ssize_t to count the
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
954 int istag;
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
955
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
956 if (svn_initialized)
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
957 return;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
958
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
959 python = strstr(headurl, "/python/");
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
960 if (!python)
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
961 Py_FatalError("subversion keywords missing");
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
962
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
963 br_start = python + 8;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
964 br_end = strchr(br_start, '/');
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
965 /* Works even for trunk,
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
966 as we are in trunk/Python/sysmodule.c */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
967 br_end2 = strchr(br_end+1, '/');
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
968
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
969 istag = strncmp(br_start, "tags", 4) == 0;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
970 if (strncmp(br_start, "trunk", 5) == 0) {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
971 strcpy(branch, "trunk");
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
972 strcpy(shortbranch, "trunk");
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
973
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
974 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
975 else if (istag || strncmp(br_start, "branches", 8) == 0) {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
976 len = br_end2 - br_start;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
977 strncpy(branch, br_start, len);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
978 branch[len] = '\0';
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
979
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
980 len = br_end2 - (br_end + 1);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
981 strncpy(shortbranch, br_end + 1, len);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
982 shortbranch[len] = '\0';
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
983 }
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
984 else {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
985 Py_FatalError("bad HeadURL");
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
986 return;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
987 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
988
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
989
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
990 svnversion = _Py_svnversion();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
991 if (strcmp(svnversion, "exported") != 0)
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
992 svn_revision = svnversion;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
993 else if (istag) {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
994 len = strlen(_patchlevel_revision);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
995 strncpy(patchlevel_revision, _patchlevel_revision + 11,
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
996 len - 13);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
997 patchlevel_revision[len - 13] = '\0';
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
998 svn_revision = patchlevel_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
999 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1000 else
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1001 svn_revision = "";
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1002
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1003 svn_initialized = 1;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1004 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1005
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1006 /* Return svnversion output if available.
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1007 Else return Revision of patchlevel.h if on branch.
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1008 Else return empty string */
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1009 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1010 Py_SubversionRevision()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1011 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1012 svnversion_init();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1013 return svn_revision;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1014 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1015
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1016 const char*
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1017 Py_SubversionShortBranch()
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1018 {
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1019 svnversion_init();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1020 return shortbranch;
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1021 }
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1022
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1023 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1024 _PySys_Init(void)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1025 {
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1026 PyObject *m, *v, *sysdict;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1027 PyObject *sysin, *sysout, *syserr;
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1028 char *s;
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1029 #ifdef MS_WINDOWS
38673
a19c20c5e5c7 Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents: 38669
diff changeset
1030 char buf[128];
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1031 #endif
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1032
8566
6e8b0e754a7f Added doc strings. Maybe the doc string for the module itself is a bit
Guido van Rossum <guido@python.org>
parents: 8314
diff changeset
1033 m = Py_InitModule3("sys", sys_methods, sys_doc);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36212
diff changeset
1034 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36212
diff changeset
1035 return NULL;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1036 sysdict = PyModule_GetDict(m);
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1037
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1038 {
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1039 /* XXX: does this work on Win/Win64? (see posix_fstat) */
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1040 struct stat sb;
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1041 if (fstat(fileno(stdin), &sb) == 0 &&
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1042 S_ISDIR(sb.st_mode)) {
36910
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1043 /* There's nothing more we can do. */
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1044 /* Py_FatalError() will core dump, so just exit. */
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1045 PySys_WriteStderr("Python error: <stdin> is a directory, cannot continue\n");
91a9e2e31e93 Try to be a bit more consistent on all platforms:
Neal Norwitz <nnorwitz@gmail.com>
parents: 36866
diff changeset
1046 exit(EXIT_FAILURE);
35673
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1047 }
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1048 }
612a12178e47 SF bug #887946, segfault if redirecting directory
Neal Norwitz <nnorwitz@gmail.com>
parents: 35572
diff changeset
1049
34511
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1050 /* Closing the standard FILE* if sys.std* goes aways causes problems
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1051 * for embedded Python usages. Closing them when somebody explicitly
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1052 * invokes .close() might be possible, but the FAQ promises they get
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1053 * never closed. However, we still need to get write errors when
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1054 * writing fails (e.g. because stdout is redirected), so we flush the
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1055 * streams and check for errors before the file objects are deleted.
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1056 * On OS X, fflush()ing stdin causes an error, so we exempt stdin
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1057 * from that procedure.
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1058 */
91038801eb45 Partially revert #1074011; don't try to fflush stdin.
Martin v. Löwis <martin@v.loewis.de>
parents: 34483
diff changeset
1059 sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
34483
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1060 sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
4a1fefdfc793 Flush std{in,out,err} before closing it. Fixes #1074011.
Martin v. Löwis <martin@v.loewis.de>
parents: 33104
diff changeset
1061 syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1062 if (PyErr_Occurred())
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1063 return NULL;
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1064 #ifdef MS_WINDOWS
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1065 if(isatty(_fileno(stdin))){
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1066 sprintf(buf, "cp%d", GetConsoleCP());
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1067 if (!PyFile_SetEncoding(sysin, buf))
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1068 return NULL;
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1069 }
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1070 if(isatty(_fileno(stdout))) {
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1071 sprintf(buf, "cp%d", GetConsoleOutputCP());
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1072 if (!PyFile_SetEncoding(sysout, buf))
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1073 return NULL;
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1074 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1075 if(isatty(_fileno(stderr))) {
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1076 sprintf(buf, "cp%d", GetConsoleOutputCP());
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1077 if (!PyFile_SetEncoding(syserr, buf))
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1078 return NULL;
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1079 }
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1080 #endif
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 28949
diff changeset
1081
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1082 PyDict_SetItemString(sysdict, "stdin", sysin);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1083 PyDict_SetItemString(sysdict, "stdout", sysout);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1084 PyDict_SetItemString(sysdict, "stderr", syserr);
7402
c7454ca7d3ac Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents: 6550
diff changeset
1085 /* Make backup copies for cleanup */
c7454ca7d3ac Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents: 6550
diff changeset
1086 PyDict_SetItemString(sysdict, "__stdin__", sysin);
c7454ca7d3ac Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents: 6550
diff changeset
1087 PyDict_SetItemString(sysdict, "__stdout__", sysout);
c7454ca7d3ac Make backup copies of stdin, stdout, stderr as __stdin__, __stdout__,
Guido van Rossum <guido@python.org>
parents: 6550
diff changeset
1088 PyDict_SetItemString(sysdict, "__stderr__", syserr);
17164
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1089 PyDict_SetItemString(sysdict, "__displayhook__",
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1090 PyDict_GetItemString(sysdict, "displayhook"));
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1091 PyDict_SetItemString(sysdict, "__excepthook__",
b44e77a12978 Add sys.excepthook.
Ka-Ping Yee <ping@zesty.ca>
parents: 15846
diff changeset
1092 PyDict_GetItemString(sysdict, "excepthook"));
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1093 Py_XDECREF(sysin);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1094 Py_XDECREF(sysout);
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1095 Py_XDECREF(syserr);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1096 PyDict_SetItemString(sysdict, "version",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1097 v = PyString_FromString(Py_GetVersion()));
9964
d44cb87e500d _PySys_Init(): Nailed small memory leak. The stringobject created for
Barry Warsaw <barry@python.org>
parents: 9885
diff changeset
1098 Py_XDECREF(v);
9746
9342c60eaac0 Add sys.hexversion, which is an integer encoding the version in hexadecimal.
Guido van Rossum <guido@python.org>
parents: 9328
diff changeset
1099 PyDict_SetItemString(sysdict, "hexversion",
9342c60eaac0 Add sys.hexversion, which is an integer encoding the version in hexadecimal.
Guido van Rossum <guido@python.org>
parents: 9328
diff changeset
1100 v = PyInt_FromLong(PY_VERSION_HEX));
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1101 Py_XDECREF(v);
36207
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1102 svnversion_init();
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1103 v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
825a041813fb Drop sys.build_number. Add sys.subversion.
Martin v. Löwis <martin@v.loewis.de>
parents: 36070
diff changeset
1104 PyDict_SetItemString(sysdict, "subversion", v);
36070
9697eeeaf246 Expose Subversion revision number (calculated via "svnversion .") to Python.
Barry Warsaw <barry@python.org>
parents: 35742
diff changeset
1105 Py_XDECREF(v);
12396
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1106 /*
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1107 * These release level checks are mutually exclusive and cover
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1108 * the field, so don't get too fancy with the pre-processor!
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1109 */
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1110 #if PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_ALPHA
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1111 s = "alpha";
14295
e5253b692e9f _PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents: 14017
diff changeset
1112 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_BETA
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1113 s = "beta";
14295
e5253b692e9f _PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents: 14017
diff changeset
1114 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_GAMMA
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1115 s = "candidate";
14295
e5253b692e9f _PySys_Init(): When setting up sys.version_info, use #if/#elif.../#endif
Fred Drake <fdrake@acm.org>
parents: 14017
diff changeset
1116 #elif PY_RELEASE_LEVEL == PY_RELEASE_LEVEL_FINAL
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1117 s = "final";
12396
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1118 #endif
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1119 PyDict_SetItemString(sysdict, "version_info",
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1120 v = Py_BuildValue("iiisi", PY_MAJOR_VERSION,
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1121 PY_MINOR_VERSION,
12398
2392d10e21f1 Simplify creation of the version_info value for clarity, per
Fred Drake <fdrake@acm.org>
parents: 12396
diff changeset
1122 PY_MICRO_VERSION, s,
12396
f82b2577fa0c Capitulate, changing version_info to a 5-tuple:
Fred Drake <fdrake@acm.org>
parents: 12394
diff changeset
1123 PY_RELEASE_SERIAL));
12394
60dd95c75999 Define version_info to be a tuple (major, minor, micro, level); level
Fred Drake <fdrake@acm.org>
parents: 12136
diff changeset
1124 Py_XDECREF(v);
25099
a69a12484d69 expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents: 24126
diff changeset
1125 PyDict_SetItemString(sysdict, "api_version",
a69a12484d69 expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents: 24126
diff changeset
1126 v = PyInt_FromLong(PYTHON_API_VERSION));
a69a12484d69 expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456.
Skip Montanaro <skip@pobox.com>
parents: 24126
diff changeset
1127 Py_XDECREF(v);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1128 PyDict_SetItemString(sysdict, "copyright",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1129 v = PyString_FromString(Py_GetCopyright()));
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1130 Py_XDECREF(v);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1131 PyDict_SetItemString(sysdict, "platform",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1132 v = PyString_FromString(Py_GetPlatform()));
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1133 Py_XDECREF(v);
5598
1f206c91daee Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents: 5550
diff changeset
1134 PyDict_SetItemString(sysdict, "executable",
1f206c91daee Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents: 5550
diff changeset
1135 v = PyString_FromString(Py_GetProgramFullPath()));
1f206c91daee Set sys.executable to full path of python (from argv[0]).
Guido van Rossum <guido@python.org>
parents: 5550
diff changeset
1136 Py_XDECREF(v);
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1137 PyDict_SetItemString(sysdict, "prefix",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1138 v = PyString_FromString(Py_GetPrefix()));
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1139 Py_XDECREF(v);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1140 PyDict_SetItemString(sysdict, "exec_prefix",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1141 v = PyString_FromString(Py_GetExecPrefix()));
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1142 Py_XDECREF(v);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1143 PyDict_SetItemString(sysdict, "maxint",
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1144 v = PyInt_FromLong(PyInt_GetMax()));
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1145 Py_XDECREF(v);
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
1146 #ifdef Py_USING_UNICODE
18298
982163c4e9d2 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents: 18136
diff changeset
1147 PyDict_SetItemString(sysdict, "maxunicode",
982163c4e9d2 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents: 18136
diff changeset
1148 v = PyInt_FromLong(PyUnicode_GetMax()));
982163c4e9d2 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Martin v. Löwis <martin@v.loewis.de>
parents: 18136
diff changeset
1149 Py_XDECREF(v);
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 19301
diff changeset
1150 #endif
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1151 PyDict_SetItemString(sysdict, "builtin_module_names",
2052
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1848
diff changeset
1152 v = list_builtin_module_names());
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1153 Py_XDECREF(v);
13968
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1154 {
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1155 /* Assumes that longs are at least 2 bytes long.
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1156 Should be safe! */
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1157 unsigned long number = 1;
13977
eb9a36163a9e Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents: 13971
diff changeset
1158 char *value;
13968
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1159
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1160 s = (char *) &number;
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1161 if (s[0] == 0)
13977
eb9a36163a9e Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents: 13971
diff changeset
1162 value = "big";
13968
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1163 else
13977
eb9a36163a9e Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents: 13971
diff changeset
1164 value = "little";
eb9a36163a9e Guido pointed out that all names in the sys module have no underscore,
Fred Drake <fdrake@acm.org>
parents: 13971
diff changeset
1165 PyDict_SetItemString(sysdict, "byteorder",
14017
128f641191c3 _PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents: 13977
diff changeset
1166 v = PyString_FromString(value));
128f641191c3 _PySys_Init(): Fix another Insure discovered memory leak; the PyString
Barry Warsaw <barry@python.org>
parents: 13977
diff changeset
1167 Py_XDECREF(v);
13968
841cf9012ac3 Add a byte_order value to the sys module. The value is "big" for
Fred Drake <fdrake@acm.org>
parents: 13694
diff changeset
1168 }
4126
c80c515999b9 Use MS_DLL_ID as sys.winver
Guido van Rossum <guido@python.org>
parents: 3877
diff changeset
1169 #ifdef MS_COREDLL
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1170 PyDict_SetItemString(sysdict, "dllhandle",
13096
8c8de5b736dc Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents: 12965
diff changeset
1171 v = PyLong_FromVoidPtr(PyWin_DLLhModule));
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1172 Py_XDECREF(v);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1173 PyDict_SetItemString(sysdict, "winver",
6352
b62a7a59414e Get DLL version from a variable.
Guido van Rossum <guido@python.org>
parents: 5955
diff changeset
1174 v = PyString_FromString(PyWin_DLLVersionString));
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1175 Py_XDECREF(v);
3490
1dfc519ea3cb Under NT, define sys.dllhandle and sys.winver (Mark H.).
Guido van Rossum <guido@python.org>
parents: 3326
diff changeset
1176 #endif
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1177 if (warnoptions == NULL) {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1178 warnoptions = PyList_New(0);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1179 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1180 else {
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1181 Py_INCREF(warnoptions);
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1182 }
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1183 if (warnoptions != NULL) {
15846
d41f9b0a40ca Neil discovered a bad DECREF on warnoptions, that caused repeated
Guido van Rossum <guido@python.org>
parents: 15812
diff changeset
1184 PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
15595
0f42f6669e80 Add definitions for PySys_ResetWarnOptions() and
Guido van Rossum <guido@python.org>
parents: 15487
diff changeset
1185 }
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1186
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1187 if (PyErr_Occurred())
5926
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1188 return NULL;
8d2194e22e67 The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
1189 return m;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1190 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1191
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1192 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1193 makepathobject(char *path, int delim)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1194 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1195 int i, n;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1196 char *p;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1197 PyObject *v, *w;
36211
6d743e5baf14 Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 36207
diff changeset
1198
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1199 n = 1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1200 p = path;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1201 while ((p = strchr(p, delim)) != NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1202 n++;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1203 p++;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1204 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1205 v = PyList_New(n);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1206 if (v == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1207 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1208 for (i = 0; ; i++) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1209 p = strchr(path, delim);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1210 if (p == NULL)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1211 p = strchr(path, '\0'); /* End of string */
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1212 w = PyString_FromStringAndSize(path, (int) (p - path));
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1213 if (w == NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1214 Py_DECREF(v);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1215 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1216 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1217 PyList_SetItem(v, i, w);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1218 if (*p == '\0')
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1219 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1220 path = p+1;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1221 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1222 return v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1223 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1224
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1225 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1226 PySys_SetPath(char *path)
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1227 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1228 PyObject *v;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1229 if ((v = makepathobject(path, DELIM)) == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1230 Py_FatalError("can't create sys.path");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1231 if (PySys_SetObject("path", v) != 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1232 Py_FatalError("can't assign sys.path");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1233 Py_DECREF(v);
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1234 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1235
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1236 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1237 makeargvobject(int argc, char **argv)
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1238 {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1239 PyObject *av;
596
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1240 if (argc <= 0 || argv == NULL) {
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1241 /* Ensure at least one (empty) argument is seen */
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1242 static char *empty_argv[1] = {""};
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1243 argv = empty_argv;
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1244 argc = 1;
e18f1fa398a3 Ensure that sys.argv[0] always exists (maybe as empty string).
Guido van Rossum <guido@python.org>
parents: 549
diff changeset
1245 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1246 av = PyList_New(argc);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1247 if (av != NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1248 int i;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1249 for (i = 0; i < argc; i++) {
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1250 #ifdef __VMS
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1251 PyObject *v;
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1252
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1253 /* argv[0] is the script pathname if known */
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1254 if (i == 0) {
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1255 char* fn = decc$translate_vms(argv[0]);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1256 if ((fn == (char *)0) || fn == (char *)-1)
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1257 v = PyString_FromString(argv[0]);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1258 else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1259 v = PyString_FromString(
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1260 decc$translate_vms(argv[0]));
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1261 } else
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1262 v = PyString_FromString(argv[i]);
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1263 #else
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1264 PyObject *v = PyString_FromString(argv[i]);
28949
ac487a7f7f2c Patch #708495: Port more stuff to OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 28556
diff changeset
1265 #endif
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1266 if (v == NULL) {
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1267 Py_DECREF(av);
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1268 av = NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1269 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1270 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1271 PyList_SetItem(av, i, v);
83
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1272 }
f6bcf3c1d714 Empty all modules' symbol tables, so most circular references are
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1273 }
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1274 return av;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1275 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1276
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1277 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1278 PySys_SetArgv(int argc, char **argv)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1279 {
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1280 #if defined(HAVE_REALPATH)
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1281 char fullpath[MAXPATHLEN];
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1282 #elif defined(MS_WINDOWS)
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1283 char fullpath[MAX_PATH];
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1284 #endif
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1285 PyObject *av = makeargvobject(argc, argv);
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1286 PyObject *path = PySys_GetObject("path");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 83
diff changeset
1287 if (av == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1288 Py_FatalError("no mem for sys.argv");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1289 if (PySys_SetObject("argv", av) != 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1290 Py_FatalError("can't assign sys.argv");
3877
408e374934e5 Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents: 3806
diff changeset
1291 if (path != NULL) {
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1292 char *argv0 = argv[0];
3877
408e374934e5 Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents: 3806
diff changeset
1293 char *p = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
1294 Py_ssize_t n = 0;
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1295 PyObject *a;
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1296 #ifdef HAVE_READLINK
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1297 char link[MAXPATHLEN+1];
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1298 char argv0copy[2*MAXPATHLEN+1];
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1299 int nr = 0;
35572
1b25fe8834ae patch [ 1119423 ] python -c readlink()s and stat()s '-c'
Georg Brandl <georg@python.org>
parents: 34511
diff changeset
1300 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0)
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1301 nr = readlink(argv0, link, MAXPATHLEN);
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1302 if (nr > 0) {
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1303 /* It's a symlink */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1304 link[nr] = '\0';
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1305 if (link[0] == SEP)
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1306 argv0 = link; /* Link to absolute path */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1307 else if (strchr(link, SEP) == NULL)
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1308 ; /* Link without path */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1309 else {
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1310 /* Must join(dirname(argv0), link) */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1311 char *q = strrchr(argv0, SEP);
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1312 if (q == NULL)
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1313 argv0 = link; /* argv0 without path */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1314 else {
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1315 /* Must make a copy */
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1316 strcpy(argv0copy, argv0);
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1317 q = strrchr(argv0copy, SEP);
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1318 strcpy(q+1, link);
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1319 argv0 = argv0copy;
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1320 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1321 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1322 }
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1323 #endif /* HAVE_READLINK */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1324 #if SEP == '\\' /* Special case for MS filename syntax */
35572
1b25fe8834ae patch [ 1119423 ] python -c readlink()s and stat()s '-c'
Georg Brandl <georg@python.org>
parents: 34511
diff changeset
1325 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1326 char *q;
27156
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1327 #ifdef MS_WINDOWS
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1328 char *ptemp;
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1329 if (GetFullPathName(argv0,
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1330 sizeof(fullpath),
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1331 fullpath,
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1332 &ptemp)) {
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1333 argv0 = fullpath;
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1334 }
585a6460f577 Patch #664376: sys.path[0] should contain absolute pathname.
Thomas Heller <theller@ctypes.org>
parents: 25666
diff changeset
1335 #endif
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1336 p = strrchr(argv0, SEP);
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1337 /* Test for alternate separator */
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1338 q = strrchr(p ? p : argv0, '/');
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1339 if (q != NULL)
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1340 p = q;
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1341 if (p != NULL) {
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1342 n = p + 1 - argv0;
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1343 if (n > 1 && p[-1] != ':')
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1344 n--; /* Drop trailing separator */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1345 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1346 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1347 #else /* All other filename syntaxes */
35572
1b25fe8834ae patch [ 1119423 ] python -c readlink()s and stat()s '-c'
Georg Brandl <georg@python.org>
parents: 34511
diff changeset
1348 if (argc > 0 && argv0 != NULL && strcmp(argv0, "-c") != 0) {
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1349 #if defined(HAVE_REALPATH)
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1350 if (realpath(argv0, fullpath)) {
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1351 argv0 = fullpath;
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1352 }
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1353 #endif
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1354 p = strrchr(argv0, SEP);
27977
0fe321e78ad3 - sys.path[0] (the directory from which the script is loaded) is now
Guido van Rossum <guido@python.org>
parents: 27712
diff changeset
1355 }
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1356 if (p != NULL) {
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1357 #ifndef RISCOS
5340
db673e98f28d Expand one level of symbolic link in sys.argv[0] before inserting its
Guido van Rossum <guido@python.org>
parents: 5047
diff changeset
1358 n = p + 1 - argv0;
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1359 #else /* don't include trailing separator */
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1360 n = p - argv0;
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17164
diff changeset
1361 #endif /* RISCOS */
4256
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1362 #if SEP == '/' /* Special case for Unix filename syntax */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1363 if (n > 1)
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1364 n--; /* Drop trailing separator */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1365 #endif /* Unix */
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1366 }
e225e70fd657 Changes to setpythonpath():
Guido van Rossum <guido@python.org>
parents: 4126
diff changeset
1367 #endif /* All others */
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1368 a = PyString_FromStringAndSize(argv0, n);
3877
408e374934e5 Always insert script directory in front of sys.path -- if there's no
Guido van Rossum <guido@python.org>
parents: 3806
diff changeset
1369 if (a == NULL)
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1370 Py_FatalError("no mem for sys.path insertion");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1371 if (PyList_Insert(path, 0, a) < 0)
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1372 Py_FatalError("sys.path.insert(0) failed");
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1373 Py_DECREF(a);
3806
93868c7a15c9 As a side effect of calling PySys_SetArgv (setpythonargv), the
Guido van Rossum <guido@python.org>
parents: 3738
diff changeset
1374 }
5372
424922afc1bb Quickly renamed.
Guido van Rossum <guido@python.org>
parents: 5340
diff changeset
1375 Py_DECREF(av);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1376 }
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1377
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1378
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1379 /* APIs to write to sys.stdout or sys.stderr using a printf-like interface.
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1380 Adapted from code submitted by Just van Rossum.
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1381
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1382 PySys_WriteStdout(format, ...)
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1383 PySys_WriteStderr(format, ...)
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1384
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1385 The first function writes to sys.stdout; the second to sys.stderr. When
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1386 there is a problem, they write to the real (C level) stdout or stderr;
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1387 no exceptions are raised.
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1388
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1389 Both take a printf-style format string as their first argument followed
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1390 by a variable length argument list determined by the format string.
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1391
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1392 *** WARNING ***
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1393
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1394 The format should limit the total size of the formatted output string to
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1395 1000 bytes. In particular, this means that no unrestricted "%s" formats
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1396 should occur; these should be limited using "%.<N>s where <N> is a
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1397 decimal number calculated so that <N> plus the maximum size of other
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1398 formatted text does not exceed 1000 bytes. Also watch out for "%f",
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1399 which can print hundreds of digits for very large numbers.
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1400
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1401 */
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1402
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1403 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
1404 mywrite(char *name, FILE *fp, const char *format, va_list va)
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1405 {
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1406 PyObject *file;
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1407 PyObject *error_type, *error_value, *error_traceback;
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1408
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1409 PyErr_Fetch(&error_type, &error_value, &error_traceback);
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1410 file = PySys_GetObject(name);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1411 if (file == NULL || PyFile_AsFile(file) == fp)
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1412 vfprintf(fp, format, va);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1413 else {
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1414 char buffer[1001];
21127
dd28a4ecb37f mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
Tim Peters <tim.peters@gmail.com>
parents: 21091
diff changeset
1415 const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
dd28a4ecb37f mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
Tim Peters <tim.peters@gmail.com>
parents: 21091
diff changeset
1416 format, va);
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1417 if (PyFile_WriteString(buffer, file) != 0) {
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1418 PyErr_Clear();
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1419 fputs(buffer, fp);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1420 }
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 37042
diff changeset
1421 if (written < 0 || (size_t)written >= sizeof(buffer)) {
21091
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1422 const char *truncated = "... truncated";
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1423 if (PyFile_WriteString(truncated, file) != 0) {
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1424 PyErr_Clear();
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1425 fputs(truncated, fp);
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1426 }
47f6533674fd Use PyOS_vsnprintf() and check its return value.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20943
diff changeset
1427 }
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1428 }
9328
81574e4646b4 Patches for mywrite() by Marc Lemburg: save/restore the error state
Guido van Rossum <guido@python.org>
parents: 8840
diff changeset
1429 PyErr_Restore(error_type, error_value, error_traceback);
8314
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1430 }
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1431
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1432 void
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1433 PySys_WriteStdout(const char *format, ...)
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1434 {
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1435 va_list va;
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1436
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1437 va_start(va, format);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1438 mywrite("stdout", stdout, format, va);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1439 va_end(va);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1440 }
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1441
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1442 void
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1443 PySys_WriteStderr(const char *format, ...)
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1444 {
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1445 va_list va;
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1446
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1447 va_start(va, format);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1448 mywrite("stderr", stderr, format, va);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1449 va_end(va);
f94d5ae642a9 New APIs to write to sys.stdout or sys.stderr using a printf-like interface.
Guido van Rossum <guido@python.org>
parents: 7402
diff changeset
1450 }