Commit Graph

1258 Commits

Author SHA1 Message Date
Jack Jansen 4df3c5284f Case-checking was broken on the Macintosh. Fixed. 2001-03-20 23:09:54 +00:00
Jeremy Hylton ce7ef599d2 Fixup handling of free variables in methods when the class scope also
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
2001-03-20 00:25:43 +00:00
Jeremy Hylton 23b4227ec8 Fix crashes in nested list comprehensions
SF bugs 409230 and 407800

Also remove bogus list comp code from symtable_assign().
2001-03-19 20:38:06 +00:00
Jeremy Hylton 30c9f3991c Variety of small INC/DECREF patches that fix reported memory leaks
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().
2001-03-13 01:58:22 +00:00
Fred Drake aec79247b1 Py_BuildValue(): Add "D" conversion to create a Python complex value from
a Py_complex C value.

Patch by Walter Dörwald.
This partially closes SF patch #407148.
2001-03-12 21:03:26 +00:00
Fred Drake 198457a978 When iterating over the names imported in a future statement, ignore the
commas in the concrete syntax; checking those causes a segfault.

This fixes SF bug #407394.
2001-03-10 02:15:37 +00:00
Martin v. Löwis 2b6727bd8a Use Py_CHARMASK for ctype macros. Fixes bug #232787. 2001-03-06 12:12:02 +00:00
Fred Drake a76ba6ed9b Add some spaces around the "=" in assignments. 2001-03-06 06:31:15 +00:00
Guido van Rossum 48a680c097 RISCOS changes by dschwertberger. 2001-03-02 06:34:14 +00:00
Guido van Rossum 207fda61a5 Refactored the warning-issuing code more.
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.
2001-03-02 03:30:41 +00:00
Tim Peters 677898a391 Thanks to Steven Majewski, finally putting MacOS X imports to bed for 2.1b1. 2001-03-02 03:28:03 +00:00
Jeremy Hylton 9f324e964e Useful future statement support for the interactive interpreter
(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().
2001-03-01 22:59:14 +00:00
Tim Peters d1e87a8288 More MacOSX fiddling. As noted in a comment, I believe all variations
of these "search the directory" schemes (including this one) are still prone
to making mistakes.
2001-03-01 18:12:00 +00:00
Tim Peters dbe6ebbeff More fiddling w/ the new-fangled Mac import code. 2001-03-01 08:47:29 +00:00
Fred Drake c63d3e9453 Suppress a compiler warning under OpenVMS; time_t is unsigned on (at least)
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.
2001-03-01 06:33:32 +00:00
Jeremy Hylton 7889107be7 Fix core dump in example from Samuele Pedroni:
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.
2001-03-01 06:09:34 +00:00
Tim Peters 5819aa8b32 Remove extra close curly in code #ifdef'ed out on my box. 2001-03-01 02:20:01 +00:00
Tim Peters 430f5d401d In Steven's apparent absence, check in *something* with a non-zero chance
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.
2001-03-01 01:30:56 +00:00
Jeremy Hylton 5125773ff1 Don't add global names to st->st_global if we're already iterating
over the elements of st->st_global!
2001-03-01 00:42:55 +00:00
Jeremy Hylton 3dd5ad3b4f undo introduction of st_global_star 2001-02-28 23:47:55 +00:00
Jeremy Hylton c176132d63 Warn about global statement at the module level.
Do better accounting for global variables.
2001-02-28 23:44:45 +00:00
Jeremy Hylton 4419ac1a97 Add warning/error handlin for problematic nested scopes cases as
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.
2001-02-28 22:54:51 +00:00
Guido van Rossum ee34ac124a Let's have some sanity. Introduce a helper to issue a symbol table
warning.
2001-02-28 22:08:12 +00:00
Guido van Rossum 0bba7f83f2 Use the new PyErr_WarnExplicit() API to issue better warnings for
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.
2001-02-28 21:55:38 +00:00
Fred Drake 9da7f3b4f4 SyntaxError__init__(): Be a little more robust when picking apart the
location information for the SyntaxError -- do not do more than we
    need to, stopping as soon as an exception has been raised.
2001-02-28 21:52:10 +00:00
Guido van Rossum 2fd456508f Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), with
explicit filename, lineno etc. arguments.
2001-02-28 21:46:24 +00:00
Fred Drake b797f1f6d2 Now that Jeremy is asking about this code, it looks really bogus to me,
so let's rip it out.  The constructor for SyntaxError does the right
thing, so we do not need to do it again.
2001-02-28 20:58:04 +00:00
Jeremy Hylton ad3d3f2f3f Improve SyntaxErrors for bad future statements. Set file and location
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().
2001-02-28 17:47:12 +00:00
Tim Peters 5687ffe0c5 SF patch 404928: Support for next Cygwin gcc (2.95.2-8) 2001-02-28 16:44:18 +00:00
Jeremy Hylton 9f1b9932b8 Print the offending line of code in the traceback for SyntaxErrors
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.
2001-02-28 07:07:43 +00:00
Tim Peters e860f9b983 Ack -- my eyes are getting bleary. Typos in the comment typo repairs. 2001-02-28 05:57:51 +00:00
Tim Peters f91ed2ddcf Comment typos. 2001-02-28 05:56:18 +00:00
Tim Peters 50d8d37b3f Implement PEP 235: Import on Case-Insensitive Platforms.
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.
2001-02-28 05:34:27 +00:00
Jeremy Hylton 280c81a940 Need to support single_input explicitly so from __future__ imports
are legal at the interactive interpreter prompt.  They don't do
anything yet...
2001-02-28 02:26:14 +00:00
Jeremy Hylton 39e2f3f824 Presumed correct compiler pass for future statements
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.
2001-02-28 01:58:08 +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 be77cf7d57 Add warnings about undefined "global"
SF bug #233532

XXX Can't figure out how to write test cases that work with warnings
2001-02-27 05:15:57 +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
Tim Peters 1e542110f9 Shuffle premature decref; nuke unreachable code block.
Fixes the "debug-build -O test_builtin.py and no test_b2.pyo" crash just
discussed on Python-Dev.
2001-02-23 22:23:53 +00:00
Barry Warsaw 0372af754e symtable_update_free_vars(), symtable_undo_free(),
symtable_enter_scope(): Removed some unnecessary backslashes at the
end of lines.  C != Python. :)
2001-02-23 18:22:59 +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
Guido van Rossum 85cd1d690c The code in PyImport_Import() tried to save itself a bit of work and
save the __builtin__ module in a static variable.  But this doesn't
work across Py_Finalise()/Py_Initialize()!  It also doesn't work when
using multiple interpreter states created with PyInterpreterState_New().

So I'm ripping out this small optimization.

This was probably broken since PyImport_Import() was introduced in
1997!  We really need a better test suite for multiple interpreter
states and repeatedly initializing.

This fixes the problems Barry reported in Demo/embed/loop.c.
2001-02-20 21:43:24 +00:00
Jeremy Hylton 2b3f0ca2ac Fix for implicit tuple + default arguments, courtesy of Michael Hudson.
SF patch #103749
2001-02-19 23:52:49 +00:00
Jeremy Hylton 384639f80e When running python -O, do not include blocks defined in asserts in
the symbol table pass.  These blocks were already ignored by the code
gen pass.  Both passes must visit the same set of blocks in the same
order.

Fixes SF buf 132820
2001-02-19 15:50:51 +00:00
Jeremy Hylton 17820c4f1b Tolerate ill-formed trees in symtable_assign(). Fixes SF bug 132510. 2001-02-19 15:33:10 +00:00
Tim Peters 4e30378e80 Bug #132313 error message confusing for assignment in lambda.
They're actually complaining about something more specific, an assignment
in a lambda as an actual argument, so that Python parses the
lambda as if it were a keyword argument.  Like f(lambda x: x[0]=42).
The "lambda x: x[0]" part gets parsed as if it were a keyword, being
bound to 42, and the resulting error msg didn't make much sense.
2001-02-18 04:45:10 +00:00
Tim Peters 6f5a4efc0a Bug #132850 unix line terminator on windows.
Miserable hack to replace the previous miserable hack in maybe_pyc_file.
2001-02-17 22:02:34 +00:00
Tim Peters 3081421d9e Change temp names created by listcomps from [%d] to _[%d], so the one-liner
[k for k in dir() if k[0] != "_"]
can be used to get the non-private names (used to contain "[1]").
2001-02-17 05:30:26 +00:00
Thomas Wouters fc93b0a81a Remove trailing comma from 'why_code' enum, which was introduced by the
continue-inside-try patch. Partly fixes SF bug #132597.
2001-02-16 11:52:31 +00:00
Tim Peters 5c4d5bfaf5 Related to SF bug 132008 (PyList_Reverse blows up).
_testcapimodule.c
    make sure PyList_Reverse doesn't blow up again
getargs.c
    assert args isn't NULL at the top of vgetargs1 instead of
    waiting for a NULL-pointer dereference at the end
2001-02-12 22:13:26 +00:00