summaryrefslogtreecommitdiffstats
path: root/Python
Commit message (Collapse)AuthorAgeFilesLines
* Add sys.excepthook.Ka-Ping Yee2001-03-232-20/+83
| | | | | | | | 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__.
* Set the line number correctly for a nested function with an exec orJeremy Hylton2001-03-221-2/+5
| | | | import *. Mark the offending stmt rather than the function def line.
* Make error messages clearer for illegal combinations of nestedJeremy Hylton2001-03-221-15/+36
| | | | functions and import */exec.
* Extend support for from __future__ import nested_scopesJeremy Hylton2001-03-223-16/+112
| | | | | | | | | | | | | | | | | | | 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.
* If a code object is compiled with nested scopes, define the CO_NESTED flag.Jeremy Hylton2001-03-222-1/+11
| | | | | Add PyEval_GetNestedScopes() which returns a non-zero value if the code for the current interpreter frame has CO_NESTED defined.
* Use PyObject_IsInstance() to check whether the first argument to anGuido van Rossum2001-03-211-13/+19
| | | | | unbound method is of the right type. Hopefully this solves SF patch #409355 (Meta-class inheritance problem); I have no easy way to test.
* Update PyNode_CompileSymtable() to understand future statementsJeremy Hylton2001-03-211-9/+15
|
* Move the code implementing isinstance() and issubclass() to new CGuido van Rossum2001-03-211-96/+6
| | | | | APIs, PyObject_IsInstance() and PyObject_IsSubclass() -- both returning an int, or -1 for errors.
* Fix PyFrame_FastToLocals() and counterpart to deal with cells andJeremy Hylton2001-03-212-55/+114
| | | | | | | | | | | | | | frees. Note there doesn't seem to be any way to test LocalsToFast(), because the instructions that trigger it are illegal in nested scopes with free variables. Fix allocation strategy for cells that are also formal parameters. Instead of emitting LOAD_FAST / STORE_DEREF pairs for each parameter, have the argument handling code in eval_code2() do the right thing. A side-effect of this change is that cell variables that are also arguments are listed at the front of co_cellvars in the order they appear in the argument list.
* Case-checking was broken on the Macintosh. Fixed.Jack Jansen2001-03-201-3/+2
|
* Fixup handling of free variables in methods when the class scope alsoJeremy Hylton2001-03-201-3/+12
| | | | | | | | | | has a binding for the name. The fix is in two places: - in symtable_update_free_vars, ignore a global stmt in a class scope - in symtable_load_symbols, add extra handling for names that are defined at class scope and free in a method Closes SF bug 407800
* Fix crashes in nested list comprehensionsJeremy Hylton2001-03-191-8/+10
| | | | | | SF bugs 409230 and 407800 Also remove bogus list comp code from symtable_assign().
* Variety of small INC/DECREF patches that fix reported memory leaksJeremy Hylton2001-03-131-4/+7
| | | | | | | | | | | | | | | | | | | | | with free variables. Thanks to Martin v. Loewis for finding two of the problems. This fixes SF buf 405583. There is also a C API change: PyFrame_New() is reverting to its pre-2.1 signature. The change introduced by nested scopes was a mistake. XXX Is this okay between beta releases? cell_clear(), the GC helper, must decref its reference to break cycles. frame_dealloc() must dealloc all cell vars and free vars in addition to locals. eval_code2() setup code must INCREF cells it copies out of the closure. The STORE_DEREF opcode implementation must DECREF the object it passes to PyCell_Set().
* Py_BuildValue(): Add "D" conversion to create a Python complex value fromFred Drake2001-03-121-0/+6
| | | | | | | a Py_complex C value. Patch by Walter Dörwald. This partially closes SF patch #407148.
* When iterating over the names imported in a future statement, ignore theFred Drake2001-03-101-1/+1
| | | | | | commas in the concrete syntax; checking those causes a segfault. This fixes SF bug #407394.
* Use Py_CHARMASK for ctype macros. Fixes bug #232787.Martin v. Löwis2001-03-061-4/+4
|
* Add some spaces around the "=" in assignments.Fred Drake2001-03-061-2/+2
|
* RISCOS changes by dschwertberger.Guido van Rossum2001-03-021-0/+58
|
* Refactored the warning-issuing code more.Guido van Rossum2001-03-021-11/+17
| | | | | | Made sure that the warnings issued by symtable_check_unoptimized() (about import * and exec) contain the proper filename and line number, and are transformed into SyntaxError exceptions with -Werror.
* Thanks to Steven Majewski, finally putting MacOS X imports to bed for 2.1b1.Tim Peters2001-03-021-9/+3
|
* Useful future statement support for the interactive interpreterJeremy Hylton2001-03-012-26/+52
| | | | | | | | | | | | | | | | | | | | | | | | (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().
* More MacOSX fiddling. As noted in a comment, I believe all variationsTim Peters2001-03-011-18/+37
| | | | | of these "search the directory" schemes (including this one) are still prone to making mistakes.
* More fiddling w/ the new-fangled Mac import code.Tim Peters2001-03-011-5/+9
|
* Suppress a compiler warning under OpenVMS; time_t is unsigned on (at least)Fred Drake2001-03-011-2/+2
| | | | | | | | | | | | the more recent versions of that platform, so we use the value (time_t)(-1) as the error value. This is the type used in the OpenVMS documentation: http://www.openvms.compaq.com/commercial/c/5763p048.htm#inde This closes SF tracker bug #404240. Also clean up an exception message when detecting overflow of time_t values beyond 4 bytes.
* Fix core dump in example from Samuele Pedroni:Jeremy Hylton2001-03-011-15/+31
| | | | | | | | | | | | | | | | | | | | | | | | from __future__ import nested_scopes x=7 def f(): x=1 def g(): global x def i(): def h(): return x return h() return i() return g() print f() print x This kind of code didn't work correctly because x was treated as free in i, leading to an attempt to load x in g to make a closure for i. Solution is to make global decl apply to nested scopes unless their is an assignment. Thus, x in h is global.
* Remove extra close curly in code #ifdef'ed out on my box.Tim Peters2001-03-011-1/+0
|
* In Steven's apparent absence, check in *something* with a non-zero chanceTim Peters2001-03-011-35/+40
| | | | | of making new-fangled Mac imports work again. May not work, and may not even compile on his boxes, but should be at worst very close on both.
* Don't add global names to st->st_global if we're already iteratingJeremy Hylton2001-03-011-6/+15
| | | | over the elements of st->st_global!
* undo introduction of st_global_starJeremy Hylton2001-02-281-3/+0
|
* Warn about global statement at the module level.Jeremy Hylton2001-02-281-2/+17
| | | | Do better accounting for global variables.
* Add warning/error handlin for problematic nested scopes cases asJeremy Hylton2001-02-281-26/+119
| | | | | | | | | | | | | | | | | | | | | | | described in PEP 227. symtable_check_unoptimized() warns about import * and exec with "in" when it is used in a function that contains a nested function with free variables. Warnings are issued unless nested scopes are in effect, in which case these are SyntaxErrors. symtable_check_shadow() warns about assignments in a function scope that shadow free variables defined in a nested scope. This will always generate a warning -- and will behave differently with nested scopes than without. Restore full checking for free vars in children, even when nested scopes are not enabled. This is needed to support warnings for shadowing. Change symtable_warn() to return an int-- the return value of PyErr_WarnExplicit. Sundry cleanup: Remove commented out code. Break long lines.
* Let's have some sanity. Introduce a helper to issue a symbol tableGuido van Rossum2001-02-281-16/+17
| | | | warning.
* Use the new PyErr_WarnExplicit() API to issue better warnings forGuido van Rossum2001-02-281-12/+21
| | | | | | | | | global after assign / use. Note: I'm not updating the PyErr_Warn() call for import * / exec combined with a function, because I can't trigger it with an example. Jeremy, just follow the example of the call to PyErr_WarnExplicit() that I *did* include.
* SyntaxError__init__(): Be a little more robust when picking apart theFred Drake2001-02-281-16/+22
| | | | | location information for the SyntaxError -- do not do more than we need to, stopping as soon as an exception has been raised.
* Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), withGuido van Rossum2001-02-281-0/+42
| | | | explicit filename, lineno etc. arguments.
* 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.
* Improve SyntaxErrors for bad future statements. Set file and locationJeremy Hylton2001-02-283-94/+109
| | | | | | | for errors raised in future.c. Move some helper functions from compile.c to errors.c and make them API functions: PyErr_SyntaxLocation() and PyErr_ProgramText().
* SF patch 404928: Support for next Cygwin gcc (2.95.2-8)Tim Peters2001-02-281-8/+2
|
* Print the offending line of code in the traceback for SyntaxErrorsJeremy Hylton2001-02-282-67/+144
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Ack -- my eyes are getting bleary. Typos in the comment typo repairs.Tim Peters2001-02-281-1/+1
|
* Comment typos.Tim Peters2001-02-281-2/+2
|
* Implement PEP 235: Import on Case-Insensitive Platforms.Tim Peters2001-02-281-138/+87
| | | | | | | | | | | | | | | | | | | | | | | | | http://python.sourceforge.net/peps/pep-0235.html Renamed check_case to case_ok. Substantial code rearrangement to get this stuff in one place in the file. Innermost loop of find_module() now much simpler and #ifdef-free, and I want to keep it that way (it's bad enough that the innermost loop is itself still in an #ifdef!). Windows semantics tested and are fine. Jason, Cygwin *should* be fine if and only if what you did before "worked" for case_ok. Jack, the semantics on your flavor of Mac have definitely changed (see the PEP), and need to be tested. The intent is that your flavor of Mac now work the same as everything else in the "lower left" box, including respecting PYTHONCASEOK. Steven, sorry, you did the most work here so far but you got screwed the worst. Happy to work with you on repairing it, but I don't understand anything about all your Mac variants. We need to add another branch (or two, three, ...?) inside case_ok. But we should not need to change anything else.
* Need to support single_input explicitly so from __future__ importsJeremy Hylton2001-02-281-0/+8
| | | | | are legal at the interactive interpreter prompt. They don't do anything yet...
* Presumed correct compiler pass for future statementsJeremy Hylton2001-02-282-29/+128
| | | | | | | | | | | | | | | | | | | | | | | | | XXX still need to integrate into symtable API compile.h: Remove ff_n_simple_stmt; obsolete. Add ff_found_docstring used internally to skip one and only one string at the beginning of a module. compile.c: Add check for from __future__ imports to far into the file. In symtable_global() check for -1 returned from symtable_lookup(), which signifies name not defined. Add missing DECERF in symtable_add_def. Free c->c_future. future.c: Add special handling for multiple statements joined on a single line using one or more semicolons; this form can include an illegal future statement that would otherwise be hard to detect. Add support for detecting and skipping doc strings.
* Improved __future__ parser; still more to doJeremy Hylton2001-02-273-43/+152
| | | | | | | | | | | | | | | Makefile.pre.in: add target future.o Include/compile.h: define PyFutureFeaters and PyNode_Future() add c_future slot to struct compiling Include/symtable.h: add st_future slot to struct symtable Python/future.c: implementation of PyNode_Future() Python/compile.c: use PyNode_Future() for nested_scopes support Python/symtable.c: include compile.h to pick up PyFutureFeatures decl
* Add warnings about undefined "global"Jeremy Hylton2001-02-271-0/+29
| | | | | | SF bug #233532 XXX Can't figure out how to write test cases that work with warnings
* Preliminary support for future nested scopesJeremy Hylton2001-02-272-115/+270
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | compile.h: #define NESTED_SCOPES_DEFAULT 0 for Python 2.1 __future__ feature name: "nested_scopes" symtable.h: Add st_nested_scopes slot. Define flags to track exec and import star. Lib/test/test_scope.py: requires nested scopes compile.c: Fiddle with error messages. Reverse the sense of ste_optimized flag on PySymtableEntryObjects. If it is true, there is an optimization conflict. Modify get_ref_type to respect st_nested_scopes flags. Refactor symtable_load_symbols() into several smaller functions, which use struct symbol_info to share variables. In new function symtable_update_flags(), raise an error or warning for import * or bare exec that conflicts with nested scopes. Also, modify handle for free variables to respect st_nested_scopes flag. In symtable_init() assign st_nested_scopes flag to NESTED_SCOPES_DEFAULT (defined in compile.h). Add preliminary and often incorrect implementation of symtable_check_future(). Add symtable_lookup() helper for future use.
* Shuffle premature decref; nuke unreachable code block.Tim Peters2001-02-231-9/+3
| | | | | Fixes the "debug-build -O test_builtin.py and no test_b2.pyo" crash just discussed on Python-Dev.
* symtable_update_free_vars(), symtable_undo_free(),Barry Warsaw2001-02-231-3/+3
| | | | | symtable_enter_scope(): Removed some unnecessary backslashes at the end of lines. C != Python. :)
* Fix for bug 133489: compiler leaks memoryJeremy Hylton2001-02-232-5/+11
| | | | | | | | | | | | | | | | | | | | Two different but related problems: 1. PySymtable_Free() must explicitly DECREF(st->st_cur), which should always point to the global symtable entry. This entry is setup by the first enter_scope() call, but there is never a corresponding exit_scope() call. Since each entry has a reference to scopes defined within it, the missing DECREF caused all symtable entries to be leaked. 2. The leak here masked a separate problem with PySymtableEntry_New(). When the requested entry was found in st->st_symbols, the entry was returned without doing an INCREF. And problem c) The ste_children slot was getting two copies of each child entry, because it was populating the slot on the first and second passes. Now only populate on the first pass.