Commit Graph

326 Commits

Author SHA1 Message Date
Fred Drake 72bc456403 Add weakref support generator-iterators.
Part of fixing SF bug #591704.
2002-08-09 18:35:52 +00:00
Skip Montanaro 496e6581e1 get rid of GETNAMEV macro - use GETITEM directly
same idea as getting rid of GETCONST & GETNAME (see patch #506436)
2002-08-06 17:47:40 +00:00
Skip Montanaro 04d80f87d7 small speedup for constant and name access
see sf #506436
2002-08-04 21:03:35 +00:00
Guido van Rossum 04e7032c6e SF patch 552161 - Py_AddPendingCall doesn't unlock on fail (Daniel
Dunbar)

Can't test this, but looks correct to me.
2002-07-17 16:57:13 +00:00
Tim Peters 0c32279626 Removed more stray instances of statichere, but left _sre.c alone. 2002-07-17 16:49:03 +00:00
Jeremy Hylton 938ace69a0 staticforward bites the dust.
The staticforward define was needed to support certain broken C
compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
static keyword when it was used with a forward declaration of a static
initialized structure.  Standard C allows the forward declaration with
static, and we've decided to stop catering to broken C compilers.  (In
fact, we expect that the compilers are all fixed eight years later.)

I'm leaving staticforward and statichere defined in object.h as
static.  This is only for backwards compatibility with C extensions
that might still use it.

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Tim Peters a64295b43a There's no need for generators to define an explicit next() method. 2002-07-17 00:15:22 +00:00
Neal Norwitz a81d220625 SF patch # 580411, move frame macros from frameobject.h into ceval.c
remove unused macros
use co alias instead of f->f_code in macros
2002-07-14 00:27:26 +00:00
Jeremy Hylton 76c81eecfa Don't stomp on an exception set by PyCell_Get() 2002-07-11 16:56:38 +00:00
Michael W. Hudson cb4d7ce7cb Now FOR_LOOP is gone, loop_subscript can go too.
make -s rules :-)
2002-06-14 13:53:29 +00:00
Guido van Rossum fea59e7f76 The opcode FOR_LOOP no longer exists. 2002-06-13 17:59:51 +00:00
Guido van Rossum c5fe5eb8d2 SF bug 567538: Generator can crash the interpreter (Finn Bock).
This was a simple typo.  Strange that the compiler didn't catch it!
Instead of WHY_CONTINUE, two tests used CONTINUE_LOOP, which isn't a
why_code at all, but an opcode; but even though 'why' is declared as
an enum, comparing it to an int is apparently not even worth a
warning -- not in gcc, and not in VC++. :-(

Will fix in 2.2 too.
2002-06-12 03:45:21 +00:00
Michael W. Hudson d95c828307 Fix for
[ 558249 ] softspace vs --disable-unicode

And #endif was in the wrong place.

Bugfix candidate, almost surely.

I think I will embark on squashing test failures in --disable-unicode builds --
a Real Bug was hiding under them.
2002-05-20 13:56:11 +00:00
Tim Peters afb2c80b29 ceval.c/do_raise(): Tighten the test to disallow raising an instance of
a str subclass.

test_descr.py/string_exceptions():  New sub-test.

For 2.3 only.  Guido doesn't want this backported.
2002-04-18 18:06:20 +00:00
Guido van Rossum cfbf1a33c1 Fix an issue that was reported in but unrelated to the main problem of
SF bug 535905 (Evil Trashcan and GC interaction).

The SETLOCAL() macro should not DECREF the local variable in-place and
then store the new value; it should copy the old value to a temporary
value, then store the new value, and then DECREF the temporary value.
This is because it is possible that during the DECREF the frame is
accessed by other code (e.g. a __del__ method or gc.collect()) and the
variable would be pointing to already-freed memory.

BUGFIX CANDIDATE!
2002-03-28 20:17:52 +00:00
Tim Peters 8e5fd53be0 SF bug 480215: softspace confused in nested print
This fixes the symptom, but PRINT_ITEM has no way to know what (if
anything) PyFile_WriteObject() writes unless the object being printed
is a string.  When the object isn't a string, this fix retains the
guess that softspace should be set after PyFile_WriteObject().
We might want to say that it's the job of filelike-object write methods
to leave the file's softspace in the correct state.  That would probably
be better -- but everyone relies on PRINT_ITEM to guess for them now.
2002-03-24 19:25:00 +00:00
Neil Schemenauer c24ea08644 Disable the parser hacks that enabled the "yield" keyword using a future
statement.
2002-03-22 23:53:36 +00:00
Neil Schemenauer 08de92a267 Re-enable GC of generator objects. 2002-03-18 20:45:09 +00:00
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