Commit Graph

308 Commits

Author SHA1 Message Date
Neil Schemenauer 6354386d65 Move some opcodes to top of big eval_frame switch statement. Skip
things_to_do block for a few common opcodes that don't do any real
work.  Closes SF patch #512256.
2002-02-17 19:10:14 +00:00
Tim Peters 373f8d81ff LOAD_FAST: rearrange branches to favor the expected case, and get
rid of a redundant NULL-pointer check in the expected case.
2002-02-12 04:31:21 +00:00
Martin v. Löwis 7198a525f3 Patch #494783: Rename cmp_op enumerators. 2002-01-01 19:59:11 +00:00
Tim Peters 54b11918be SF bug #496549 -Qnew and in-place division "/=".
eval_frame():  Under -Qnew, INPLACE_DIVIDE wasn't getting handed off to
INPLACE_TRUE_DIVIDE (like BINARY_DIVIDE was getting handed off to
BINARY_TRUE_DIVIDE).

Bugfix candidate.
2001-12-25 18:49:11 +00:00
Tim Peters b6d14daa1c SF bug #494668: PUSH() should assert-fail on overflow.
eval_frame():  Added asserts to the top of the eval loop, to verify
that the eval stack pointer is in bounds, plus some comments.
2001-12-19 04:11:07 +00:00
Martin v. Löwis 8d3ce5a6b3 Patch #494384: Disable more Unicode API if Unicode is not used. 2001-12-18 22:36:40 +00:00
Tim Peters b519638d1e _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
to Guido for the revelation).
2001-12-16 19:44:20 +00:00
Tim Peters cb479e78e0 _PyEval_SliceIndex(): Repaired the comments, and added XXX comments
about its dubious treatment of NULL (also opened a bug report on that,
but don't want to risk changing it this late in the 2.2 game).
2001-12-16 19:11:44 +00:00
Jeremy Hylton 733c8935f9 Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
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.
2001-12-13 19:51:56 +00:00
Guido van Rossum 35974fbf31 Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Had nothing to do with rich comparisons -- some stack cleanup code was
lost as a result of merging in Neil Schemenauer's generators patch.
Reinserted the stack cleanup code, skipping it when yielding.
2001-12-06 21:28:18 +00:00
Guido van Rossum 2556f2e1e2 Fix a typo (probably caused by autocompletion <blush>) that caused a
leak when a class defined a __metaclass__.  This fixes the problem
reported on python-dev by Ping; I dunno if it's the same as SF bug
#489669 (since that mentions Unicode).
2001-12-06 14:09:56 +00:00
Tim Peters 3caca2326e SF bug #488514: -Qnew needs work
Big Hammer to implement -Qnew as PEP 238 says it should work (a global
option affecting all instances of "/").

pydebug.h, main.c, pythonrun.c:  define a private _Py_QnewFlag flag, true
iff -Qnew is passed on the command line.  This should go away (as the
comments say) when true division becomes The Rule.  This is
deliberately not exposed to runtime inspection or modification:  it's
a one-way one-shot switch to pretend you're using Python 3.

ceval.c:  when _Py_QnewFlag is set, treat BINARY_DIVIDE as
BINARY_TRUE_DIVIDE.

test_{descr, generators, zipfile}.py:  fiddle so these pass under
-Qnew too.  This was just a matter of s!/!//! in test_generators and
test_zipfile.  test_descr was trickier, as testbinop() is passed
assumptions that "/" is the same as calling a "__div__" method; put
a temporary hack there to call "__truediv__" instead when the method
name is "__div__" and 1/2 evaluates to 0.5.

Three standard tests still fail under -Qnew (on Windows; somebody
please try the Linux tests with -Qnew too!  Linux runs a whole bunch
of tests Windows doesn't):
    test_augassign
    test_class
    test_coercion
I can't stay awake longer to stare at this (be my guest).  Offhand
cures weren't obvious, nor was it even obvious that cures are possible
without major hackery.

Question:  when -Qnew is in effect, should calls to __div__ magically
change into calls to __truediv__?  See "major hackery" at tail end of
last paragraph <wink>.
2001-12-06 06:23:26 +00:00
Guido van Rossum 354797ccad Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
and assign_slice() weren't properly DECREF'ing the temporary slice
object they created.  (Shame on me. :-)
2001-12-03 19:45:06 +00:00
Guido van Rossum bb8f59a371 unpack_iterable(): Add a missing DECREF in an error case. Reported by
Armin Rigo (SF bug #488477).  Added a testcase to test_unpack_iter()
in test_iter.py.
2001-12-03 19:33:25 +00:00
Tim Peters b13680bf03 SF bug #483469: crash on unbounded recursion in __del__.
PyEval_EvalCodeEx():  increment tstate->recursion_depth around the
decref of the frame, because the C stack for this call is still in
use and the decref can lead to __del__ methods getting called.

While this gives tstate->recursion_depth a value proportional to the
depth of the C stack (instead of a small constant no matter how
deeply __del__s recurse), it's not enough to stop the reported crash
when using the default recursion limit on Windows.

Bugfix candidate.
2001-11-27 23:29:29 +00:00
Marc-André Lemburg 0c4d8d05a8 Fix for bug #480188: printing unicode objects 2001-11-20 15:17:25 +00:00
Marc-André Lemburg 4962fc8fed Backing out the fast path for interned string compares again as requested. 2001-11-08 08:34:43 +00:00
Marc-André Lemburg c52d713b7a Add fast-path for comparing interned (true) string objects.
This patch boosts performance for comparing identical string object
by some 20% on my machine while not causing any noticable slow-down
for other operations (according to tests done with pybench).
2001-11-07 14:54:49 +00:00
Tim Peters 6e6a63f01c SF Patch (but with no patch) 472555 Remove trailing common in enumeration.
Some AIX compiler didn't like the trailing comma at the end of the
why_code enum decl.
2001-10-18 20:49:35 +00:00
Jeremy Hylton 14368158c2 For debug build, check that the stack pointer never exceeds the stack size. 2001-10-17 13:29:30 +00:00
Skip Montanaro f118cb1d6f make getarray static - it's only called from ceval.c and is not an
extern-able name.
2001-10-15 20:51:38 +00:00
Fred Drake de26cfc1e1 Suppress a bunch of "value computed is not used" warnings when building in
debug mode (--with-pydebug).
2001-10-13 06:11:28 +00:00
Tim Peters b1c469843f Introduced the oddly-missing PyList_CheckExact(), and used it to replace
a hard-coded type check.
2001-10-05 20:41:38 +00:00
Tim Peters c1e6d969ba Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact. 2001-10-05 20:21:03 +00:00
Fred Drake 4ec5d5699d Fix bug in profiler modifications detected only in debug builds.
The new profiler event stream includes a "return" event even when an
exception is being propogated, but the machinery that called the profile
hook did not save & restore the exception.  In debug mode, the exception
was detected during the execution of the profile callback, which did not
have the proper internal flags set for the exception.  Saving & restoring
the exception state solves the problem.
2001-10-04 19:26:43 +00:00
Fred Drake 8f51f54319 Rationalize the events passed to the profiler (no changes for the tracer).
The profiler does not need to know anything about the exception state,
so we no longer call it when an exception is raised.  We do, however,
make sure we *always* call the profiler when we exit a frame.  This
ensures that timing events are more easily isolated by a profiler and
finally clauses that do a lot of work don't have their time
mis-allocated.

When an exception is propogated out of the frame, the C callback for
the profiler now receives a PyTrace_RETURN event with an arg of NULL;
the Python-level profile hook function will see a 'return' event with
an arg of None.  This means that from Python it is impossible for the
profiler to determine if the frame exited with an exception or if it
returned None, but this doesn't matter for profiling.  A C-based
profiler could tell the difference, but this doesn't seem important.

ceval.c:eval_frame():  Simplify the code in two places so that the
                       profiler is called for every exit from a frame
                       and not for exceptions.

sysmodule.c:profile_trampoline():  Make sure we don't expose Python
                                   code to NULL; use None instead.
2001-10-04 14:48:42 +00:00
Tim Peters 8b13b3ede2 SF bug [#466173] unpack TypeError unclear
Replaced 3 instances of "iter() of non-sequence" with
"iteration over non-sequence".
Restored "unpack non-sequence" for stuff like "a, b = 1".
2001-09-30 05:58:42 +00:00
Jeremy Hylton c631489289 Prevent a NULL pointer from being pushed onto the stack.
It's possible for PyErr_NormalizeException() to set the traceback
pointer to NULL.  I'm not sure how to provoke this directly from
Python, although it may be possible.  The error occurs when an
exception is set using PyErr_SetObject() and another exception occurs
while PyErr_NormalizeException() is creating the exception instance.

XXX As a result of this change, it's possible for an exception to
occur but sys.last_traceback to be left undefined.  Not sure if this
is a problem.
2001-09-26 19:24:45 +00:00
Thomas Wouters 1ee6422111 Don't swap the arguments to PyFrame_BlockSetup when recreating the recently
popped frame-block. What an embarrassing bug! Especially for Jeremy, since
he accepted the patch :-)

This fixes SF bugs #463359 and #462937, and possibly other, *very* obscure
bugs with very deeply nested loops that continue the loop and then break out
of it or raise an exception.
2001-09-24 19:32:01 +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
Fred Drake b9a96282f1 Admit that we'll never add the args for a "call" event to the profile
and trace functions; this now declares that None will be passed for the
"call" event.
This closes SF bug/suggestion #460315.
2001-09-13 16:56:43 +00:00
Guido van Rossum 7851eea5f2 build_class(): one more (hopefully the last) step on the way to
backwards compatibility.  When using the class of the first base as
the metaclass, use its __class__ attribute in preference over its
ob_type slot.  This ensures that we can still use classic classes as
metaclasse, as shown in the original "Metaclasses" essay.  This also
makes all the examples in Demo/metaclasses/ work again (maybe these
should be turned into a test suite?).
2001-09-12 19:19:18 +00:00
Neil Schemenauer 6c0f20088f Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
way it's called each time a generator is resumed.  The tracing of normal
functions should be unaffected by this change.
2001-09-04 19:03:35 +00:00
Guido van Rossum 46add98758 Do the int inlining only if the type is really an int, not whenever
PyInt_Check() succeeds.  That returns true for subtypes of int, which
may override __add__ or __sub__.
2001-08-30 16:06:23 +00:00
Sjoerd Mullender 2f38f81fec Removed some unreachable break statements to silence SGI compiler. 2001-08-30 14:05:20 +00:00
Guido van Rossum 87780dfa97 When an inlined operation on two small ints causes overflow, don't
raise the exception here -- call the generic function (which may
convert the arguments to long and try again).
2001-08-23 02:58:07 +00:00
Guido van Rossum 50d756e262 Fix SF bug #443600:
Change to get/set/del slice operations so that if the object doesn't
support slicing, *or* if either of the slice arguments is not an int
or long, we construct a slice object and call the get/set/del item
operation instead.  This makes it possible to design classes that
support slice arguments of non-integral types.
2001-08-18 17:43:36 +00:00
Tim Peters e2c18e90da ceval, PyEval_MergeCompilerFlags: wasn't merging in the
CO_FUTURE_DIVISION flag.  Redid this to use Jeremy's PyCF_MASK #define
instead, so we dont have to remember to fiddle individual feature names
here again.

pythonrun.h:  Also #define a PyCF_MASK_OBSOLETE mask.  This isn't used
yet, but will be as part of the PEP 264 implementation (compile() mustn't
raise an error just because old code uses a flag name that's become
obsolete; a warning may be appropriate, but not an error; so compile() has
to know about obsolete flags too, but nobody is going to remember to
update compile() with individual obsolete flag names across releases either
-- i.e., this is the flip side of PyEval_MergeCompilerFlags's oversight).
2001-08-17 20:47:47 +00:00
Martin v. Löwis e3eb1f2b23 Patch #427190: Implement and use METH_NOARGS and METH_O. 2001-08-16 13:15:00 +00:00
Jeremy Hylton 910d7d46dc Remove much dead code from ceval.c
The descr changes moved the dispatch for calling objects from
call_object() in ceval.c to PyObject_Call() in abstract.c.
call_object() and the many functions it used in ceval.c were no longer
used, but were not removed.

Rename meth_call() as PyCFunction_Call() so that it can be called by
the CALL_FUNCTION opcode in ceval.c.

Also, fix error message that referred to PyEval_EvalCodeEx() by its
old name eval_code2().  (I'll probably refer to it by its old name,
too.)
2001-08-12 21:52:24 +00:00
Jeremy Hylton b857ba261f Refactor future feature handling
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.
2001-08-10 21:41:33 +00:00
Guido van Rossum 4668b000a1 Implement PEP 238 in its (almost) full glory.
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.
2001-08-08 05:00:18 +00:00
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Tim Peters 5ba5866281 Part way to allowing "from __future__ import generators" to communicate
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.
2001-07-16 02:29:45 +00:00
Neil Schemenauer f8c7c20ba5 GC for generator objects. 2001-07-12 13:27:49 +00:00
Fred Drake 9e3ad78444 This change adjusts the profiling/tracing support so that the common
path (with no profile/trace function) through eval_code2() and
eval_frame() avoids several checks.

In the common cases of calls, returns, and exception propogation,
eval_code2() and eval_frame() used to test two values in the
thread-state: the profiling function and the tracing function.  With
this change, a flag is set in the thread-state if either of these is
active, allowing a single check to suffice when both are NULL.  This
also simplifies the code needed when either function is in use but is
already active (to avoid profiling/tracing the profiler/tracer); the
flag is set to 0 when the profile/trace code is entered, allowing the
same check to suffice for "already in the tracer" for call/return/
exception events.
2001-07-03 23:39:52 +00:00
Fred Drake 5755ce693d Revise the interface to the profiling and tracing support for the
Python interpreter.

This change adds two new C-level APIs:  PyEval_SetProfile() and
PyEval_SetTrace().  These can be used to install profile and trace
functions implemented in C, which can operate at much higher speeds
than Python-based functions.  The overhead for calling a C-based
profile function is a very small fraction of a percent of the overhead
involved in calling a Python-based function.

The machinery required to call a Python-based profile or trace
function been moved to sysmodule.c, where sys.setprofile() and
sys.setprofile() simply become users of the new interface.

As a side effect, SF bug #436058 is fixed; there is no longer a
_PyTrace_Init() function to declare.
2001-06-27 19:19:46 +00:00
Tim Peters e77f2e2798 gen_getattr: make the gi_running and gi_frame members discoverable (but
not writable -- too dangerous!) from Python code.
2001-06-26 22:24:51 +00:00
Tim Peters d8e1c9e177 Add "gi_" (generator-iterator) prefix to names of genobject members.
Makes it much easier to find references via dumb editor search (former
"frame" in particular was near-hopeless).
2001-06-26 20:58:58 +00:00
Tim Peters ad1a18b78e Change the semantics of "return" in generators, as discussed on the
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.
2001-06-23 06:19:16 +00:00