summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix for SF bug [ #492403 ] exec() segfaults on closure's func_codeJeremy Hylton2001-12-131-3/+3
| | | | | | | | Based on the patch from Danny Yoo. The fix is in exec_statement() in ceval.c. There are also changes to introduce use of PyCode_GetNumFree() in several places.
* SF bug #488687 reported by Neal NorwitzJeremy Hylton2001-12-041-1/+1
| | | | | | | | | The error for assignment to __debug__ used ste->ste_opt_lineno instead of n->n_lineno. The latter was at best incorrect; often the slot was uninitialized. Two fixes here: Use the correct lineno for the error. Initialize ste_opt_lineno in PySymtable_New(); while there are no current cases where it is referenced unless it has already been assigned to, there is no harm in initializing it.
* code_repr(), com_addop_varname(), com_list_comprehension(),Barry Warsaw2001-11-281-32/+42
| | | | | | | | com_arglist(), symtable_check_unoptimized(), symtable_params(), symtable_global(), symtable_list_comprehension(): Conversion of sprintf() to PyOS_snprintf() for buffer overrun avoidance.
* Fixes for possible buffer overflows in sprintf() usages.Marc-André Lemburg2001-11-281-1/+1
|
* Use PyObject_CheckReadBuffer().Jeremy Hylton2001-11-091-11/+2
|
* Fix SF buf #480096: Assign to __debug__ still allowedJeremy Hylton2001-11-091-2/+7
| | | | | | Easy enough to catch assignment in the compiler. The perverse user can still change the value of __debug__, but that may be the least he can do.
* Part of SF bug #478003 possible memory leaks in err handling.Tim Peters2001-11-041-1/+4
| | | | | PyNode_CompileSymtable: if symtable_init() fails, free the memory allocated for the PyFutureFeatures struct.
* Fix for SF bug [ #471928 ] global made w/nested list comprehensionsJeremy Hylton2001-10-181-19/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The symbol table pass didn't have an explicit case for the list_iter node which is used only for a nested list comprehension. As a result, the target of the list comprehension was treated as a use instead of an assignment. Fix is to add a case to symtable_node() to handle list_iter. Also, rework and document a couple of the subtler implementation issues in the symbol table pass. The symtable_node() switch statement depends on falling through the last several cases, in order to handle some of the more complicated nodes like atom. Add a comment explaining the behavior before the first fall through case. Add a comment /* fall through */ at the end of case so that it is explicitly marked as such. Move the for_stmt case out of the fall through logic, which simplifies both for_stmt and default. (The default used the local variable start to skip the first three nodes of a for_stmt when it fell through.) Rename the flag argument to symtable_assign() to def_flag and add a comment explaining its use: The third argument to symatble_assign() is a flag to be passed to symtable_add_def() if it is eventually called. The flag is useful to specify the particular type of assignment that should be recorded, e.g. an assignment caused by import.
* Fix computation of stack depth for classdef and closures.Jeremy Hylton2001-10-171-44/+44
| | | | | | | | | | | | | | | | | | | | | | Also minor tweaks to internal routines. Use PyCF_MASK instead of explicit list of flags. For the MAKE_CLOSURE opcode, the number of items popped off the stack depends on both the oparg and the number of free variables for the code object. Fix the code so it accounts for the free variables. In com_classdef(), record an extra pop to account for the STORE call after the BUILD_CLASS. Get rid of some commented out debugging code in com_push() and com_pop(). Factor string resize logic into helper routine com_check_size(). In com_addbyte(), remove redudant if statement after assert. (They test the same condition.) In several routines, use string macros instead of string functions.
* Very subtle syntax change: in a list comprehension, the testlist inGuido van Rossum2001-10-151-0/+1
| | | | | | | | | | | | | | | "for <var> in <testlist> may no longer be a single test followed by a comma. This solves SF bug #431886. Note that if the testlist contains more than one test, a trailing comma is still allowed, for maximum backward compatibility; but this example is not: [(x, y) for x in range(10), for y in range(10)] ^ The fix involved creating a new nonterminal 'testlist_safe' whose definition doesn't allow the trailing comma if there's only one test: testlist_safe: test [(',' test)+ [',']]
* Add optional docstrings to member descriptors. For backwardsGuido van Rossum2001-09-201-1/+1
| | | | | | | | | | | | | | | compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
* Supply code objects a new-style tp_members slot and tp_getattr impl.Jeremy Hylton2001-09-141-16/+34
| | | | | The chief effects are to make dir() do something useful and supply them with an __class__.
* SF bug [#458941] Looks like a unary minus bug.Tim Peters2001-09-071-16/+49
| | | | | | | | | | com_factor(): when a unary minus is attached to a float or imaginary zero, don't optimize the UNARY_MINUS opcode away: the const dict can't distinguish between +0.0 and -0.0, so ended up treating both like the first one added to it. Optimizing UNARY_PLUS away isn't a problem. (BTW, I already uploaded the 2.2a3 Windows installer, and this isn't important enough to delay the release.)
* When re-writing a factor containing a unary negation of a literal, onlyFred Drake2001-08-301-0/+3
| | | | | affect nodes without another operator. This was causing negated exponentiations to drop the exponentiation. This closes SF bug #456756.
* Removed unreachable goto statement to silence SGI compiler.Sjoerd Mullender2001-08-301-1/+0
|
* If an integer constant can't be generated from an integer literalJeremy Hylton2001-08-271-5/+2
| | | | because of overflow, generate a long instead.
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-13/+25
| | | | | | | | - 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.
* Fix SF bug [ #450909 ] __future__.division fails at promptJeremy Hylton2001-08-141-2/+6
| | | | | | When code is compiled and compiler flags are passed in, be sure to update cf_flags with any features defined by future statements in the compiled code.
* SF Patch [ 429024 ] deal with some unary ops at compile timeJeremy Hylton2001-08-121-3/+66
| | | | | | | | | | | | | Revised version of Fred's patch, including support for ~ operator. If the unary +, -, or ~ operator is applied to a constant, don't generate a UNARY_xxx opcode. Just store the approriate value as a constant. If the value is negative, extend the string containing the constant and insert a negative in the 0th position. For ~, compute the inverse of int and longs and use them directly, but be prepared to generate code for all other possibilities (invalid numbers, floats, complex).
* Remove st_nested_scopes from struct symtable,Jeremy Hylton2001-08-111-130/+46
| | | | | | | because nested scopes are always enabled. (Accidentally checked in one small change along this path yesterday, wreaking havoc in the Windows build.)
* st_nested_scopes was uninitialized trash. Jeremy should fix in a betterTim Peters2001-08-111-0/+6
| | | | way; see code comments.
* Refactor future feature handlingJeremy Hylton2001-08-101-27/+4
| | | | | | | | | | | 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.
* Implement PEP 238 in its (almost) full glory.Guido van Rossum2001-08-081-4/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | This introduces: - A new operator // that means floor division (the kind of division where 1/2 is 0). - The "future division" statement ("from __future__ import division) which changes the meaning of the / operator to implement "true division" (where 1/2 is 0.5). - New overloadable operators __truediv__ and __floordiv__. - New slots in the PyNumberMethods struct for true and floor division, new abstract APIs for them, new opcodes, and so on. I emphasize that without the future division statement, the semantics of / will remain unchanged until Python 3.0. Not yet implemented are warnings (default off) when / is used with int or long arguments. This has been on display since 7/31 as SF patch #443474. Flames to /dev/null.
* Another bug fix for recent import * warning (caught by Thomas Wouters)Jeremy Hylton2001-08-061-3/+3
| | | | | Only return if symtable_warn() returns -1, indicating that the warning was turned into an error.
* Fix error message for import * in function/class scopeJeremy Hylton2001-08-061-1/+1
|
* Fix SF bug [ #445474 ] warn about import * inside functionsJeremy Hylton2001-08-061-0/+5
| | | | Reported by the Man himself.
* jcompile(): inherit the CO_GENERATOR_ALLOWED flag from the 'base'Guido van Rossum2001-07-161-0/+1
| | | | compiling struct.
* Part way to allowing "from __future__ import generators" to communicateTim Peters2001-07-161-4/+13
| | | | | | | | | | 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.
* Another "if 0:" hack, this time to complain about otherwise invisibleTim Peters2001-06-281-2/+61
| | | | | | "return expr" instances in generators (which latter may be generators due to otherwise invisible "yield" stmts hiding in "if 0" blocks). This was fun the first time, but this has gotten truly ugly now.
* SF bug #436207: "if 0: yield x" is ignored.Tim Peters2001-06-261-1/+33
| | | | Not anymore <wink>. Pure hack. Doesn't fix any other "if 0:" glitches.
* Change the semantics of "return" in generators, as discussed on theTim Peters2001-06-231-25/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Iterators list and Python-Dev; e.g., these all pass now: def g1(): try: return except: yield 1 assert list(g1()) == [] def g2(): try: return finally: yield 1 assert list(g2()) == [1] def g3(): for i in range(3): yield None yield None assert list(g3()) == [None] * 4 compile.c: compile_funcdef and com_return_stmt: Just van Rossum's patch to compile the same code for "return" regardless of function type (this goes back to the previous scheme of returning Py_None). ceval.c: gen_iternext: take a return (but not a yield) of Py_None as meaning the generator is exhausted.
* Disallow 'yield' in a 'try' block when there's a 'finally' clause.Tim Peters2001-06-231-0/+10
| | | | | Derived from Thomas Wouters's patch on the Iterators list, but doesn't try to read c->c_block[c->c_nblocks].
* Merging the gen-branch into the main line, at Guido's direction. Yay!Tim Peters2001-06-181-9/+51
| | | | | Bugfix candidate in inspect.py: it was referencing "self" outside of a method.
* SF bug 430991: wrong co_lnotabTim Peters2001-06-091-10/+54
| | | | | | | | | Armin Rigo pointed out that the way the line-# table got built didn't work for lines generating more than 255 bytes of bytecode. Fixed as he suggested, plus corresponding changes to pyassem.py, plus added some long overdue docs about this subtle table to compile.c. Bugfix candidate (line numbers may be off in tracebacks under -O).
* SF patch #416249, from Mark Favas: 2.1c1 compile: unused vrbl cleanupTim Peters2001-05-091-2/+0
|
* Several small changes. Mostly reformatting, adding parens.Jeremy Hylton2001-05-081-10/+11
| | | | | | | | | Check for free in class and method only if nested scopes are enabled. Add assertion to verify that no free variables occur when nested scopes are disabled. XXX When should nested scopes by made non-optional on the trunk?
* Fix 2.1 nested scopes crash reported by Evan SimpsonJeremy Hylton2001-04-271-6/+20
| | | | | | | | The new test case demonstrates the bug. Be more careful in symtable_resolve_free() to add a var to cells or frees only if it won't be added under some other rule. XXX Add new assertion that will catch this bug.
* Iterators phase 1. This comprises:Guido van Rossum2001-04-201-18/+6
| | | | | | | | | | | | | | | | | | | | | | new slot tp_iter in type object, plus new flag Py_TPFLAGS_HAVE_ITER new C API PyObject_GetIter(), calls tp_iter new builtin iter(), with two forms: iter(obj), and iter(function, sentinel) new internal object types iterobject and calliterobject new exception StopIteration new opcodes for "for" loops, GET_ITER and FOR_ITER (also supported by dis.py) new magic number for .pyc files new special method for instances: __iter__() returns an iterator iteration over dictionaries: "for x in dict" iterates over the keys iteration over files: "for x in file" iterates over lines TODO: documentation test suite decide whether to use a different way to spell iter(function, sentinal) decide whether "for key in dict" is a good idea use iterators in map/filter/reduce, min/max, and elsewhere (in/not in?) speed tuning (make next() a slot tp_next???)
* Make some private symbols static.Guido van Rossum2001-04-141-1/+2
|
* Warn when assigning to __debug__ instead of raising an error.Jeremy Hylton2001-04-091-7/+2
|
* Make it illegal to assign to __debug__ as per Guido's request.Jeremy Hylton2001-03-231-1/+12
|
* 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.
* If a code object is compiled with nested scopes, define the CO_NESTED flag.Jeremy Hylton2001-03-221-0/+2
| | | | | Add PyEval_GetNestedScopes() which returns a non-zero value if the code for the current interpreter frame has CO_NESTED defined.
* Update PyNode_CompileSymtable() to understand future statementsJeremy Hylton2001-03-211-9/+15
|
* Fix PyFrame_FastToLocals() and counterpart to deal with cells andJeremy Hylton2001-03-211-51/+69
| | | | | | | | | | | | | | 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.
* 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().
* 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.
* Useful future statement support for the interactive interpreterJeremy Hylton2001-03-011-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | (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().