Commit Graph

1284 Commits

Author SHA1 Message Date
Guido van Rossum f68d8e52e7 Make some private symbols static. 2001-04-14 17:55:09 +00:00
Jeremy Hylton 37832f0c8d split long line 2001-04-13 17:50:20 +00:00
Jeremy Hylton c76770c68c Change error message raised when free variable is not yet bound. It
now raises NameError instead of UnboundLocalError, because the var in
question is definitely not local.  (This affects test_scope.py)

Also update the recent fix by Ping using get_func_name().  Replace
tests of get_func_name() return value with call to get_func_desc() to
match all the other uses.
2001-04-13 16:51:46 +00:00
Guido van Rossum d9994e0115 Patch by Ping (SF bug 415879, Exception.__init__() causes segfault):
Calling an unbound method on a C extension class without providing
   an instance can yield a segfault.  Try "Exception.__init__()" or
   "ValueError.__init__()".

   This is a simple fix. The error-reporting bits in call_method
   mistakenly treat the misleadingly-named variable "func" as a
   function, when in fact it is a method.

   If we let get_func_name take care of the work, all is fine.
2001-04-13 15:42:40 +00:00
Guido van Rossum 23f7aed2a7 Because this code was derived from Python 1.6.1 (amongst others), the
CNRI copyright should be updated to include 2001.
2001-04-12 20:53:31 +00:00
Guido van Rossum ce260d569e Update copyright to PSF. 2001-04-12 12:27:34 +00:00
Jeremy Hylton 512a237725 Fix exception handling for non-PyFunction objects, SF bug 414743.
Fix based on patch #414750 by Michael Hudson.

New functions get_func_name() and get_func_desc() return reasonable
names and descriptions for all objects.  XXX Even objects that aren't
actually callable.
2001-04-11 13:52:29 +00:00
Guido van Rossum bceccf5f43 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger 2001-04-10 22:07:43 +00:00
Tim Peters 44714007e8 test_pickle works on sizeof(long)==8 boxes again.
pickle.py
    The code implicitly assumed that all ints fit in 4 bytes, causing all
    sorts of mischief (from nonsense results to corrupted pickles).
    Repaired that.
marshal.c
    The int marshaling code assumed that right shifts of signed longs
    sign-extend.  Repaired that.
2001-04-10 05:02:52 +00:00
Jeremy Hylton a830b3859b Warn when assigning to __debug__ instead of raising an error. 2001-04-09 16:07:59 +00:00
Tim Peters 388ed08cbf SF patch #413552 - Premature decref on object
Jeffery Collins pointed out that filterstring decrefs a character object
before it's done using it.  This works by accident today because another
module always happens to have an active reference too at the time.  The
accident doesn't work after his Pippy modifications, and since it *is*
an accident even in the mainline Python, it should work by design there too.
The patch accomplishes that.
2001-04-07 20:34:48 +00:00
Jeremy Hylton 673a4fda51 Bug fix: compile() called from a nested-scopes-enable Python was not
using nested scopes to compile its argument.  Pass compiler flags
through to underlying compile call.
2001-03-26 19:53:38 +00:00
Guido van Rossum 66e8e86cf8 Finishing touch to Ping's changes. This is a patch that Ping sent me
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.
2001-03-23 17:54:43 +00:00
Fred Drake 6a12d8d3b4 call_sys_exitfunc(): Remove unused variable f. 2001-03-23 17:34:02 +00:00
Ka-Ping Yee 26fabb0016 Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
sys.exitfunc gets the last word on the exit status of the program.
2001-03-23 15:36:41 +00:00
Jeremy Hylton 897b82123d Make it illegal to assign to __debug__ as per Guido's request. 2001-03-23 14:08:38 +00:00
Guido van Rossum 4131830c23 Fix memory leak with SyntaxError. (The DECREF was originally hidden
inside a piece of code that was deemed reduntant; the DECREF was
unfortunately *not* redundant!)
2001-03-23 04:01:07 +00:00
Ka-Ping Yee b5c5132d1a Add sys.excepthook.
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__.
2001-03-23 02:46:52 +00:00
Jeremy Hylton 2e2cded1b5 Set the line number correctly for a nested function with an exec or
import *.  Mark the offending stmt rather than the function def line.
2001-03-22 03:57:58 +00:00
Jeremy Hylton 280e6bd742 Make error messages clearer for illegal combinations of nested
functions and import */exec.
2001-03-22 03:51:05 +00:00
Jeremy Hylton bc32024769 Extend support for from __future__ import nested_scopes
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.
2001-03-22 02:47:58 +00:00
Jeremy Hylton 061d106a0f If a code object is compiled with nested scopes, define the CO_NESTED flag.
Add PyEval_GetNestedScopes() which returns a non-zero value if the
code for the current interpreter frame has CO_NESTED defined.
2001-03-22 02:32:48 +00:00
Guido van Rossum 66b0e9c2a7 Use PyObject_IsInstance() to check whether the first argument to an
unbound method is of the right type.  Hopefully this solves SF patch
#409355 (Meta-class inheritance problem); I have no easy way to test.
2001-03-21 19:17:22 +00:00
Jeremy Hylton ded4bd776f Update PyNode_CompileSymtable() to understand future statements 2001-03-21 19:01:33 +00:00
Guido van Rossum 823649d544 Move the code implementing isinstance() and issubclass() to new C
APIs, PyObject_IsInstance() and PyObject_IsSubclass() -- both
returning an int, or -1 for errors.
2001-03-21 18:40:58 +00:00
Jeremy Hylton 220ae7c0bf Fix PyFrame_FastToLocals() and counterpart to deal with cells and
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.
2001-03-21 16:43:47 +00:00
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