summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
Commit message (Collapse)AuthorAgeFilesLines
* Missing DECREFs when exception is raised in sys.excepthook.Jeremy Hylton2001-12-071-0/+3
| | | | | | | Bug fix candidate for 2.1 branch. (I imagine the other recent leak patches are bug fix candidates, too, but I forgot to mark mine as such.)
* SF bug #488514: -Qnew needs workTim Peters2001-12-061-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Big Hammer to implement -Qnew as PEP 238 says it should work (a global option affecting all instances of "/"). pydebug.h, main.c, pythonrun.c: define a private _Py_QnewFlag flag, true iff -Qnew is passed on the command line. This should go away (as the comments say) when true division becomes The Rule. This is deliberately not exposed to runtime inspection or modification: it's a one-way one-shot switch to pretend you're using Python 3. ceval.c: when _Py_QnewFlag is set, treat BINARY_DIVIDE as BINARY_TRUE_DIVIDE. test_{descr, generators, zipfile}.py: fiddle so these pass under -Qnew too. This was just a matter of s!/!//! in test_generators and test_zipfile. test_descr was trickier, as testbinop() is passed assumptions that "/" is the same as calling a "__div__" method; put a temporary hack there to call "__truediv__" instead when the method name is "__div__" and 1/2 evaluates to 0.5. Three standard tests still fail under -Qnew (on Windows; somebody please try the Linux tests with -Qnew too! Linux runs a whole bunch of tests Windows doesn't): test_augassign test_class test_coercion I can't stay awake longer to stare at this (be my guest). Offhand cures weren't obvious, nor was it even obvious that cures are possible without major hackery. Question: when -Qnew is in effect, should calls to __div__ magically change into calls to __truediv__? See "major hackery" at tail end of last paragraph <wink>.
* Use PyOS_snprintf instead of sprintf.Jeremy Hylton2001-11-281-1/+1
|
* PyOS_getsig(), PyOS_setsig(): The minimal amount of work to avoid theBarry Warsaw2001-11-131-0/+12
| | | | | | | | | | | | | uninitialized memory reads reported in bug #478001. Note that this doesn't address the following larger issues: - Error conditions are not documented for PyOS_*sig() in the C API. - Nothing that actually calls PyOS_*sig() in the core interpreter and extension modules actually /checks/ the return value of the call. Fixing those is left as an exercise for a later day.
* SF patch #467455 : Enhanced environment variables, by Toby Dickenson.Guido van Rossum2001-10-121-3/+14
| | | | | | | | | | | | | | | | | | | | | | This patch changes to logic to: if env.var. set and non-empty: if env.var. is an integer: set flag to that integer if flag is zero: # [actually, <= 0 --GvR] set flag to 1 Under this patch, anyone currently using PYTHONVERBOSE=yes will get the same output as before. PYTHONVERBNOSE=2 will generate more verbosity than before. The only unusual case that the following three are still all equivalent: PYTHONVERBOSE=yespleas PYTHONVERBOSE=1 PYTHONVERBOSE=0
* Add warning mode for classic division, almost exactly as specified inGuido van Rossum2001-08-311-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PEP 238. Changes: - add a new flag variable Py_DivisionWarningFlag, declared in pydebug.h, defined in object.c, set in main.c, and used in {int,long,float,complex}object.c. When this flag is set, the classic division operator issues a DeprecationWarning message. - add a new API PyRun_SimpleStringFlags() to match PyRun_SimpleString(). The main() function calls this so that commands run with -c can also benefit from -Dnew. - While I was at it, I changed the usage message in main() somewhat: alphabetized the options, split it in *four* parts to fit in under 512 bytes (not that I still believe this is necessary -- doc strings elsewhere are much longer), and perhaps most visibly, don't display the full list of options on each command line error. Instead, the full list is only displayed when -h is used, and otherwise a brief reminder of -h is displayed. When -h is used, write to stdout so that you can do `python -h | more'. Notes: - I don't want to use the -W option to control whether the classic division warning is issued or not, because the machinery to decide whether to display the warning or not is very expensive (it involves calling into the warnings.py module). You can use -Werror to turn the warnings into exceptions though. - The -Dnew option doesn't select future division for all of the program -- only for the __main__ module. I don't know if I'll ever change this -- it would require changes to the .pyc file magic number to do it right, and a more global notion of compiler flags. - You can usefully combine -Dwarn and -Dnew: this gives the __main__ module new division, and warns about classic division everywhere else.
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-0/+4
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* Oops. Two fixes for SF bug #422004 are not needed. :-)Guido van Rossum2001-08-161-1/+0
|
* Bunchathings:Guido van Rossum2001-08-161-5/+6
| | | | | | | | | | | - initsigs(): Ignore SIGXFZ so writing files beyond the file system size limit won't kill us. - Py_Initialize(): call _Py_ReadyTypes() instead of readying types here. - Py_Initialize(): call _PyImport_FixupExtension() for module "extensions". (SF bug #422004.)
* Py_Initialize(): Apply patch by Jürgen Hermann to callBarry Warsaw2001-08-131-0/+1
| | | | | | | | _PyImport_FixupExtension() on the exceptions module. Now reload(exceptions) acts just like reload(sys) instead of raising an ImportError. This closes SF bug #422004.
* Refactor future feature handlingJeremy Hylton2001-08-101-17/+7
| | | | | | | | | | | Replace uses of PyCF_xxx with CO_xxx. Replace individual feature slots in PyFutureFeatures with single bitmask ff_features. When flags must be transfered among the three parts of the interpreter that care about them -- the pythonrun layer, the compiler, and the future feature parser -- can simply or (|) the definitions.
* Apply SF patch #424554: check for PYTHONDUMPREFS to be set instead ofGuido van Rossum2001-08-091-5/+1
| | | | asking to print the references.
* - Rename PyType_InitDict() to PyType_Ready().Guido van Rossum2001-08-071-1/+4
| | | | | | - Add an explicit call to PyType_Ready(&PyList_Type) to pythonrun.c (just for the heck of it, really -- we should either explicitly ready all types, or none).
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-3/+6
|
* Add -E command line switch (ignore environment variables like PYTHONHOMENeil Schemenauer2001-07-231-6/+7
| | | | and PYTHONPATH).
* PyRun_StringFlags(): forgot to pass the flags on toGuido van Rossum2001-07-161-1/+4
| | | | | PyParser_SimpleParseString(). Now calls PyParser_SimpleParseStringFlags() with the correct flag.
* Ugly. A pile of new xxxFlags() functions, to communicate to the parserTim Peters2001-07-161-9/+30
| | | | | | | | | | | | | | | | | | | | | | | that 'yield' is a keyword. This doesn't help test_generators at all! I don't know why not. These things do work now (and didn't before this patch): 1. "from __future__ import generators" now works in a native shell. 2. Similarly "python -i xxx.py" now has generators enabled in the shell if xxx.py had them enabled. 3. This program (which was my doctest proxy) works fine: from __future__ import generators source = """\ def f(): yield 1 """ exec compile(source, "", "single") in globals() print type(f())
* future.c: insert a cosmetic space.Tim Peters2001-07-161-1/+1
| | | | | pythonrun.c, run_pyc_file(): repair semantic error wrt CO_GENERATOR vs CO_GENERATOR_ALLOWED.
* Part way to allowing "from __future__ import generators" to communicateTim Peters2001-07-161-3/+7
| | | | | | | | | | that info to code dynamically compiled *by* code compiled with generators enabled. Doesn't yet work because there's still no way to tell the parser that "yield" is OK (unlike nested_scopes, the parser has its fingers in this too). Replaced PyEval_GetNestedScopes by a more-general PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was *intended* to be part of the public API, so just did.
* Temporarily disable the message to stderr. Jeremy will know what to doMarc-André Lemburg2001-06-131-1/+3
| | | | about this...
* Bug fix: compile() called from a nested-scopes-enable Python was notJeremy Hylton2001-03-261-1/+1
| | | | | using nested scopes to compile its argument. Pass compiler flags through to underlying compile call.
* Finishing touch to Ping's changes. This is a patch that Ping sent meGuido van Rossum2001-03-231-11/+11
| | | | | | | | but apparently he had to go to school, so I am checking it in for him. This makes PyRun_HandleSystemExit() a static instead, called handle_system_exit(), and let it use the current exception rather than passing in an exception. This slightly simplifies the code.
* call_sys_exitfunc(): Remove unused variable f.Fred Drake2001-03-231-1/+1
|
* Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().Ka-Ping Yee2001-03-231-32/+37
| | | | sys.exitfunc gets the last word on the exit status of the program.
* Fix memory leak with SyntaxError. (The DECREF was originally hiddenGuido van Rossum2001-03-231-0/+1
| | | | | inside a piece of code that was deemed reduntant; the DECREF was unfortunately *not* redundant!)
* Add sys.excepthook.Ka-Ping Yee2001-03-231-9/+36
| | | | | | | | Update docstring and library reference section on 'sys' module. New API PyErr_Display, just for displaying errors, called by excepthook. Uncaught exceptions now call sys.excepthook; if that fails, we fall back to calling PyErr_Display directly. Also comes with sys.__excepthook__ and sys.__displayhook__.
* Extend support for from __future__ import nested_scopesJeremy Hylton2001-03-221-12/+82
| | | | | | | | | | | | | | | | | | | If a module has a future statement enabling nested scopes, they are also enable for the exec statement and the functions compile() and execfile() if they occur in the module. If Python is run with the -i option, which enters interactive mode after executing a script, and the script it runs enables nested scopes, they are also enabled in interactive mode. XXX The use of -i with -c "from __future__ import nested_scopes" is not supported. What's the point? To support these changes, many function variants have been added to pythonrun.c. All the variants names end with Flags and they take an extra PyCompilerFlags * argument. It is possible that this complexity will be eliminated in a future version of the interpreter in which nested scopes are not optional.
* Useful future statement support for the interactive interpreterJeremy Hylton2001-03-011-15/+25
| | | | | | | | | | | | | | | | | | | | | | | | (Also remove warning about module-level global decl, because we can't distinguish from code passed to exec.) Define PyCompilerFlags type contains a single element, cf_nested_scopes, that is true if a nested scopes future statement has been entered at the interactive prompt. New API functions: PyNode_CompileFlags() PyRun_InteractiveOneFlags() -- same as their non Flags counterparts except that the take an optional PyCompilerFlags pointer compile.c: In jcompile() use PyCompilerFlags argument. If cf_nested_scopes is true, compile code with nested scopes. If it is false, but the code has a valid future nested scopes statement, set it to true. pythonrun.c: Create a new PyCompilerFlags object in PyRun_InteractiveLoop() and thread it through to PyRun_InteractiveOneFlags().
* Now that Jeremy is asking about this code, it looks really bogus to me,Fred Drake2001-02-281-18/+0
| | | | | so let's rip it out. The constructor for SyntaxError does the right thing, so we do not need to do it again.
* Print the offending line of code in the traceback for SyntaxErrorsJeremy Hylton2001-02-281-36/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | raised by the compiler. XXX For now, text entered into the interactive intepreter is not printed in the traceback. Inspired by a patch from Roman Sulzhyk compile.c: Add helper fetch_program_text() that opens a file and reads until it finds the specified line number. The code is a near duplicate of similar code in traceback.c. Modify com_error() to pass two arguments to SyntaxError constructor, where the second argument contains the offending text when possible. Modify set_error_location(), now used only by the symtable pass, to set the text attribute on existing exceptions. pythonrun.c: Change parse_syntax_error() to continue of the offset attribute of a SyntaxError is None. In this case, it sets offset to -1. Move code from PyErr_PrintEx() into helper function print_error_text(). In the helper, only print the caret for a SyntaxError if offset > 0.
* Bug #132850 unix line terminator on windows.Tim Peters2001-02-171-10/+14
| | | | Miserable hack to replace the previous miserable hack in maybe_pyc_file.
* Ugly fix for SF bug 131239 (-x flag busted).Tim Peters2001-02-111-4/+15
| | | | | | Bug was introduced by tricks played to make .pyc files executable via cmdline arg. Then again, -x worked via a trick to begin with. If anyone can think of a portable way to test -x, be my guest!
* Move a bunch of definitions that were internal to compile.c toJeremy Hylton2001-02-021-0/+14
| | | | | | | | | | | | | | | | | | symtable.h, so that they can be used by external module. Improve error handling in symtable_enter_scope(), which return an error code that went unchecked by most callers. XXX The error handling in symtable code is sloppy in general. Modify symtable to record the line number that begins each scope. This can help to identify which code block is being referred to when multiple blocks are bound to the same name. Add st_scopes dict that is used to preserve scope info when PyNode_CompileSymtable() is called. Otherwise, this information is tossed as soon as it is no longer needed. Add Py_SymtableString() to pythonrun; analogous to Py_CompileString().
* It's unclear whether PyMarshal_XXX() are part of the public or private API.Tim Peters2001-01-281-1/+1
| | | | | | | | | | They're named as if public, so I did a Bad Thing by changing PyMarshal_ReadObjectFromFile() to suck up the remainder of the file in one gulp: anyone who counted on that leaving the file pointer merely at the end of the next object would be screwed. So restored PyMarshal_ReadObjectFromFile() to its earlier state, renamed the new greedy code to PyMarshal_ReadLastObjectFromFile(), and changed Python internals to call the latter instead.
* Bug #128475: mimetools.encode (sometimes) fails when called from a thread.Tim Peters2001-01-211-1/+10
| | | | | | | | pythonrun.c: In Py_Finalize, don't reset the initialized flag until after the exit funcs have run. atexit.py: in _run_exitfuncs, mutate the list of pending calls in a threadsafe way. This wasn't a contributor to bug 128475, it just burned my eyeballs when looking at that bug.
* Get rid of the initialization of _PyCompareState_Key.Guido van Rossum2001-01-171-2/+0
|
* Fix signed/unsigned wng. Unfortunately, (unsigned char) << intTim Peters2001-01-051-2/+2
| | | | has type int in C.
* Recognize pyc files even if they don't end in pyc.Martin v. Löwis2001-01-041-7/+33
| | | | Patch #103067 with modifications as discussed in email.
* Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() orGuido van Rossum2000-09-161-0/+34
| | | | sigaction() (if HAVE_SIGACTION is defined).
* REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum2000-09-011-9/+0
| | | | This should match the situation in the 1.6b1 tree.
* PyOS_CheckStack(): Better ANSI'fy this while we're at it.Fred Drake2000-08-311-1/+1
|
* Add a comment explaining the return value of PyOS_CheckStack().Fred Drake2000-08-311-1/+4
|
* Hard to believe Guido compiled this! Function lacked a return stmt.Tim Peters2000-08-271-1/+1
|
* Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),Guido van Rossum2000-08-271-7/+33
| | | | | | | | | | | | | | PyRun_FileEx(). These are the same as their non-Ex counterparts but have an extra argument, a flag telling them to close the file when done. Then this is used by Py_Main() and execfile() to close the file after it is parsed but before it is executed. Adding APIs seems strange given the feature freeze but it's the only way I see to close the bug report without incompatible changes. [ Bug #110616 ] source file stays open after parsing is done (PR#209)
* implements PyOS_CheckStack for Windows and MSVC. this fixes aFredrik Lundh2000-08-271-0/+29
| | | | | | couple of potential stack overflows, including bug #110615. closes patch #101238
* Fix to [ Bug #111165 ] doc-string removal masked by PYTHONOPTIMIZEMarc-André Lemburg2000-08-251-3/+3
|
* Remove the osdefs.h #include; it was not needed in the final version ofFred Drake2000-08-151-1/+0
| | | | my last set of changes.
* When raising a SyntaxError, make a best-effort attempt to set theFred Drake2000-08-151-1/+19
| | | | | | | | filename and lineno attributes, but do not mask the SyntaxError if we fail. This is part of what is needed to close SoruceForge bug #110628 (Jitterbug PR#278).
* Mass ANSIfication of function definitions. Doesn't cover all 'extern'Thomas Wouters2000-07-221-94/+45
| | | | declarations yet, those come later.
* Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in eitherThomas Wouters2000-07-161-1/+1
| | | | | | | | | | comments, docstrings or error messages. I fixed two minor things in test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't"). There is a minor style issue involved: Guido seems to have preferred English grammar (behaviour, honour) in a couple places. This patch changes that to American, which is the more prominent style in the source. I prefer English myself, so if English is preferred, I'd be happy to supply a patch myself ;)