Commit Graph

2531 Commits

Author SHA1 Message Date
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
Neal Norwitz c1f213ebdc Remove unused macro, check is done elsewhere 2005-12-06 06:36:36 +00:00
Neal Norwitz e536892541 Remove unnecessary extern variable 2005-12-05 07:16:38 +00:00
Martin v. Löwis b45b315855 Patch #1350409: Port signal handling to VS 2005. 2005-11-28 17:34:23 +00:00
Neal Norwitz 3a9a3e7864 Fix memory leaks 2005-11-27 20:38:31 +00:00
Neal Norwitz 3715c3e576 Fix a few more ref leaks. Backport candidate 2005-11-24 22:09:18 +00:00
Georg Brandl f06e30af4a bug #1281408: make Py_BuildValue work with unsigned longs and long longs 2005-11-24 15:37:42 +00:00
Neal Norwitz 7bcabc60a3 Fix a few more memory leaks
Document more info about the benefits of configuring without
pymalloc when running valgrind
2005-11-20 23:58:38 +00:00
Neal Norwitz 4737b2348b Last batch of ref leaks in new AST code.
Also converted a bunch of assert(0) to SystemError's.

There are still printfs, etc that need to be cleaned up.
2005-11-19 23:58:29 +00:00
Nick Coghlan 944d3eb154 Correctly handle identifiers for anonymous scopes and align genexpr name with symtable.c 2005-11-16 12:46:55 +00:00
Nick Coghlan 99b2533539 Bring handling of genexpr in line with other anonymous scope names 2005-11-16 12:45:24 +00:00
Neal Norwitz a3fd07d524 add more doc 2005-11-16 05:49:04 +00:00
Neal Norwitz ef78529e86 version was not initialized properly 2005-11-16 05:04:51 +00:00
Neal Norwitz 6b34789046 Fix another memory leak or two (one real, one potential) 2005-11-15 07:17:53 +00:00
Neal Norwitz af8f974967 Add a note about how to do the memory deallocation a bit.
This needs a lot of work.
2005-11-15 05:09:44 +00:00
Neal Norwitz e76adcd78a Fix a whole bunch of potential memory leaks (and some real ones too)
in error conditions.
2005-11-15 05:04:31 +00:00
Neal Norwitz 79792651c4 Convert all internal errors from Exception to SystemError
Remove an abort() and let a SystemError be raised.
2005-11-14 04:25:03 +00:00
Neal Norwitz daae6161b5 Use convenience function 2005-11-14 00:47:57 +00:00
Neal Norwitz e8c0536d57 Fix memory leak with bad generator expression 2005-11-14 00:18:03 +00:00
Neal Norwitz 7b3d5e1779 remove useless debug print helper. fix a couple of exceptions 2005-11-13 21:17:28 +00:00
Neal Norwitz 7b5a604d24 Whoops, checkin consistent versions of *all* files to stop polluting
a bunch of names
2005-11-13 19:14:20 +00:00
Neal Norwitz b6fc9df8fc Fix a lot of memory and ref leaks in error paths.
(Call symtable_exit_block or compiler_exit_scope as appropriate)

Use PyMem_Free on c_future since it was allocated with PyMem_Malloc
2005-11-13 18:50:34 +00:00
Neal Norwitz 6576bd844f Prevent name pollution by making lots of internal functions static. 2005-11-13 18:41:28 +00:00
Neal Norwitz 2744c6cc35 make internal method static 2005-11-13 01:08:38 +00:00
Neal Norwitz 67715f0420 - SF Bug #1350188, "setdlopenflags" leads to crash upon "import"
It was possible dlerror() returns a NULL pointer, use a default error
  message in this case.
2005-11-09 06:59:35 +00:00
Martin v. Löwis ab0f947a21 Remove .cvsignore files, as they live in svn:ignore
properties now.
2005-10-30 22:01:41 +00:00
Neil Schemenauer 982e8d671c Refactor code for translating "power" nodes. 2005-10-25 09:16:05 +00:00
Neil Schemenauer c5dd10aa1d Write a separate ast_for_testlist_gexp() function instead of overloading
ast_for_testlist().  Also, write a ast_for_class_bases() function and in
the process fix a memory leak.  Add some assertions.
2005-10-25 07:54:54 +00:00
Neil Schemenauer c396d9edd6 Ensure that compiler_exit_scope() is called as necessary to free memory
allocated by compiler_enter_scope().  Change return type for
compiler_exit_scope() to be void.
2005-10-25 06:30:14 +00:00
Neal Norwitz 62c2fac9a0 Do not pollute name block_ty, prefix with _Py_ 2005-10-24 00:30:44 +00:00
Neal Norwitz f1d50684c6 Fix problem handling EXTENDED_ARGs from SF bug # 1333982 2005-10-23 23:00:41 +00:00
Neal Norwitz 7d37f2ff40 cleanup a bit and reuse instrsize (instruction size). working towards fixing problems with EXTENDED_ARG 2005-10-23 22:40:47 +00:00
Neal Norwitz 12ebfd79f8 Use PyErr_NoMemory() instead of rolling our own.
Get rid of "int i" unused warnings from Python-ast.c which we are generating.
2005-10-23 19:22:48 +00:00
Neil Schemenauer dad06a159e Remove unnecessary local variable. 2005-10-23 18:52:36 +00:00
Neil Schemenauer 2dfcef5c57 Fix check_unoptimized() function. The only optimized namespaces are
in function blocks.  This elimiates spurious warnings about "import *" and
related statements at the class level.
2005-10-23 18:50:36 +00:00
Neil Schemenauer 8b528b28f1 Fix private name mangling. The symtable also must do mangles so that
the scope of names can be correctly determined.
2005-10-23 18:37:42 +00:00
Neil Schemenauer 3a44aaa30f Use PyTuple_Pack instead of Py_BuildValue. 2005-10-23 17:21:54 +00:00
Neil Schemenauer d403c45386 Fix arigo's funky LOAD_NAME bug: implicit globals inside classes have
historically been looked up using LOAD_NAME, not LOAD_GLOBAL.
looked up by LOAD_NAME, not
2005-10-23 04:24:49 +00:00
Neil Schemenauer ac699efad8 Don't stop generating code for import statements after the first "import as"
part.  Fixes one bug from #1333982.
2005-10-23 03:45:42 +00:00
Neil Schemenauer 147b75931d Add an assert. 2005-10-23 03:38:19 +00:00
Neil Schemenauer ccd19218bc Use <lamba> as the function name for lambdas (matches old compiler). 2005-10-21 18:09:19 +00:00
Jeremy Hylton ec97a28b60 Fix a bunch of imports to use code.h instead of compile.h.
Remove duplicate declarations from compile.h
2005-10-21 14:58:06 +00:00
Armin Rigo 3144130217 ANSI-C-ify the placement of local var declarations. 2005-10-21 12:57:31 +00:00
Michael W. Hudson aee2e2829d the ast-branch changed the stack discipline of MAKE_CLOSURE, so we need to
bump MAGIC.
2005-10-21 11:32:20 +00:00
Neal Norwitz 37c0844b35 Fix SF bug #1167751, Argument genexp corner case
Incorrect code was generated for:

  foo(a = i for i in range(10))

This should have generated a SyntaxError.  Fix the Grammar so
it raises a SyntaxError and test it.

I'm uncertain whether this should be backported.  It makes
something that was Syntactically valid invalid.  However,
the code would either be completely broken or do the wrong thing.
2005-10-21 06:24:02 +00:00
Neal Norwitz 57071ce545 Oops, "=" is not a comparison operator 2005-10-21 05:15:07 +00:00
Neal Norwitz 5f5153e871 Fix some mods that got dropped from the AST merge 2005-10-21 04:28:38 +00:00
Jeremy Hylton 3e0055f8c6 Merge ast-branch to head
This change implements a new bytecode compiler, based on a
transformation of the parse tree to an abstract syntax defined in
Parser/Python.asdl.

The compiler implementation is not complete, but it is in stable
enough shape to run the entire test suite excepting two disabled
tests.
2005-10-20 19:59:25 +00:00
Neal Norwitz 708e51a6b1 Fix SF bug #976608, Unhelpful error message when mtime of a module is -1
Will backport.
2005-10-03 04:48:15 +00:00
Neal Norwitz 11bd119226 SF bug #887946, segfault if redirecting directory
Also provide a warning if a directory is passed on the command line.
Add minimal command line test.

Will backport.
2005-10-03 00:54:56 +00:00
Neal Norwitz 40d3781416 - Fix segfault with invalid coding.
- SF Bug #772896, unknown encoding results in MemoryError, which is not helpful

I will only backport the segfault fix.  I'll let Anthony decide if he wants
the other changes backported.  I will do the backport if asked.
2005-10-02 01:48:49 +00:00
Michael W. Hudson ce7da6c5e9 Forward port bugfix:
[ 1307978 ] Unsatisfied symbols: _PyGILState_NoteThreadState (code)

(note that this only happens in a threads-disabled build).
2005-09-30 08:20:24 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Armin Rigo 1c2d7e5363 clean-up tracing of C functions. In particular, don't call the trace func
with an exception currently set!
2005-09-20 18:34:01 +00:00
Armin Rigo 71d7e704b8 Removed a check "if (args != NULL)" which is always True and makes no sense. 2005-09-20 18:13:03 +00:00
Armin Rigo a6eb56cf46 Don't call memset() before checking that the ptr is not NULL. 2005-09-20 18:07:47 +00:00
Georg Brandl 6953772d90 patch [ 1119423 ] python -c readlink()s and stat()s '-c' 2005-09-15 13:00:34 +00:00
Georg Brandl 77c85e63b4 bug [ 868706 ] Calling builtin function 'eval' from C causes seg fault. 2005-09-15 10:46:13 +00:00
Georg Brandl 6dd14619bb Complete format code support in getargs.c::skipitem(), which is called when
evaluating keyword arguments.
2005-09-14 19:29:53 +00:00
Guido van Rossum 8ee3e5aa93 - Changes donated by Elemental Security to make it work on AIX 5.3
with IBM's 64-bit compiler (SF patch #1284289).  This also closes SF
  bug #105470: test_pwd fails on 64bit system (Opteron).
2005-09-14 18:09:42 +00:00
Guido van Rossum 539c662f10 - Changes donated by Elemental Security to make it work on HP-UX 11 on
Itanium2 with HP's 64-bit compiler (SF patch #1225212).
2005-09-14 17:49:54 +00:00
Georg Brandl 0c55f2946b Patch #1290454: Fix reload() error message when parent module is not in
sys.modules.
2005-09-14 06:56:20 +00:00
Georg Brandl 99d7e4e8eb Whitespace normalization. 2005-08-31 22:21:15 +00:00
Georg Brandl 02c42871cf Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418)
2005-08-26 06:42:30 +00:00
Martin v. Löwis d35edda682 Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Will backport to 2.4.
2005-08-24 08:39:24 +00:00
Raymond Hettinger a710b331da SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Fix over-aggressive PyErr_Clear().  The same code fragment appears in
various guises in list.extend(), map(), filter(), zip(), and internally
in PySequence_Tuple().
2005-08-21 11:03:59 +00:00
Raymond Hettinger beb3101b05 Add a C API for sets and frozensets. 2005-08-16 03:47:52 +00:00
Barry Warsaw e2eca0b709 Port from the Python 2.4 branch, patches for SF bug # 900092,
hotshot.stats.load.
2005-08-15 18:14:19 +00:00
Tim Peters ea9dcdc062 com_yield_expr(): Squash new compiler wng about unreferenced local. 2005-08-03 18:33:05 +00:00
Phillip J. Eby 0d6615fd29 PEP 342 implementation. Per Guido's comments, the generator throw()
method still needs to support string exceptions, and allow None for the
third argument.  Documentation updates are needed, too.
2005-08-02 00:46:46 +00:00
Raymond Hettinger d794666048 * Improve code for the empty frozenset singleton:
- Handle both frozenset() and frozenset([]).
  - Do not use singleton for frozenset subclasses.
  - Finalize the singleton.
  - Add test cases.
* Factor-out set_update_internal() from set_update().  Simplifies the
  code for several internal callers.
* Factor constant expressions out of loop in set_merge_internal().
* Minor comment touch-ups.
2005-08-01 21:39:29 +00:00
Georg Brandl e35b657efd Fix cleanup DECREF logic in builtin_filter function. 2005-07-19 22:20:20 +00:00
Georg Brandl 9a3240e8e6 bug 1234979 addition 2005-07-09 15:26:33 +00:00
Georg Brandl af410b510d bug [ 1234979 ] Lock.acquire treats only 1 as True 2005-07-08 22:26:13 +00:00
Brett Cannon c9371d4a1b Fix signedness of various char variables to stop causing a warning under gcc 4. 2005-06-25 08:23:41 +00:00
Brett Cannon 55fa66dd45 Add comments about PyThreadState and the usage of its fields. 2005-06-25 07:07:35 +00:00
Michael W. Hudson 188d4366be Fix bug:
[ 1163563 ] Sub threads execute in restricted mode

basically by fixing bug 1010677 in a non-broken way.

Backport candidate.
2005-06-20 16:52:57 +00:00
Michael W. Hudson 867f2d45cd You can have more than one thread state for a thread if they
correspond to different interpreters (I hope, please revert if this is
wrong :).
2005-06-16 11:35:00 +00:00
Michael W. Hudson f2ca5af439 Fix bug
[ 1180997 ] lax error-checking in new-in-2.4 marshal stuff

which I'd assigned to Martin, but actually turned out to be easy to fix.

Also, a test.
2005-06-13 18:28:46 +00:00
Michael W. Hudson 01fca11080 Remove extraneous format character from PyArg_ParseTuple call in
marshal_loads.

Bugfix candidate.
2005-06-13 17:50:18 +00:00
Michael W. Hudson 6d6917be00 Fix a couple of crashing-on-malformed data marshal bugs. 2005-06-03 15:17:16 +00:00
Michael W. Hudson df88846ebc This is my patch:
[ 1180995 ] binary formats for marshalling floats

Adds 2 new type codes for marshal (binary floats and binary complexes), a
new marshal version (2), updates MAGIC and fiddles the de-serializing of
code objects to be less likely to clobber the real reason for failing if
it fails.
2005-06-03 14:41:55 +00:00
Michael W. Hudson ba283e2b7f This is my patch:
[ 1181301 ] make float packing copy bytes when they can

which hasn't been reviewed, despite numerous threats to check it in
anyway if noone reviews it.  Please read the diff on the checkin list,
at least!

The basic idea is to examine the bytes of some 'probe values' to see if
the current platform is a IEEE 754-ish platform, and if so
_PyFloat_{Pack,Unpack}{4,8} just copy bytes around.

The rest is hair for testing, and tests.
2005-05-27 15:23:20 +00:00
Jason Tishler 7961aa6135 Patch #1197318: Cygwin case-sensitive import patch
A problem regarding importing symlinked modules was recently reported on the
Cygwin mailing list:

    http://cygwin.com/ml/cygwin/2005-04/msg00257.html

The following test case demonstrates the problem:

$ ls -l
total 1
lrwxrwxrwx    1 jt       None            6 Apr 23 13:32 bar.py -> foo.py
-rw-r--r--    1 jt       None           24 Apr 18 20:13 foo.py

$ python -c 'import bar'
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named bar

Since Cygwin's case_ok() uses a modified version of the Windows's version, the
symlinked bar module actually resolves to file foo.py instead of bar.py. This
obviously causes the matching code to fail (regardless of case).

The patch fixes this problem by making Cygwin use the Mac OS X case_ok()
instead of a modified Window's version.
2005-05-20 00:56:54 +00:00
Michael W. Hudson 774479c68b Fix:
[ 1176893 ] Readline segfault

by unsilly-ing PyGILState_Release().

Backport candidate.
2005-04-18 08:46:17 +00:00
Hye-Shik Chang b6fa2814f7 Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define
a default value of recursion limit from build systems.  1000 levels
are still too high for some 64bit systems.
2005-04-04 15:49:02 +00:00
Michael W. Hudson 5253c30791 I suppose a bug report or even a fix would be a better response, but
commit a yelp about a noted flaw the error messages for METH_KEYWORDS
functions under some circumstances.
2005-03-30 16:41:55 +00:00
Anthony Baxter 12b6f6cac7 Move exception finalisation later in the shutdown process - this
fixes the crash seen in bug #1165761
2005-03-29 13:36:16 +00:00
Martin v. Löwis 8b8fb3db5a Add 0 to _POSIX_SEMAPHORES. Will backport to 2.4. 2005-03-28 12:34:20 +00:00
Anthony Baxter 19b2369d42 Patch #1163249 - Correctly handle _POSIX_SEMAPHORES == -1 to mean no
support for posix semaphores.
2005-03-16 04:15:07 +00:00
Raymond Hettinger 96229b1918 Add two new functions, any() and all(). 2005-03-11 06:49:40 +00:00
Brett Cannon 409d8f2ebd Allow classes to be defined with empty parentheses. This means that
``class C(): pass`` is no longer a syntax error.
2005-03-05 06:47:57 +00:00
Martin v. Löwis 96d743ec8b Patch #1115086: support PY_LONGLONG in structmember. 2005-03-03 23:00:26 +00:00
Martin v. Löwis 6ce7ed23d0 Revert previous checkin on getargs 'L' code. Try to convert all
numbers in PyLong_AsLongLong, and update test suite accordingly.
Backported to 2.4.
2005-03-03 12:26:35 +00:00
Martin v. Löwis 4bf108d74f Patch #802188: better parser error message for non-EOL following line cont. 2005-03-03 11:45:45 +00:00
Martin v. Löwis ff232d7230 Clear internal call error in 'L' format. Fixes #723201.
Backported to 2.4.
2005-03-03 09:24:38 +00:00
Brett Cannon 5dc8ced4a8 Silence a gcc warning about putting in parentheses around && expressions mixed
with || expressions.  Also clarifies intend of 'if' conditional.
2005-03-03 07:01:48 +00:00
Raymond Hettinger e63a078635 Preserve sign of -0.0 when result is run through marshal. 2005-02-23 13:37:55 +00:00
Raymond Hettinger 07359a7fed Document how the pattern recognizer keeps all of its references in bounds.
Add a test in case the underlying assumptions ever change (i.e. the
compiler starts generating code blocks that are not punctuated by
RETURN_VALUE).
2005-02-21 20:03:14 +00:00
Raymond Hettinger 80121491e0 Teach the peepholer to fold unary operations on constants.
Afterwards, -0.5 loads in a single step and no longer requires a runtime
UNARY_NEGATIVE operation.
2005-02-20 12:41:32 +00:00
Raymond Hettinger b615bf0681 Remove the set conversion which didn't work with: [] in (0,) 2005-02-10 01:42:32 +00:00
Raymond Hettinger 5e547969f8 Have set conversion replace existing constant if not used elsewhere. 2005-02-09 21:24:51 +00:00
Guido van Rossum 0f1f63cf07 Close the discussion in SF bug 1069160. 2005-02-08 02:07:57 +00:00
Raymond Hettinger 7fcb7869ba Adopt Skip's idea to optimize lists of constants in the context
of a "in" or "not in" test.
2005-02-07 19:32:38 +00:00
Raymond Hettinger a164574937 Transform "x in (1,2,3)" to "x in frozenset([1,2,3])".
Inspired by Skip's idea to recognize the throw-away nature of sequences
in this context and to transform their type to one with better performance.
2005-02-06 22:05:42 +00:00
Jeremy Hylton c9add9a483 Fix bug that allowed future statements virtually anywhere in a module.
If we exit via the break here, we need to set ff_last_lineno or
FUTURE_POSSIBLE() will remain true.  The bug affected statements
containing a variety of expressions, but not all expressions.  It has
been present since Python 2.2.
2005-02-04 18:38:43 +00:00
Martin v. Löwis 13a1fde4da Partially revert #1074011; don't try to fflush stdin.
Backported to 2.3 and 2.4.
2005-01-27 18:56:16 +00:00
Raymond Hettinger 9feb267caf Do not fold a constant if a large sequence will result.
Saves space in the presence of code like: (None,)*10000
2005-01-26 12:50:05 +00:00
Anthony Baxter c560a00966 happy new year! (on the trunk) 2005-01-25 12:40:01 +00:00
Martin v. Löwis 8e3ca8af26 Flush std{in,out,err} before closing it. Fixes #1074011.
Will backport to 2.4 and 2.3.
2005-01-23 09:41:49 +00:00
Michael W. Hudson 75eabd2944 Change the name of the macro used by --with-tsc builds to the less
inscrutable READ_TIMESTAMP.
2005-01-18 15:56:11 +00:00
Michael W. Hudson 969f485cba -X died some time ago; remove a tiny bit of associated cruft. 2005-01-18 15:26:11 +00:00
Andrew MacIntyre 2bea474476 make thread stack size compile-time tunable on OS/2 2005-01-17 12:16:36 +00:00
Fred Drake d7c27bef52 remove unused variable 2005-01-12 16:00:55 +00:00
Raymond Hettinger a422c34b70 SF 1098985: set objects cannot be marshalled 2005-01-11 03:03:27 +00:00
Skip Montanaro c9a4762bd6 comment tweak 2005-01-08 21:58:58 +00:00
Armin Rigo 664b43b3f4 Re-running python with/without the -Qnew flag uses incorrectly optimized
bytecodes from the previously saved .pyc files.  Fixed by disabling the static
optimization of BINARY_DIVIDE between two constants.
2005-01-07 18:10:51 +00:00
Raymond Hettinger c34f8673a1 Teach the peephole optimizer to fold simple constant expressions. 2005-01-02 06:17:33 +00:00
Armin Rigo 2ccea17856 Any call to marshal.dumps() with the new optional argument 'version' just
immediately segfaults, due to a typo!  This was obviously never tested...
Added a test for it, and also fixed the documentation.
2004-12-20 12:25:57 +00:00
Brett Cannon 9e635cf3ae Put parentheses around the assignment in the 'while' loop conditional
expression in min_max() to shut gcc up.
2004-12-07 00:25:35 +00:00
Raymond Hettinger 3b0c7c20a1 SF patch #1077353: add key= argument to min and max
(First draft of patch contributed by Steven Bethard.)
2004-12-03 08:30:39 +00:00
Kurt B. Kaiser 4c79a83e0c Hye-Shik Chang's fix for Bug 875692.
Improve signal handling, especially when using threads, by forcing an early
re-execution of PyEval_EvalFrame() "periodic" code when things_to_do is not
cleared by Py_MakePendingCalls().

M Misc/NEWS
M Python/ceval.c
2004-11-23 18:06:08 +00:00
Tim Peters fb1ffb0ebb SF bug 1061968: threads: segfault or Py_FatalError at exit
PyGILState_Ensure():  The fix in 2.4a3 for bug 1010677 reintroduced thread
shutdown race bug 225673.  Repaired by (once again) ensuring the GIL is
held whenever deleting a thread state.

Alas, there's no useful test case for this shy bug.  Four years ago, only
Guido could provoke it, on his box, and today only Armin can provoke it
on his box.  I've never been able to provoke it (but not for lack of
trying!).

This is a critical fix for 2.3.5 too, since the fix for 1010677 got
backported there already and so also reintroduced 225673.  I don't intend to
backport this fix.  For whoever (if anyone) does, there are other thread
fixes in 2.4 that need backporting too, and I bet they need to happen first
for this patch to apply cleanly.
2004-11-08 04:30:21 +00:00
Jeremy Hylton 16b047904c SF patch 1025636: Check for NULL returns in compile.c:com_import_stmt
There is no test for this change, because there is no way to provoke memory errors on demand.  Test suite passes, though.
2004-11-07 14:04:00 +00:00
Raymond Hettinger ec6eb369d5 SF patch #1035255: Remove CoreServices / CoreFoundation dependencies in core
(Contributed by Bob Ippolito.)

This patch trims down the Python core on Darwin by making it
independent of CoreFoundation and CoreServices. It does this by:

Changed linker flags in configure/configure.in
Removed the unused PyMac_GetAppletScriptFile
Moved the implementation of PyMac_StrError to the MacOS module
Moved the implementation of PyMac_GetFullPathname to the
Carbon.File module
2004-11-05 07:02:59 +00:00
Raymond Hettinger 5dec096e6a Maintain peepholer's cumlc invariant by updating the running total
everytime a LOAD_CONSTANT is encountered, created, or overwritten.

Added two tests to cover cases affected by the patch.
2004-11-02 04:20:10 +00:00
Raymond Hettinger 099ecfbec9 Simplify and future proof NOP counting in the peepholer.
No longer assumes that the input is NOP free.
2004-11-01 15:19:11 +00:00
Armin Rigo d7bcf4deb1 Fixed a comment and added another one. 2004-10-30 21:08:59 +00:00
Raymond Hettinger effb3931ea Adopt some peepholer suggestions from Armin Rigo:
* Use simpler, faster two pass algorithm for markblocks().
* Free the blocks variable if not NULL and exiting without change.
* Verify that the rest of the compiler has not set an exception.
* Make the test for tuple of constants less restrictive.
* Embellish the comment for chained conditional jumps.
2004-10-30 08:55:08 +00:00
Raymond Hettinger 23109ef11e SF bug #1053819: Segfault in tuple_of_constants
Peepholer could be fooled into misidentifying a tuple_of_constants.
Added code to count consecutive occurrences of LOAD_CONST.
Use the count to weed out the misidentified cases.
Added a unittest.
2004-10-26 08:59:14 +00:00
Raymond Hettinger 9047c8f73d SF bug #1048870: call arg of lambda not updating 2004-10-24 00:10:06 +00:00
Anthony Baxter 9ceaa72ebe Patch #975056 - fixes for restartable signals on *BSD. In addition,
a few remaining calls to signal() were converted to PyOS_setsig().
2004-10-13 14:48:50 +00:00
Tim Peters 7f468f29f4 SF patch 1044089: New C API function PyEval_ThreadsInitialized(), by Nick
Coghlan, for determining whether PyEval_InitThreads() has been called.
Also purged the undocumented+unused _PyThread_Started int.
2004-10-11 02:40:51 +00:00
Tim Peters 89c0ec9beb Revert rev 2.35. It was based on erroneous reasoning -- the current
thread's id can't get duplicated, because (of course!) the current thread
is still running.  The code should work either way, but reverting the
gratuitous change should make backporting easier, and gets the bad
reasoning out of 2.35's new comments.
2004-10-10 05:30:40 +00:00
Tim Peters 8470558a04 PyInterpreterState_New(), PyThreadState_New(): use malloc/free directly.
This appears to finish repairs for SF bug 1041645.

This is a critical bugfix.
2004-10-10 02:47:33 +00:00
Tim Peters 263091e388 find_key(): This routine wasn't thread-correct, and accounts for the
release-build failures noted in bug 1041645.

This is a critical bugfix.  I'm not going to backport it, though (no time).
2004-10-10 01:58:44 +00:00
Tim Peters 5c14e6498a PyGILState_Release(): If we need to delete the TLS entry for this thread,
that must be done under protection of the GIL, for reasons explained in
new comments.
2004-10-09 23:55:36 +00:00
Tim Peters f9becec8cd _PyGILState_Init(), PyGILState_Ensure(): Since PyThread_set_key_value()
can fail, check its return value, and die if it does fail.

_PyGILState_Init():  Assert that the thread doesn't already have an
association for autoTLSkey.  If it does, PyThread_set_key_value() will
ignore the attempt to (re)set the association, which the code clearly
doesn't want.
2004-10-09 22:47:13 +00:00
Tim Peters fda787fcec Document the results of painful reverse-engineering of the "portable TLS"
code.

PyThread_set_key_value():  It's clear that this code assumes the passed-in
value isn't NULL, so document that it must not be, and assert that it
isn't.  It remains unclear whether existing callers want the odd semantics
actually implemented by this function.
2004-10-09 22:33:09 +00:00
Tim Peters 19717fa33a Style guide & consistency changes. No semantic changes. 2004-10-09 17:38:29 +00:00
Tim Peters 4c1f5ecfe3 Trim trailing whitespace. 2004-10-09 17:25:05 +00:00
Raymond Hettinger db29e0fe8c SF patch #1035498: -m option to run a module as a script
(Contributed by Nick Coghlan.)
2004-10-07 06:46:25 +00:00
Raymond Hettinger fb09f0e85c Finalize the freelist of list objects. 2004-10-07 03:58:07 +00:00
Martin v. Löwis 507a485984 Print verbose messages to stderr. Fixes #1036752. 2004-10-03 08:51:35 +00:00
Raymond Hettinger fec0c466ad Improve error message for augmented assignments to genexps or listcomps.
Rather than introduce new logic, took the approach of making the message
itself more general.
2004-09-29 23:54:08 +00:00
Raymond Hettinger 8ffc1410e2 Fix two erroneous error messages. 2004-09-29 21:47:10 +00:00
Raymond Hettinger 06cc973d06 Replaced a test with an assertion.
(Suggested by Michael Hudson.)
2004-09-28 17:22:12 +00:00
Phillip J. Eby 7ec642a4d2 Fix for SF bug #1029475 : reload() doesn't work with PEP 302 loaders. 2004-09-23 04:37:36 +00:00
Raymond Hettinger 2c31a058eb SF patch #1031667: Fold tuples of constants into a single constant
Example:
>>> import dis
>>> dis.dis(compile('1,2,3', '', 'eval'))
  0           0 LOAD_CONST               3 ((1, 2, 3))
              3 RETURN_VALUE
2004-09-22 18:44:21 +00:00
Raymond Hettinger cfc3192677 SF bug #1014215: Unspecific errors with metaclass
High level error message was stomping useful detailed messages from lower
level routines.

The new approach is to augment string error messages returned by the low
level routines.  The provides both high and low level information.  If
the exception value is not a string, no changes are made.

To see the improved messages in action, type:
   import random
   class R(random): pass
   class B(bool): pass
2004-09-16 16:41:57 +00:00
Anthony Baxter 1a4ddaecc7 SF patch #1007189, multi-line imports, for instance:
"from blah import (foo, bar
baz, bongo)"
2004-08-31 10:07:13 +00:00
Martin v. Löwis 87fa785f0f Centralize WITH_TSC processing. 2004-08-29 15:51:52 +00:00
Raymond Hettinger 1792bfbf90 Bypass peepholing of code with lineno tables having intervals >= 255.
Allows the lineno fixup code to remain simple and not have to deal with
multibyte codings.

* Add an assertion to that effect.
* Remove the XXX comment on the subject.
2004-08-25 17:19:38 +00:00
Raymond Hettinger 65d3c0537a Fix typo in comment and add clarification. 2004-08-25 15:15:56 +00:00
Martin v. Löwis 8d494f3241 Patch #1015021: Stop claiming that coerce can return None.
Will backport to 2.3.
2004-08-25 10:42:41 +00:00
Raymond Hettinger ef0a82b682 Simplify chains of conditional jumps.
(Suggested by Neal Norwitz.)
2004-08-25 03:18:29 +00:00
Tim Peters c885443479 Stop producing or using OverflowWarning. PEP 237 thought this would
happen in 2.3, but nobody noticed it still was getting generated (the
warning was disabled by default).  OverflowWarning and
PyExc_OverflowWarning should be removed for 2.5, and left notes all over
saying so.
2004-08-25 02:14:08 +00:00
Raymond Hettinger a12fa148d7 Incorporate review comments courtesy of Neal Norwitz:
* Perform the code length check earlier.
* Eliminate the extra PyMem_Free() upon hitting an EXTENDED_ARG.
* Assert that the NOP count used in jump retargeting matches the NOPs
  eliminated in the final step.
* Add an XXX note to indicate that more work is being to done to
  handle linenotab with intervals > 255.
2004-08-24 04:34:16 +00:00
Raymond Hettinger fd2d1f7870 SF Patch #1013667: Cleanup Peepholer Output
* Make a pass to eliminate NOPs.  Produce code that is more readable,
  more compact, and a tiny bit faster.  Makes the peepholer more flexible
  in the scope of allowable transformations.

* With Guido's okay, bumped up the magic number so that this patch gets
  widely exercised before the alpha goes out.
2004-08-23 23:37:48 +00:00
Martin v. Löwis 336e85f56a Patch #900727: Add Py_InitializeEx to allow embedding without signals. 2004-08-19 11:31:58 +00:00
Raymond Hettinger 1a7892924f Move the bytecode optimizer upstream so that its results are saved in pyc
files and not re-optimized upon import.  Saves a bit of startup time while
still remaining decoupled from the rest of the compiler.

As a side benefit, handcoded bytecode is not run through the optimizer
when new code objects are created.  Hopefully, a handcoder has already
created exactly what they want to have run.

(Idea suggested by Armin Rigo and Michael Hudson.  Initially avoided
 because of worries about compiler coupling; however, only the nexus
 point needed to be moved so there won't be a conflict when the AST
 branch is loaded.)
2004-08-18 05:22:06 +00:00
Michael W. Hudson 0ccff074cd This is Mark Russell's patch:
[ 1009560 ] Fix @decorator evaluation order

From the description:

Changes in this patch:

- Change Grammar/Grammar to require
newlines between adjacent decorators.

- Fix order of evaluation of decorators
in the C (compile.c) and python
(Lib/compiler/pycodegen.py) compilers

- Add better order of evaluation check
to test_decorators.py (test_eval_order)

- Update the decorator documentation in
the reference manual (improve description
of evaluation order and update syntax
description)

and the comment:

Used Brett's evaluation order (see
http://mail.python.org/pipermail/python-dev/2004-August/047835.html)

(I'm checking this in for Anthony who was having problems getting SF to
talk to him)
2004-08-17 17:29:16 +00:00
Matthias Klose a2542bee59 The attached patch fixes FTBFS on GNU/k*BSD. The problem happens on GNU/k*BSD
because GNU/k*BSD uses gnu pth to provide pthreads, but will also happen on any
system that does the same.

python fails to build because it doesn't detect gnu pth in pthread
emulation. See C comments in patch for details.

patch taken from http://bugs.debian.org/264315
2004-08-16 11:35:51 +00:00
Brett Cannon add33601c2 Correct the order of application for decorators. Meant to be bottom-up and not
top-down.  Now matches the PEP.
2004-08-15 07:21:25 +00:00
Brett Cannon 31f8350f43 Fix incorrect comment for (struct compiling)->c_cellvars 2004-08-15 01:15:01 +00:00
Michael W. Hudson 800ba2375a This is my patch:
[ 1005891 ] support --with-tsc on PPC

plus a trivial change to settscdump's docstring and a Misc/NEWS entry.
2004-08-12 18:19:17 +00:00
Tim Peters d459f536c5 code_new(): Wouldn't compile on Windows, because of gcc'ism. 2004-08-12 18:16:43 +00:00
Michael W. Hudson 6093462739 Fix bug
[ 1005248 ] new.code() not cleanly checking its arguments

using the result of new.code() can still destroy the sun, but merely
calling the function shouldn't any more.

I also rewrote the existing tests of new.code() to use vastly less
un-bogus arguments, and added tests for the previous insane behaviours.
2004-08-12 17:56:29 +00:00
Martin v. Löwis fd39ad4937 Patch #1005468: Disambiguate "min() or max()" exception string. 2004-08-12 14:42:37 +00:00
Armin Rigo 618fbf5469 This was quite a dark bug in my recent in-place string concatenation
hack: it would resize *interned* strings in-place!  This occurred because
their reference counts do not have their expected value -- stringobject.c
hacks them.  Mea culpa.
2004-08-07 20:58:32 +00:00
Jeremy Hylton 4c989ddc9c Subclasses of string can no longer be interned. The semantics of
interning were not clear here -- a subclass could be mutable, for
example -- and had bugs.  Explicitly interning a subclass of string
via intern() will raise a TypeError.  Internal operations that attempt
to intern a string subclass will have no effect.

Added a few tests to test_builtin that includes the old buggy code and
verifies that calls like PyObject_SetAttr() don't fail.  Perhaps these
tests should have gone in test_string.
2004-08-07 19:20:05 +00:00
Michael W. Hudson 34553388ef Fix
[ 991812 ] PyArg_ParseTuple can miss errors with warnings as exceptions

as suggested in the report.

This is definitely a 2.3 candidate (as are most of the checkins I've
made in the last month...)
2004-08-07 17:57:16 +00:00
Raymond Hettinger 98bd1814e2 SF bug #1004088: big code objects (>64K) may be optimized incorrectly
Will backport.
2004-08-06 19:46:34 +00:00
Raymond Hettinger 52a21b8e65 SF patch #980695: efficient string concatenation
(Original patch by Armin Rigo).
2004-08-06 18:43:09 +00:00
Michael W. Hudson e51c4f9a10 Revert 2.312; turns out interning the file name did do some good (reducing
.pyc size) after all.
2004-08-04 10:26:08 +00:00
Michael W. Hudson 782d8ffb42 Don't intern the filename of a file being compiled.
Hard to believe it ever helped anything, and it hurts finding reference
leaks.
2004-08-03 10:24:03 +00:00
Michael W. Hudson a3711f73c1 Fix for the unfortunate fact that PyDict_GetItem and PyObject_GetItem
have differing refcount semantics.  If anyone sees a prettier way to
acheive the same ends, then please go for it.

I think this is the first time I've ever used Py_XINCREF.
2004-08-02 14:50:43 +00:00
Michael W. Hudson 52db519faa for some reason, the lack of adherence to Python's C whitespace rules
must have annoyed me at some point.
2004-08-02 13:21:09 +00:00
Anthony Baxter 4e7785aa4f fix for @decorators under a debug build. 2004-08-02 11:08:15 +00:00
Raymond Hettinger 66bd233225 Completed the patch for Bug #215126.
* Fixes an incorrect variable in a PyDict_CheckExact.
* Allow general mapping locals arguments for the execfile() function
  and exec statement.
* Add tests.
2004-08-02 08:30:07 +00:00
Anthony Baxter c2a5a63654 PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.
2004-08-02 06:10:11 +00:00
Tim Peters 1cd701732f PyImport_ExecCodeModuleEx(): remove module from sys.modules in error cases.
PyImport_ReloadModule():  restore the module to sys.modules in error cases.
load_package():  semantic-neutral refactoring from an earlier stab at
                 this patch; giving it a common error exit made the code
                 easier to follow, so retaining that part.
_RemoveModule():  new little utility to delete a key from sys.modules.
2004-08-02 03:52:12 +00:00
Tim Peters a7c650934d lock_held() docs: Use True/False instead of 1/0. The LaTeX docs were
already correct, so not changed here.
2004-08-01 23:26:05 +00:00
Tim Peters 86c7d2f220 Trimmed trailing whitespace. 2004-08-01 23:24:21 +00:00
Martin v. Löwis c2632a5c34 Patch #984714: Properly diagnose E_DECODE errors.
Backported to 2.3.
2004-07-21 05:35:02 +00:00
Neil Schemenauer 3a313e3655 Check the type of values returned by __int__, __float__, __long__,
__oct__, and __hex__.  Raise TypeError if an invalid type is
returned.  Note that PyNumber_Int and PyNumber_Long can still
return ints or longs.  Fixes SF bug #966618.
2004-07-19 16:29:17 +00:00
Raymond Hettinger 11a70c79b9 Upgrade None assignment SyntaxWarning to a SyntaxError. 2004-07-17 21:46:25 +00:00
Tim Peters db5860b7c7 optimize_code(): Repaired gross error in new special-casing for None.
The preceding case statement was missing a terminating "break" stmt,
so fell into the new code by mistake.  This caused uncaught out-of-bounds
accesses to the "names" tuple, leading to a variety of insane behaviors.
2004-07-17 05:00:52 +00:00
Raymond Hettinger 76d962d700 Treat None as a constant. 2004-07-16 12:16:48 +00:00
Jack Jansen e497978201 Fix for 838140: don't call NSUnlinkModule when we fail to find our
expected entrypoint. The unlinking will crash the application if the
module contained ObjC code. The price of this is small: a little wasted
memory, and only in a case than isn't expected to occur often.
2004-07-15 22:28:48 +00:00
Jack Jansen 59f072ad7c Moved PyMac_GetScript() to _localemodule, which is the only place where
it is used, and made it private. Should fix #978662.
2004-07-15 13:31:39 +00:00
Michael W. Hudson c849e63eb0 This is Pete Shinners' patch from his bug report
[ 984722 ] Py_BuildValue loses reference counts on error

I'm ever-so-slightly uneasy at the amount of work this can do with an
exception pending, but I don't think that this can result in anything
more serious than a strange error message.
2004-07-14 11:28:06 +00:00
Brett Cannon 711e7d97e4 Add PyArg_VaParseTupleAndKeywords(). Document this function and
PyArg_VaParse().

Closes patch #550732.  Thanks Greg Chapman.
2004-07-10 22:20:32 +00:00
Neal Norwitz 739a8f86d6 Fix a couple of signed/unsigned comparison warnings 2004-07-08 01:55:58 +00:00
Neal Norwitz 93468eac72 Remove unused macros in .c files 2004-07-08 01:49:00 +00:00
Michael W. Hudson 30ea2f223f This closes patch:
[ 960406 ] unblock signals in threads

although the changes do not correspond exactly to any patch attached to
that report.

Non-main threads no longer have all signals masked.

A different interface to readline is used.

The handling of signals inside calls to PyOS_Readline is now rather
different.

These changes are all a bit scary!  Review and cross-platform testing
much appreciated.
2004-07-07 17:44:12 +00:00
Raymond Hettinger 513ffe8112 * Fix missing return after error message is set.
* Add a test case that would have caught it.
2004-07-06 13:44:41 +00:00
Thomas Heller 1df04617b7 When importing an extension on Windows, the code reads the PE 'import
table' of the dll, to make sure that the dll really was build for the
correct Python version.  It does this by looking for an entry
'pythonXY.dll' (X.Y is the Python version number).

The code now checks the size of the dll's import table before reading
entries from it.  Before this patch, the code crashed trying to read
the import table when the size was zero (as in Win2k's wmi.dll, for
example).

Look for imports of 'pythonXY_d.dll' in a debug build instead of
'pythonXY.dll'.

Fixes SF 951851: Crash when reading "import table" of certain windows dlls.

Already backported to the 2.3 branch.
2004-07-02 08:53:57 +00:00
Raymond Hettinger 214b1c3aae SF Bug #215126: Over restricted type checking on eval() function
The builtin eval() function now accepts any mapping for the locals argument.
Time sensitive steps guarded by PyDict_CheckExact() to keep from slowing
down the normal case.  My timings so no measurable impact.
2004-07-02 06:41:07 +00:00
Martin v. Löwis ef82d2fdfe Patch #923098: Share interned strings in marshal. 2004-06-27 16:51:46 +00:00
Martin v. Löwis 8d97e33bb7 Patch #966493: Cleanup generator/eval_frame exposure. 2004-06-27 15:43:12 +00:00
Raymond Hettinger a7f56bc0cc Get ceval.c to compile again by moving declarations before other statments. 2004-06-26 04:34:33 +00:00
Nicholas Bastin d858a7763a Massive performance improvement for C extension and builtin tracing code 2004-06-25 23:31:06 +00:00
Raymond Hettinger 43ea47ff06 Move NOP to end of code transformation. 2004-06-24 09:25:39 +00:00
Nicholas Bastin 941b8bc41a Less ugly #ifdefs for C profiling fix 2004-06-22 15:37:51 +00:00
Nicholas Bastin bbffbd1983 One forgotten C profiling #ifdef 2004-06-22 04:18:47 +00:00
Nicholas Bastin 4c70b69fb1 Making C profiling a configure option (at least temporarily) 2004-06-22 03:51:38 +00:00
Raymond Hettinger 9c18e81fb2 Install two code generation optimizations that depend on NOP.
Reduces the cost of "not" to almost zero.
2004-06-21 16:31:15 +00:00
Armin Rigo 8817fcdba5 Performance tweak: allow stack_pointer and oparg to be register variables.
SF patch #943898
2004-06-17 10:22:40 +00:00
Neal Norwitz 0f5aed4e41 Remove compiler warning 2004-06-13 20:32:17 +00:00
Neal Norwitz d85c452604 Make private function static 2004-06-13 20:31:49 +00:00
Martin v. Löwis 737ea82a5a Patch #774665: Make Python LC_NUMERIC agnostic. 2004-06-08 18:52:54 +00:00
Martin v. Löwis f30d60edbc Patch #510695: Add TSC profiling for the VM. 2004-06-08 08:17:44 +00:00
Thomas Heller 25653242fe Fix a refcount bug in an obscure code corner.
Already backported.
2004-06-07 15:04:10 +00:00
Raymond Hettinger f2c0830585 SF bug #963956: Bad error mesage when subclassing a module
Add a more informative message for the common user mistake of subclassing
from a module name rather than another class (i.e. random instead of
random.random).
2004-06-05 06:16:22 +00:00
Martin v. Löwis e440e47e91 Patch #957398: Add public API for Generator Object/Type. 2004-06-01 15:22:42 +00:00
Fred Drake 8759090562 starting to add comments to explain what's here 2004-05-28 20:21:36 +00:00
Raymond Hettinger 354433a59d SF patch #872326: Generator expression implementation
(Code contributed by Jiwon Seo.)

The documentation portion of the patch is being re-worked and will be
checked-in soon.  Likewise, PEP 289 will be updated to reflect Guido's
rationale for the design decisions on binding behavior (as described in
in his patch comments and in discussions on python-dev).

The test file, test_genexps.py, is written in doctest format and is
meant to exercise all aspects of the the patch.  Further additions are
welcome from everyone.  Please stress test this new feature as much as
possible before the alpha release.
2004-05-19 08:20:33 +00:00
Anthony Baxter c3d931685b forward-port 1.17.12.1 2004-05-13 11:54:19 +00:00
Raymond Hettinger c8aa08b172 Some (but not all) of the why code bitfield tests ran faster as
separate equality tests.  Now, all are set to their best timing.
2004-04-11 14:59:33 +00:00
Raymond Hettinger 5bed456056 Revert 2.393, elimination of pre-decrementing, which
did not stand-up to additional timings.
2004-04-10 23:34:17 +00:00
Raymond Hettinger 7eddd78a15 Use continue instead of break whereever possible. 2004-04-07 14:38:08 +00:00
Raymond Hettinger d3b836d202 * Improve readability and remove data dependencies by converting
pre-increment forms to post-increment forms.  Post-incrementing
also eliminates the need for negative array indices for oparg fetches.

* In exception handling code, check for class based exceptions before
  the older string based exceptions.
2004-04-07 13:17:27 +00:00
Raymond Hettinger 467a698bd2 Small code improvements for readability, code size, and/or speed.
BINARY_SUBSCR:
    * invert test for normal case fall through
    * eliminate err handling code by jumping to slow_case

LOAD_LOCALS:
    * invert test for normal case fall through
    * continue instead of break for the non-error case

STORE_NAME and DELETE_NAME:
    * invert test for normal case fall through

LOAD_NAME:
    * continue instead of break for the non-error case

DELETE_FAST:
    * invert test for normal case fall through

LOAD_DEREF:
    * invert test for normal case fall through
    * continue instead of break for the non-error case
2004-04-07 11:39:21 +00:00
Raymond Hettinger 7c9586545e Simplify previous checkin (bitfields for WHY codes).
Restores the self-documenting enum declaration.
2004-04-06 10:11:10 +00:00
Raymond Hettinger 06032cb664 Coded WHY flags as bitfields (taking inspiration from tp_flags).
This allows multiple flags to be tested in a single compare
which eliminates unnecessary compares and saves a few bytes.
2004-04-06 09:37:35 +00:00
Tim Peters 8a5c3c76be Since the fast_yield branch target was introduced, it appears that most
tests of "why" against WHY_YIELD became useless.  This patch removes them,
but assert()s that why != WHY_YIELD everywhere such a test was removed.
The test suite ran fine under a debug build (i.e., the asserts never
triggered).
2004-04-05 19:36:21 +00:00
Jeremy Hylton d4ceb31664 Bump the magic number to avoid sharing bytecode between 2.3 and 2.4.
Revise the long comment that explained details of the magic number
in gory detail.
2004-04-01 02:45:22 +00:00
Andrew MacIntyre da4d6cb573 OS/2 VACPP build updates/fixes 2004-03-29 11:53:38 +00:00
Armin Rigo 01ab279056 Marshal clean-up (SF patch #873224) 2004-03-26 15:09:27 +00:00
Nicholas Bastin 2786d90617 A few more PyThreadState_Get to PyThreadState_GET conversions 2004-03-25 02:16:23 +00:00
Nicholas Bastin e5662aedef Changed random calls to PyThreadState_Get() to use the macro 2004-03-24 22:22:12 +00:00
Nicholas Bastin c69ebe8d50 Enable the profiling of C functions (builtins and extensions) 2004-03-24 21:57:10 +00:00
Martin v. Löwis 83969eeeeb Decref all if ensure_fromlist fails. Fixes #876533.
Backported to 2.3.
2004-03-23 16:28:13 +00:00
Armin Rigo 5d2c68359b Lost reference. 2004-03-22 20:16:58 +00:00
Armin Rigo bf57a14522 Fix SF bug #765624. 2004-03-22 19:24:58 +00:00
Armin Rigo 80d937e986 Fix for line events in the case:
def f(a):
    if a:
      print 5
    else:
      pass
2004-03-22 17:52:53 +00:00
Nicholas Bastin a7604bf1b4 Moved tracebackobject to traceback.h, Closes SF Bug #497067 2004-03-21 18:37:23 +00:00
Raymond Hettinger ff5bc50bb0 Improve byte coding for multiple assignments.
Gives 30% speedup on "a,b=1,2" and 25% on "a,b,c=1,2,3".
2004-03-21 15:12:00 +00:00
Armin Rigo 9dbf9084e8 Cancelled checkin, sorry. 2004-03-20 21:50:13 +00:00
Armin Rigo 1515fc2a01 A 2% speed improvement with gcc on low-endian machines. My guess is that this
new pattern for NEXTARG() is detected and optimized as a single (*short)
loading.
2004-03-20 20:03:17 +00:00
Raymond Hettinger fba1cfc49a LIST_APPEND is predicably followed by JUMP_ABSOLUTE.
Reduces loop overhead by an additional 10%.
2004-03-12 16:33:17 +00:00
Raymond Hettinger 2d783e9b16 Move the code for BREAK and CONTINUE_LOOP to be near FOR_ITER.
Makes it more likely that all loop operations are in the cache
at the same time.
2004-03-12 09:12:22 +00:00
Raymond Hettinger db0de9e7ca Speedup for-loops by inlining PyIter_Next(). Saves duplicate tests
and a function call resulting in a 15% reduction of total loop overhead
(as measured by timeit.Timer('pass')).
2004-03-12 08:41:36 +00:00
Raymond Hettinger f114a3ae63 Refactor and optimize code for UNPACK_SEQUENCE.
* Defer error handling for wrong number of arguments to the
  unpack_iterable() function.  Cuts the code size almost in half.

* Replace function calls to PyList_Size() and PyTuple_Size() with
  their smaller and faster macro counterparts.

* Move the constant structure references outside of the inner loops.
2004-03-08 23:25:30 +00:00
Raymond Hettinger dd80f76265 SF patch #910929: Optimize list comprehensions
Add a new opcode, LIST_APPEND, and apply it to the code generation for
list comprehensions.  Reduces the per-loop overhead by about a third.
2004-03-07 07:31:06 +00:00
Hye-Shik Chang 30e97dbe96 SF Patch #902444: Use process scope thread on FreeBSD. System scope
is too expensive on FreeBSD's KSE threading infrastructure and
even test_threadedimport fails on default setting.
2004-03-04 06:35:57 +00:00
Skip Montanaro 6babcc2ad4 typo 2004-03-03 08:42:23 +00:00
Skip Montanaro 786ea6bc23 Add pystack definition to Misc/gdbinit with some explanation of its behavior
and add flag comments to ceval.c and main.c alerting people to the coupling
between pystack and the layout of those files.
2004-03-01 15:44:05 +00:00
Michael W. Hudson ecfeb7f095 This is my patch #876198 plus a NEWS entry and a header frob.
Remove the ability to use (from C) arbitrary objects supporting the
read buffer interface as the co_code member of code objects.
2004-02-12 15:28:27 +00:00
Skip Montanaro 7befb9966e remove support for missing ANSI C header files (limits.h, stddef.h, etc). 2004-02-10 16:50:21 +00:00
Raymond Hettinger a72169871d SF patch #884022: dynamic execution profiling vs opcode prediction
(Contributed by Andrew I MacIntyre.)

disables opcode prediction when dynamic execution
profiling is in effect, so the profiling counters at
the top of the main interpreter loop in eval_frame()
are updated for each opcode.
2004-02-08 19:59:27 +00:00
Skip Montanaro f1afe6682c Remove support for systems defining Py_PTHREAD_D[467] in
Python/thread_pthread.h.
2004-02-07 13:00:18 +00:00
Raymond Hettinger 1dd8309246 SF patch #864059: optimize eval_frame
Simplified version of Neal Norwitz's patch which adds gotos for
opcodes that set "why".  This skips a number of tests where the
outcome of the tests are known in advance.
2004-02-06 18:32:33 +00:00
Hye-Shik Chang ff83c2bacc Fix input() builtin function to respect compiler flags.
(SF patch 876178, patch by mwh, unittest by perky)
2004-02-02 13:39:01 +00:00
Skip Montanaro b9949dbe6c Remove support for DYNIX, IRIX 4, --with-sgi-dl, --with-dl-dld 2004-01-17 04:04:13 +00:00
Skip Montanaro 4d474becd8 remove DGUX support. 2004-01-17 00:29:32 +00:00
Raymond Hettinger b86269db45 Apply pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects.
Now, any object that reports its length can benefit from pre-sizing.
2004-01-04 11:00:08 +00:00
Raymond Hettinger 77f3c87113 Apply map/zip pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects.
Now, any object that reports its length can benefit from pre-sizing.
2004-01-04 08:54:44 +00:00
Jeremy Hylton ecd9129c94 Add comment to mollify Tim. 2004-01-02 23:25:32 +00:00
Hye-Shik Chang 7db07e6972 Fix gcc 3.3 warnings related to Py_UNICODE_WIDE. 2003-12-29 01:36:01 +00:00
Raymond Hettinger 64958a15d7 Guido grants a Christmas wish:
sorted() becomes a regular function instead of a classmethod.
2003-12-17 20:43:33 +00:00
Fred Drake d75ede3238 Remove the PendingDeprecationWarning from apply(). apply() will
remain deprecated in the documentation.
2003-12-05 17:34:27 +00:00
Tim Peters 1d7323e4e7 Py_Finalize(): disabled the second call of cyclic gc, and added extensive
comments about why both calls to cyclic gc here can cause problems.

I'll backport to 2.3 maint.  Since the calls were introduced in 2.3,
that will be the end of it.
2003-12-01 21:35:27 +00:00
Guido van Rossum 6c9e130524 - Removed FutureWarnings related to hex/oct literals and conversions
and left shifts.  (Thanks to Kalle Svensson for SF patch 849227.)
  This addresses most of the remaining semantic changes promised by
  PEP 237, except for repr() of a long, which still shows the trailing
  'L'.  The PEP appears to promise warnings for operations that
  changed semantics compared to Python 2.3, but this is not
  implemented; we've suffered through enough warnings related to
  hex/oct literals and I think it's best to be silent now.
2003-11-29 23:52:13 +00:00
Jack Jansen eddc1449ba Getting rid of all the code inside #ifdef macintosh too. 2003-11-20 01:44:59 +00:00
Jack Jansen 4bae2d5e46 Getting rid of code dependent on GUSI or the MetroWerks compiler. 2003-11-19 22:52:23 +00:00
Jack Jansen a53f4eba19 Getting rid of code conditional on TARGET_API_MAC_*. 2003-11-19 16:34:04 +00:00
Jack Jansen 37249c5524 WITHOUT_FRAMEWORKS conditional code bites the dust: this was for
pre-carbon MacOS9 support.
2003-11-19 15:32:46 +00:00
Jack Jansen fb2765666f Getting rid of support for the ancient Apple MPW compiler. 2003-11-19 15:24:47 +00:00
Jack Jansen 6196322066 MacOS9 support is gone. 2003-11-19 14:55:33 +00:00
Raymond Hettinger a690a9967e * Migrate set() and frozenset() from the sandbox.
* Install the unittests, docs, newsitem, include file, and makefile update.
* Exercise the new functions whereever sets.py was being used.

Includes the docs for libfuncs.tex.  Separate docs for the types are
forthcoming.
2003-11-16 16:17:49 +00:00
Martin v. Löwis f56d015a71 Patch #804543: strdup saved locales. Backported to 2.3. 2003-11-13 07:43:21 +00:00
Raymond Hettinger 85c20a41df Implement and apply PEP 322, reverse iteration 2003-11-06 14:06:48 +00:00
Jeremy Hylton 904ed86a77 Make undetected error on stack unwind a fatal error. 2003-11-05 17:29:35 +00:00
Armin Rigo 2b3eb4062c Deleting cyclic object comparison.
SF patch 825639
http://mail.python.org/pipermail/python-dev/2003-October/039445.html
2003-10-28 12:05:48 +00:00
Alex Martelli a253e183b8 regressing the performance bugfix -- Guido wants the performance bug left
alone, because there can be no guarantee re the semantics of += vs + .
2003-10-25 23:24:14 +00:00
Armin Rigo 1d313ab9d1 oh dear. Wrong manipulation. Committed a version of ceval.c from my
no-cyclic-comparison patch at the same time as errors.c.

Reverting ceval.c to the previous revision.
2003-10-25 14:33:09 +00:00
Armin Rigo 092381a979 Made function declaration a proper C prototype 2003-10-25 14:29:27 +00:00
Alex Martelli a2777d3a55 Changed builtin_sum to use PyNumber_InPlaceAdd (same semantics, but fixes
a performance bug in sum(manylists)), same as in 2.3 maintenance branch.
2003-10-25 12:49:56 +00:00
Raymond Hettinger 5cf6394b12 Use PyArg_UnpackTuple() where possible. 2003-10-25 06:41:37 +00:00
Martin v. Löwis f8d59d28e0 Patch #828384: Don't discard nested exception in AddObject. 2003-10-24 20:05:32 +00:00
Walter Dörwald f0dfc7ac5c Fix a bunch of typos in documentation, docstrings and comments.
(From SF patch #810751)
2003-10-20 14:01:56 +00:00
Martin v. Löwis dd7eb146a8 Patch #792869: Clarify error message for parameters declared global,
rename LOCAL_GLOBAL to PARAM_GLOBAL.
2003-10-18 22:05:25 +00:00
Raymond Hettinger 8ae4689657 Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)
2003-10-12 19:09:37 +00:00
Jeremy Hylton 9832613beb Fix SF bug [ 808594 ] leak on lambda with duplicate arguments error.
Refactor code so that one helper routine sets error location and
increments st_errors.

Bug fix candidate.
2003-09-22 04:26:44 +00:00
Martin v. Löwis 70849f84a0 Patch #805613: Fix usage of the PTH library. 2003-09-20 11:13:36 +00:00
Raymond Hettinger cc1798e0c0 Improve the leak fix so that PyTuple_New is only called when needed. 2003-09-16 04:27:52 +00:00
Jeremy Hylton 364f6becad Correct check of PyUnicode_Resize() return value. 2003-09-16 03:17:16 +00:00
Jeremy Hylton 1aad9c7dad Reflow long lines and reformat. 2003-09-16 03:10:59 +00:00
Raymond Hettinger 37a724d718 Fix leak discovered in test_new by Michael Hudson.
Will backport to 2.3.1
2003-09-15 21:43:16 +00:00
Martin v. Löwis e81e9b1d3b Patch #794826: Add __file__ in dynamically loaded modules for multiple
interpreters. Fixes #698282. Will backport to 2.3.
2003-09-04 18:45:59 +00:00
Jason Tishler 6bc06eca70 Bug #794140: cygwin builds do not embed
The embed2.diff patch solves the user's problem by exporting the missing
symbols from the Python core so Python can be embedded in another Cygwin
application (well, at lest vim).
2003-09-04 11:59:50 +00:00
Jeremy Hylton 376e63d5cd Fix for SF bug [ 784075 ] Fatal Python error: unknown scope
Make sure the inner function is not compiled when there is a syntax
error in the default arguments.
2003-08-28 14:42:14 +00:00
Walter Dörwald c58a3a10a9 Fix a crash: when sq_item failed the code continued blindly and used the
NULL pointer. (Detected by Michael Hudson, patch provided by Neal Norwitz).

Fix refcounting leak in filtertuple().
2003-08-18 18:28:45 +00:00
Walter Dörwald e98147a8e5 Fix refcount leak in the UnicodeError constructor:
When parsing the constructor arguments failed, a
reference to the argument tuple was leaked.
2003-08-14 20:59:07 +00:00
Neil Schemenauer 689735562d Make filter(bool, ...) as fast as filter(None, ...). 2003-08-14 20:37:34 +00:00
Walter Dörwald a54b92b2eb Add a unicode prefix to the characters in the UnicodeEncodeError and
UnicodeTranslateError message.
2003-08-12 17:34:49 +00:00
Walter Dörwald fd196bd263 Enhance message for UnicodeEncodeError and UnicodeTranslateError.
If there is only one bad character it will now be printed in a
form that is a valid Python string.
2003-08-12 17:32:43 +00:00
Michael W. Hudson 68debc935b Fix refcounting and cut & paste error (?) in last checkin.
This should go onto release23-maint, too.
2003-08-11 12:20:24 +00:00
Martin v. Löwis a2c17c5820 Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Verify that the encoding actually exists. Fixes #775985.
Will backport to 2.3.
2003-08-09 09:47:11 +00:00
Raymond Hettinger eaef615116 As discussed on python-dev, changed builtin.zip() to handle zero arguments
by returning an empty list instead of raising a TypeError.
2003-08-02 07:42:57 +00:00
Jason Tishler fac083d14a Patch 775605: Cygwin pthread_sigmask() workaround patch
Cygwin's pthread_sigmask() implementation appears to be buggy. This
patch works around this problem by using sigprocmask() instead.

This patch is implemented in a general way so it could be used by other
platforms too. If this approach is deemed too risky, then I can work up
a patch that just hacks Python/thread_pthread.h for Cygwin.

Note that I tested this patch against 2.3c1 under Red Hat Linux 8.0 too.

[snip]
And finally, I need someone to regenerate pyconfig.h.in and configure
with the same versions of the autotools that are normally used by
Python.

Neal kindly regenerated pyconfig.h.in and configure for me.
2003-07-22 15:20:49 +00:00
Mark Hammond 5f4e8ca376 Correct previous patch looking for warnings module: sys.modules, not
sys.__modules__.
2003-07-16 01:54:38 +00:00
Mark Hammond edd07737d7 Fix [ 771097 ] frozen programs fail due to implicit import of "warnings".
If the initial import of warnings fails, clear the error.  When the module
is actually needed, if the original import failed, see if it has managed
to find its way to sys.modules yet and if so, remember it.
2003-07-15 23:03:55 +00:00
Jeremy Hylton 1955fcf67a SF patch 763201: handling of SyntaxErrors in symbol table build
Fixes for three related bugs, including errors that caused a script to
be ignored without printing an error message.  The key problem was a bad
interaction between syntax warnings and syntax errors.  If an
exception was already set when a warning was issued, the warning could
clobber the exception.

The PyErr_Occurred() check in issue_warning() isn't entirely
satisfying (the caller should know whether there was already an
error), but a better solution isn't immediately obvious.

Bug fix candidate.
2003-07-15 20:23:26 +00:00
Martin v. Löwis f9ce67d65f Initialize thread_id to 0 in unthreaded build. Fixes #770247. 2003-07-13 10:41:53 +00:00
Fred Drake 1e5fc55c4d - fix typo
- there's a weird variable name here (zimpimport), but I'll leave that
  for someone that's familiar with the ZIP import support
2003-07-11 15:01:02 +00:00
Tim Peters e5e065b669 New function sys.getcheckinterval(), to complement setcheckinterval(). 2003-07-06 18:36:54 +00:00
Tim Peters 2e7e7df969 An Anonymous Coward on c.l.py posted a little program with bizarre
behavior, creating many threads very quickly.  A long debugging session
revealed that the Windows implementation of PyThread_start_new_thread()
was choked with "laziness" errors:

1. It checked MS _beginthread() for a failure return, but when that
   happened it returned heap trash as the function result, instead of
   an id of -1 (the proper error-return value).

2. It didn't consider that the Win32 CreateSemaphore() can fail.

3. When creating a great many threads very quickly, it's quite possible
   that any particular bootstrap call can take virtually any amount of
   time to return.  But the code waited for a maximum of 5 seconds, and
   didn't check to see whether the semaphore it was waiting for got
   signaled.  If it in fact timed out, the function could again return
   heap trash as the function result.  This is actually what confused
   the test program, as the heap trash usually turned out to be 0, and
   then multiple threads all got id 0 simultaneously, confusing the
   hell out of threading.py's _active dict (mapping id to thread
   object).  A variety of baffling behaviors followed from that.

WRT #1 and #2, error returns are checked now, and "thread.error: can't
start new thread" gets raised now if a new thread (or new semaphore)
can't be created.  WRT #3, we now wait for the semaphore without a
timeout.

Also removed useless local vrbls, folded long lines, and changed callobj
to a stack auto (it was going thru malloc/free instead, for no discernible
reason).

Bugfix candidate.
2003-07-04 04:40:45 +00:00
Neal Norwitz c5131bc256 Fix SF #762455, segfault when sys.stdout is changed in getattr
Will backport.
2003-06-29 14:48:32 +00:00
Guido van Rossum b8b6d0c2c6 Add PyThreadState_SetAsyncExc(long, PyObject *).
A new API (only accessible from C) to interrupt a thread by sending it
an exception.  This is not always effective, but might help some people.
Requested by Just van Rossum and Alex Martelli.  It is intentional
that you have to write your own C extension to call it from Python.

Docs will have to wait.
2003-06-28 21:53:52 +00:00
Jeremy Hylton c44dbc46fe Better error message 2003-06-21 21:35:25 +00:00
Raymond Hettinger b9572c3456 Removed bytecode transformation for sequence packing/unpacking.
It depended on the previously removed basic block checker to
prevent a jump into the middle of the transformed block.

Clears SF 757818: tuple assignment -- SystemError: unknown opcode
2003-06-20 16:13:17 +00:00
Neil Schemenauer 00b0966f20 Don't use the module object setattr when importing submodules. Instead,
operate on the module dictionary directly.  This prevents spurious
depreciation warnings from being raised if a submodule name shadows
a builtin name.
2003-06-16 21:03:07 +00:00
Neil Schemenauer c4b570f218 Use fast_next_opcode shortcut for forward jump opcodes (it's safe and
gives a small speedup).
2003-06-01 19:21:12 +00:00
Raymond Hettinger 40174c358f SF bug #733667: kwargs handled incorrectly
The fast_function() inlining optimization only
applies when there are zero keyword arguments.
2003-05-31 07:04:16 +00:00
Neil Schemenauer ca2a2f11d0 Don't use fast_next_opcode for JUMP_* opcodes. This fixes the problem
reported by Kurt B. Kaiser.
2003-05-30 23:59:44 +00:00
Jack Jansen 4eb45e7804 Added functions CFObj_New and CFObj_Convert, general functions to convert
between CF objects and their Python representation. Fixes 734695.
2003-05-27 21:39:58 +00:00
Neal Norwitz a1d654e13a SF bug #644345, Poor error message for augmented assign
Update error message.  Hopefully this is clearer to some people.
2003-05-22 22:00:04 +00:00
Jeremy Hylton f9415e6245 Use macro to get length of list.
Remove comment about how code used to work.
2003-05-22 16:22:33 +00:00
Jeremy Hylton 521482d84f Remove comment with very long lines that explained what the code used
to do.

XXX Please be careful when checking in patches to avoid checking in
junk that explains what the patched code used to do.
2003-05-22 15:47:02 +00:00
Jeremy Hylton 4d508adae3 Fix for SF [ 734869 ] Lambda functions in list comprehensions
The compiler was reseting the list comprehension tmpname counter for each function, but the symtable was using the same counter for the entire module.  Repair by move tmpname into the symtable entry.

Bugfix candidate.
2003-05-21 17:34:50 +00:00
Tim Peters 12d55a7caa cmp_type(): The grammar stopped allowing '=' as a comparison operator
about a decade ago.  Put the code still allowing for it in cmp_type()
out of its lonely misery.
2003-05-12 19:16:52 +00:00
Martin v. Löwis a94568a753 Patch #734231: Update RiscOS support. In particular, correct
riscospath.extsep, and use os.extsep throughout.
2003-05-10 07:36:56 +00:00
Martin v. Löwis 5467d4c0e3 Patch #612627: Add encoding attribute to file objects, and determine
the terminal encoding on Windows and Unix.
2003-05-10 07:10:12 +00:00
Martin v. Löwis cd12bfc142 Patch #708604: Check more function results. Will backport to 2.2. 2003-05-03 10:53:08 +00:00
Martin v. Löwis e6bbb4d16f Patch #684981: Add cleanup capability for argument parsers. Fixes 501716. 2003-05-03 10:00:22 +00:00
Martin v. Löwis c16f3bd8a3 Patch #708495: Port more stuff to OpenVMS. 2003-05-03 09:14:54 +00:00
Martin v. Löwis 9e29625a1b Patch #729300: Disable error message if Python is not built for threads. 2003-05-01 05:25:29 +00:00
Michael W. Hudson 26848a34d1 Use Tim's suggestion to fix
[ 708901 ] Lineno calculation sometimes broken

A one line patch to compile.c and a rather-more-than-one-line patch
to test_dis.  Hey ho.

Possibly a backport candidate -- tho' lnotab is less used in 2.2...
2003-04-29 17:07:36 +00:00
Michael W. Hudson 58ee2af48e Armin Rigo's fix & test for
[ 729622 ] line tracing hook errors

with massaging from me to integrate test into test suite.
2003-04-29 16:18:47 +00:00
Raymond Hettinger f4cf76dd5e Revert the previous enhancement to the bytecode optimizer.
The additional code complexity and new NOP opcode were not worth it.
2003-04-24 05:45:23 +00:00
Alex Martelli a9b9c9fa9f some more error-message enhancements 2003-04-23 13:34:35 +00:00
Alex Martelli f471d4783a complete and clarify some error messages for range() 2003-04-23 13:00:44 +00:00
Mark Hammond 6cb9029a22 PyGILState cleanup was too early - destructors called via module cleanup may use the API. 2003-04-22 11:18:00 +00:00
Alex Martelli 41c9f880d8 fixed a potential refcount bug (thanks Raymond!). 2003-04-22 09:24:48 +00:00
Alex Martelli a70b19147f Adding new built-in function sum, with docs and tests. 2003-04-22 08:12:33 +00:00
Raymond Hettinger 060641d511 Improved the bytecode optimizer.
* Can now test for basic blocks.
* Optimize inverted comparisions.
* Optimize unary_not followed by a conditional jump.
* Added a new opcode, NOP, to keep code size constant.
* Applied NOP to previous transformations where appropriate.

Note, the NOP would not be necessary if other functions were
added to re-target jump addresses and update the co_lnotab mapping.
That would yield slightly faster and cleaner bytecode at the
expense of optimizer simplicity and of keeping it decoupled
from the line-numbering structure.
2003-04-22 06:49:11 +00:00
Tim Peters cf615b5275 handle_system_exit(): This leaked the current exception info, in
particular leaving the traceback object (and everything reachable
from it) alive throughout shutdown.  The patch is mostly from Guido.

Bugfix candidate.
2003-04-19 18:47:02 +00:00
Mark Hammond 8d98d2cb95 New PyGILState_ API - implements pep 311, from patch 684256. 2003-04-19 15:41:53 +00:00
Martin v. Löwis 910ae6283a Patch #716969: Detect thread creation failure. Will backport to 2.2. 2003-04-19 07:44:52 +00:00
Martin v. Löwis 1509a152b3 Patch #711835: Remove unnecessary lock operations. Will backport to 2.2. 2003-04-18 11:11:09 +00:00
Guido van Rossum fce26e7f9f Roll back changes to 'h' format code -- too much breaks. Other
changes stay.
2003-04-18 00:12:30 +00:00
Jack Jansen dbd6503e97 dded missing k and K format specifiers to Py_BuildValue and friends. 2003-04-17 22:01:10 +00:00
Jack Jansen 84c2b1b9aa Oops, 'k' is the new format code for un unchecked 32 bit quantity,
not 'K'.
2003-04-17 20:44:21 +00:00
Jack Jansen ecc6635ae4 Converted manually written code to the new K format specifier.
Untested, but at least it still compiles.
2003-04-17 20:40:07 +00:00
Tim Peters 269b2a6797 _Py_PrintReferences(): Changed to print object address at start of each
new line.

New pvt API function _Py_PrintReferenceAddresses():  Prints only the
addresses and refcnts of the live objects.  This is always safe to call,
because it has no dependence on Python's C API.

Py_Finalize():  If envar PYTHONDUMPREFS is set, call (the new)
_Py_PrintReferenceAddresses() right before dumping final pymalloc stats.
We can't print the reprs of the objects here because too much of the
interpreter has been shut down.  You need to correlate the addresses
displayed here with the object reprs printed by the earlier
PYTHONDUMPREFS call to _Py_PrintReferences().
2003-04-17 19:52:29 +00:00
Thomas Heller a4ea603b05 SF # 595026: support for masks in getargs.c.
New functions:
  unsigned long PyInt_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
  unsigned long PyLong_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);

New and changed format codes:

b unsigned char 0..UCHAR_MAX
B unsigned char none **
h unsigned short 0..USHRT_MAX
H unsigned short none **
i int INT_MIN..INT_MAX
I * unsigned int 0..UINT_MAX
l long LONG_MIN..LONG_MAX
k * unsigned long none
L long long LLONG_MIN..LLONG_MAX
K * unsigned long long none

Notes:

* New format codes.

** Changed from previous "range-and-a-half" to "none"; the
range-and-a-half checking wasn't particularly useful.

New test test_getargs2.py, to verify all this.
2003-04-17 18:55:45 +00:00
Guido van Rossum e13ddc9ec8 - New C API PyGC_Collect(), same as calling gc.collect().
- Call this in Py_Finalize().
- Expand the Misc/NEWS text on PY_LONG_LONG.
2003-04-17 17:29:22 +00:00
Guido van Rossum 66ebd91244 A missing piece of the PEP 269 patch: add PyParser_SetError(), a
wrapper around err_input().
2003-04-17 16:02:26 +00:00
Tim Peters d08e3824d4 Trimmed trailing whitespace. 2003-04-17 15:24:21 +00:00
Tim Peters 9cf25ce3a0 Py_Finalize(): Reverted recent changes that tried to move the
PYTHONDUMPREFS output after most teardown.  Attempts to use
PYTHONDUMPREFS with the Zope3 test suite died with Py_FatalError(),
since _Py_PrintReferences() can end up executing arbitrary Python code
(for objects that override __repr__), and that requires an intact
interpreter.
2003-04-17 15:21:01 +00:00
Guido van Rossum 0fc8f00252 - pythunrun.c, Py_Finalize(): move the call to _Py_PrintReferences()
even farther down, to just before the call to
  _PyObject_DebugMallocStats().  This required the following changes:

- pystate.c, PyThreadState_GetDict(): changed not to raise an
  exception or issue a fatal error when no current thread state is
  available, but simply return NULL without raising an exception
  (ever).

- object.c, Py_ReprEnter(): when PyThreadState_GetDict() returns NULL,
  don't raise an exception but return 0.  This means that when
  printing a container that's recursive, printing will go on and on
  and on.  But that shouldn't happen in the case we care about (see
  first bullet).

- Updated Misc/NEWS and Doc/api/init.tex to reflect changes to
  PyThreadState_GetDict() definition.
2003-04-15 15:12:39 +00:00
Guido van Rossum d922fa46ce Move the call to _Py_PrintReferences() a bit further down. This
prevents it from showing stuff (like codec state) that is cleared when
the interpreter state is cleared.
2003-04-15 14:10:09 +00:00
Guido van Rossum 28e83e3a66 Some errors from range() should be TypeError, not ValueError. 2003-04-15 12:43:26 +00:00
Raymond Hettinger 255a3d08a1 Extend SF patch #707257: Improve code generation
to cover the case for:  "x,y,z=1,2,3".  Gives a 30% speed-up.

Also, added FOR_ITER to the list of opcodes that can jump.
2003-04-15 10:35:07 +00:00
Guido van Rossum 817d6c9c9e Prompted by Tim's comment, when handle_range_longs() sees an
unexpected type, report the actual type rather than 'float'.  (It's
hard to even reach this code with a float. :-)
2003-04-14 18:25:04 +00:00
Tim Peters 874e1f7ed3 handle_range_longs(): refcount handling is very delicate here, and
the code erroneously decrefed the istep argument in an error case.  This
caused a co_consts tuple to lose a float constant prematurely, which
eventually caused gc to try executing static data in floatobject.c (don't
ask <wink>).  So reworked this extensively to ensure refcount correctness.
2003-04-13 22:13:08 +00:00
Guido van Rossum efbbb1c602 Patch by Chad Netzer (with significant change):
- range() now works even if the arguments are longs with magnitude
  larger than sys.maxint, as long as the total length of the sequence
  fits.  E.g., range(2**100, 2**101, 2**100) is the following list:
  [1267650600228229401496703205376L].  (SF patch #707427.)
2003-04-11 18:43:06 +00:00
Neal Norwitz 5c16c7b014 Move declaration of enc to scope where it is used 2003-04-10 21:53:14 +00:00
Guido van Rossum 6b3fffaf99 PyErr_NormalizeException(): in the type==NULL test, we should simply
return.  Setting an exception can mess with the exception state, and
continuing is definitely wrong (since type is dereferenced later on).
Some code that calls this seems to be prepared for a NULL exception
type, so let's be safe rather than sorry and simply assume there's
nothing to normalize in this case.
2003-04-10 20:29:48 +00:00
Guido van Rossum a12fe4e81f - New function sys.call_tracing() allows pdb to debug code
recursively.
- pdb has a new command, "debug", which lets you step through
  arbitrary code from the debugger's (pdb) prompt.
2003-04-09 19:06:21 +00:00
Raymond Hettinger ff41c48a77 SF patch #701494: more apply removals 2003-04-06 09:01:11 +00:00
Martin v. Löwis b9a0f91218 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285. 2003-03-29 10:06:18 +00:00
Raymond Hettinger 5b75c38cc9 Factored out test for absolute jumps. 2003-03-28 12:05:00 +00:00
Raymond Hettinger f6f575ae6f SF patch #707257: Improve code generation
Adds a single function to improve generated bytecode.  Has a single line
attachment point, so it is completely de-coupled from both the compiler
and ceval.c.

Makes three simple transforms that do not require a basic block analysis
or re-ordering of code.  Gives improved timings on pystone, pybench,
and any code using either "while 1" or "x,y=y,x".
2003-03-26 01:07:54 +00:00
Tim Peters b39903b0a0 symtable_cellvar_offsets(): This leaked references to little integers
in normal cases, and also in error cases.

Bugfix candidate.
2003-03-24 17:22:24 +00:00
Tim Peters 7571a0fbcf Improved new Py_TRACE_REFS gimmicks.
Arranged that all the objects exposed by __builtin__ appear in the list
of all objects.  I basically peed away two days tracking down a mystery
leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because
the object leaking the references didn't appear in the sys.getobjects(0)
list.  The object happened to be False.  Now False is in the list, along
with other popular & previously missing leak candidates (like None).
Alas, we still don't have a choke point covering *all* Python objects,
so the list of all objects may still be incomplete.
2003-03-23 17:52:28 +00:00
Neal Norwitz a11e4c13b1 SF patch #708201, unchecked return value in import.c by Jason Harper
Will backport.
2003-03-23 14:31:01 +00:00
Neal Norwitz df5126df56 Include Python.h first which defines _XOPEN_SOURCE
which allows the file to compile and removes a warning about _XOPEN_SOURCE
being redefined (works on AIX 4.3 and 5.1 at least).
2003-03-22 16:35:37 +00:00
Gustavo Niemeyer 5ddd4c3f77 Fixed SF bug #663074. The codec system was using global static
variables to store internal data. As a result, any atempts to use the
unicode system with multiple active interpreters, or successive
interpreter executions, would fail.

Now that information is stored into members of the PyInterpreterState
structure.
2003-03-19 00:35:36 +00:00
Raymond Hettinger 7dc52212aa Eliminate data dependency in predict macro.
Added two predictions:
  GET_ITER --> FOR_ITER
  FOR_ITER --> STORE_FAST or UNPACK_SEQUENCE

Improves timings on pybench and timeit.py. Pystone results are neutral.
2003-03-16 20:14:44 +00:00
Raymond Hettinger ac2072920d Fix comment and whitespace. 2003-03-16 15:41:11 +00:00
Raymond Hettinger f606f87b31 Introduced macros for a simple opcode prediction protocol.
Applied to common cases:
    COMPARE_OP is often followed by a JUMP_IF.
    JUMP_IF is usually followed by POP_TOP.

Shows improved timings on PyStone, PyBench, and specific tests
using timeit.py:
    python timeit.py -s "x=1" "if x==1: pass"
    python timeit.py -s "x=1" "if x==2: pass"
    python timeit.py -s "x=1" "if x: pass"
    python timeit.py -s "x=100" "while x!=1: x-=1"

Potential future candidates:
    GET_ITER predicts FOR_ITER
    FOR_ITER predicts STORE_FAST or UNPACK_SEQUENCE

Also, applied missing goto fast_next_opcode to DUP_TOPX.
2003-03-16 03:11:04 +00:00
Raymond Hettinger 080cb3268f SF patch #701907: More use of fast_next_opcode
My previous patches should have used fast_next_opcode
in a few places instead of continue.

Also, applied one PyInt_AS_LONG macro in a place where
the type had already been checked.
2003-03-14 01:37:42 +00:00
Fred Drake 6a9a3292f5 Declare all variables at the start of their scope. 2003-03-05 17:31:21 +00:00
Martin v. Löwis 73d538b9c6 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
and not as a side effect of setlocale. Expose it as sys.getfilesystemencoding.
Adjust test case.
2003-03-05 15:13:47 +00:00
Jack Jansen ad5e76a8fb Use Carbon.File for FSSpec and FSRef conversion, not macfs. 2003-03-02 23:16:50 +00:00
Guido van Rossum c9fbb72ba5 Added implementation notes for [re]set_exc_info(). 2003-03-01 03:36:33 +00:00
Guido van Rossum 46d3dc37e4 - New function sys.exc_clear() clears the current exception. This is
rarely needed, but can sometimes be useful to release objects
  referenced by the traceback held in sys.exc_info()[2].  (SF patch
  #693195.)  Thanks to Kevin Jacobs!
2003-03-01 03:20:41 +00:00
Michael W. Hudson e46d1559c9 In the process of adding all the extended slice support I attempted to
change _PyEval_SliceIndex to round massively negative longs up to
-INT_MAX, instead of 0 but botched it.  Get it right.

Thx to Armin for the report.
2003-02-27 14:50:34 +00:00
Raymond Hettinger 21012b8235 Micro-optimizations.
* List/Tuple checkexact is faster for the common case.
* Testing for Py_True and Py_False can be inlined for faster looping.
2003-02-26 18:11:50 +00:00
Just van Rossum 5bfba3aeb9 Addendum to #683658:
import warnings.py _after_ site.py has run. This ensures that site.py
is again the first .py to be imported, giving it back full control over
sys.path.
2003-02-25 20:25:12 +00:00
Walter Dörwald b671c0c418 Remove unused variables. 2003-02-24 15:33:31 +00:00
Neal Norwitz 3e59076b1d Fix SF bug #690435, apply fails to check if warning raises exception
(patch provided by Greg Chapman)
2003-02-23 21:45:43 +00:00
Michael W. Hudson c85b6a2d4d After the removal of SET_LINENO, PyCode_Addr2Line has always been
called to find tb_lineno -- even if Py_OptimizeFlag is true.

So don't call it again when printing the traceback.
2003-02-22 13:07:53 +00:00
Guido van Rossum 6297a7a9fb - PyEval_GetFrame() is now declared to return a PyFrameObject *
instead of a plain PyObject *.  (SF patch #686601 by Ben Laurie.)
2003-02-19 15:53:17 +00:00
Guido van Rossum 162e38c6a3 - sys.path[0] (the directory from which the script is loaded) is now
turned into an absolute pathname, unless it is the empty string.
  (SF patch #664376, by Skip Montanaro.)
2003-02-19 15:25:10 +00:00
Mark Hammond a43fd0c899 Fix bug 683658 - PyErr_Warn may cause import deadlock. 2003-02-19 00:33:33 +00:00
Neal Norwitz 08ea61ad45 Remove PyArg_ParseTuple() for methods which take no args,
use METH_NOARGS instead
2003-02-17 18:18:00 +00:00
Marc-André Lemburg 9cac1c4574 Patch for bug reported in patch #686627: import race condition in
codecs registry startup.
2003-02-14 20:25:56 +00:00
Guido van Rossum 4b499dd3fb - Finally fixed the bug in compile() and exec where a string ending
with an indented code block but no newline would raise SyntaxError.
  This would have been a four-line change in parsetok.c...  Except
  codeop.py depends on this behavior, so a compilation flag had to be
  invented that causes the tokenizer to revert to the old behavior;
  this required extra changes to 2 .h files, 2 .c files, and 2 .py
  files.  (Fixes SF bug #501622.)
2003-02-13 22:07:59 +00:00