Commit Graph

2823 Commits

Author SHA1 Message Date
Georg Brandl 49aafc9f2c Variant of patch #697613: don't exit the interpreter on a SystemExit
exception if the -i command line option or PYTHONINSPECT environment
variable is given, but break into the interactive interpreter just like
on other exceptions or normal program exit.
 (backport)
2007-03-07 00:34:46 +00:00
Georg Brandl 098cd69ff9 Bug #1674503: close the file opened by execfile() in an error condition. 2007-03-06 12:17:50 +00:00
Georg Brandl 0fca97a5fb Patch #1674228: when assigning a slice (old-style), check for the
sq_ass_slice instead of the sq_slice slot.
2007-03-05 22:28:08 +00:00
Raymond Hettinger 20e1199fbe Fix embarrassing typo and fix constantification of None 2007-03-02 19:20:46 +00:00
Jeremy Hylton 819de6ce20 tabify
Note that ast.c still has a mix of tabs and spaces, because it
attempts to use four-space indents for more of the new code.
2007-02-27 16:13:23 +00:00
Jeremy Hylton 37075c5ace Fix long-standing bug in name mangling for package imports
Reported by Mike Verdone.
2007-02-27 01:01:59 +00:00
Neal Norwitz f83b751f4b SF #1669182, 2.5 was already fixed. Just assert in 2.6 since string exceptions
are gone.
2007-02-26 23:48:27 +00:00
Neal Norwitz 88516a6039 When printing an unraisable error, don't print exceptions. before the name.
This duplicates the behavior whening normally printing exceptions.
2007-02-26 22:41:45 +00:00
Neal Norwitz 7b7d1c8282 Fix a couple of problems in generating the AST code:
* use %r instead of backticks since backticks are going away in Py3k
 * PyArena_Malloc() already sets PyErr_NoMemory so we don't need to do it again
 * the signature for ast2obj_int incorrectly used a bool, rather than a long
2007-02-26 18:10:47 +00:00
Jeremy Hylton 7c1e347f73 Reformat long lines. 2007-02-26 16:14:51 +00:00
Jeremy Hylton 714b112ae5 Put declarations before code. 2007-02-25 16:01:58 +00:00
Jeremy Hylton c5ceb251b3 Fix crash in exec when unicode filename can't be decoded.
I can't think of an easy way to test this behavior.  It only occurs
when the file system default encoding and the interpreter default
encoding are different, such that you can open the file but not decode
its name.
2007-02-25 15:57:45 +00:00
Brett Cannon 0db62aaf09 Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
is specified at the top of the file.  Also add a note that Python/Python-ast.c
needs to be committed separately after a change to the AST grammar to capture
the revision number of the change (which is what __version__ is set to).
2007-02-12 03:51:02 +00:00
Brett Cannon d080d4b047 Check in changed Python-ast.c from a cosmetic change to Python.asdl (in
r53731).
2007-02-11 19:44:41 +00:00
Brett Cannon 129bd52146 No more raising of string exceptions!
The next step of PEP 352 (for 2.6) causes raising a string exception to trigger
a TypeError.  Trying to catch a string exception raises a DeprecationWarning.
References to string exceptions has been removed from the docs since they are
now just an error.
2007-01-30 21:34:36 +00:00
Martin v. Löwis 6c5c502b91 Make PyTraceBack_Here use the current thread, not the
frame's thread state. Fixes #1579370.
Will backport.
2007-01-23 21:11:47 +00:00
Thomas Wouters afea529088 SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
When running the interpreter in an environment that would cause it to set
stdout/stderr/stdin's encoding, having a sitecustomize that would replace
them with something other than PyFile objects would crash the interpreter.
Fix it by simply ignoring the encoding-setting for non-files.

This could do with a test, but I can think of no maintainable and portable
way to test this bug, short of adding a sitecustomize.py to the buildsystem
and have it always run with it (hmmm....)
2007-01-23 13:42:00 +00:00
Anthony Baxter 83955ef639 update to (c) years to include 2007 2007-01-06 04:45:54 +00:00
Raymond Hettinger 4bd97d4549 SF# 1409443: Expand comment to cover the interaction between f->f_lasti and the PREDICT macros. 2007-01-06 01:14:41 +00:00
Neal Norwitz 72cd02c041 Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).

Will backport.
2007-01-05 05:25:22 +00:00
Armin Rigo 7037085959 Forgot a case where the locals can now be a general mapping
instead of just a dictionary.  (backporting...)
2006-11-29 21:59:22 +00:00
Neal Norwitz 85dbec6da7 Bug #1588287: fix invalid assertion for `1,2` in debug builds.
Will backport
2006-11-04 19:25:22 +00:00
Neal Norwitz f733a013b2 Update comments, remove commented out code.
Move assembler structure next to assembler code to make it easier to
move it to a separate file.
2006-10-29 18:30:10 +00:00
Georg Brandl 2c4fb8d601 Clean up a leftover from old listcomp generation code. 2006-10-29 08:47:08 +00:00
Neal Norwitz 21997afb0c Fix bug #1565514, SystemError not raised on too many nested blocks.
It seems like this should be a different error than SystemError, but
I don't have any great ideas and SystemError was raised in 2.4 and earlier.

Will backport.
2006-10-28 21:19:07 +00:00
Neal Norwitz 837ce9389e Add some asserts. In sysmodule, I think these were to try to silence
some warnings from Klokwork.  They verify the assumptions of the format
of svn version output.

The assert in the thread module helped debug a problem on HP-UX.
2006-10-28 21:15:30 +00:00
Andrew M. Kuchling 1f3ebe0b10 [Bug #1542016] Report PCALL_POP value. This makes the return value of sys.callstats() match its docstring.
Backport candidate.  Though it's an API change, this is a pretty obscure
portion of the API.
2006-10-27 13:22:46 +00:00
Martin v. Löwis b5bc537c5e Patch #1549049: Rewrite type conversion in structmember.
Fixes #1545696 and #1566140. Will backport to 2.5.
2006-10-27 06:16:31 +00:00
Neal Norwitz cbeb687c68 Update the peephole optimizer to remove more dead code (jumps after returns)
and inline jumps to returns.
2006-10-14 21:33:38 +00:00
Georg Brandl 8134d06e08 Bug #1283491: follow docstring convention wrt. keyword-able args in sum(). 2006-10-12 12:33:07 +00:00
Armin Rigo 7ccbca93a2 Forward-port of r52136,52138: a review of overflow-detecting code.
* unified the way intobject, longobject and mystrtoul handle
  values around -sys.maxint-1.

* in general, trying to entierely avoid overflows in any computation
  involving signed ints or longs is extremely involved.  Fixed a few
  simple cases where a compiler might be too clever (but that's all
  guesswork).

* more overflow checks against bad data in marshal.c.

* 2.5 specific: fixed a number of places that were still confusing int
  and Py_ssize_t.  Some of them could potentially have caused
  "real-world" breakage.

* list.pop(x): fixing overflow issues on x was messy.  I just reverted
  to PyArg_ParseTuple("n"), which does the right thing.  (An obscure
  test was trying to give a Decimal to list.pop()... doesn't make
  sense any more IMHO)

* trying to write a few tests...
2006-10-04 12:17:45 +00:00
Jeremy Hylton 82271f13e7 Fix for SF bug 1569998: break permitted inside try.
The compiler was checking that there was something on the fblock
stack, but not that there was a loop on the stack.  Fixed that and
added a test for the specific syntax error.

Bug fix candidate.
2006-10-04 02:24:52 +00:00
Brett Cannon 5a9aa4f31c Fix minor typo in a comment. 2006-10-03 21:58:55 +00:00
Brett Cannon 94b69f6ba3 Very minor grammatical fix in a comment. 2006-09-28 22:10:14 +00:00
Neal Norwitz d3f91908dd Remove extra semi-colons reported by Johnny Lee on python-dev. Backport if anyone cares. 2006-09-23 04:11:38 +00:00
Neal Norwitz 3a23017bb2 Bug #1557232: fix seg fault with def f((((x)))) and def f(((x),)).
These tests should be improved.  Hopefully this fixes variations when
flipping back and forth between fpdef and fplist.

Backport candidate.
2006-09-22 08:18:10 +00:00
Walter Dörwald d14bf61d05 Fix typo. 2006-09-21 15:09:55 +00:00
Georg Brandl ec6c2dfb63 Forward-port of rev. 51857:
Building with HP's cc on HP-UX turned up a couple of problems.
_PyGILState_NoteThreadState was declared as static inconsistently.
Make it static as it's not necessary outside of this module.

Some tests failed because errno was reset to 0. (I think the tests
that failed were at least: test_fcntl and test_mailbox).
Ensure that errno doesn't change after a call to Py_END_ALLOW_THREADS.
This only affected debug builds.
2006-09-11 09:38:35 +00:00
Neal Norwitz 2a399b0f11 Properly handle a NULL returned from PyArena_New().
(Also fix some whitespace)

Klocwork #364.
2006-09-11 04:28:16 +00:00
Neal Norwitz ca460d9722 with and as are now keywords. There are some generated files I can't recreate. 2006-09-06 06:28:06 +00:00
Georg Brandl 98775dfebc Bug #1550983: emit better error messages for erroneous relative
imports (if not in package and if beyond toplevel package).
2006-09-06 06:09:31 +00:00
Neal Norwitz d042132268 M-x untabify 2006-09-05 04:00:12 +00:00
Neal Norwitz e4d4f00aee Add a comment about some refactoring. (There's probably more that should be done.) I will reformat this file in the next checkin due to the inconsistent tabs/spaces. 2006-09-05 03:58:26 +00:00
Neal Norwitz dac090d3e6 Bug #1520864 (again): unpacking singleton tuples in list comprehensions and
generator expressions (x for x, in ... ) works again.

Sigh, I only fixed for loops the first time, not list comps and genexprs too.
I couldn't find any more unpacking cases where there is a similar bug lurking.

This code should be refactored to eliminate the duplication.  I'm sure
the listcomp/genexpr code can be refactored.  I'm not sure if the for loop
can re-use any of the same code though.

Will backport to 2.5 (the only place it matters).
2006-09-05 03:53:08 +00:00
Neal Norwitz 477ca1c953 Fix SF #1552093, eval docstring typo (3 ps in mapping) 2006-09-05 02:25:41 +00:00
Neal Norwitz 0c6ae5bad4 Handle a few more error conditions.
Klocwork 301 and 302.  Will backport.
2006-08-21 20:16:24 +00:00
Neal Norwitz 4f096d9487 Patch #1542451: disallow continue anywhere under a finally
I'm undecided if this should be backported to 2.5 or 2.5.1.
Armin suggested to wait (I'm of the same opinion).  Thomas W thinks
it's fine to go in 2.5.
2006-08-21 19:47:08 +00:00
Neal Norwitz 87557cd72a Add assert to make Klocwork happy (#276) 2006-08-21 18:01:30 +00:00
Jeremy Hylton 644dddcc3f Move peephole optimizer to separate file. 2006-08-21 16:19:37 +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 3cb31ac704 cpathname could be NULL if it was longer than MAXPATHLEN. Don't try
to write the .pyc to NULL.

Check results of PyList_GetItem() and PyModule_GetDict() are not NULL.

Klocwork 282, 283, 285
2006-08-13 18:10:47 +00:00
Neal Norwitz df6a6494cb Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.

Klocwork 231-232
2006-08-13 18:10:10 +00:00
Neal Norwitz 8a87f5d37e Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments.  This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward.  I don't want this to hold up release if possible.
2006-08-12 17:03:09 +00:00
Neal Norwitz 0f7dbf731a PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Klocwork #298-299.
2006-08-12 03:17:41 +00:00
Neal Norwitz 421c1319ad Whoops, how did that get in there. :-) Revert all the parts of 51227 that were not supposed to go it. Only Modules/_ctypes/cfields.c was supposed to be changed 2006-08-12 02:12:30 +00:00
Neal Norwitz 6b4953fd3d Check returned pointer is valid.
Klocwork #233
2006-08-12 02:06:34 +00:00
Neal Norwitz edb2168079 This code is actually not used unless WITHOUT_COMPLEX is defined.
However, there was no error checking that PyFloat_FromDouble returned
a valid pointer.  I believe this change is correct as it seemed
to follow other code in the area.

Klocwork # 292.
2006-08-12 01:47:59 +00:00
Neal Norwitz 43bd4db933 It's highly unlikely, though possible for PyEval_Get*() to return NULLs.
So be safe and do an XINCREF.

Klocwork # 221-222.
2006-08-12 01:46:42 +00:00
Neal Norwitz 84167d09cd Even though _Py_Mangle() isn't truly public anyone can call it and
there was no verification that privateobj was a PyString.  If it wasn't
a string, this could have allowed a NULL pointer to creep in below and crash.

I wonder if this should be PyString_CheckExact?  Must identifiers be strings
or can they be subclasses?

Klocwork #275
2006-08-12 01:45:47 +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
Tim Peters 4643c2fda1 Followup to bug #1069160.
PyThreadState_SetAsyncExc():  internal correctness changes wrt
refcount safety and deadlock avoidance.  Also added a basic test
case (relying on ctypes) and repaired the docs.
2006-08-10 22:45:34 +00:00
Armin Rigo 97ff04789d Concatenation on a long string breaks (SF #1526585). 2006-08-09 15:37:26 +00:00
Georg Brandl 209307eb3b Introduce an upper bound on tuple nesting depth in
C argument format strings; fixes rest of #1523610.
2006-08-09 07:03:22 +00:00
Georg Brandl 7e3ba2a699 Bug #1535165: fixed a segfault in input() and raw_input() when
sys.stdin is closed.
2006-08-06 08:23:54 +00:00
Thomas Heller 74d36f0d95 On Windows, make PyErr_Warn an exported function again. 2006-08-04 18:17:40 +00:00
Neal Norwitz 9a70f95ee8 There were really two issues 2006-08-04 05:12:19 +00:00
Neal Norwitz 0cbd805a10 Bug #1333982: string/number constants were inappropriately stored
in the byte code and co_consts even if they were not used, ie
immediately popped off the stack.
2006-08-04 05:09:28 +00:00
Neal Norwitz 4ffedadb10 Bug #1191458: tracing over for loops now produces a line event
on each iteration.  I'm not positive this is the best way to handle
this.  I'm also not sure that there aren't other cases where
the lnotab is generated incorrectly.  It would be great if people
that use pdb or tracing could test heavily.

Also:
 * Remove dead/duplicated code that wasn't used/necessary
   because we already handled the docstring prior to entering the loop.
 * add some debugging code into the compiler (#if 0'd out).
2006-08-04 04:58:47 +00:00
Neal Norwitz c173b488dc Add some asserts and update comments 2006-07-30 19:18:13 +00:00
Neal Norwitz 07aadb14f3 Add PyErr_WarnEx() so C code can pass the stacklevel to warnings.warn().
This provides the proper warning for struct.pack().
PyErr_Warn() is now deprecated in favor of PyErr_WarnEx().
As mentioned by Tim Peters on python-dev.
2006-07-30 06:55:48 +00:00
Neal Norwitz 0d62a06206 Patch #1531113: Fix augmented assignment with yield expressions.
Also fix a SystemError when trying to assign to yield expressions.
2006-07-30 06:53:31 +00:00
Phillip J. Eby f7575d0cb7 Bug #1529871: The speed enhancement patch #921466 broke Python's compliance
with PEP 302.  This was fixed by adding an ``imp.NullImporter`` type that is
used in ``sys.path_importer_cache`` to cache non-directory paths and avoid
excessive filesystem operations during imports.
2006-07-28 21:12:07 +00:00
Tim Peters bc24eee333 Bug #1521947: possible bug in mystrtol.c with recent gcc.
In general, C doesn't define anything about what happens when
an operation on a signed integral type overflows, and PyOS_strtol()
did several formally undefined things of that nature on signed
longs.  Some version of gcc apparently tries to exploit that now,
and PyOS_strtol() could fail to detect overflow then.

Tried to repair all that, although it seems at least as likely to me
that we'll get screwed by bad platform definitions for LONG_MIN
and/or LONG_MAX now.  For that reason, I don't recommend backporting
this.

Note that I have no box on which this makes a lick of difference --
can't really test it, except to note that it didn't break anything
on my boxes.

Silent change:  PyOS_strtol() used to return the hard-coded 0x7fffffff
in case of overflow.  Now it returns LONG_MAX.  They're the same only on
32-bit boxes (although C doesn't guarantee that either ...).
2006-07-27 01:14:53 +00:00
Georg Brandl 5f135787ec Part of bug #1523610: fix miscalculation of buffer length.
Also add a guard against NULL in converttuple and add a test case
(that previously would have crashed).
2006-07-26 08:03:10 +00:00
Andrew MacIntyre 82247cb7d1 bugfix: PyThread_start_new_thread() returns the thread ID, not a flag;
will backport.
2006-07-23 13:00:04 +00:00
Neal Norwitz f71847e645 If the for loop isn't entered, entryblock will be NULL. If passed
to stackdepth_walk it will be dereffed.

Not sure if I found with failmalloc or Klockwork #55.
2006-07-23 07:51:58 +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
Neal Norwitz 33722aec57 Speel initialise write. Tanks Anthony. 2006-07-21 07:59:02 +00:00
Neal Norwitz e1fdb32ff2 Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
2006-07-21 05:32:28 +00:00
Tim Peters 112aad3630 SF bug 1524317: configure --without-threads fails to build
Moved the code for _PyThread_CurrentFrames() up, so it's no longer
in a huge "#ifdef WITH_THREAD" block (I didn't realize it /was/ in
one).

Changed test_sys's test_current_frames() so it passes with or without
thread supported compiled in.

Note that test_sys fails when Python is compiled without threads,
but for an unrelated reason (the old test_exit() fails with an
indirect ImportError on the `thread` module).  There are also
other unrelated compilation failures without threads, in extension
modules (like ctypes); at least the core compiles again.

Do we really support --without-threads?  If so, there are several
problems remaining.
2006-07-19 00:03:19 +00:00
Neal Norwitz a5e4f22bfb Reported by Klocwork #151.
v2 can be NULL if exception2 is NULL.  I don't think that condition can happen,
but I'm not sure it can't either.  Now the code will protect against either
being NULL.
2006-07-17 00:59:04 +00:00
Neal Norwitz c0cde4da2a Fix memory leak under some conditions.
Reported by Klocwork, #98.
2006-07-16 02:17:36 +00:00
Neal Norwitz 84be93b2db Bug #1512814, Fix incorrect lineno's when code within a function
had more than 255 blank lines.  Byte codes need to go first, line #s second.
2006-07-16 01:50:38 +00:00
Georg Brandl 9dceedbb97 Accept long options "--help" and "--version". 2006-07-12 15:31:17 +00:00
Neal Norwitz a1f1090109 Actually change the MAGIC #. Create a new section for 2.5c1 and mention the impact of changing the MAGIC #. 2006-07-12 07:28:29 +00:00
Neal Norwitz edef2be4af Bug #1520864: unpacking singleton tuples in for loop (for x, in) work again. 2006-07-12 05:26:17 +00:00
Thomas Heller 249f6b1bf4 Add missing Py_DECREFs. 2006-07-11 16:44:25 +00:00
Tim Peters 32a8361f2d After approval from Anthony, merge the tim-current_frames
branch into the trunk.  This adds a new sys._current_frames()
function, which returns a dict mapping thread id to topmost
thread stack frame.
2006-07-10 21:08:24 +00:00
Neal Norwitz ed65755608 Bug #1512814, Fix incorrect lineno's when code at module scope
started after line 256.
2006-07-10 00:04:44 +00:00
Neal Norwitz 28746aba9b On 64 bit systems, int literals that use less than 64 bits are now ints
rather than longs.  This also fixes the test for eval(-sys.maxint - 1).
2006-07-09 22:14:42 +00:00
Neil Schemenauer 6ec6ab02c3 Fix SF bug 1441486: bad unary minus folding in compiler. 2006-07-09 21:19:29 +00:00
Neil Schemenauer 0e07b60a4e Fix AST compiler bug #1501934: incorrect LOAD/STORE_GLOBAL generation. 2006-07-09 16:16:34 +00:00
Neal Norwitz fb48afa708 Fix SF bug #1519018: 'as' is now validated properly in import statements 2006-07-08 05:31:37 +00:00
Neal Norwitz a4df11d9c3 Fix refleaks reported by Shane Hathaway in SF patch #1515361. This change
contains only the changes related to leaking the copy variable.
2006-07-06 04:28:59 +00:00
Martin v. Löwis fcfff0a7fa Bug #1417699: Reject locale-specific decimal point in float()
and atof().
2006-07-03 12:19:50 +00:00
Hye-Shik Chang e6a1cb9700 Bug #1511381: codec_getstreamcodec() in codec.c is corrected to
omit a default "error" argument for NULL pointer.  This allows
the parser to take a codec from cjkcodecs again.
(Reported by Taewook Kang and reviewed by Walter Doerwald)
2006-06-23 21:16:18 +00:00
Andrew MacIntyre 9291332de1 Patch #1454481: Make thread stack size runtime tunable.
Heavily revised, comprising revisions:
46640 - original trunk revision (backed out in r46655)
46647 - markup fix (backed out in r46655)
46692:46918 merged from branch aimacintyre-sf1454481

branch tested on buildbots (Windows buildbots had problems
not related to these changes).
2006-06-13 15:04:24 +00:00
Neal Norwitz 245ce8db46 i and j are initialized below when used. No need to do it twice 2006-06-12 02:16:10 +00:00
Neal Norwitz b9845e72f9 Get rid of f_restricted too. Doc the other 4 ints that were already removed
at the NeedForSpeed sprint.
2006-06-12 02:11:18 +00:00
Neal Norwitz 2585ad58e6 Fix indentation of case and a Py_ssize_t issue. 2006-06-12 02:09:34 +00:00
Martin v. Löwis 0e8bd7e1cc Patch #1495999: Part two of Windows CE changes.
- update header checks, using autoconf
- provide dummies for getenv, environ, and GetVersion
- adjust MSC_VER check in socketmodule.c
2006-06-10 12:23:46 +00:00
Georg Brandl 98251f8a2f Argh. "integer" is a very confusing word ;)
Actually, checking for INT_MAX and INT_MIN is correct since
the format code explicitly handles a C "int".
2006-06-08 13:31:07 +00:00
Georg Brandl 22ccbbc4ec Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. 2006-06-08 12:45:01 +00:00
Tim Peters 02f1d0dc78 _PySys_Init(): It's rarely a good idea to size a buffer to the
exact maximum size someone guesses is needed.  In this case, if
we're really worried about extreme integers, then "cp%d" can
actually need 14 bytes (2 for "cp" + 1 for \0 at the end +
11 for -(2**31-1)).  So reserve 128 bytes instead -- nothing is
actually saved by making a stack-local buffer tiny.
2006-06-06 00:25:07 +00:00
Brett Cannon 4f7a7220c1 Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int.
Closes bug #1501223.
2006-06-05 23:51:55 +00:00
Tim Peters 28eeefe566 Revert revisions:
46640 Patch #1454481:  Make thread stack size runtime tunable.
46647 Markup fix

The first is causing many buildbots to fail test runs, and there
are multiple causes with seemingly no immediate prospects for
repairing them.  See python-dev discussion.

Note that a branch can (and should) be created for resolving these
problems, like

svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH

followed by merging rev 46647 to the new branch.
2006-06-04 23:52: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
Andrew MacIntyre 63f0db682e clean up function declarations to conform to PEP-7 style. 2006-06-04 12:59:59 +00:00
Andrew MacIntyre 6539d2d3c7 Patch #1454481: Make thread stack size runtime tunable. 2006-06-04 12:31:09 +00:00
Armin Rigo 35f6d36951 [ 1497053 ] Let dicts propagate the exceptions in user __eq__().
[ 1456209 ] dictresize() vulnerability ( <- backport candidate ).
2006-06-01 13:19:12 +00:00
Georg Brandl bf92f46572 Convert more modules to METH_VARARGS. 2006-05-29 21:58:42 +00:00
Georg Brandl 96a8c3954c Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
2006-05-29 21:04:52 +00:00
Georg Brandl 80181e2b78 Fix compiler warning. 2006-05-29 14:33:55 +00:00
Georg Brandl b569ee4863 Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671. 2006-05-29 14:28:05 +00:00
Georg Brandl a1121fa935 Fix #1494605. 2006-05-29 14:13:21 +00:00
Georg Brandl 5f6861df93 Correct None refcount issue in Mac modules. (Are they
still used?)
2006-05-28 21:57:35 +00:00
Georg Brandl 0fd1291c38 The empty string is a valid import path.
(fixes #1496539)
2006-05-28 20:11:45 +00:00
Tim Peters 5e9d6cfbda PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both:  `className` was referenced before being checked for NULL.
2006-05-28 10:41:29 +00:00
Richard Jones 7b9558d37d Conversion of exceptions over from faked-up classes to new-style C types. 2006-05-27 12:29:24 +00:00
Fredrik Lundh 7a83089c06 needforspeed: backed out the Py_LOCAL-isation of ceval; the massive in-
lining killed performance on certain Intel boxes, and the "aggressive"
macro itself gives most of the benefits on others.
2006-05-27 10:39:48 +00:00
Tim Peters 7df5e7f4b2 Patch 1145039.
set_exc_info(), reset_exc_info():  By exploiting the
likely (who knows?) invariant that when an exception's
`type` is NULL, its `value` and `traceback` are also NULL,
save some cycles in heavily-executed code.

This is a "a kronar saved is a kronar earned" patch:  the
speedup isn't reliably measurable, but it obviously does
reduce the operation count in the normal (no exception
raised) path through PyEval_EvalFrameEx().

The tim-exc_sanity branch tries to push this harder, but
is still blowing up (at least in part due to pre-existing
subtle bugs that appear to have no other visible
consequences!).

Not a bugfix candidate.
2006-05-26 23:14:37 +00:00
Georg Brandl 7784f12d74 Replace Py_BuildValue("OO") by PyTuple_Pack. 2006-05-26 20:04:44 +00:00
Georg Brandl f4ef11659c Need for speed: Patch #921466 : sys.path_importer_cache is now used to cache valid and
invalid file paths for the built-in import machinery which leads to
  fewer open calls on startup.

  Also fix issue with PEP 302 style import hooks which lead to more open()
  calls than necessary.
2006-05-26 18:03:31 +00:00
Fredrik Lundh 1b94940165 Py_LOCAL shouldn't be used for data; it works for some .NET 2003 compilers,
but Trent's copy thinks that it's an anachronism...
2006-05-26 12:01:49 +00:00
Fredrik Lundh 57640f5c57 needforspeed: added PY_LOCAL_AGGRESSIVE macro to enable "aggressive"
LOCAL inlining; also added some missing whitespace
2006-05-26 11:54:04 +00:00
Fredrik Lundh b8b3c8e276 needforspeed: added Py_LOCAL macro, based on the LOCAL macro used
for SRE and others.  applied Py_LOCAL to relevant portion of ceval,
which gives a 1-2% speedup on my machine.  ymmv.
2006-05-26 11:29:39 +00:00
Brett Cannon 0ed05875b2 Swap out bare malloc()/free() use for PyMem_MALLOC()/PyMem_FREE() . 2006-05-25 20:44:08 +00:00
Georg Brandl 684fd0c8ec Replace PyObject_CallFunction calls with only object args
with PyObject_CallFunctionObjArgs, which is 30% faster.
2006-05-25 19:15:31 +00:00
Tim Peters da53afa1b0 A new table to help string->integer conversion was added yesterday to
both mystrtoul.c and longobject.c.  Share the table instead.  Also
cut its size by 64 entries (they had been used for an inscrutable
trick originally, but the code no longer tries to use that trick).
2006-05-25 17:34:03 +00:00
Thomas Wouters 143bdfcee6 Update graminit.c for the fix for #1488915, Multiple dots in relative import
statement raise SyntaxError, and add testcase.
2006-05-25 11:26:25 +00:00
Walter Dörwald c611f17418 Replace tab inside comment with space. 2006-05-25 08:53:28 +00:00
Tim Peters b713ec2531 Bug #1334662 / patch #1335972: int(string, base) wrong answers.
In rare cases of strings specifying true values near sys.maxint,
and oddball bases (not decimal or a power of 2), int(string, base)
could deliver insane answers.  This repairs all such problems, and
also speeds string->int significantly.  On my box, here are %
speedups for decimal strings of various lengths:

length speedup
------ -------
 1       12.4%
 2       15.7%
 3       20.6%
 4       28.1%
 5       33.2%
 6       37.5%
 7       41.9%
 8       46.3%
 9       51.2%
10       19.5%
11       19.9%
12       23.9%
13       23.7%
14       23.3%
15       24.9%
16       25.3%
17       28.3%
18       27.9%
19       35.7%

Note that the difference between 9 and 10 is the difference between
short and long Python ints on a 32-bit box.  The patch doesn't
actually do anything to speed conversion to long:  the speedup is
due to detecting "unsigned long" overflow more quickly.

This is a bugfix candidate, but it's a non-trivial patch and it
would be painful to separate the "bug fix" from the "speed up" parts.
2006-05-23 18:45:30 +00:00
Richard Jones cebbefc98d Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects. 2006-05-23 18:28:17 +00:00
Georg Brandl 658d513328 PyErr_NewException now accepts a tuple of base classes as its
"base" parameter.
2006-05-23 11:17:21 +00:00
Martin v. Löwis a43190bc78 Patch #1492356: Port to Windows CE (patch set 1). 2006-05-22 09:15:18 +00:00
Neal Norwitz 4eafe9ee4f Oops, I forgot to include this file in the last commit (46046):
Bug/Patch #1481770: Use .so extension for shared libraries on HP-UX for ia64.

I suppose this could be backported if anyone cares.
2006-05-19 07:05:01 +00:00
Neal Norwitz 5ef922447c Fix #1474677, non-keyword argument following keyword. 2006-05-19 06:43:50 +00:00
Neal Norwitz 02104df4c8 Fix #132 from Coverity, retval could have been derefed
if a continue inside a try failed.
2006-05-19 06:31:23 +00:00
Martin v. Löwis 2a0ad4db3a Remove bogus DECREF of self.
Change __str__() functions to METH_O.
Change WindowsError__str__ to use PyTuple_Pack.
2006-05-15 09:22:27 +00:00
Neal Norwitz 373f0a718c - Bug #1487966: Fix SystemError with conditional expression in assignment
Most of the test_syntax changes are just updating the numbers.
2006-05-15 07:04:36 +00:00
Martin v. Löwis 879768dd97 Change WindowsError to carry the Win32 error code in winerror,
and the DOS error code in errno. Revert changes where
WindowsError catch blocks unnecessarily special-case OSError.
2006-05-11 13:28:43 +00:00
Neal Norwitz b255069d43 Micro optimization. In the first case, we know that frame->f_exc_type
is NULL, so there's no reason to do anything with it.  In the second case,
we know frame->f_exc_type is not NULL, so we can just do an INCREF.
2006-05-09 05:38:56 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Neal Norwitz c4edb0ec81 SF #1479181: split open() and file() from being aliases for each other. 2006-05-02 04:43:14 +00:00
Neal Norwitz abab1d44bb Fix a warning on ppc (debian) 2006-04-28 05:28:54 +00:00
Neal Norwitz 237bf40746 Fix a warning on alpha 2006-04-28 05:28:30 +00:00
Thomas Wouters 9df4e6f673 - Add new Warning class, ImportWarning
- Warn-raise ImportWarning when importing would have picked up a directory
   as package, if only it'd had an __init__.py. This swaps two tests (for
   case-ness and __init__-ness), but case-test is not really more expensive,
   and it's not in a speed-critical section.

 - Test for the new warning by importing a common non-package directory on
   sys.path: site-packages

 - In regrtest.py, silence warnings generated by the build-environment
   because Modules/ (which is added to sys.path for Setup-created modules)
   has 'zlib' and '_ctypes' directories without __init__.py's.
2006-04-27 23:13:20 +00:00
Thomas Wouters 1ddba60e3d Define MAXPATHLEN to be at least PATH_MAX, if that's defined. Python uses
MAXPATHLEN-sized buffers for various output-buffers (like to realpath()),
and that's correct on BSD platforms, but not Linux (which uses PATH_MAX, and
does not define MAXPATHLEN.) Cursory googling suggests Linux is following a
newer standard than BSD, but in cases like this, who knows. Using the
greater of PATH_MAX and 1024 as a fallback for MAXPATHLEN seems to be the
most portable solution.
2006-04-25 15:29:46 +00:00
Martin v. Löwis 6685128b97 Fix more ssize_t issues. 2006-04-22 11:40:03 +00:00
Thomas Wouters 79cdce35de Teach Python/ceval.c's inlining of 'str += str' about Py_ssize_t sizes; this
was having funny effects when called on >2Gb strings ;P
2006-04-19 15:09:44 +00:00
Thomas Heller 1b04664eab Change those parts of the Python-api that were functions in 2.4, and
are now macros to exported functions again.

Fixes [ 1465834 ] bdist_wininst preinstall script support is broken in 2.5a1.
2006-04-18 18:51:06 +00:00
Jeremy Hylton a4ebc135ac Refactor: Move code that uses co_lnotab from ceval to codeobject 2006-04-18 14:47:00 +00:00
Martin v. Löwis 45294a9562 Remove types from type_list if they have no objects
and unlist_types_without_objects is set.
Give dump_counts a FILE* argument.
2006-04-18 06:24:08 +00:00
Skip Montanaro b507972cdd C++ compiler cleanup: cast... 2006-04-18 00:57:15 +00:00
Skip Montanaro 53a6d1de83 C++ compiler cleanup: extern "C" a couple declarations, cast int to size_t 2006-04-18 00:55:46 +00:00
Skip Montanaro 7ff54e7706 C++ compiler cleanup: migrate to modsupport.h 2006-04-18 00:53:48 +00:00
Ronald Oussoren 6c1074888e This patches fixes a number of byteorder problems in MacOSX specific code. 2006-04-17 13:40:08 +00:00
Neal Norwitz 1a26920506 moduleName can be NULL 2006-04-17 00:33:23 +00:00
Thomas Wouters b8f81d4863 Add missing DECREF to PyErr_WriteUnraisable(). That function reports
exceptions that can't be raised any further, because (for instance) they
occur in __del__ methods. The coroutine tests in test_generators was
triggering this leak. Remove the leakers' testcase, and add a simpler
testcase that explicitly tests this leak to test_generators.

test_generators now no longer leaks at all, on my machine. This fix may also
solve other leaks, but my full refleakhunting run is still busy, so who
knows?
2006-04-15 23:27:28 +00:00
Thomas Wouters c6e55068ca Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
using a custom, nearly-identical macro. This probably changes how some of
these functions are compiled, which may result in fractionally slower (or
faster) execution. Considering the nature of traversal, visiting much of the
address space in unpredictable patterns, I'd argue the code readability and
maintainability is well worth it ;P
2006-04-15 21:47:09 +00:00
Martin v. Löwis ab0e284a24 Zap ZAP. 2006-04-15 18:14:21 +00:00
Thomas Wouters edf17d8798 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
tp_clear methods.
2006-04-15 17:28:34 +00:00
Martin v. Löwis 841747cb56 Fix sys.getobjects(0): we get a reference to the
arena's "private" list of objects, so there might
be two references to that list.
2006-04-15 12:46:09 +00:00
Martin v. Löwis 5cb6936672 Make Py_BuildValue, PyObject_CallFunction and
PyObject_CallMethod aware of PY_SSIZE_T_CLEAN.
2006-04-14 09:08:42 +00:00
Neal Norwitz 615461603c SF Bug #1454485, array.array('u') could crash the interpreter when
passing a string.  Martin already fixed the actual crash by ensuring
Py_UNICODE is unsigned.  As discussed on python-dev, this fix
removes the possibility of creating a unicode string from a raw buffer.

There is an outstanding question of how to fix the crash in 2.4.
2006-04-14 05:20:28 +00:00
Neal Norwitz 8c0dc84398 ALIGNMENT_SHIFT is not used 2006-04-14 03:53:34 +00:00
Martin v. Löwis da69041123 Force 8-alignment of memory blocks, as needed on
64-bit machines that require pointers to be aligned (e.g. IA64)
2006-04-13 19:16:13 +00:00
Martin v. Löwis f33dea2961 Fix type errors. 2006-04-13 13:08:58 +00:00
Martin v. Löwis 0cc56e5c59 Introduce asdl_int_seq, to hold cmpop_ty. 2006-04-13 12:29:43 +00:00
Skip Montanaro 869bacd465 revert - breaks build of Python/ast.c w/ gcc 2006-04-13 09:48:28 +00:00
Skip Montanaro b940671186 Use union to discriminate pointer types from enum/int types. 2006-04-13 09:37:01 +00:00
Georg Brandl 7f573f7319 Add a test for Py_ssize_t. Correct typo in getargs.c. 2006-04-13 07:59:30 +00:00
Martin v. Löwis b1ed7fac12 Replace INT_MAX with PY_SSIZE_T_MAX. 2006-04-13 07:52:27 +00:00
Anthony Baxter ac6bd46d5c spread the extern "C" { } magic pixie dust around. Python itself builds now
using a C++ compiler. Still lots and lots of errors in the modules built by
setup.py, and a bunch of warnings from g++ in the core.
2006-04-13 02:06:09 +00:00
Anthony Baxter d691f1a35f casting nastiness to make C++ compiler happy 2006-04-13 01:23:28 +00:00
Armin Rigo e170937af6 Ignore the references to the dummy objects used as deleted keys
in dicts and sets when computing the total number of references.
2006-04-12 17:06:05 +00:00
Anthony Baxter 97300387ec avoid C++ name mangling for the _Py.*SizeT functions 2006-04-12 04:38:54 +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
Anthony Baxter 2c33fc77fe per Jeremy's email, remove the _WITH_CAST versions of macros. g++
still has errors from the casts of asdl_seq_GET to cmpop_ty, but
otherwise it's C++ clean.
2006-04-12 00:43:09 +00:00
Thomas Wouters ced6cddc03 Part two of the fix for SF bug #1466641: Regenerate graminit.c and add test
for the bogus failure.
2006-04-12 00:07:59 +00:00
Anthony Baxter 64182fe0b3 Some more changes to make code compile under a C++ compiler. 2006-04-11 12:14:09 +00:00
Anthony Baxter 7b782b61c5 more low-hanging fruit to make code compile under a C++ compiler. Not
entirely happy with the two new VISIT macros in compile.c, but I
couldn't see a better approach.
2006-04-11 12:01:56 +00:00
Martin v. Löwis 2845750c5b Convert 0 to their respective enum types. Convert
void* to their respective _ty types. Fix signature of
ast_for_exprlist.
2006-04-11 09:17:27 +00:00
Martin v. Löwis 9eec489c4a Regenerate. 2006-04-11 09:03:33 +00:00
Martin v. Löwis 01b810106c Make _kind types global for C++ compilation.
Explicitly cast void* to int to cmpop_ty.
2006-04-11 08:06:50 +00:00
Anthony Baxter a863d334aa low-hanging fruit in Python/ - g++ still hates all the enum_kind declarations
in Python/Python-ast.c. Not sure what to do about those.
2006-04-11 07:43:46 +00:00
Phillip J. Eby 2ba96610bf SF Patch #1463867: Improved generator finalization to allow generators
that are suspended outside of any try/except/finally blocks to be
garbage collected even if they are part of a cycle.  Generators that
suspend inside of an active try/except or try/finally block (including
those created by a ``with`` statement) are still not GC-able if they
are part of a cycle, however.
2006-04-10 17:51:05 +00:00
Neal Norwitz 14bc4e4d89 Use PyObject_* allocator since FutureFeatures is small 2006-04-10 06:57:06 +00:00
Neal Norwitz b183a25c29 Fix some warnings on HP-UX when using cc/aCC 2006-04-10 01:03:32 +00:00
Martin v. Löwis ad7c44c047 Regenerate. 2006-04-07 06:26:31 +00:00
Thomas Wouters 4bdaa271d6 Fix refleak in __import__("") (probably the cause of the 2 refleaks in
test_builtin.)
2006-04-05 13:39:37 +00:00
Thomas Wouters 8ddab27182 Fix __import__("") to raise ValueError rather than return None. 2006-04-04 16:17:02 +00:00
Jeremy Hylton ed40ea1159 Generate line number table entries for except handlers.
Re-enable all the tests in test_trace.py except one.  Still not sure that these tests test what they used to test, but they pass.  One failing test seems to be caused by undocumented line number table behavior in Python 2.4.
2006-04-04 14:26:39 +00:00
Martin v. Löwis c95dd9488a Disable .DLL as an extension for extension modules. 2006-04-04 07:04:07 +00:00
Jeremy Hylton 2f327c14eb Add lineno, col_offset to excephandler to enable future fix for
tracing/line number table in except blocks.

Reflow long lines introduced by col_offset changes.  Update test_ast
to handle new fields in excepthandler.

As note in Python.asdl says, we might want to rethink how attributes
are handled.  Perhaps they should be the same as other fields, with
the primary difference being how they are defined for all types within
a sum.

Also fix asdl_c so that constructors with int fields don't fail when
passed a zero value.
2006-04-04 04:00:23 +00:00
Martin v. Löwis ea62d2535f Bug #1421664: Set sys.stderr.encoding 2006-04-03 10:56:49 +00:00
Neal Norwitz cbce280d4f Don't abbreviate ABS, use long name ABSOLUTE. 2006-04-03 06:26:32 +00:00
Neal Norwitz 19379f18a6 * Fix a refleak of *_attributes.
* Cleanup formatting a bit (add spaces).
* Move static var initialized inside init_types() since that's the only place
  it's used.
2006-04-03 04:50:58 +00:00
Neal Norwitz 92e212f7d9 Accept keyword arguments for __import__ and doc the addition of the level param from PEP 328. 2006-04-03 04:48:37 +00:00
Jeremy Hylton 12603c41da Expand comments on line numbers and blocks.
Reorder compiler_set_lineno() call for consistency.
2006-04-01 16:18:02 +00:00
Georg Brandl ccadf84a1b Patch #1460496: round() now accepts keyword arguments. 2006-03-31 18:54:53 +00:00
Jeremy Hylton 296aef8ebb Expand comments.
Explicitly clear all elements from arena->a_objects and remove
assert() that refcount is 1.  It's possible for a program to get a
reference to the list via sys.getobjects() or via gc functions.
2006-03-31 16:41:22 +00:00
Tim Peters 62e97f023b In format strings slinging Py_ssize_t, unconditionally
interpolate PY_FORMAT_SIZE_T instead of #if'ing on
MS_WIN64.
2006-03-28 21:44:32 +00:00
Armin Rigo d34fa52a06 answer a question from a comment 2006-03-28 19:10:40 +00:00
Neal Norwitz 33b730e33c Fix SF bug #1458903 with AST compiler.
def foo((x)): was getting recognized as requiring tuple unpacking
which is not correct.

Add tests for this case and the proper way to unpack a tuple of one:
	def foo((x,)):

test_inpsect was incorrect before.  I'm not sure why it was passing,
but that has been corrected with a test for both functions above.
This means the test (and therefore inspect.getargspec()) are broken in 2.4.
2006-03-27 08:58:23 +00:00
Tim Peters c9d78aa470 Years in the making.
objimpl.h, pymem.h:  Stop mapping PyMem_{Del, DEL} and PyMem_{Free, FREE}
to PyObject_{Free, FREE} in a release build.  They're aliases for the
system free() now.

_subprocess.c/sp_handle_dealloc():  Since the memory was originally
obtained via PyObject_NEW, it must be released via PyObject_FREE (or
_DEL).

pythonrun.c, tokenizer.c, parsermodule.c:  I lost count of the number of
PyObject vs PyMem mismatches in these -- it's like the specific
function called at each site was picked at random, sometimes even with
memory obtained via PyMem getting released via PyObject.  Changed most
to use PyObject uniformly, since the blobs allocated are predictably
small in most cases, and obmalloc is generally faster than system
mallocs then.

If extension modules in real life prove as sloppy as Python's front
end, we'll have to revert the objimpl.h + pymem.h part of this patch.
Note that no problems will show up in a debug build (all calls still go
thru obmalloc then). Problems will show up only in a release build, most
likely segfaults.
2006-03-26 23:27:58 +00:00
Skip Montanaro 4ec3c26952 Found this in an old email message from Hartmut Goebel. 2006-03-25 14:12:03 +00:00
Hye-Shik Chang d478f3453f Patch #1396919: Reenable the system scope threads on FreeBSD 5.4
and later versions because they bumped the default setting to
get our basic tests to run correctly..
2006-03-23 12:32:36 +00:00
Neal Norwitz 90768424f8 Fix a ssize_t issue 2006-03-23 05:48:09 +00:00
Neal Norwitz e98ccf6690 Forward port MvL's fix in 43227:
Fix crash when a Unicode string containing an encoding declaration is
compile()d. Fixes #1115379.
2006-03-23 05:39:47 +00:00
Neal Norwitz 2aa9a5dfdd Use macro versions instead of function versions when we already know the type.
This will hopefully get rid of some Coverity warnings, be a hint to
developers, and be marginally faster.

Some asserts were added when the type is currently known, but depends
on values from another function.
2006-03-20 01:53:23 +00:00
Walter Dörwald ba8e180f3b Release codecs variable earlier. 2006-03-18 14:05:43 +00:00
Georg Brandl 5c170fd4a9 Fix some missing checks after PyTuple_New, PyList_New, PyDict_New 2006-03-17 19:03:25 +00:00
Nick Coghlan 77858684e4 Fix bug 1441408 where a double colon didn't trigger extended slice semantics (applies patch 1452332) 2006-03-17 17:59:10 +00:00
Walter Dörwald d53850a2be Fix wrong argument format in PyCodec_IncrementalEncoder() and
PyCodec_IncrementalDecoder().

Factor out common code from PyCodec_Encoder()/PyCodec_Decoder(),
PyCodec_IncrementalEncoder()/PyCodec_IncrementalDecoder() and
PyCodec_StreamReader()/PyCodec_StreamWriter().
2006-03-16 21:46:40 +00:00
Neal Norwitz 4fe4ed2525 Make mktuple consistent with mklist to get rid of Coverity warnings. Also use macro version of SetItem since we know everything is setup. 2006-03-16 08:20:19 +00:00
Walter Dörwald abb02e5994 Patch #1436130: codecs.lookup() now returns a CodecInfo object (a subclass
of tuple) that provides incremental decoders and encoders (a way to use
stateful codecs without the stream API). Functions
codecs.getincrementaldecoder() and codecs.getincrementalencoder() have
been added.
2006-03-15 11:35:15 +00:00
Nick Coghlan eadee9a744 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly 2006-03-13 12:31:58 +00:00
Guido van Rossum f669436189 Um, I thought I'd already checked this in.
Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
2006-03-10 02:28:35 +00:00
Neal Norwitz 72c2c062d7 Try to be a bit more consistent on all platforms:
python .
  python < .

both print a message, return non-zero and do not core dump.
2006-03-09 05:58:11 +00:00
Guido van Rossum 38fff8c4e4 Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
2006-03-07 18:50:55 +00:00
Guido van Rossum 9d7855076a Address an coverity issue. Coverity was complaining about a line that's fine,
but an earlier line checked for v != NULL unnecessarily.
2006-03-07 18:31:44 +00:00
Hye-Shik Chang 4af5c8cee4 SF #1444030: Fix several potential defects found by Coverity.
(reviewed by Neal Norwitz)
2006-03-07 15:39:21 +00:00
Martin v. Löwis 725507b52e Change int to Py_ssize_t in several places.
Add (int) casts to silence compiler warnings.
Raise Python exceptions for overflows.
2006-03-07 12:08:51 +00:00
Neal Norwitz f2e0c45492 Fix warnings on x86 (32-bit). 2006-03-06 23:31:27 +00:00
Neal Norwitz 3e90fa5940 Try to cleanup the error handling a bit so there aren't false positives
from static analysis.  v was already checked for NULL above, so we don't
need a second check.
2006-03-06 23:07:34 +00:00
Martin v. Löwis 99b93c2824 Use %Id for size_t-ish things on Win64. 2006-03-05 05:33:54 +00:00
Neal Norwitz 4281cef205 Use Py_ssize_t for _Py_RefTotal.
I tried to handle Win64 properly, but please review.
2006-03-04 19:58:13 +00:00
Neal Norwitz 9589ee276a Tabify 2006-03-04 19:01:22 +00:00
Neal Norwitz e92fba0a12 Get rid of run_err_mod(). It was only used in two places.
One place it wasn't necessary since mod was already checked.
Inline the check that mod != NULL for the other use.
2006-03-04 18:52:26 +00:00
Neal Norwitz 10be2ea85d SF bug 1442442: LIST_APPEND optimization got lost in the AST merge.
Add it back.
2006-03-03 20:29:11 +00:00
Neal Norwitz 9742f27a9a Remove commented code 2006-03-03 19:13:57 +00:00
Brett Cannon 3909ff69e2 Text moved to PEP 339. 2006-03-02 22:08:16 +00:00
Brett Cannon 5118517c16 Fix minor docstring typo. 2006-03-02 22:07:40 +00:00
Tim Peters f6386306fb Document the purpose of the struct _block members. 2006-03-02 21:41:18 +00:00
Tim Peters 6fd92dc44f Added words about what PyArena_Malloc() does. 2006-03-02 21:14:45 +00:00
Tim Peters 8cfaa0e729 Trimmed trailing whitespace. 2006-03-02 20:37:32 +00:00
Brett Cannon 2e63b73a2c Fix refleak in PyErr_Display(). 2006-03-02 18:34:57 +00:00
Neal Norwitz d9cf85f421 Fix refleak if from __future__ import was not first 2006-03-02 08:08:42 +00:00
Neal Norwitz 814e938d08 Use Py_ssize_t since we are working with list size below 2006-03-02 07:54:28 +00:00
Brett Cannon 46872b1613 Add a missing Py_DECREF to BaseException__unicode__ . 2006-03-02 04:31:55 +00:00
Neal Norwitz 3a5468efb0 Update known issues to reflect reality 2006-03-02 04:06:10 +00:00
Martin v. Löwis 03e5bc02c9 Fix memory leak on attributes. 2006-03-02 00:31:27 +00:00
Thomas Wouters 695934a0ef Make Py_ssize_t clean. 2006-03-01 23:49:13 +00:00
Martin v. Löwis 49c5da1d88 Patch #1440601: Add col_offset attribute to AST nodes. 2006-03-01 22:49:05 +00:00
Thomas Wouters 7464b43e41 Fix incompatible assignment warning from previous checkin. 2006-03-01 22:34:09 +00:00
Thomas Wouters 7f401ef73d Fix gcc (4.0.x) warning about use of uninitialized variables.
(PyMarshal_ReadShortFromFile() is only used in zipimport.c, I don't believe
the extra initializations will matter one way or another.)
2006-03-01 22:30:47 +00:00
Brett Cannon 54ac29497e Document PEP 352 changes. Also added GeneratorExit. 2006-03-01 22:10:49 +00:00
Thomas Wouters 65b3dab50e Fix uninitialized value. (Why are we using bools instead of ints, like we do
everywhere else?)
2006-03-01 22:06:23 +00:00
Martin v. Löwis 0b300be895 Fix more memory leaks. Will backport to 2.4. 2006-03-01 21:33:54 +00:00
Thomas Wouters c3547a311e Fix C99-ism, and add XXX to comment 2006-03-01 21:31:21 +00:00
Martin v. Löwis 056a69cba6 Reconst parameters that lost their const in the AST merge. 2006-03-01 16:55:42 +00:00
Jeremy Hylton e9357b21c0 Tabify and reflow some long lines.
Much of the peephole optimizer is now indented badly, but it's about
to be revised anyway.
2006-03-01 15:47:05 +00:00
Jeremy Hylton 224003baef Add missing DECREF. 2006-03-01 15:02:24 +00:00
Thomas Wouters 572a9f32dc Use %zd format characters for Py_ssize_t types. 2006-03-01 05:38:39 +00:00
Thomas Wouters 7f59732716 Put back the essence of Jeremy's original XXX comment. 2006-03-01 05:32:33 +00:00
Brett Cannon bf36409e2a PEP 352 implementation. Creates a new base class, BaseException, which has an
added message attribute compared to the previous version of Exception.  It is
also a new-style class, making all exceptions now new-style.  KeyboardInterrupt
and SystemExit inherit from BaseException directly.  String exceptions now
raise DeprecationWarning.

Applies patch 1104669, and closes bugs 1012952 and 518846.
2006-03-01 04:25:17 +00:00
Martin v. Löwis 762467475d Use Py_ssize_t for PyArg_UnpackTuple arguments. 2006-03-01 04:06:10 +00:00
Neal Norwitz 53d960c010 Don't pollute namespace as bad as before. All the types are static now. 2006-02-28 22:47:29 +00:00
Thomas Wouters 8ae1295c5b Make 'as' an actual keyword when with's future statement is used. Not
actually necessary for functionality, but good for transition.
2006-02-28 22:42:15 +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 1a5e21e033 Updates to the with-statement:
- New semantics for __exit__() -- it must re-raise the exception
  if type is not None; the with-statement itself doesn't do this.
  (See the updated PEP for motivation.)

- Added context managers to:
  - file
  - thread.LockType
  - threading.{Lock,RLock,Condition,Semaphore,BoundedSemaphore}
  - decimal.Context

- Added contextlib.py, which defines @contextmanager, nested(), closing().

- Unit tests all around; bot no docs yet.
2006-02-28 21:57:43 +00:00
Thomas Wouters 5e9f1fa706 Generally inehrit codeflags that are in PyCF_MASK, instead of writing it out
in multiple places. This makes compile()/eval()/etc also inherit the
absolute-import codeflag, like division and with-statement already were.
2006-02-28 20:02:27 +00:00
Jeremy Hylton 56820c2bab Add some stats collection in debugging mode.
No good way to extract output yet.
2006-02-28 19:57:06 +00:00
Thomas Wouters 34aa7ba114 from __future__ import with_statement addon for 'with', mostly written by
Neal.
2006-02-28 19:02:24 +00:00
Jeremy Hylton 99b4ee6373 Use simple PyList to implement list of PyObject pointers 2006-02-28 18:52:28 +00:00
Jeremy Hylton 08533fdad6 Tabify 2006-02-28 18:29:00 +00:00
Jeremy Hylton a829313d7b Remove asdl_seq_APPEND() and simplify asdl seq implementation.
Clarify intended use of set_context() and check errors at all call sites.
2006-02-28 17:58:27 +00:00
Jeremy Hylton 77f1bb2778 Real arena implementation
Replace the toy arena implementation with a real one,
based on allocating 8K chunks of memory by default.
2006-02-28 17:53:04 +00:00
Thomas Wouters f7f438ba3b SF patch #1438387, PEP 328: relative and absolute imports.
- IMPORT_NAME takes an extra argument from the stack: the relativeness of
   the import. Only passed to __import__ when it's not -1.

 - __import__() takes an optional 5th argument for the same thing; it
   __defaults to -1 (old semantics: try relative, then absolute)

 - 'from . import name' imports name (be it module or regular attribute)
   from the current module's *package*. Likewise, 'from .module import name'
   will import name from a sibling to the current module.

 - Importing from outside a package is not allowed; 'from . import sys' in a
   toplevel module will not work, nor will 'from .. import sys' in a
   (single-level) package.

 - 'from __future__ import absolute_import' will turn on the new semantics
   for import and from-import: imports will be absolute, except for
   from-import with dots.

Includes tests for regular imports and importhooks, parser changes and a
NEWS item, but no compiler-package changes or documentation changes.
2006-02-28 16:09:29 +00:00
Martin v. Löwis ace990cf5a Regenerate. 2006-02-28 00:32:31 +00:00
Brett Cannon a7446e3438 Check the return code for PyErr_Warn() when warning about raising string
exceptions.  This was triggered when 'warnings' had a filter set to "error"
that caught the string exception deprecation warning.
2006-02-27 23:39:10 +00:00
Tim Peters a7444f47b2 PyErr_ProgramText(): Grrrrrr.
In a Windows debug build, trying to open a file using
an empty string as the name causes assertion death
inside MS's C runtime code.  We probably need to worm
around that in many places.  I'm worming around it here
to stop the new test_with.py from assert-dying in the
Windows debug build (it calls compile() with an empty
string for "the file name", which indirectly leads to
C-level code in Python trying to fopen("", "r")).
2006-02-27 23:29:46 +00:00
Thomas Wouters 1175c43a12 Clarify C-style exception handling with proper label name. 2006-02-27 22:49:54 +00:00
Thomas Wouters bfe51ea5c8 Fix assertions. 2006-02-27 22:48:55 +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
Jeremy Hylton c7d37264bb Fix parsing of subscriptlist.
(Armin's SF bug report).
d = {}
d[1,] = 1
Now handled correctly
2006-02-27 17:29:29 +00:00
Tim Peters f4e6928c4d Patch 1413181, by Gabriel Becedillas.
PyThreadState_Delete():  if the auto-GIL-state machinery knows about
the thread state, forget it (since the thread state is being deleted,
continuing to remember it can't help, but can hurt if another thread
happens to get created with the same thread id).

I'll backport to 2.4 next.
2006-02-27 17:15:31 +00:00
Thomas Wouters 8622e93eab And some more cleanup. 2006-02-27 17:14:45 +00:00
Thomas Wouters 106203c6e0 Clean up from-import handling. 2006-02-27 17:05:19 +00:00
Jeremy Hylton 9ebfbf0a43 Simplify ast_for_trailer() in anticipation of more changes. 2006-02-27 16:50:35 +00:00
Thomas Wouters aa8b6c5855 Fix old not-reading-pep-308-right artifact. 2006-02-27 16:46:22 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Thomas Wouters fa443cda87 Fix assertion errors in debug build, brought on by PEP 308 patch. 2006-02-27 15:43:57 +00:00
Martin v. Löwis 577b5b960d Create _ast module.
Cleanup Python-ast.c generation.
2006-02-27 15:23:19 +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 d3a5f53a27 Avoid reinitializing the types twice. 2006-02-27 00:09:50 +00:00
Martin v. Löwis 8d0701daf1 Stop generating empty arrays. 2006-02-26 23:40:20 +00:00
Neal Norwitz 59090a7334 Oops, I forgot to check this in with the change to Grammar/Grammar.
Implement change suggested by Jiwon Seo on python-dev.
['(' gen_for ')'] is redundant with test, so remove it.
2006-02-26 22:29:38 +00:00
Martin v. Löwis 2b366e41c3 Check whether there are flags. 2006-02-26 22:12:35 +00:00
Martin v. Löwis ce1d5d2527 Fix iterating over cmpop_ty lists. 2006-02-26 20:51:25 +00:00
Martin v. Löwis bd260da900 Generate code to recursively copy an AST into
a tree of Python objects. Expose this through compile().
2006-02-26 19:42:26 +00:00
Neal Norwitz 9a27617239 Based on discussion with Martin and Thomas on python-checkins
add a Py_SAFE_DOWNCAST() to make the code correct.
2006-02-20 18:57:39 +00:00
Neal Norwitz 20dd93f427 Fix compiler warning on amd64. We can't use zd here since this is
ultimately going to snprintf() not the python string formatter.  Right?
2006-02-19 19:34:15 +00:00
Neal Norwitz a361bd8dce Fix compiler warning (int vs Py_ssize_t mismatch 2006-02-19 19:31:50 +00:00
Georg Brandl 1dc5a84aee Bug #801349: document that start/stop/step slice arguments can be None 2006-02-19 00:12:42 +00:00
Martin v. Löwis dde99d2633 Remove size constraints in SLICE opcodes. 2006-02-17 15:57:41 +00:00
Martin v. Löwis 67baee6287 Move cast to suppress warning. 2006-02-16 14:37:48 +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 720ddb625b Use PyString_FromFormat for formatting error messages. 2006-02-16 07:11:33 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Armin Rigo f5b3e36493 Renamed _length_cue() to __length_hint__(). See:
http://mail.python.org/pipermail/python-dev/2006-February/060524.html
2006-02-11 21:32:43 +00:00
Georg Brandl b69406dc09 Update general copyright years to 2006. 2006-02-11 15:30:36 +00:00
Thomas Wouters 03ca23d892 Explain the clearing of the stack in a comment in Python/ceval.c's
call_function(), rather than commenting on the lack of an explanation in a
comment.
2006-02-10 22:51:45 +00:00
Brett Cannon 82a9394237 Add doc discussing how AST compiler is structured and designed.
It is out of date, though, thanks to lacking info on the arena API.  It also
should eventually be removed in favor of updating PEP 339.
2006-02-09 02:43:14 +00:00
Neal Norwitz 96e48d4698 Use C-style comment 2006-02-05 02:07:19 +00:00
Jeremy Hylton c960f26044 Improved handling of syntax errors.
Expand set of errors caught in set_context().  Some new errors, some
old error messages changed for consistency.

Fixed error checking in generator expression code.  The first set of
tests were impossible condition given the grammar.  In general, the
ast code uses REQ() for those sanity checks.

Fix some error handling for augmented assignments.  As comments in the
code explain, set_context() ought to work here, but I got unexpected
crashes when I tried it.  Should come back to this.

Add note to Grammar that yield expression is a special case.

Add doctest cases for SyntaxErrors raised by ast.c.
2006-01-27 15:18:39 +00:00
Georg Brandl d704817b66 typo 2006-01-20 17:53:27 +00:00
Neal Norwitz 1ac754fa10 Check return result from Py_InitModule*(). This API can fail.
Probably should be backported.
2006-01-19 06:09:39 +00:00
Tim Peters e93e64fb1a Repair bizarre indentation created by VC 7.1. 2006-01-08 02:28:41 +00:00
Tim Peters 5db42c4c50 alias_for_import_name(): Dueling compiler warnings ;-)
Squash new warnings from VC 7.1 about mixing signed and
unsigned types in comparisons.  I can see why `len` was
changed to size_t here, but don't see why `i` was also
changed.  Change `i` back to int.
2006-01-08 02:25:34 +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 d39d861a36 Fix icc warnings: strlen() returns size_t 2006-01-08 01:03:36 +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 08b401f67a Fix icc warnings: single bit fields should be unsigned, shadowing local variables 2006-01-07 21:24:09 +00:00
Neal Norwitz 406c640344 Fix icc warnings: shadowing local variables 2006-01-07 21:23:26 +00:00
Tim Peters e86e7a5b62 svnversion_init(): Use standard layout for function defn. 2006-01-06 02:42:46 +00:00
Tim Peters 216b78bdaa Trimmed trailing whitespace. 2006-01-06 02:40:53 +00:00
Martin v. Löwis 43b57805fb Drop sys.build_number. Add sys.subversion. 2006-01-05 23:38:54 +00:00
Hye-Shik Chang 23f391c6a1 Fix a warning from gcc by adding a missed const qualifier. 2006-01-04 01:30:17 +00:00
Martin v. Löwis 5b43126e03 Regenerate. 2006-01-02 21:18:55 +00:00
Martin v. Löwis 94962615b7 Adjust usage of compiler_use_new_block to its return type. 2006-01-02 21:15:05 +00:00
Fredrik Lundh 24f0fa97c5 SF#1391872
Floating point literals don't work in non-US locale in 2.5.  Patch and
new locale tests by Hye-Shik Chang.
2005-12-29 20:35:52 +00:00
Tim Peters 35c3f4f249 do_mkvalue(), 'I' and 'k' cases: squash legitimate
compiler warnings about mixing signed and unsigned types
in comparisons.
2005-12-24 06:23:41 +00:00
Tim Peters c3d12ac88c const poisoning, spreading to fix new const warnings
in _winreg.c.
2005-12-24 06:03:06 +00:00
Neal Norwitz 4ac13dfc3a Remove extra parens 2005-12-19 06:10:07 +00:00
Neal Norwitz 30b5c5d011 Fix SF bug #1072182, problems with signed characters.
Most of these can be backported.
2005-12-19 06:05:18 +00:00
Neal Norwitz 5d0ad50f5a Bug #889500, fix line number on SyntaxWarning for global declarations. 2005-12-19 04:27:42 +00:00
Fredrik Lundh 93d69a7948 fixed compilation with an ordinary C89 compiler 2005-12-18 15:44:21 +00:00
Neal Norwitz 51abbc7b4a Fix Armin's bug 1333982. He found it, he didn't created it :-)
This code generated a C assertion:
        assert 1, ([s for s in x] +
                   [s for s in x])
        pass

assert was completely broken, it needed to use the proper block.
compiler_use_block() is now no longer used, so remove it.
2005-12-18 07:06:23 +00:00
Neal Norwitz 0e7a0ed335 Fix compiler warnings 2005-12-18 05:37:36 +00:00
Neal Norwitz 4e6bf49a5e Handle more error conditions with SystemError 2005-12-18 05:32:41 +00:00
Neal Norwitz db83eb3170 Fix Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
Needs backport.
2005-12-18 05:29:30 +00:00
Neal Norwitz e7214a130b Get float() to be more portable across platforms. Disable hex strings. 2005-12-18 05:03:17 +00:00
Neal Norwitz 87b801cc2d Set MemoryError when alloc fails 2005-12-18 04:42:47 +00:00
Neal Norwitz 3c52c5a888 Wrap long lines in the grammar 2005-12-18 04:12:30 +00:00
Neal Norwitz 84456bdab3 Cleanup a bit and make things more consistent.
Don't double check for NULLs and don't initialize if not necessary.
No functional changes.
2005-12-18 03:16:20 +00:00
Barry Warsaw 2a38a86c1c Expose Subversion revision number (calculated via "svnversion .") to Python.
Add C API function Py_GetBuildNumber(), add it to the interactive prompt
banner (i.e. Py_GetBuildInfo()), and add it as the sys.build_number
attribute.  The build number is a string instead of an int because it may
contain a trailing 'M' if there are local modifications.
2005-12-18 01:27:35 +00:00
Neal Norwitz f599f424a2 SF patch #1355913, PEP 341 - Unification of try/except and try/finally
Modified since ast-arenas was implemented.
2005-12-17 21:33:47 +00:00
Neal Norwitz adb69fcdff Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
simplifies a lot of error handling code, and fixes many memory leaks.
2005-12-17 20:54:49 +00:00
Neal Norwitz 6f0d479c78 Fix an int/long mismatch identified here:
http://www.tortall.net/mu/blog/2005/12/01

Pointed out from SF #1365916.

Backport candidate.
2005-12-15 06:40:36 +00:00
Neal Norwitz 897ff817d5 SF #1373150, diffs in working copy after a build
Strip off leading dots and slash so the generated files are the same regardless
of whether you configure in the checkout directory or build.

If anyone configures in a different directory, we might want a cleaner
approach using os.path.*().  Hopefully this is good enough.
2005-12-11 21:18:22 +00:00
Neal Norwitz f8d403dd97 SF #1377897, Bus error in ast
If a line had multiple semi-colons and ended with a semi-colon, we would
loop too many times and access a NULL node.  Exit the loop early if
there are no more children.
2005-12-11 20:12:40 +00:00
Neal Norwitz 8ad64aaacc SF #1370197, memory leak - ast_error_finish (in error conditions). 2005-12-11 20:08:33 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Neal Norwitz 28b32ac6bc Simplify logic for handling import * 2005-12-06 07:41:30 +00:00
Neal Norwitz b15ec09343 Reduce scope of feature 2005-12-06 07:26:02 +00:00