Commit Graph

48 Commits

Author SHA1 Message Date
Benjamin Peterson 25f2d89f32 uhh PySTEntry->ste_unoptimized has to be exposed too 2008-08-17 02:23:43 +00:00
Benjamin Peterson e0d4c7b5bd expose PySTEntry.nested so the symtable module will work 2008-08-17 01:09:17 +00:00
Benjamin Peterson e0d12eb85c PySTEntry's constructor is static; there's no point in a fancy API name 2008-08-16 23:29:40 +00:00
Benjamin Peterson 0847332716 include filename and line number in SyntaxError 2008-08-16 22:11:33 +00:00
Gregory P. Smith dd96db63f6 This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
2008-06-09 04:58:54 +00:00
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Georg Brandl a48f3ab895 Patch #2511: Give the "excepthandler" AST item proper attributes by making it a Sum. 2008-03-30 06:40:17 +00:00
Neal Norwitz 5becac576c Handle memory allocation failure. Found by Adam Olsen 2008-03-15 22:36:01 +00:00
Christian Heimes 5224d28d38 Patch #1759: Backport of PEP 3129 class decorators
with some help from Georg
2008-02-23 15:01:05 +00:00
Martin v. Löwis 6819210b9e PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
2007-07-21 06:55:02 +00:00
Neal Norwitz 7605936dee Handle PyString_FromInternedString() failing (unlikely, but possible).
Klocwork #325

(I'm not backporting this, but if someone wants to, feel free.)
2006-08-19 04:52:03 +00:00
Neal Norwitz 6f5ff3f3eb Klocwork made another run and found a bunch more problems.
This is the first batch of fixes that should be easy to verify based on context.

This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).
2006-08-12 01:43:40 +00:00
Neal Norwitz 18b6adf9b2 Handle more mem alloc issues found with failmalloc 2006-07-23 07:50:36 +00:00
Neal Norwitz b59d08c2fb Fix more memory allocation issues found with failmalloc. 2006-07-22 16:20:49 +00:00
Neal Norwitz d12bd012a6 Handle more memory allocation failures without crashing. 2006-07-21 07:59:47 +00:00
Georg Brandl ddbaa660d3 Patch #1346214: correctly optimize away "if 0"-style stmts
(thanks to Neal for review)
2006-06-04 21:56:52 +00:00
Anthony Baxter 019aec618a Make symtable.c safe for C++ compilers. Changed macros in the same way as
compile.c to add a cast.
2006-04-12 04:00:50 +00:00
Neal Norwitz 090b3dde06 No need to export PySTEntry_New, it is only used in symtable.c 2006-02-28 22:36:46 +00:00
Guido van Rossum c2e20744b2 PEP 343 -- the with-statement.
This was started by Mike Bland and completed by Guido
(with help from Neal).

This still needs a __future__ statement added;
Thomas is working on Michael's patch for that aspect.

There's a small amount of code cleanup and refactoring
in ast.c, compile.c and ceval.c (I fixed the lltrace
behavior when EXT_POP is used -- however I had to make
lltrace a static global).
2006-02-27 22:32:47 +00:00
Thomas Wouters dca3b9c797 PEP 308 implementation, including minor refdocs and some testcases. It
breaks the parser module, because it adds the if/else construct as well as
two new grammar rules for backward compatibility. If no one else fixes
parsermodule, I guess I'll go ahead and fix it later this week.

The TeX code was checked with texcheck.py, but not rendered. There is
actually a slight incompatibility:

>>> (x for x in lambda:0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: iteration over non-sequence

changes into

>>> (x for x in lambda: 0)
  File "<stdin>", line 1
    (x for x in lambda: 0)
                     ^
SyntaxError: invalid syntax

Since there's no way the former version can be useful, it's probably a
bugfix ;)
2006-02-27 00:24:13 +00:00
Martin v. Löwis d96ee90993 Use Py_ssize_t to count the 2006-02-16 14:37:16 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Tim Peters d8fe7ab711 analyze_cells(): This no longer compiled under VC 7.1.
Move declaration of local `flags` to top of block.
2006-01-08 02:19:07 +00:00
Neal Norwitz 46b7bda9bc Fix icc warnings: conversion from "long" to "int" may lose significant bits 2006-01-08 01:06:06 +00:00
Neal Norwitz daf595f8a9 Fix icc warnings: shadowing local variable (i) and complex is set but not used, so remove 2006-01-07 21:24:54 +00:00
Neal Norwitz 5d0ad50f5a Bug #889500, fix line number on SyntaxWarning for global declarations. 2005-12-19 04:27:42 +00:00
Neal Norwitz 3715c3e576 Fix a few more ref leaks. Backport candidate 2005-11-24 22:09:18 +00:00
Neal Norwitz 4737b2348b Last batch of ref leaks in new AST code.
Also converted a bunch of assert(0) to SystemError's.

There are still printfs, etc that need to be cleaned up.
2005-11-19 23:58:29 +00:00
Nick Coghlan 99b2533539 Bring handling of genexpr in line with other anonymous scope names 2005-11-16 12:45:24 +00:00
Neal Norwitz b6fc9df8fc Fix a lot of memory and ref leaks in error paths.
(Call symtable_exit_block or compiler_exit_scope as appropriate)

Use PyMem_Free on c_future since it was allocated with PyMem_Malloc
2005-11-13 18:50:34 +00:00
Neal Norwitz 62c2fac9a0 Do not pollute name block_ty, prefix with _Py_ 2005-10-24 00:30:44 +00:00
Neil Schemenauer 2dfcef5c57 Fix check_unoptimized() function. The only optimized namespaces are
in function blocks.  This elimiates spurious warnings about "import *" and
related statements at the class level.
2005-10-23 18:50:36 +00:00
Neil Schemenauer 8b528b28f1 Fix private name mangling. The symtable also must do mangles so that
the scope of names can be correctly determined.
2005-10-23 18:37:42 +00:00
Jeremy Hylton ec97a28b60 Fix a bunch of imports to use code.h instead of compile.h.
Remove duplicate declarations from compile.h
2005-10-21 14:58:06 +00:00
Armin Rigo 3144130217 ANSI-C-ify the placement of local var declarations. 2005-10-21 12:57:31 +00:00
Jeremy Hylton 3e0055f8c6 Merge ast-branch to head
This change implements a new bytecode compiler, based on a
transformation of the parse tree to an abstract syntax defined in
Parser/Python.asdl.

The compiler implementation is not complete, but it is in stable
enough shape to run the entire test suite excepting two disabled
tests.
2005-10-20 19:59:25 +00:00
Raymond Hettinger 354433a59d SF patch #872326: Generator expression implementation
(Code contributed by Jiwon Seo.)

The documentation portion of the patch is being re-worked and will be
checked-in soon.  Likewise, PEP 289 will be updated to reflect Guido's
rationale for the design decisions on binding behavior (as described in
in his patch comments and in discussions on python-dev).

The test file, test_genexps.py, is written in doctest format and is
meant to exercise all aspects of the the patch.  Further additions are
welcome from everyone.  Please stress test this new feature as much as
possible before the alpha release.
2004-05-19 08:20:33 +00:00
Jeremy Hylton 4d508adae3 Fix for SF [ 734869 ] Lambda functions in list comprehensions
The compiler was reseting the list comprehension tmpname counter for each function, but the symtable was using the same counter for the entire module.  Repair by move tmpname into the symtable entry.

Bugfix candidate.
2003-05-21 17:34:50 +00:00
Jeremy Hylton 2990640d8a Add a comment explaining the st_symbols cache. 2001-12-10 00:53:18 +00:00
Tim Peters 0f2d4b84a6 PySymtableEntry_New(): I'm not sure what this routine is doing, but it
was obviously leaking an int object when whatever the heck it's looking for
was found.  Repaired that.  This accounts for why entering function and
class definitions at an interactive prompt leaked a reference to the
integer 1 each time.
Bugfix candidate.
2001-12-08 23:40:38 +00:00
Jeremy Hylton 86424e333f SF bug #488687 reported by Neal Norwitz
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.
2001-12-04 02:41:46 +00:00
Barry Warsaw 4b4ab20f2c ste_repr(): Conversion of sprintf() to PyOS_snprintf() for buffer
overrun avoidance.
2001-11-28 21:36:28 +00:00
Guido van Rossum 6f7993765a Add optional docstrings to member descriptors. For backwards
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.
2001-09-20 20:46:19 +00:00
Tim Peters 5ca576ed0a Merging the gen-branch into the main line, at Guido's direction. Yay!
Bugfix candidate in inspect.py:  it was referencing "self" outside of
a method.
2001-06-18 22:08:13 +00:00
Jeremy Hylton 4db62b1e14 Improved __future__ parser; still more to do
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
2001-02-27 19:07:02 +00:00
Jeremy Hylton 29906eef3a Preliminary support for future nested scopes
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.
2001-02-27 04:23:34 +00:00
Jeremy Hylton 74b3bc47df Fix for bug 133489: compiler leaks memory
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.
2001-02-23 17:55:27 +00:00
Jeremy Hylton cb17ae8b19 Relax the rules for using 'from ... import *' and exec in the presence
of nested functions.  Either is allowed in a function if it contains
no defs or lambdas or the defs and lambdas it contains have no free
variables.  If a function is itself nested and has free variables,
either is illegal.

Revise the symtable to use a PySymtableEntryObject, which holds all
the revelent information for a scope, rather than using a bunch of
st_cur_XXX pointers in the symtable struct.  The changes simplify the
internal management of the current symtable scope and of the stack.

Added new C source file: Python/symtable.c.  (Does the Windows build
process need to be updated?)

As part of these changes, the initial _symtable module interface
introduced in 2.1a2 is replaced.  A dictionary of
PySymtableEntryObjects are returned.
2001-02-09 22:22:18 +00:00