Commit Graph

2531 Commits

Author SHA1 Message Date
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
Neal Norwitz 2294c0d4ec Cleanup from patch #683257:
Add missing INCREFs and re-indent returns to be consistent.
 Add \n\ for lines in docstring
 Add a pathetic test
 Add docs
2003-02-12 23:02:21 +00:00
Guido van Rossum c4f4ca91e1 Provide access to the import lock, fixing SF bug #580952. This is
mostly from SF patch #683257, but I had to change unlock_import() to
return an error value to avoid fatal error.

Should this be backported?  The patch requested this, but it's a new
feature.
2003-02-12 21:46:11 +00:00
Guido van Rossum 66b1259dbc SF #660455 : patch by NNorwitz.
"Unsigned" (i.e., positive-looking, but really negative) hex/oct
constants with a leading minus sign are once again properly negated.
The micro-optimization for negated numeric constants did the wrong
thing for such hex/oct constants.  The patch avoids the optimization
for all hex/oct constants.

This needs to be backported to Python 2.2!
2003-02-12 16:57:47 +00:00
Walter Dörwald 8dd19321bb Change filtertuple() to use tp_as_sequence->sq_item
instead of PyTuple_GetItem, so an overwritten __getitem__
in a tuple subclass works. SF bug #665835.
2003-02-10 17:36:40 +00:00
Tim Peters 2c646c9fc1 Squashed compiler wng about signed/unsigned clash in comparison. 2003-02-10 14:48:29 +00:00
Walter Dörwald 1918f7755e Change filterstring() and filterunicode(): If the
object is not a real str or unicode but an instance
of a subclass, construct the output via looping
over __getitem__. This guarantees that the result
is the same for function==None and function==lambda x:x

This doesn't happen for tuples, because filtertuple()
uses PyTuple_GetItem().

(This was discussed on SF bug #665835).
2003-02-10 13:19:13 +00:00
Just van Rossum b9b8e9cf6d My previous checkin caused compile() to no longer accept buffers, as noted
my MAL. Fixed. (Btw. eval() still doesn't take buffers, but that was so
even before my patch.)
2003-02-10 09:22:01 +00:00
Just van Rossum 3aaf42c613 patch #683515: "Add unicode support to compile(), eval() and exec"
Incorporated nnorwitz's comment re. Py__USING_UNICODE.
2003-02-10 08:21:10 +00:00
Jeremy Hylton 985eba53f5 Small function call optimization and special build option for call stats.
-DCALL_PROFILE: Count the number of function calls executed.

When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made.  It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.

Optimization:

When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx().  The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc.  The inlined version simply allocates the frame and
copies the arguments values into the frame.

The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables.  This change allows fast_function() to get into the fast
path with fewer tests.

I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
2003-02-05 23:13:00 +00:00
Neil Schemenauer 5042da6b1e If a float is passed where a int is expected, issue a DeprecationWarning
instead of raising a TypeError.  Closes #660144 (again).
2003-02-04 20:59:40 +00:00
Walter Dörwald c3da83fcd7 Make sure filter() never returns tuple, str or unicode
subclasses. (Discussed in SF patch #665835)
2003-02-04 20:24:45 +00:00
Walter Dörwald 531e000d2e PyUnicode_Resize() doesn't free its argument in case of a failure,
so we can jump to the error handling code that does.
(Spotted by Neal Norwitz)
2003-02-04 16:57:49 +00:00
Walter Dörwald 903f1e0c40 filterstring() and filterunicode() in Python/bltinmodule.c
blindly assumed that tp_as_sequence->sq_item always returns
a str or unicode object. This might fail with str or unicode
subclasses.

This patch checks whether the object returned from __getitem__
is a str/unicode object and raises a TypeError if not (and
the filter function returned true).

Furthermore the result for __getitem__ can be more than one
character long, so checks for enough memory have to be done.
2003-02-04 16:28:00 +00:00
Neal Norwitz 94c30c0124 SF #661437, apply() should get PendingDeprecation 2003-02-03 20:23:33 +00:00
Jeremy Hylton 4f0dcc9a9a Provide __module__ attributes for functions defined in C and Python.
__module__ is the string name of the module the function was defined
in, just like __module__ of classes.  In some cases, particularly for
C functions, the __module__ may be None.

Change PyCFunction_New() from a function to a macro, but keep an
unused copy of the function around so that we don't change the binary
API.

Change pickle's save_global() to use whichmodule() if __module__ is
None, but add the __module__ logic to whichmodule() since it might be
used outside of pickle.
2003-01-31 18:33:18 +00:00
Fred Drake ceead6d957 Style consistency, so "grep ^function ..." works as expected. 2003-01-30 15:08:25 +00:00
Martin v. Löwis 8afd7571a1 Patch #636005: Filter unicode into unicode. 2003-01-25 22:46:11 +00:00
Neil Schemenauer b808e99d34 Raise a TypeError if a float is passed when an integer is specified.
Calling PyInt_AsLong() on a float truncates it which is almost never
the desired behavior.  This closes SF bug #660144.
2003-01-24 22:15:21 +00:00
Jack Jansen a038270590 MacPython-OS9 has had an abort() function for quite a while now, so there's no reason to stall in an endless loop, just call abort() on a fatal error. 2003-01-24 16:17:18 +00:00
Jack Jansen 9363dca3f8 MacPython-OS9 specific fix: If there are non-string items on sys.path don't try to intern them. This has the theoretical problem that resource filenames on sys.path cannot be unicode objects, but in practice that shouldn't matter. 2003-01-24 16:15:45 +00:00
Martin v. Löwis d7ceb222bd Patch #671459: Invoke import hooks in Py_NewInterpreter. 2003-01-22 09:00:38 +00:00
Martin v. Löwis dfc33fd8db Don't use Posix semaphores on Solaris 8. Fixes #662787. 2003-01-21 10:14:41 +00:00
Raymond Hettinger 4bad9ba282 SF patch #670367: Micro-optimizations for ceval.c
Make the code slightly shorter, faster, and easier to
read.

* Eliminate unused DUP_TOPX code for x==1.
compile.c always generates DUP_TOP instead.

* Since only two cases remain for DUP_TOPX, replace
the switch-case with if-elseif.

* The in-lined integer compare does a CheckExact on
both arguments. Since the second is a little more
likely to fail, test it first.

* The switch-case for IS/IS_NOT and IN/NOT_IN can
separate the regular and inverted cases with no
additional work. For all four paths, saves a test and
jump.
2003-01-19 05:08:13 +00:00
Jack Jansen b2a57722a8 It turns out that some calls return AEDesc records that are "borrowed",
the AEDesc data shouldn't be disposed when the Python object is.

Added a C call AEDesc_NewBorrowed() to create these objects and a Python
method old=AEDesc.AutoDispose(onoff) to change auto-dispose state.
2003-01-17 23:11:17 +00:00
Michael W. Hudson 976249be74 A. Lloyd Flanagan pointed out a spelling error on c.l.py. 2003-01-16 15:39:07 +00:00
Raymond Hettinger 8bb90a59a6 Replaced POP() with STACKADJ(-1) on lines where the result wasn't used.
The two are semantically equivalent, but the first triggered a compiler
warning about an unused variable.  Note, the preceding steps had already
accessed and decreffed the variable so the reference counts were fine.
2003-01-14 12:43:10 +00:00
Raymond Hettinger 71731d7f70 As discussed on python-dev, removed from DUP_TOPX support for the
parameter being either four or five.  Currently, compile.c does not
generate calls with a parameter higher than three.

May have to be reverted if the second alpha or beta shakes out some
other tool generating this op code with a parameter of four or five.
2003-01-10 16:45:17 +00:00
Neal Norwitz 37aa066164 As discussed briefly on python-dev, add Pending Deprecation Warning
when a string exception is raised.  Note that raising string exceptions
is deprecated in an exception message.
2003-01-10 15:31:15 +00:00
Raymond Hettinger 663004bb3d SF patch #664320: Replace push/pop clusters in ceval.c
Replaced groups of pushes and pops with indexed access to the stack and
a single adjustment (if needed) to the stacklevel.

Avoids scores of unnecessary increments and decrements to the stackpointer.
Removes unnecessary sequential dependencies so that the compiler has more
freedom for optimizations.  Frees the processor for more parallel and
pipelined execution by using mostly read-only access and having few pointer
adjustments just prior to a read or write.
2003-01-09 15:24:30 +00:00
Thomas Heller 27bb71e963 Patch #664376: sys.path[0] should contain absolute pathname.
This fixes the problem on Windows - that's the only system where I can
test it.

It leaves sys.argv alone and only changes sys.path[0] to an absolute
pathname.
2003-01-08 14:33:48 +00:00
Raymond Hettinger 69bf8f3f4e SF bug #655271: Slightly modify locals() doc
Clarify the operation of locals().
2003-01-04 02:16:22 +00:00
Guido van Rossum 908ec365dc Another copyright update. (JvR: can you backport this to the 2.3a1
release branch?)
2003-01-02 16:27:15 +00:00
Jeremy Hylton accb62b28e SF patch [ 597919 ] compiler package and SET_LINENO
A variety of changes from Michael Hudson to get the compiler working
with 2.3.  The primary change is the handling of SET_LINENO:

# The set_lineno() function and the explicit emit() calls for
# SET_LINENO below are only used to generate the line number table.
# As of Python 2.3, the interpreter does not have a SET_LINENO
# instruction.  pyassem treats SET_LINENO opcodes as a special case.

A few other small changes:
 - Remove unused code from pycodegen and pyassem.
 - Fix error handling in parsermodule.  When PyParser_SimplerParseString()
   fails, it sets an exception with detailed info.  The parsermodule
   was clobbering that exception and replacing it was a generic
   "could not parse string" exception.  Keep the original exception.
2002-12-31 18:17:44 +00:00
Neal Norwitz b2501f4cd1 Since the *_Init() are private, prefix with _, suggested by Skip 2002-12-31 03:42:13 +00:00
Neal Norwitz 7b8e35ed7d Fix SF #639945, 64-bit bug on AIX
I can't test this on the snake farm (no aix box is working).
This change works for the submitter seems correct.
Can anybody test this on 32- and 64- bit AIX?
2002-12-31 00:06:24 +00:00
Neal Norwitz c91ed400e0 SF #561244, Micro optimizations
Initialize the small integers and __builtins__ in startup.
This removes some if conditions.
Change XDECREF to DECREF for values which shouldn't be NULL.
2002-12-30 22:29:22 +00:00
Just van Rossum 52e14d640b PEP 302 + zipimport:
- new import hooks in import.c, exposed in the sys module
- new module called 'zipimport'
- various changes to allow bootstrapping from zip files

I hope I didn't break the Windows build (or anything else for that
matter), but then again, it's been sitting on sf long enough...

Regarding the latest discussions on python-dev: zipimport sets
pkg.__path__ as specified in PEP 273, and likewise, sys.path item such as
/path/to/Archive.zip/subdir/ are supported again.
2002-12-30 22:08:05 +00:00
Raymond Hettinger bbfb910416 Make error message more specific for min() and max().
Suggested by MvL.
2002-12-29 18:31:19 +00:00
Raymond Hettinger ea3fdf44a2 SF patch #659536: Use PyArg_UnpackTuple where possible.
Obtain cleaner coding and a system wide
performance boost by using the fast, pre-parsed
PyArg_Unpack function instead of PyArg_ParseTuple
function which is driven by a format string.
2002-12-29 16:33:45 +00:00
Just van Rossum 8982595870 Backing out patch #642578 in anticipation of final acceptance of PEP 302. 2002-12-25 23:13:34 +00:00
Jack Jansen 0a116f3a29 Squashed compiler warnings by adding casts, making sure prototypes are in
scope and looking at types.
2002-12-23 21:03:36 +00:00
Guido van Rossum 633d90c7a3 Oops. Roll back that last change. It wasn't ready for release. :-( 2002-12-23 16:51:42 +00:00
Guido van Rossum 9c8a0866c9 Add warning for assignment to None, True and False. This is patch
549213 by Jeremy (checking in for him since he's away and busy).
2002-12-23 16:35:23 +00:00
Neal Norwitz 06982221bb SF # 654960, remove unnecessary static variable
The static variable (implicit) was not necessary.
The c_globals can be None or True now.
2002-12-18 01:18:44 +00:00
Gustavo Niemeyer 78429a6aa6 Fixing bug
[#448679] Left to right

* Python/compile.c
  (com_dictmaker): Reordered evaluation of dictionaries to follow strict
  LTR evaluation.

* Lib/compiler/pycodegen.py
  (CodeGenerator.visitDict): Reordered evaluation of dictionaries to
  follow strict LTR evaluation.

* Doc/ref/ref5.tex
  Documented the general LTR evaluation order idea.

* Misc/NEWS
  Documented change in evaluation order of dictionaries.
2002-12-16 13:54:02 +00:00
Jack Jansen c389ec8d55 Got rid of old (non-carbon-ppc and even cfm68k) file extensions for
extension modules.
2002-12-16 13:16:25 +00:00
Just van Rossum bbfd859521 Fixed potential crash: v can be NULL here, so use Py_XDECREF rather than Py_DECREF 2002-12-15 13:45:32 +00:00
Jack Jansen 72f3b7a5de Added missing casts. 2002-12-13 15:23:10 +00:00
Walter Dörwald d9a6ad3beb Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
supported as the second argument. This has the same meaning as
for isinstance(), i.e. issubclass(X, (A, B)) is equivalent
to issubclass(X, A) or issubclass(X, B). Compared to isinstance(),
this patch does not search the tuple recursively for classes, i.e.
any entry in the tuple that is not a class, will result in a
TypeError.

This closes SF patch #649608.
2002-12-12 16:41:44 +00:00
Martin v. Löwis 95292d6caa Constify filenames and scripts. Fixes #651362. 2002-12-11 14:04:59 +00:00
Martin v. Löwis b023381466 Patch #650415: Avoid redefinition of macros. 2002-12-11 13:12:30 +00:00
Martin v. Löwis 79acb9edfa Patch #614055: Support OpenVMS. 2002-12-06 12:48:53 +00:00
Andrew MacIntyre c4c127b850 reformat for PEP-7 style conformance 2002-12-04 12:29:37 +00:00
Andrew MacIntyre 6904959921 typo fix: declaration required for VACPP not EMX+gcc 2002-12-04 12:27:06 +00:00
Martin v. Löwis 779ffc066e Add compile-time errors for unsupported systems. 2002-12-02 22:17:01 +00:00
Just van Rossum 3eb166b49b Slightly improved version of patch #642578: "Expose PyImport_FrozenModules
in imp". This adds two functions to the imp module: get_frozenmodules()
and set_frozenmodules().
2002-11-29 20:47:40 +00:00
Martin v. Löwis 52ea7e9244 Patch #632973: Implement _getdefaultlocale for OS X. 2002-11-26 09:05:36 +00:00
Martin v. Löwis ba2cf078d2 Properly compute array size even for --disable-unicode. 2002-11-21 23:53:25 +00:00
Walter Dörwald dffda2eaf9 Wrap uargs declaration in a #ifdef Py_USING_UNICODE, so that
the --disable-unicode build doesn't complain about an
unused variable.
2002-11-21 20:23:11 +00:00
Walter Dörwald 4c6c76559d Move three variables that are only used inside an if block into the block,
so the --disable-unicode build doesn't complain about unused variables.
2002-11-21 20:13:40 +00:00
Walter Dörwald bf73db835a Fix PEP 293 related problems with --disable-unicode builds
reported by Michael Hudson in
http://mail.python.org/pipermail/python-dev/2002-November/030299.html
2002-11-21 20:08:33 +00:00
Neil Schemenauer 89350a41b9 Remove _Py_ResetReferences. Fixes bug #529750 "Circular reference makes
Py_Init crash".  refchain cannot be cleared because objects can live across
Py_Finalize() and Py_Initialize() if they are kept alive by circular
references.
2002-11-17 17:52:44 +00:00
Neal Norwitz addfe0c09c Make private functions static so we don't pollute the namespace 2002-11-10 14:33:26 +00:00
Michael W. Hudson 5f26dda25d Restore to ANSI C. 2002-11-09 14:47:18 +00:00
Michael W. Hudson 006c75265f This is Richie Hindle's patch:
[ 631276 ] Exceptions raised by line trace function

It conflicted with the patches from Armin I just checked it, so I had
to so some bits by hand.
2002-11-08 13:08:46 +00:00
Michael W. Hudson 019a78e76d Assorted patches from Armin Rigo:
[ 617309 ] getframe hook (Psyco #1)
[ 617311 ] Tiny profiling info (Psyco #2)
[ 617312 ] debugger-controlled jumps (Psyco #3)

These are forward ports from 2.2.2.
2002-11-08 12:53:11 +00:00
Jack Jansen dde800ec4e Got rid of the python.rsrc resource file. The error message strings and
dialogs are now stored in Mac/Lib, and loaded on demand through macresource.
Not only does this simplify a MacPython based on Apple's Python, but
it also makes Mac error codes come out symbolically when running command
line python (if you have Mac/Lib in your path).

The resource files are copied from Mac/Resources. The old ones will disappear
after the OS9 build procedure has been adjusted.
2002-11-07 23:07:05 +00:00
Michael W. Hudson cbd6fb9006 Handle really big steps in extended slices.
Fixes a test failure on 64 bit platforms (I hope).
2002-11-06 15:17:32 +00:00
Neal Norwitz 40cac739c2 Fix SF # 551504, python -v sometimes fails to find init (HPUX)
Joseph Winston recommends removing DYNAMIC_PATH, since it can
cause some dynamic libraries to not load on HP-UX 11.
2002-11-02 20:58:05 +00:00
Martin v. Löwis 566f6afe9a Patch #512981: Update readline input stream on sys.stdin/out change. 2002-10-26 14:39:10 +00:00
Jack Jansen 8fce2ef84c Made MacOS.Error a class style exception (at last!). 2002-10-19 22:02:21 +00:00
Fred Drake 8ed0204bc9 If we have a filename and __main__.__file__ hasn't already been set,
set it.
Closes SF issue #624729.
2002-10-17 21:24:58 +00:00
Mark Hammond 8696ebcd28 Add os.path.supports_unicode_filenames for all platforms,
sys.getwindowsversion() on Windows (new enahanced Tim-proof <wink>
version), and fix test_pep277.py in a few minor ways.
Including doc and NEWS entries.
2002-10-08 02:44:31 +00:00
Tim Peters 92e4dd8657 s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
__STDC__ is defined (or something like that ...).
2002-10-05 01:47:34 +00:00
Martin v. Löwis a7a76d3d9e Patch #618347: Work around Solaris 2.6 pthread.h bug. Will backport to 2.2. 2002-10-04 07:21:24 +00:00
Mark Hammond 3d61a06aa2 Fix [ 616716 ] Bug in PyErr_SetExcFromWindows
Ensure that even if FormatMessage fails we (a) don't crash, and (b) provide something useful.

Bugfix candidate.
2002-10-04 00:13:02 +00:00
Mark Hammond da7efaa681 Fix errors to pep277 checkin identified by Neal Norwitz. 2002-10-04 00:09:38 +00:00
Michael W. Hudson ca803a0dd7 One last tweak to the tracing machinery: this actually computes what I intended
all along.  Before instr_lb tended to be too high.

I don't think this actually makes any difference, given what the compiler
produces, but it makes me a bit happier.
2002-10-03 09:53:11 +00:00
Michael W. Hudson 3ae3315f44 Clamp code objects' tp_compare result to [-1, 1].
Bugfix candidate.
2002-10-03 09:50:47 +00:00
Mark Hammond c2e85bd4e2 Patch 594001: PEP 277 - Unicode file name support for Windows NT. 2002-10-03 05:10:39 +00:00
Michael W. Hudson fb4d6ecd07 Fix for the recursion_level bug Armin Rigo reported in sf
patch #617312, both on the trunk and the 22-maint branch.

Also added a test case, and ported the test_trace I wrote for HEAD
to 2.2.2 (with all those horrible extra 'line' events ;-).
2002-10-02 13:13:45 +00:00
Martin v. Löwis eb42b026db Add encoding name in LookupError. Fixes #615013. Will backport to 2.2. 2002-09-26 16:01:24 +00:00
Neal Norwitz 2c96ab2b61 Two more cases of switch(PySequence_Size()) without checking for case -1.
(Same problem as last checkin for SF bug 610610)
Need to clear the error and proceed.

Backport candidate
2002-09-18 22:37:17 +00:00
Guido van Rossum 98b2a42bc4 Fix SF bug 610610 (reported by Martijn Pieters, diagnosed by Neal Norwitz).
The switch in Exception__str__ didn't clear the error if
PySequence_Size() raised an exception.  Added a case -1 which clears
the error and falls through to the default case.

Definite backport candidate (this dates all the way to Python 2.0).
2002-09-18 04:06:32 +00:00
Michael W. Hudson 02ff6a9952 A slight change to SET_LINENO-less tracing.
This makes things a touch more like 2.2.  Read the comments in
Python/ceval.c for more details.
2002-09-11 15:36:32 +00:00
Skip Montanaro 066a8df3a4 missed this one on the previous multi-file checkin - see
http://python.org/sf/602191
2002-09-03 20:24:31 +00:00
Guido van Rossum 602d45194c Add a custom __str__ method to KeyError that applies repr() to the
missing key.  (Also added a guard to SyntaxError__str__ to prevent
calling PyString_Check(NULL).)
2002-09-03 20:24:09 +00:00
Skip Montanaro 99dba27e9a Bump default check interval to 100 instructions. Computers are much faster
than when this interval was first established.  Checking too frequently just
adds needless overhead because most of the time there is nothing to do and
no other threads ready to run.
2002-09-03 20:19:06 +00:00
Skip Montanaro d581d7792b replace thread state objects' ticker and checkinterval fields with two
globals, _Py_Ticker and _Py_CheckInterval.  This also implements Jeremy's
shortcut in Py_AddPendingCall that zeroes out _Py_Ticker.  This allows the
test in the main loop to only test a single value.

The gory details are at

    http://python.org/sf/602191
2002-09-03 20:10:45 +00:00
Skip Montanaro 8e790e7007 expose PYTHON_API_VERSION macro as sys.api_version. Closes patch # 601456. 2002-09-03 13:25:17 +00:00
Walter Dörwald f7bcd1d65c Check string for NULL before using it to format the error message.
(Spotted by Neal Norwitz)
2002-09-02 18:22:32 +00:00
Walter Dörwald 70bb0d4e65 Removed bogus PyUnicodeTranslateError_GetEncoding, as
UnicodeTranslateError doesn't have an encoding attribute.
(Spotted by Neal Norwitz)
2002-09-02 16:41:55 +00:00
Walter Dörwald fd08e4c9ed Limit the length of attribute names in exception messages
to prevent buffer overflows (spotted by Neal Norwitz).
2002-09-02 16:10:06 +00:00
Walter Dörwald 3aeb632c31 PEP 293 implemention (from SF patch http://www.python.org/sf/432401) 2002-09-02 13:14:32 +00:00
Guido van Rossum f689492070 Because MWH changed the bytecode again, moved the magic number *back*
to 62011.  This should get the snake-farm to throw away its old .pyc
files, amongst others.
2002-08-31 15:16:14 +00:00
Michael W. Hudson 53d58bb369 Further SET_LINENO reomval fixes. See comments in patch #587933.
Use a slightly different strategy to determine when not to call the line
trace function.  This removes the need for the RETURN_NONE opcode, so
that's gone again.  Update docs and comments to match.

Thanks to Neal and Armin!

Also add a test suite.  This should have come with the original patch...
2002-08-30 13:09:51 +00:00
Peter Schneider-Kamp 4c0134248c execfile should call PyErr_SetFromErrnoWithFilename instead of
simply PyErr_SetFromErrno

This closes bug 599163.
2002-08-27 16:58:00 +00:00
Fred Drake e20131efc3 Fix a couple of whitespace consistency nits. 2002-08-26 21:20:30 +00:00
Fred Drake 6049cb8918 Simplify, and avoid PyModule_GetDict() while we're at it. 2002-08-26 21:15:11 +00:00
Guido van Rossum 86c659a329 The error messages in err_args() -- which is only called when the
required number of args is 0 or 1 -- were reversed.  Also change "1"
into "exactly one", the same words as used elsewhere for this
condition.
2002-08-23 14:11:35 +00:00
Michael W. Hudson c230b0e1f9 Comment typo repair. 2002-08-20 15:43:16 +00:00
Michael W. Hudson 62897c5c13 My patch #597221. Use f_lasti more consistently. 2002-08-20 15:19:14 +00:00
Guido van Rossum d8dbf847b6 Add a warning comment to the LOAD_GLOBAL inline code. 2002-08-19 21:17:53 +00:00
Guido van Rossum 3a4dfc87e6 Another ugly inlining hack, expanding the two PyDict_GetItem() calls
in LOAD_GLOBAL.  Besides saving a C function call, it saves checks
whether f_globals and f_builtins are dicts, and extracting and testing
the string object's hash code is done only once.  We bail out of the
inlining if the name is not exactly a string, or when its hash is -1;
because of interning, neither should ever happen.  I believe interning
guarantees that the hash code is set, and I believe that the 'names'
tuple of a code object always contains interned strings, but I'm not
assuming that -- I'm simply testing hash != -1.

On my home machine, this makes a pystone variant with new-style
classes and slots run at the same speed as classic pystone!  (With
new-style classes but without slots, it is still a lot slower.)
2002-08-19 20:24:07 +00:00
Jeremy Hylton 192690e2d2 Inline fast_cfunction() in new call_function().
Also, don't handle METH_OLDARGS on the fast path.  All the interesting
builtins have been converted to use METH_NOARGS, METH_O, or
METH_VARARGS.

Result is another 1-2% speedup.  If I can cobble together 10 of these,
it might make a difference.
2002-08-16 18:36:11 +00:00
Jeremy Hylton e8c0432403 Move body of CALL_FUNCTION opcode into helper function.
This makes the code much easier to ready, because it is at a sane
indentation level.  On my box this shows a 1-2% speedup, which means
nothing, except that I'm not going to worry about the performance
effects of the change.
2002-08-16 17:47:26 +00:00
Guido van Rossum c13f724af0 Streamline the fast track for CFunction calls a bit more: there was
nothing special done if keyword arguments were present, so test for
that earlier and fall through to the normal case if there are any.
This ought to slow down CFunction calls with keyword args, but I don't
care; it's a tiny (1%) improvement for pystone.
2002-08-16 16:14:00 +00:00
Guido van Rossum c7903a13d2 A nice little speed-up for filter():
- Use PyObject_Call() instead of PyEval_CallObject(), saves several
  layers of calls and checks.

- Pre-allocate the argument tuple rather than calling Py_BuildValue()
  each time round the loop.

- For filter(None, seq), avoid an INCREF and a DECREF.
2002-08-16 07:04:56 +00:00
Guido van Rossum b7164621fa Add warnings for arguments named None. All set. (I could add a
warning for 'global None', but that's either accompanied by an
assignment to None, which will trigger a warning, or not, in which
case it's harmless. :-)
2002-08-16 02:48:11 +00:00
Guido van Rossum 63dd79ac04 Add warning for None used as keyword argument name in function call.
Still to do: function definition arguments (including *None and
**None).
2002-08-16 02:24:56 +00:00
Guido van Rossum 3ac99d4910 Add warnings for assignment or deletion of variables and attributes
named 'None'.  Still to do: function definition parameter lists, and
function call keyword arguments.
2002-08-16 02:13:49 +00:00
Guido van Rossum b081e0c74c Minor cleanup of parsename() and parsestr(): the 'struct compiling *'
argument should be called 'c', like everywhere else.  Renamed a
complex variable 'c' to 'z' and moved it inside the only scope where
it's used.
2002-08-16 01:57:32 +00:00
Michael W. Hudson dd32a91cc0 This is my patch
[ 587993 ] SET_LINENO killer

Remove SET_LINENO.  Tracing is now supported by inspecting co_lnotab.

Many sundry changes to document and adapt to this change.
2002-08-15 14:59:02 +00:00
Skip Montanaro 118ec70ea2 provide less mysterious error messages when seeing end-of-line in
single-quoted strings or end-of-file in triple-quoted strings.
closes patch 586561.
2002-08-15 01:20:16 +00:00
Fred Drake 233cc5987b Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
sense now that extension types can support __init__ directly rather
than requiring function constructors.
2002-08-14 20:57:56 +00:00
Barry Warsaw 9f00739551 Added a FutureWarning for constructs that will change semantically in
the future.  Changed PEP 237 hex constant warnings from
DeprecationWarning to FutureWarning.  Updated the documentation.
2002-08-14 15:51:29 +00:00
Martin v. Löwis 31d2df5b60 Patch #550192: Set softspace to 0 in raw_input(). 2002-08-14 15:46:02 +00:00
Martin v. Löwis 8a8da798a5 Patch #505705: Remove eval in pickle and cPickle. 2002-08-14 07:46:28 +00:00
Guido van Rossum 715eca932e Use PyErr_WarnExplicit() to warn about hex/oct constants, so the
correct filename and line number are reported.
2002-08-12 21:54:46 +00:00
Guido van Rossum 3cb8e54da0 Reset errno to zero after calling PyErr_Warn(). It can potentially do
a lot of work, including I/O (e.g. to import warnings.py), which might
affect errno.
2002-08-11 14:06:15 +00:00
Marc-André Lemburg cc8764ca9d Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.
u'%c' will now raise a ValueError in case the argument is an
integer outside the valid range of Unicode code point ordinals.

Closes SF bug #593581.
2002-08-11 12:23:04 +00:00
Guido van Rossum 078151da90 Implement stage B0 of PEP 237: add warnings for operations that
currently return inconsistent results for ints and longs; in
particular: hex/oct/%u/%o/%x/%X of negative short ints, and x<<n that
either loses bits or changes sign.  (No warnings for repr() of a long,
though that will also change to lose the trailing 'L' eventually.)

This introduces some warnings in the test suite; I'll take care of
those later.
2002-08-11 04:24:12 +00:00
Fred Drake 72bc456403 Add weakref support generator-iterators.
Part of fixing SF bug #591704.
2002-08-09 18:35:52 +00:00
Martin v. Löwis 2863c10a86 Use Py_FatalError instead of abort. 2002-08-07 15:18:57 +00:00
Martin v. Löwis 019934b3cc Fix PEP 263 code --without-unicode. Fixes #591943. 2002-08-07 12:33:18 +00:00
Skip Montanaro 496e6581e1 get rid of GETNAMEV macro - use GETITEM directly
same idea as getting rid of GETCONST & GETNAME (see patch #506436)
2002-08-06 17:47:40 +00:00
Skip Montanaro 04d80f87d7 small speedup for constant and name access
see sf #506436
2002-08-04 21:03:35 +00:00
Martin v. Löwis 00f1e3f5a5 Patch #534304: Implement phase 1 of PEP 263. 2002-08-04 17:29:52 +00:00
Andrew MacIntyre 80d4e2acf5 SF patch #578297:
Change the parser and compiler to use PyMalloc.

Only the files implementing processes that will request memory
allocations small enough for PyMalloc to be a win have been
changed, which are:-
 - Python/compile.c
 - Parser/acceler.c
 - Parser/node.c
 - Parser/parsetok.c

This augments the aggressive overallocation strategy implemented by
Tim Peters in PyNode_AddChild() [Parser/node.c], in reducing the
impact of platform malloc()/realloc()/free() corner case behaviour.
Such corner cases are known to be triggered by test_longexp and
test_import.

Jeremy Hylton, in accepting this patch, recommended this as a
bugfix candidate for 2.2.  While the changes to Python/compile.c
and Parser/node.c backport easily (and could go in), the changes
to Parser/acceler.c and Parser/parsetok.c require other not
insignificant changes as a result of the differences in the memory
APIs between 2.3 and 2.2, which I'm not in a position to work
through at the moment.  This is a pity, as the Parser/parsetok.c
changes are the most important after the Parser/node.c changes, due
to the size of the memory requests involved and their frequency.
2002-08-04 06:28:21 +00:00
Jack Jansen 21ed16acbe Added one call to Py_Main(), for OSX framework builds only, that will get the
actual script to run in case we are running from an applet. If we are indeed
running an applet we skip the normal option processing leaving it all to the
applet code.

This allows us to get use the normal python binary in the Python.app bundle,
giving us all the normal command line options through PythonLauncher while
still allowing Python.app to be used as the template for building applets.

Consequently, pythonforbundle is gone, and Mac/Python/macmain.c isn't used
on OSX anymore.
2002-08-02 14:11:24 +00:00
Thomas Heller 37d5a15e02 Whitespace normalization. 2002-07-30 11:44:44 +00:00
Thomas Heller 3e1c18ad0c Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
See there for a description.

Added test case.

Bugfix candidate for 2.2.x, not sure about previous versions:
probably low priority, because virtually no one runs debug builds.
2002-07-30 11:40:57 +00:00
Thomas Heller 085358a3e2 New functions for extension writers on Windows:
PyErr_SetExcFromWindowsErr(), PyErr_SetExcFromWindowsErrWithFilename().

Similar to PyErr_SetFromWindowsErrWithFilename() and
PyErr_SetFromWindowsErr(), but they allow to specify
the exception type to raise. Available on Windows.

See SF patch #576458.
2002-07-29 14:27:41 +00:00
Mark Hammond a290527376 Excise DL_IMPORT/EXPORT from object.h, and related files. This patch
also adds 'extern' to PyAPI_DATA rather than at each declaration, as
discussed with Tim and Guido.
2002-07-29 13:42:14 +00:00
Martin v. Löwis 75d2d94e0f Patch #554716: Use __va_copy where available. 2002-07-28 10:23:27 +00:00
Skip Montanaro 21ee37c94e remove spurious SET_LINENO from com_list_for and com_list_if. All they do
is slow things down unnecessarily and make tracing much more verbose.
Something like

    def f(n):
	return [i for i in range(n) if i%2]

should have at most two SET_LINENO instructions, not four.  When tracing,
the current line number should be printed once, not 2*n+1 times.
2002-07-25 06:18:42 +00:00
Mark Hammond 8235ea1c3a Land Patch [ 566100 ] Rationalize DL_IMPORT and DL_EXPORT. 2002-07-19 06:55:41 +00:00
Mark Hammond e21262ca9e Fix bug [ 549731 ] Unicode encoders appears to leak references.
Python 2.2.1 bugfix candidate.
2002-07-18 23:06:17 +00:00
Guido van Rossum 04e7032c6e SF patch 552161 - Py_AddPendingCall doesn't unlock on fail (Daniel
Dunbar)

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

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

XXX I haven't updated the documentation.
2002-07-17 16:30:39 +00:00
Tim Peters a64295b43a There's no need for generators to define an explicit next() method. 2002-07-17 00:15:22 +00:00
Neal Norwitz a81d220625 SF patch # 580411, move frame macros from frameobject.h into ceval.c
remove unused macros
use co alias instead of f->f_code in macros
2002-07-14 00:27:26 +00:00
Jeremy Hylton 76c81eecfa Don't stomp on an exception set by PyCell_Get() 2002-07-11 16:56:38 +00:00
Tim Peters 34b2569327 _Py_AskYesNo(): Removed this function. It was defined only in a
Py_TRACE_REFS build, but wasn't referenced.
2002-07-09 18:22:55 +00:00
Thomas Heller 6b17abf6c0 Fix SF Bug 564931: compile() traceback must include filename. 2002-07-09 09:23:27 +00:00
Tim Peters 7c321a80f9 The Py_REF_DEBUG/COUNT_ALLOCS/Py_TRACE_REFS macro minefield: added
more trivial lexical helper macros so that uses of these guys expand
to nothing at all when they're not enabled.  This should help sub-
standard compilers that can't do a good job of optimizing away the
previous "(void)0" expressions.

Py_DECREF:  There's only one definition of this now.  Yay!  That
was that last one in the family defined multiple times in an #ifdef
maze.

Py_FatalError():  Changed the char* signature to const char*.

_Py_NegativeRefcount():  New helper function for the Py_REF_DEBUG
expansion of Py_DECREF.  Calling an external function cuts down on
the volume of generated code.  The previous inline expansion of abort()
didn't work as intended on Windows (the program often kept going, and
the error msg scrolled off the screen unseen).  _Py_NegativeRefcount
calls Py_FatalError instead, which captures our best knowledge of
how to abort effectively across platforms.
2002-07-09 02:57:01 +00:00
Tim Peters 4be93d0e84 Rearranged and added comments to object.h, to clarify many things
that have taken me "too long" to reverse-engineer over the years.
Vastly reduced the nesting level and redundancy of #ifdef-ery.
Took a light stab at repairing comments that are no longer true.

sys_gettotalrefcount():  Changed to enable under Py_REF_DEBUG.
It was enabled under Py_TRACE_REFS, which was much heavier than
necessary.  sys.gettotalrefcount() is now available in a
Py_REF_DEBUG-only build.
2002-07-07 19:59:50 +00:00
Martin v. Löwis 6238d2b024 Patch #569753: Remove support for WIN16.
Rename all occurrences of MS_WIN32 to MS_WINDOWS.
2002-06-30 15:26:10 +00:00
Jack Jansen e739a0dbe9 Got rid of an extraneous semicolon. 2002-06-26 20:39:20 +00:00
Jeremy Hylton bd23289e4d Silence compiler warning 2002-06-25 19:26:34 +00:00
Raymond Hettinger 0ae0c07661 SF 569257 -- Name mangle double underscored variable names in __slots__. 2002-06-20 22:23:15 +00:00
Fred Drake ba3ff1ba7b Fix the docstring for sys.getrefcount().
Closes SF bug #571759.
2002-06-20 21:36:19 +00:00
Fred Drake 8311518a58 PyModule_AddObject(): Added missing exceptions.
Closes SF bug #523473.
2002-06-17 17:16:57 +00:00
Walter Dörwald 3430d70e03 Apply diff2.txt from SF patch http://www.python.org/sf/566999
This patch enhances Python/import.c/find_module() so
that unicode objects found in sys.path will be treated
as legal directory names (The current code ignores
anything that is not a str). The unicode name is
converted to str using Py_FileSystemDefaultEncoding.
2002-06-17 10:43:59 +00:00
Guido van Rossum bea18ccde6 SF patch 568629 by Oren Tirosh: types made callable.
These built-in functions are replaced by their (now callable) type:

    slice()
    buffer()

and these types can also be called (but have no built-in named
function named after them)

    classobj (type name used to be "class")
    code
    function
    instance
    instancemethod (type name used to be "instance method")

The module "new" has been replaced with a small backward compatibility
placeholder in Python.

A large portion of the patch simply removes the new module from
various platform-specific build recipes.  The following binary Mac
project files still have references to it:

    Mac/Build/PythonCore.mcp
    Mac/Build/PythonStandSmall.mcp
    Mac/Build/PythonStandalone.mcp

[I've tweaked the code layout and the doc strings here and there, and
added a comment to types.py about StringTypes vs. basestring.  --Guido]
2002-06-14 20:41:17 +00:00
Michael W. Hudson cb4d7ce7cb Now FOR_LOOP is gone, loop_subscript can go too.
make -s rules :-)
2002-06-14 13:53:29 +00:00
Neal Norwitz eda5a8ea0f Fix SF bug # 561858 Assertion with very long lists
Write 4 bytes for co_stacksize, etc. to prevent writing out
bad .pyc files which can cause a crash when read back in.

(I forgot that frozen needs to be updated too for the test.)
2002-06-14 01:11:57 +00:00
Neal Norwitz 7fdcb41131 Fix SF bug # 561858 Assertion with very long lists
Write 4 bytes for co_stacksize, etc. to prevent writing out
bad .pyc files which can cause a crash when read back in.
2002-06-14 01:07:39 +00:00
Martin v. Löwis 14f8b4cfcb Patch #568124: Add doc string macros. 2002-06-13 20:33:02 +00:00
Guido van Rossum fea59e7f76 The opcode FOR_LOOP no longer exists. 2002-06-13 17:59:51 +00:00
Guido van Rossum c5fe5eb8d2 SF bug 567538: Generator can crash the interpreter (Finn Bock).
This was a simple typo.  Strange that the compiler didn't catch it!
Instead of WHY_CONTINUE, two tests used CONTINUE_LOOP, which isn't a
why_code at all, but an opcode; but even though 'why' is declared as
an enum, comparing it to an int is apparently not even worth a
warning -- not in gcc, and not in VC++. :-(

Will fix in 2.2 too.
2002-06-12 03:45:21 +00:00
Martin v. Löwis f90ae20354 Patch #488073: AtheOS port. 2002-06-11 06:22:31 +00:00
Martin v. Löwis a3fb4f7816 Patch #505375: Make doc strings optional. 2002-06-09 13:33:54 +00:00
Raymond Hettinger c4c453f5ae Skip Montanaro's patch, SF 559833, exposing xrange type in builtins.
Also, added more regression tests to cover the new type and test its
conformity with range().
2002-06-05 23:12:45 +00:00
Neal Norwitz 32a7e7f6b6 Change name from string to basestring 2002-05-31 19:58:02 +00:00
Jeremy Hylton 05ab2e693c Fix SF bug [ 561825 ] Confusing error for "del f()"
In the error message, say del for del and assign for everything else.
2002-05-31 14:08:29 +00:00
Guido van Rossum 5e2c5fa1bd imp_load_module(): correct and comment the sense of the test for '+'
in the mode (it's forbidden).
2002-05-30 17:33:07 +00:00
Jeremy Hylton 4ae6faed9f Cover a few corners in the 'U' mode integration to make imp work.
get_file() must convert 'U' to "r" PY_STDIOTEXTMODE before calling
fopen().

imp_load_module() must accept 'r' or 'U' or something with '+'.

Also reflow some long lines.
2002-05-30 17:15:25 +00:00
Neal Norwitz d68f5171eb As discussed on python-dev, add a mechanism to indicate features
that are in the process of deprecation (PendingDeprecationWarning).
Docs could be improved.
2002-05-29 15:54:55 +00:00
Guido van Rossum 05459c5e5e Accept u"..." literals even when Unicode is disabled. But these
literals must not contain \u, \U or \N escapes.  (XXX Should they also
not contain non-ASCII characters?)
2002-05-28 18:47:29 +00:00
Jack Jansen c88da1faa5 File modes in filedescr entries are also passed to Python, so we now put "U"
in there, and convert it to "rb" (or "r" for non-universal-newline builds)
before passing it to fopen().

Fixes #561326.
2002-05-28 10:58:19 +00:00
Guido van Rossum cacfc07d08 - A new type object, 'string', is added. This is a common base type
for 'str' and 'unicode', and can be used instead of
  types.StringTypes, e.g. to test whether something is "a string":
  isinstance(x, string) is True for Unicode and 8-bit strings.  This
  is an abstract base class and cannot be instantiated directly.
2002-05-24 19:01:59 +00:00
Guido van Rossum 2d3b986480 Disambiguate the grammar for backtick.
The old syntax suggested that a trailing comma was OK inside backticks,
but in fact (due to ideosyncrasies of pgen) it was not.  Fix the grammar
to avoid the ambiguity.  Fred: you may want to update the refman.
2002-05-24 15:47:06 +00:00
Tim Peters 84ee323cb9 John Aycock correctly pointed out that the grammar for
"power" was formally ambiguous.  Here's his fix.
2002-05-23 20:05:40 +00:00
Michael W. Hudson d95c828307 Fix for
[ 558249 ] softspace vs --disable-unicode

And #endif was in the wrong place.

Bugfix candidate, almost surely.

I think I will embark on squashing test failures in --disable-unicode builds --
a Real Bug was hiding under them.
2002-05-20 13:56:11 +00:00
Tim Peters 39a86c2188 SF bug 555042: zip() may trigger MemoryError.
NOT a bugfix candidate:  this is a fix to an optimization introduced
in 2.3.
2002-05-12 07:19:38 +00:00
Tim Peters 67d687a114 builtin_zip(): Take a good guess at how big the result list will be,
and allocate it in one gulp.

This isn't a bugfix, it's just a minor optimization that may or may not
pay off.
2002-04-29 21:27:32 +00:00
Tim Peters 5de9842b34 Repair widespread misuse of _PyString_Resize. Since it's clear people
don't understand how this function works, also beefed up the docs.  The
most common usage error is of this form (often spread out across gotos):

	if (_PyString_Resize(&s, n) < 0) {
		Py_DECREF(s);
		s = NULL;
		goto outtahere;
	}

The error is that if _PyString_Resize runs out of memory, it automatically
decrefs the input string object s (which also deallocates it, since its
refcount must be 1 upon entry), and sets s to NULL.  So if the "if"
branch ever triggers, it's an error to call Py_DECREF(s):  s is already
NULL!  A correct way to write the above is the simpler (and intended)

	if (_PyString_Resize(&s, n) < 0)
		goto outtahere;

Bugfix candidate.
2002-04-27 18:44:32 +00:00
Guido van Rossum 7dab2426ca - New builtin function enumerate(x), from PEP 279. Example:
enumerate("abc") is an iterator returning (0,"a"), (1,"b"), (2,"c").
  The argument can be an arbitrary iterable object.
2002-04-26 19:40:56 +00:00
Neil Schemenauer 89e3ee0ccf If Py_OptimizeFlag is false then always evaluate assert conditions, don't
test __debug__ at runtime.  Closes SF patch #548833.
2002-04-26 01:58:53 +00:00
Jeremy Hylton 1b0bf9b761 Ignore SIGXFSZ.
The SIGXFSZ signal is sent when the maximum file size limit is
exceeded (RLIMIT_FSIZE).  Apparently, it is also sent when the 2GB
file limit is reached on platforms without large file support.

The default action for SIGXFSZ is to terminate the process and dump
core.  When it is ignored, the system call that caused the limit to be
exceeded returns an error and sets errno to EFBIG.  Python
always checks errno on I/O syscalls, so there is nothing to do with
the signal.
2002-04-23 20:31:01 +00:00
Tim Peters 51e7f5caba Moving pymalloc along.
+ Redirect PyMem_{Del, DEL} to the object allocator's free() when
  pymalloc is enabled.  Needed so old extensions can continue to
  mix PyObject_New with PyMem_DEL.

+ This implies that pgen needs to be able to see the PyObject_XYZ
  declarations too.  pgenheaders.h now includes Python.h.  An
  implication is that I expect obmalloc.o needs to get linked into
  pgen on non-Windows boxes.

+ When PYMALLOC_DEBUG is defined, *all* Py memory API functions
  now funnel through the debug allocator wrapper around pymalloc.
  This is the default in a debug build.

+ That caused compile.c to fail:  it indirectly mixed PyMem_Malloc
  with raw platform free() in one place.  This is verbotten.
2002-04-22 02:33:27 +00:00
Tim Peters afb2c80b29 ceval.c/do_raise(): Tighten the test to disallow raising an instance of
a str subclass.

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

For 2.3 only.  Guido doesn't want this backported.
2002-04-18 18:06:20 +00:00
Jack Jansen 7b8c7546eb Mass checkin of universal newline support.
Highlights: import and friends will understand any of \r, \n and \r\n
as end of line. Python file input will do the same if you use mode 'U'.
Everything can be disabled by configuring with --without-universal-newlines.

See PEP278 for details.
2002-04-14 20:12:41 +00:00
Martin v. Löwis 314fc79ce8 Patch #542659: Eliminate duplicate check for NULL of freevars/cellvars. 2002-04-14 09:53:49 +00:00
Tim Peters 0e871188e8 _PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Added code to call this when PYMALLOC_DEBUG is enabled, and envar
PYTHONMALLOCSTATS is set, whenever a new arena is obtained and once
late in the Python shutdown process.
2002-04-13 08:29:14 +00:00
Tim Peters 2bbdba3c00 Removed more hair in support of future-generator stmts. 2002-04-12 01:20:10 +00:00
Jack Jansen 8ab04b4d65 Got rid of ifdefs for long-obsolete GUSI versions. 2002-04-11 20:46:23 +00:00
Guido van Rossum 50ee94fd41 is_builtin() is not a Boolean -- it can return -1, 0, 1. [SF #541652] 2002-04-09 18:00:58 +00:00
Marc-André Lemburg 95de5c1631 Move Unicode finalization further down in the chain.
Fixes bug #525620.
2002-04-08 08:19:36 +00:00
Guido van Rossum b8bff3f4a9 Return bools from functions named is_<whatever>(). 2002-04-07 06:34:38 +00:00
Guido van Rossum 55474766f0 Fix by Greg Chapman from SF bug 534347: Potential AV in vgetargskeywords.
Bugfix candidate.
2002-04-04 16:22:30 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
2002-04-03 22:41:51 +00:00
Neal Norwitz 7829335763 Get rid of another use of PyArg_Parse() 2002-04-01 01:41:20 +00:00
Neal Norwitz 031829d3ef Use symbolic METH_VARARGS instead of 1 for ml_flags 2002-03-31 14:37:44 +00:00
Tim Peters 1f7df3595a Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols. 2002-03-29 03:29:08 +00:00
Neil Schemenauer 835840560b Call PyObject_GC_UnTrack before putting an object on the list of trash. 2002-03-29 03:07:29 +00:00
Skip Montanaro 995895f023 add comment reminding people about class hierarchy in Doc/lib/libexcs.tex 2002-03-28 20:57:51 +00:00
Guido van Rossum cfbf1a33c1 Fix an issue that was reported in but unrelated to the main problem of
SF bug 535905 (Evil Trashcan and GC interaction).

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

BUGFIX CANDIDATE!
2002-03-28 20:17:52 +00:00
Fred Drake 7bf9715a8b Introduce two new flag bits that can be set in a PyMethodDef method
descriptor, as used for the tp_methods slot of a type.  These new flag
bits are both optional, and mutually exclusive.  Most methods will not
use either.  These flags are used to create special method types which
exist in the same namespace as normal methods without having to use
tedious construction code to insert the new special method objects in
the type's tp_dict after PyType_Ready() has been called.

If METH_CLASS is specified, the method will represent a class method
like that returned by the classmethod() built-in.

If METH_STATIC is specified, the method will represent a static method
like that returned by the staticmethod() built-in.

These flags may not be used in the PyMethodDef table for modules since
these special method types are not meaningful in that case; a
ValueError will be raised if these flags are found in that context.
2002-03-28 05:33:33 +00:00
Neal Norwitz 0c766a0bb6 Change sys_exit to use METH_VARARGS.
sys.exit() now requires 0-1 arguments.  Previously 2+ arguments were allowed.
2002-03-27 13:03:09 +00:00
Tim Peters fdba55fe8e I've been waiting 8 years for KSR to re-emerge from bankruptcy. If they
ever do, they can damn well #define _POSIX_THREADS their own damn selves.
2002-03-25 06:49:10 +00:00
Tim Peters 8e5fd53be0 SF bug 480215: softspace confused in nested print
This fixes the symptom, but PRINT_ITEM has no way to know what (if
anything) PyFile_WriteObject() writes unless the object being printed
is a string.  When the object isn't a string, this fix retains the
guess that softspace should be set after PyFile_WriteObject().
We might want to say that it's the job of filelike-object write methods
to leave the file's softspace in the correct state.  That would probably
be better -- but everyone relies on PRINT_ITEM to guess for them now.
2002-03-24 19:25:00 +00:00
Neil Schemenauer 0f2103fb16 Fix wording of sys.exit docstring. Close SF bug 534113. 2002-03-23 20:46:35 +00:00
Neil Schemenauer c24ea08644 Disable the parser hacks that enabled the "yield" keyword using a future
statement.
2002-03-22 23:53:36 +00:00
Neil Schemenauer 08de92a267 Re-enable GC of generator objects. 2002-03-18 20:45:09 +00:00
Martin v. Löwis 42ab61eeab Document that _POSIX_SEMAPHORES is predefined. 2002-03-17 17:19:00 +00:00
Martin v. Löwis cc89866b65 Patch #525532: Add support for POSIX semaphores. 2002-03-17 09:53:51 +00:00
Martin v. Löwis 7d1cd6947d Patch #504224: add plan9 threads include to thread.c. 2002-03-09 12:10:54 +00:00
Martin v. Löwis 3484a18af1 Patch #494045: patches errno and stat to cope on plan9. 2002-03-09 12:07:51 +00:00
Tim Peters d50e544b9f Docstring for filter(): Someone on the Tutor list reasonably complained
that it didn't tell enough of the truth.
Bugfix candidate (I guess -- it helps and it's harmless).
2002-03-09 00:06:26 +00:00
Martin v. Löwis cfeb3b6ab8 Patch #50002: Display line information for bad \x escapes:
- recognize "SyntaxError"s by the print_file_and_line attribute.
- add the syntaxerror attributes to all exceptions in compile.c.
Fixes #221791
2002-03-03 21:30:27 +00:00
Neal Norwitz 290d31e2fc SF #506611, fix sys.setprofile(), sys.settrace() core dumps
when no arguments are passed
2002-03-03 15:12:58 +00:00
Tim Peters e64ef931d6 SF patch 522961: Leak in Python/thread_nt.h, from Gerald S. Williams.
A file-static "threads" dict mapped thread IDs to Windows handles, but
was never referenced, and entries never got removed.  This gets rid of
the YAGNI-dict entirely.
Bugfix candidate.
2002-02-28 21:34:34 +00:00
Michael W. Hudson 494cdb6d78 Add 2002 to PSF copyrights.
Doc/README is odd; it assigns some copyright to the PSF in 2000, when
I didn't think it existed...
2002-02-27 13:29:46 +00:00
Andrew MacIntyre d940054ad4 OS/2 EMX port changes (Python part of patch #450267):
Python/
    dynload_shlib.c  // EMX port emulates dlopen() etc. for DL extensions
    import.c         // changes to support 8.3 DLL name limit (VACPP+EMX)
                     //  and case sensitive import semantics
    importdl.h
    thread_os2.h
2002-02-26 11:41:34 +00:00
Neil Schemenauer 6354386d65 Move some opcodes to top of big eval_frame switch statement. Skip
things_to_do block for a few common opcodes that don't do any real
work.  Closes SF patch #512256.
2002-02-17 19:10:14 +00:00
Tim Peters 373f8d81ff LOAD_FAST: rearrange branches to favor the expected case, and get
rid of a redundant NULL-pointer check in the expected case.
2002-02-12 04:31:21 +00:00
Jack Jansen 58e7a68dea Removed a spurious }. (How did it get there in the first place??) 2002-02-11 16:21:00 +00:00
Marc-André Lemburg bd3be8f0ca Fix to the UTF-8 encoder: it failed on 0-length input strings.
Fix for the UTF-8 decoder: it will now accept isolated surrogates
(previously it raised an exception which causes round-trips to
fail).

Added new tests for UTF-8 round-trip safety (we rely on UTF-8 for
marshalling Unicode objects, so we better make sure it works for
all Unicode code points, including isolated surrogates).

Bumped the PYC magic in a non-standard way -- please review. This
was needed because the old PYC format used illegal UTF-8 sequences
for isolated high surrogates which now raise an exception.
2002-02-07 11:33:49 +00:00
Jack Jansen a762f4ca18 Got rid of an extra level of {} and funny formatting that was still
there because of the NeXT history.
2002-02-01 22:24:56 +00:00
Jack Jansen d4c76bf65a A new dynload_next, which actually only works on OSX but isn't renamed yet.
By default every module is imported in its own namespace, but this can
be changed by defining USE_DYLD_GLOBAL_NAMESPACE. In a future version this
define will be replaced by a runtime setting, but that needs a bit more
thought.

This code is largely based on code and feedback from Steven Majewski,
Marcel Prastawa, Manoj Plakal and other on pythonmac-sig.
2002-02-01 16:01:05 +00:00
Neal Norwitz 150d09d360 Fix missing space between words. Bugfix candidate. 2002-01-29 00:56:37 +00:00
Neal Norwitz 2a47c0fa23 Fix spelling mistakes. Bugfix candidates. 2002-01-29 00:53:41 +00:00
Martin v. Löwis fb0da9d770 Test for error status of shl_findsym. Fixes #505417. 2.2.1 candiate. 2002-01-26 20:03:48 +00:00
Michael W. Hudson ff06671acf Fix for
[ #496154 ] Typos in dynload_beos.c

as suggested in the report.  A little embarassing; 2.2.1 candidate for sure.
2002-01-23 15:51:12 +00:00
Fred Drake 7bb1c9a11d Remove the unused & broken PyThread_*_sema() functions and related constants.
This closes SF patch #504215.
2002-01-19 22:02:55 +00:00
Guido van Rossum 340cbe74b9 A tentative fix for SF bug #503837 (Roeland Rengelink):
type.__module__ problems (again?)

This simply initializes the __module__ local in a class statement from
the __name__ global.  I'm not 100% sure that this is the correct fix,
although it usually does the right thing.  The problem is that if the
class statement executes in a custom namespace, the __name__ global
may be taken from __builtins__, in which case it would have the value
__builtin__, or it may not exist at all (if the custom namespace also
has a custom __builtins__), in which case the class statement will
fail.

Nevertheless, unless someone finds a better solution, this is a 2.2.1
bugfix too.
2002-01-15 21:06:07 +00:00
Jack Jansen 7668957508 Workaround for what is probably a problem in Apple's gcc: <pthread.h> fails
on a function pointer formal argument called "destructor", which is typedeffed
as a different function pointer type in object.h.
2002-01-15 20:36:14 +00:00
Martin v. Löwis cdc4451222 Include <unistd.h> in Python.h. Fixes #500924. 2002-01-12 11:05:12 +00:00
Marc-André Lemburg 3e3eacb5fc Fixed "u#" parser marker to pass through Unicode objects as-is without
going through the buffer interface API.

Added tests for this to the _testcapi module and updated docs.
2002-01-09 16:21:27 +00:00
Martin v. Löwis 7198a525f3 Patch #494783: Rename cmp_op enumerators. 2002-01-01 19:59:11 +00:00
Martin v. Löwis a6e975801e Patch #497098: build support for GNU/Hurd. 2002-01-01 18:41:33 +00:00
Tim Peters 54b11918be SF bug #496549 -Qnew and in-place division "/=".
eval_frame():  Under -Qnew, INPLACE_DIVIDE wasn't getting handed off to
INPLACE_TRUE_DIVIDE (like BINARY_DIVIDE was getting handed off to
BINARY_TRUE_DIVIDE).

Bugfix candidate.
2001-12-25 18:49:11 +00:00
Barry Warsaw b2dd86defe PyOS_vsnprintf(): Change PyMem_Malloc() call to PyMem_MALLOC() macro,
(ditto for PyMem_Free() -> PyMem_FREE()) to fix and close SF bug
#495875 on systems that HAVE_SNPRINTF=0.

Check in on both release-22 branch and trunk.
2001-12-21 16:32:15 +00:00
Tim Peters b6d14daa1c SF bug #494668: PUSH() should assert-fail on overflow.
eval_frame():  Added asserts to the top of the eval loop, to verify
that the eval stack pointer is in bounds, plus some comments.
2001-12-19 04:11:07 +00:00
Martin v. Löwis 8d3ce5a6b3 Patch #494384: Disable more Unicode API if Unicode is not used. 2001-12-18 22:36:40 +00:00
Tim Peters b519638d1e _PyEval_SliceIndex(): explain why a NULL argument is allowed (thanks
to Guido for the revelation).
2001-12-16 19:44:20 +00:00
Tim Peters cb479e78e0 _PyEval_SliceIndex(): Repaired the comments, and added XXX comments
about its dubious treatment of NULL (also opened a bug report on that,
but don't want to risk changing it this late in the 2.2 game).
2001-12-16 19:11:44 +00:00
Jeremy Hylton 733c8935f9 Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Based on the patch from Danny Yoo.  The fix is in exec_statement() in
ceval.c.

There are also changes to introduce use of PyCode_GetNumFree() in
several places.
2001-12-13 19:51:56 +00:00
Jeremy Hylton 2990640d8a Add a comment explaining the st_symbols cache. 2001-12-10 00:53:18 +00:00
Tim Peters 0f2d4b84a6 PySymtableEntry_New(): I'm not sure what this routine is doing, but it
was obviously leaking an int object when whatever the heck it's looking for
was found.  Repaired that.  This accounts for why entering function and
class definitions at an interactive prompt leaked a reference to the
integer 1 each time.
Bugfix candidate.
2001-12-08 23:40:38 +00:00
Jeremy Hylton 0702858d73 Missing DECREFs when exception is raised in sys.excepthook.
Bug fix candidate for 2.1 branch.

(I imagine the other recent leak patches are bug fix candidates, too,
but I forgot to mark mine as such.)
2001-12-07 15:35:35 +00:00
Jack Jansen e3d7622fb3 Don't fail on importing things with undefined references. Unfortunately we
still fail on importing modules that link with libraries that fail
their initialization code (such as windowing libraries when we don't have
access to the window server) and that is what I really wanted to fix.
2001-12-06 22:58:56 +00:00
Guido van Rossum 35974fbf31 Fix for SF bug #489671 (Neil Norwitz): memory leak in test_richcmp.
Had nothing to do with rich comparisons -- some stack cleanup code was
lost as a result of merging in Neil Schemenauer's generators patch.
Reinserted the stack cleanup code, skipping it when yielding.
2001-12-06 21:28:18 +00:00
Guido van Rossum 2556f2e1e2 Fix a typo (probably caused by autocompletion <blush>) that caused a
leak when a class defined a __metaclass__.  This fixes the problem
reported on python-dev by Ping; I dunno if it's the same as SF bug
#489669 (since that mentions Unicode).
2001-12-06 14:09:56 +00:00
Tim Peters 3caca2326e SF bug #488514: -Qnew needs work
Big Hammer to implement -Qnew as PEP 238 says it should work (a global
option affecting all instances of "/").

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

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

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

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

Question:  when -Qnew is in effect, should calls to __div__ magically
change into calls to __truediv__?  See "major hackery" at tail end of
last paragraph <wink>.
2001-12-06 06:23:26 +00:00
Guido van Rossum 6b70599450 Fix SF bug #486144: Uninitialized __slot__ vrbl is None.
There's now a new structmember code, T_OBJECT_EX, which is used for
all __slot__ variables (except __weakref__, which has special behavior
anyway).  This new code raises AttributeError when the variable is
NULL rather than converting NULL to None.
2001-12-04 16:23:42 +00:00
Jeremy Hylton 86424e333f SF bug #488687 reported by Neal Norwitz
The error for assignment to __debug__ used ste->ste_opt_lineno instead
of n->n_lineno.  The latter was at best incorrect; often the slot was
uninitialized.  Two fixes here: Use the correct lineno for the error.
Initialize ste_opt_lineno in PySymtable_New(); while there are no
current cases where it is referenced unless it has already been
assigned to, there is no harm in initializing it.
2001-12-04 02:41:46 +00:00
Tim Peters 22a51efc1c More sprintf -> PyOS_snprintf. 2001-12-04 01:11:32 +00:00
Guido van Rossum 354797ccad Fix the final two issues in Armin Rigo's SF bug #488477: apply_slice()
and assign_slice() weren't properly DECREF'ing the temporary slice
object they created.  (Shame on me. :-)
2001-12-03 19:45:06 +00:00
Guido van Rossum bb8f59a371 unpack_iterable(): Add a missing DECREF in an error case. Reported by
Armin Rigo (SF bug #488477).  Added a testcase to test_unpack_iter()
in test_iter.py.
2001-12-03 19:33:25 +00:00
Tim Peters faad5ad590 mysnprintf.c: Massive rewrite of PyOS_snprintf and PyOS_vsnprintf, to
use wrappers on all platforms, to make this as consistent as possible x-
platform (in particular, make sure there's at least one \0 byte in
the output buffer).  Also document more of the truth about what these do.

getargs.c, seterror():  Three computations of remaining buffer size were
backwards, thus telling PyOS_snprintf the buffer is larger than it
actually is.  This matters a lot now that PyOS_snprintf ensures there's a
trailing \0 byte (because it didn't get the truth about the buffer size,
it was storing \0 beyond the true end of the buffer).

sysmodule.c, mywrite():  Simplify, now that PyOS_vsnprintf guarantees to
produce a \0 byte.
2001-12-03 00:43:33 +00:00
Tim Peters 080d5b3f0b mywrite(): The test for trouble in PyOS_vsnprintf was wrong on both
ends.  Also, when there is trouble, ensure the buffer has a traiing
0 byte.
2001-12-02 08:29:16 +00:00
Guido van Rossum 64be0b4aa5 When the number of bytes written to the malloc'ed buffer is larger
than the argument string size, copy as many bytes as will fit
(including a terminating '\0'), rather than not copying anything.
This to make it satisfy the C99 spec.
2001-12-01 16:00:10 +00:00
Tim Peters cffed4bc21 SF bug 486278 SystemError: Python/getargs.c:1086: bad.
vgetargskeywords():  Now that this routine is checking for bad input
(rather than dump core in some cases), some bad calls are raising errors
that previously "worked".  This patch makes the error strings more
revealing, and changes the exceptions from SystemError to RuntimeError
(under the theory that SystemError is more of a "can't happen!" assert-
like thing, and so inappropriate for bad arguments to a public C API
function).
2001-11-29 03:26:37 +00:00
Jeremy Hylton b048b26db0 Two screwups fixed for sizeof(char *) instead of sizeof(char []).
Also change all the helper functions to pass along the size of the
msgbuf and use PyOS_snprintf() when writing into the buffer.
2001-11-28 22:14:37 +00:00
Tim Peters 75cdad5584 More sprintf -> PyOS_snprintf. 2001-11-28 22:07:30 +00:00
Jeremy Hylton f16e05e7ec Use PyOS_snprintf() at some cost even though it was correct before.
seterror() uses a char array and a pointer to the current position in
that array.  Use snprintf() and compute the amount of space left in
the buffer based on the current pointer position.
2001-11-28 21:46:59 +00:00
Jeremy Hylton 5d3d134d56 Use PyOS_vsnprintf() and check its return value.
If it returns -1 (which indicates overflow on old Linux platforms and
perhaps on Windows) or size greater than buffer, write a message
indicating that the previous message was truncated.
2001-11-28 21:44:53 +00:00
Barry Warsaw 4b4ab20f2c ste_repr(): Conversion of sprintf() to PyOS_snprintf() for buffer
overrun avoidance.
2001-11-28 21:36:28 +00:00
Barry Warsaw 857bf52d56 aix_loaderror(): Conversion of sprintf() to PyOS_snprintf() for buffer
overrun avoidance.
2001-11-28 21:35:49 +00:00
Barry Warsaw 8f6d868bbb code_repr(), com_addop_varname(), com_list_comprehension(),
com_arglist(), symtable_check_unoptimized(), symtable_params(),
symtable_global(), symtable_list_comprehension():

    Conversion of sprintf() to PyOS_snprintf() for buffer overrun
    avoidance.
2001-11-28 21:10:39 +00:00
Jeremy Hylton 518ab1c02a Use PyOS_snprintf instead of sprintf. 2001-11-28 20:42:20 +00:00
Jeremy Hylton ef58b31991 Use PyOS_snprintf instead of sprintf.
Also replace a switch statement with one case and a default to an
if/else.
2001-11-28 20:37:25 +00:00
Jeremy Hylton 23ae987401 Use PyOS_snprintf when possible. 2001-11-28 20:29:22 +00:00
Jeremy Hylton 05bd787c6c Use PyOS_snprintf instead of sprintf.
Just being sure.  The old code looks like it was safe, but there's no
harm in double-checking.
2001-11-28 20:24:33 +00:00
Marc-André Lemburg d4c0a9c59b Fixes for possible buffer overflows in sprintf() usages. 2001-11-28 11:47:00 +00:00
Tim Peters b13680bf03 SF bug #483469: crash on unbounded recursion in __del__.
PyEval_EvalCodeEx():  increment tstate->recursion_depth around the
decref of the frame, because the C stack for this call is still in
use and the decref can lead to __del__ methods getting called.

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

Bugfix candidate.
2001-11-27 23:29:29 +00:00
Tim Peters 6d20b43a4e SF bug 485175: buffer overflow in traceback.c.
Bugfix candidate.
tb_displayline():  the sprintf format was choking off the file name, but
used plain %s for the function name (which can be arbitrarily long).
Limit both to 500 chars max.
2001-11-27 20:30:42 +00:00
Marc-André Lemburg 0c4d8d05a8 Fix for bug #480188: printing unicode objects 2001-11-20 15:17:25 +00:00
Tim Peters 36515e28ed Since the MAGIC number scheme is going to break on January 1st, document
what it is more carefully and point out some of the subtleties.
2001-11-18 04:06:29 +00:00
Barry Warsaw afeb2a4d89 PyOS_getsig(), PyOS_setsig(): The minimal amount of work to avoid the
uninitialized memory reads reported in bug #478001.

Note that this doesn't address the following larger issues:

- Error conditions are not documented for PyOS_*sig() in the C API.

- Nothing that actually calls PyOS_*sig() in the core interpreter and
  extension modules actually /checks/ the return value of the call.

Fixing those is left as an exercise for a later day.
2001-11-13 23:08:26 +00:00
Jeremy Hylton 9f64caaf00 Use PyObject_CheckReadBuffer(). 2001-11-09 22:02:48 +00:00
Martin v. Löwis 107b7daf5a Include sys_getdefaultencoding in #ifdef Py_USING_UNICODE. Fixes #479571. 2001-11-09 20:59:39 +00:00
Jeremy Hylton 778e265462 Fix SF buf #480096: Assign to __debug__ still allowed
Easy enough to catch assignment in the compiler.  The perverse user
can still change the value of __debug__, but that may be the least he
can do.
2001-11-09 19:50:08 +00:00
Fred Drake 03459a5cd7 Fix memory leak. This is part of SF patch #478006. 2001-11-09 16:00:41 +00:00
Marc-André Lemburg 4962fc8fed Backing out the fast path for interned string compares again as requested. 2001-11-08 08:34:43 +00:00
Marc-André Lemburg c52d713b7a Add fast-path for comparing interned (true) string objects.
This patch boosts performance for comparing identical string object
by some 20% on my machine while not causing any noticable slow-down
for other operations (according to tests done with pybench).
2001-11-07 14:54:49 +00:00
Jack Jansen 537a69fe66 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me. 2001-11-05 14:39:22 +00:00
Tim Peters 603c6831d0 SF patch 473749 compile under OS/2 VA C++, from Michael Muller.
Changes enabling Python to compile under OS/2 Visual Age C++.
2001-11-05 02:45:59 +00:00
Tim Peters 8c5e41559c Part of SF bug #478003 possible memory leaks in err handling.
PyNode_CompileSymtable:  if symtable_init() fails, free the memory
allocated for the PyFutureFeatures struct.
2001-11-04 19:26:58 +00:00
Jack Jansen 666b1e7e2f Link the core with CoreServices, not with Carbon, and don't use any Carbon
routines. As of 10.1 using Carbon will crash Python if no window server is
available (ssh connection, console mode, MacOSX Server). This fixes bug
#466907.

A result of this mod is that the default 8bit encoding on OSX is now ASCII,
for the time being. Also, the extension modules that need the Carbon
framework now explicitly include it in setup.py.
2001-10-31 12:11:48 +00:00
Tim Peters a6ca4f40d0 SF patch #474500: Make OS/2 locks work like posix locks, from Michael
Muller.
2001-10-31 03:50:45 +00:00
Jack Jansen 550fdae2f5 On the macintosh don't take a quick exit in find_module() for frozen submodule imports: the frozen import goes through a different mechanism. 2001-10-30 13:08:39 +00:00
Tim Peters a427a2b8d0 Rename "dictionary" (type and constructor) to "dict". 2001-10-29 22:25:45 +00:00
Tim Peters c2f011201a vgetargskeywords()
+ Squash another potential buffer overrun.
+ Simplify the keyword-arg loop by decrementing the count of keywords
  remaining instead of incrementing Yet Another Variable; also break
  out early if the number of keyword args remaining hits 0.

Since I hit the function's closing curly brace with this patch, that's
enough of this for now <wink>.
2001-10-27 07:25:06 +00:00
Tim Peters b639d49798 vgetargskeywords: Now that it's clear that nkwlist must equal max, and
we're ensuring that's true during the format parse, get rid of nkwlist.
2001-10-27 07:00:56 +00:00
Tim Peters dc5eff9170 vgetargskeywords: Prevent another potential sprintf buffer overrun. 2001-10-27 06:53:00 +00:00
Tim Peters 62d48e1735 vgetargskeywords: Verify kwlist has the required length while parsing
the format, instead of waiting until after we can overindex it by
mistake.
2001-10-27 06:42:16 +00:00
Tim Peters 0af4916ad4 vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
this routine will report an error now when it didn't before, but, if so,
it's a legitimate error that should never have been suppressed.
2001-10-27 06:14:32 +00:00
Tim Peters 077f574db1 vgetargskeywords: The keywords arg is a dict (if non-NULL), so use the
dict API everywhere on it instead of sometimes using the slower mapping
API.
2001-10-27 05:50:39 +00:00
Tim Peters 61dde63e3b vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.
The "need" for this was probably removed by an earlier patch that stopped
the loop right before it from passing NULL to a dict lookup routine.
I still haven't convinced myself that the next loop is correct, so am
leaving the next mysterious PyErr_Clear() call in for now.
2001-10-27 05:30:17 +00:00
Tim Peters b054be41c0 vgetargskeywords:
+ Generally test nkeywords against 0 instead of keywords against NULL
  (saves a little work if an empty keywords dict is passed, and is
  conceptually more on-target regardless).
+ When a call erroneously specifies a keyword argument both by position
  and by keyword name:
    - It was easy to provoke this routine into an internal buffer overrun
      by using a long argument name.  Now uses PyErr_format instead (which
      computes a safe buffer size).
    - Improved the error msg.
2001-10-27 05:07:41 +00:00
Tim Peters b0872fc8a6 vgetargskeywords:
+ Got rid of now-redundant dict typecheck.
+ Renamed nkwds to nkwlist.  Now all the "counting" vrbls have names
  related to the things they're counting in an obvious way.
2001-10-27 04:45:34 +00:00
Tim Peters 6fb2635f25 vgetargskeywords:
+ Renamed argslen to nargs.
+ Renamed kwlen to nkeywords.  This one was especially confusing because
  kwlen wasn't the length of the kwlist argument, but of the keywords
  argument.
2001-10-27 04:38:11 +00:00
Tim Peters 28bf7a9770 vgetargskeywords:
+ Removed now-redundant tuple typecheck.
+ Renamed "tplen" local to "argslen" (it's the length of the "args"
  argument; I suppose "tp" was for "Tim Peters should rename me
  someday <wink>).
2001-10-27 04:33:41 +00:00
Tim Peters f8cd3e8621 PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
introduced this bug just a little while ago, when *adding* internal error
checks).

vgetargskeywords:  Rewrote the section that crawls over the format string.
+ Added block comment so it won't take the next person 15 minutes to
  reverse-engineer what it's doing.
+ Lined up the "else" clauses.
+ Rearranged the ifs in decreasing order of likelihood (for speed).
2001-10-27 04:26:57 +00:00
Tim Peters 45772cde7e PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
and raise an error if they're insane.
vgetargskeywords:  the same, except that since this is an internal routine,
just assert that the arguments are sane.
2001-10-27 03:58:40 +00:00
Tim Peters a9f4739a1b tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
the kwlist vector whenever there was a mix of positional and keyword
arguments, and the number of positional arguments exceeded the length
of the kwlist vector.  If there was just one more positional arg than
keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString,
which set an internal error that vgetargskeywords() then squashed (but
it's impossible to say whether it knew it was masking an error).  If
more than one more positional argument, it went on to pass random trash
to PyMapping_HasKeyString, which is why the example at the start
happened to kill the process.

Pure bugfix candidate.
2001-10-27 00:46:09 +00:00
Tim Peters f4331c1c38 vgetargskeywords(): remove test that can't succeed. Not a bugfix, just
removing useless obfuscation.
2001-10-27 00:17:34 +00:00
Fred Drake 9cd0efcee9 Use PyDict_Copy() and PyDict_Update() instead of using PyObject_CallMethod()
to call the corresponding methods.  This is not a performance improvement
since the times are still swamped by disk I/O, but cleans up the code just
a little.
2001-10-25 21:38:59 +00:00
Fred Drake a768882b00 Convert getrefcount() to METH_O, and sys_excepthook() to use
PyArg_UnpackTuple().
2001-10-24 20:47:48 +00:00
Guido van Rossum e2ae77b8b8 SF patch #474590 -- RISC OS support 2001-10-24 20:42:55 +00:00
Fred Drake e4616e6752 PyArg_UnpackTuple(): New argument unpacking function suggested by Jim
Fulton, based on code Jim supplied.
2001-10-23 21:09:29 +00:00
Fred Drake 563dfc2f73 Style conformance: function name begins a new line *consistently*.
Make convertbuffer() static like the prototype says.  Not used elsewhere.
2001-10-23 14:41:08 +00:00
Jeremy Hylton fd14d8e187 Make traceback objects collectable.
This should eliminate the traceback returned by sys.exc_info() as a
common source of memory leaks.
2001-10-22 22:17:41 +00:00
Tim Peters d7c3652aa7 Removed two pointless and obfuscating macros. 2001-10-22 19:34:09 +00:00
Guido van Rossum b8cf3e64be SF patch #470393 (Jim Ahlstrom): Add missing marshal function
In Include/, marshal.h declares both
    PyMarshal_ReadLongFromFile()
    and PyMarshal_ReadShortFromFile(),
    but the second is missing from marshal.c.

[Shouldn't the return type be declared as 'short' instead of 'int'?
But 'int' is what was in marshal.h all those years...  --Guido]
2001-10-19 01:46:21 +00:00
Martin v. Löwis 8a57f00081 Move dlfcn.h block out of NetBSD block, assuming that NetBSD before
199712 didn't have dlfcn.h, or that it wouldn't conflict with the other
stuff defined.
2001-10-18 21:24:04 +00:00
Tim Peters 6e6a63f01c SF Patch (but with no patch) 472555 Remove trailing common in enumeration.
Some AIX compiler didn't like the trailing comma at the end of the
why_code enum decl.
2001-10-18 20:49:35 +00:00
Tim Peters 84a0657ee9 Squash compiler wng about signed/unsigned mismatch. 2001-10-18 18:57:31 +00:00
Guido van Rossum 8f4d3316de First part of SF patch #416704: More robust freeze, by Toby Dickenson.
This fixes the behavior reported by SF bug #404545, where a file
x.y.py could be imported by the statement "import x.y" when there's a
frozen package x (I believe even if x.y also exists as a frozen
module).
2001-10-18 18:54:11 +00:00
Guido van Rossum 4114a4afec Fix the frozen bytecode for __hello__ (betcha didn't know that existed
:-).

Add a test that prevents the __hello__ bytecode from going stale
unnoticed again.

The test also tests the loophole noted in SF bug #404545.  This test
will fail right now; I'll check in the fix in a minute.
2001-10-18 18:49:37 +00:00
Jeremy Hylton 961dfe0d85 Fix for SF bug [ #471928 ] global made w/nested list comprehensions
The symbol table pass didn't have an explicit case for the list_iter
node which is used only for a nested list comprehension.  As a result,
the target of the list comprehension was treated as a use instead of
an assignment.  Fix is to add a case to symtable_node() to handle
list_iter.

Also, rework and document a couple of the subtler implementation
issues in the symbol table pass.  The symtable_node() switch statement
depends on falling through the last several cases, in order to handle
some of the more complicated nodes like atom.  Add a comment
explaining the behavior before the first fall through case.  Add a
comment /* fall through */ at the end of case so that it is explicitly
marked as such.

Move the for_stmt case out of the fall through logic, which simplifies
both for_stmt and default.  (The default used the local variable start
to skip the first three nodes of a for_stmt when it fell through.)

Rename the flag argument to symtable_assign() to def_flag and add a
comment explaining its use:

   The third argument to symatble_assign() is a flag to be passed to
   symtable_add_def() if it is eventually called.  The flag is useful
   to specify the particular type of assignment that should be
   recorded, e.g. an assignment caused by import.
2001-10-18 16:15:10 +00:00
Martin v. Löwis 0eb1ed556b Patch to bug #472202: Correctly recognize NetBSD before 199712. 2001-10-18 11:45:19 +00:00
Jeremy Hylton 14368158c2 For debug build, check that the stack pointer never exceeds the stack size. 2001-10-17 13:29:30 +00:00
Jeremy Hylton 93a569d634 Fix computation of stack depth for classdef and closures.
Also minor tweaks to internal routines.
Use PyCF_MASK instead of explicit list of flags.

For the MAKE_CLOSURE opcode, the number of items popped off the stack
depends on both the oparg and the number of free variables for the
code object.  Fix the code so it accounts for the free variables.

In com_classdef(), record an extra pop to account for the STORE call
after the BUILD_CLASS.

Get rid of some commented out debugging code in com_push() and
com_pop().

Factor string resize logic into helper routine com_check_size().

In com_addbyte(), remove redudant if statement after assert.  (They
test the same condition.)

In several routines, use string macros instead of string functions.
2001-10-17 13:22:22 +00:00
Guido van Rossum 2c40adb1e4 Fix a bug in the previous checkin. The wrong bootstrap function was
passed to _beginthread().
2001-10-16 21:50:04 +00:00
Guido van Rossum d892357bf7 SF patch #471852 (anonymous) notes that getattr(obj, name, default)
masks any exception, not just AttributeError.  Fix this.
2001-10-16 21:31:32 +00:00
Guido van Rossum 3c28863e08 Partial patch from SF #452266, by Jason Petrone.
This changes Pythread_start_thread() to return the thread ID, or -1
for an error.  (It's technically an incompatible API change, but I
doubt anyone calls it.)
2001-10-16 21:13:49 +00:00
Guido van Rossum ae9e7960d3 SF patch #471839: Bug when extensions import extensions (Shane Hathaway)
When an extension imports another extension in its
    initXXX() function, the variable _Py_PackageContext is
    prematurely reset to NULL. If the outer extension then
    calls Py_InitModule(), the extension is installed in
    sys.modules without its package name. The
    manifestation of this bug is a "SystemError:
    _PyImport_FixupExtension: module <package>.<extension>
    not loaded".

    To fix this, importdl.c just needs to retain the old
    value of _Py_PackageContext and restore it after the
    initXXX() method is called. The attached patch does this.

    This patch applies to Python 2.1.1 and the current CVS.
2001-10-16 20:07:34 +00:00
Jeremy Hylton 26633f4c00 Put descr name in "bad memberdescr type" error message. 2001-10-16 16:51:56 +00:00
Skip Montanaro f118cb1d6f make getarray static - it's only called from ceval.c and is not an
extern-able name.
2001-10-15 20:51:38 +00:00
Guido van Rossum 1c917072ca Very subtle syntax change: in a list comprehension, the testlist in
"for <var> in <testlist> may no longer be a single test followed by
a comma.  This solves SF bug #431886.  Note that if the testlist
contains more than one test, a trailing comma is still allowed, for
maximum backward compatibility; but this example is not:

    [(x, y) for x in range(10), for y in range(10)]
                              ^

The fix involved creating a new nonterminal 'testlist_safe' whose
definition doesn't allow the trailing comma if there's only one test:

    testlist_safe: test [(',' test)+ [',']]
2001-10-15 15:44:05 +00:00
Martin v. Löwis 69c0ff3836 Do not define _POSIX_THREADS if unistd.h defines it.
Check for pthread_sigmask before using it. Fixes remaining problem in #470781.
2001-10-15 14:34:42 +00:00
Fred Drake de26cfc1e1 Suppress a bunch of "value computed is not used" warnings when building in
debug mode (--with-pydebug).
2001-10-13 06:11:28 +00:00
Guido van Rossum 9abaf4d3b7 SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
This patch changes to logic to:

   if env.var. set and non-empty:
       if env.var. is an integer:
           set flag to that integer
   if flag is zero: # [actually, <= 0 --GvR]
       set flag to 1

   Under this patch, anyone currently using
   PYTHONVERBOSE=yes will get the same output as before.

   PYTHONVERBNOSE=2 will generate more verbosity than
   before.

   The only unusual case that the following three are
   still all equivalent:
   PYTHONVERBOSE=yespleas
   PYTHONVERBOSE=1
   PYTHONVERBOSE=0
2001-10-12 22:17:56 +00:00
Guido van Rossum 80230998b9 Add SF patch #468347 -- mask signals for non-main pthreads, by Jason Lowe:
This patch updates Python/thread_pthread.h to mask all
   signals for any thread created. This will keep all
   signals masked for any thread that isn't the initial
   thread. For Solaris and Linux, the two platforms I was
   able to test it on, it solves bug #465673 (pthreads
   need signal protection) and probably will solve bug
   #219772 (Interactive InterPreter+ Thread -> core dump
   at exit).

   I'd be great if this could get some testing on other
   platforms, especially HP-UX pre 11.00 and post 11.00,
   as I had to make some guesses for the DCE thread case.
   AIX is also a concern as I saw some mention of using
   sigthreadmask() as a pthread_sigmask() equivalent, but
   this patch doesn't use sigthreadmask(). I don't have
   access to AIX.
2001-10-12 21:49:17 +00:00
Jeremy Hylton 4819e97a48 Undo part of 2.59: 't' case of convertsimple() should not use convertbuffer().
convertbuffer() uses the buffer interface's getreadbuffer(), but 't'
should use getcharbuffer().
2001-10-11 14:40:37 +00:00
Jeremy Hylton 0407aeae01 One more place where PyString_AsString() was used after a
PyString_Check() had already succeeded.
2001-10-10 02:51:57 +00:00
Jeremy Hylton a4c8cd7b2c Use AS_STRING() following the check and avoid an extra call. 2001-10-10 02:51:08 +00:00
Guido van Rossum 03290ecbf1 Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,
not other sequences (then we'd have to except strings, and we'd still
be susceptible to recursive attacks).
2001-10-07 20:54:12 +00:00
Fred Drake bb9fa21cfe weakref.ReferenceError becomes a built-in exception now that weak ref objects
are moving into the core; with these changes, it will be possible for the
exception to be raised without the weakref module ever being imported.
2001-10-05 21:50:08 +00:00
Tim Peters b1c469843f Introduced the oddly-missing PyList_CheckExact(), and used it to replace
a hard-coded type check.
2001-10-05 20:41:38 +00:00
Tim Peters c1e6d969ba Get rid of unique local ISSTRICTINT macro in favor of std PyInt_CheckExact. 2001-10-05 20:21:03 +00:00
Fred Drake 4ec5d5699d Fix bug in profiler modifications detected only in debug builds.
The new profiler event stream includes a "return" event even when an
exception is being propogated, but the machinery that called the profile
hook did not save & restore the exception.  In debug mode, the exception
was detected during the execution of the profile callback, which did not
have the proper internal flags set for the exception.  Saving & restoring
the exception state solves the problem.
2001-10-04 19:26:43 +00:00
Greg Ward 201baee7ea Remove a couple of unused local variables (bug #445960, compiler warnings
on IRIX 6.5).
2001-10-04 14:52:06 +00:00
Fred Drake 8f51f54319 Rationalize the events passed to the profiler (no changes for the tracer).
The profiler does not need to know anything about the exception state,
so we no longer call it when an exception is raised.  We do, however,
make sure we *always* call the profiler when we exit a frame.  This
ensures that timing events are more easily isolated by a profiler and
finally clauses that do a lot of work don't have their time
mis-allocated.

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

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

sysmodule.c:profile_trampoline():  Make sure we don't expose Python
                                   code to NULL; use None instead.
2001-10-04 14:48:42 +00:00
Tim Peters c15c4f1f39 SF bug [#467265] Compile errors on SuSe Linux on IBM/s390.
Unknown whether this fixes it.
- stringobject.c, PyString_FromFormatV:  don't assume that va_list is of
  a type that can be copied via an initializer.
- errors.c, PyErr_Format:  add a va_end() to balance the va_start().
2001-10-02 21:32:07 +00:00
Tim Peters 8b13b3ede2 SF bug [#466173] unpack TypeError unclear
Replaced 3 instances of "iter() of non-sequence" with
"iteration over non-sequence".
Restored "unpack non-sequence" for stuff like "a, b = 1".
2001-09-30 05:58:42 +00:00
Jeremy Hylton e2e2c9f41e PyErr_NormalizeException()
If a new exception occurs while an exception instance is being
created, try harder to make sure there is a traceback.  If the
original exception had a traceback associated with it and the new
exception does not, keep the old exception.

Of course, callers to PyErr_NormalizeException() must still be
prepared to have tb set to NULL.

XXX This isn't an ideal solution, but it's better than no traceback at
all.  It occurs if, for example, the exception occurs when the call to
the constructor fails before any Python code is executed.  Guido
suggests that it there is Python code that was about to be executed
-- but wasn't, say, because it was called with the wrong number of
arguments -- then we should point at the first line of the code object
anyway.
2001-09-26 19:58:38 +00:00
Jeremy Hylton c631489289 Prevent a NULL pointer from being pushed onto the stack.
It's possible for PyErr_NormalizeException() to set the traceback
pointer to NULL.  I'm not sure how to provoke this directly from
Python, although it may be possible.  The error occurs when an
exception is set using PyErr_SetObject() and another exception occurs
while PyErr_NormalizeException() is creating the exception instance.

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

This fixes SF bugs #463359 and #462937, and possibly other, *very* obscure
bugs with very deeply nested loops that continue the loop and then break out
of it or raise an exception.
2001-09-24 19:32:01 +00:00
Guido van Rossum 6f7993765a Add optional docstrings to member descriptors. For backwards
compatibility, this required all places where an array of "struct
memberlist" structures was declared that is referenced from a type's
tp_members slot to change the type of the structure to PyMemberDef;
"struct memberlist" is now only used by old code that still calls
PyMember_Get/Set.  The code in PyObject_GenericGetAttr/SetAttr now
calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef
argument.

As examples, I added actual docstrings to the attributes of a few
types: file, complex, instance method, super, and xxsubtype.spamlist.

Also converted the symtable to new style getattr.
2001-09-20 20:46:19 +00:00
Guido van Rossum c299fc16f2 Add support for restricting access based on restricted execution mode.
Renamed the 'readonly' field to 'flags' and defined some new flag
bits: READ_RESTRICTED and WRITE_RESTRICTED, as well as a shortcut
RESTRICTED that means both.
2001-09-17 19:28:08 +00:00
Jeremy Hylton c785f4841c Supply code objects a new-style tp_members slot and tp_getattr impl.
The chief effects are to make dir() do something useful and supply
them with an __class__.
2001-09-14 20:08:07 +00:00
Tim Peters 742dfd6f17 Get rid of builtin_open() entirely (the C code and docstring, not the
builtin function); Guido pointed out that it could be just another
name in the __builtin__ dict for the file constructor now.
2001-09-13 21:49:44 +00:00
Tim Peters 4b7625ee83 _PyBuiltin_Init(): For clarity, macroize this purely repetitive code. 2001-09-13 21:37:17 +00:00
Fred Drake b9a96282f1 Admit that we'll never add the args for a "call" event to the profile
and trace functions; this now declares that None will be passed for the
"call" event.
This closes SF bug/suggestion #460315.
2001-09-13 16:56:43 +00:00
Tim Peters 59c9a645e2 SF bug [#460467] file objects should be subclassable.
Preliminary support.  What's here works, but needs fine-tuning.
2001-09-13 05:38:56 +00:00
Guido van Rossum 7851eea5f2 build_class(): one more (hopefully the last) step on the way to
backwards compatibility.  When using the class of the first base as
the metaclass, use its __class__ attribute in preference over its
ob_type slot.  This ensures that we can still use classic classes as
metaclasse, as shown in the original "Metaclasses" essay.  This also
makes all the examples in Demo/metaclasses/ work again (maybe these
should be turned into a test suite?).
2001-09-12 19:19:18 +00:00
Jack Jansen 697842f58c Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
parameter for the return string (as unix pathnames are not limited
by the 255 char pstring limit).
Implemented the function for MachO-Python, where it returns unix pathnames.
2001-09-10 22:00:39 +00:00
Guido van Rossum d0b69eceb4 Improve threading on Solaris, according to SF patch #460269, submitted
by bbrox@bbrox.org / lionel.ulmer@free.fr.

This adds a configure check and if all goes well turns on the
PTHREAD_SCOPE_SYSTEM thread attribute for new threads.

This should remove the need to add tiny sleeps at the start of threads
to allow other threads to be scheduled.
2001-09-10 14:10:54 +00:00
Jeremy Hylton 77b8b67919 Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Reported by Fredrik Lundh on python-dev.

The conversimple() code that handles Unicode arguments and converts
them to the default encoding now calls converterr() with the original
Unicode argument instead of the NULL returned by the failed encoding
attempt.
2001-09-10 01:54:43 +00:00
Tim Peters 51e2651b29 SF bug [#458941] Looks like a unary minus bug.
com_factor():  when a unary minus is attached to a float or imaginary zero,
don't optimize the UNARY_MINUS opcode away:  the const dict can't
distinguish between +0.0 and -0.0, so ended up treating both like the
first one added to it.  Optimizing UNARY_PLUS away isn't a problem.

(BTW, I already uploaded the 2.2a3 Windows installer, and this isn't
important enough to delay the release.)
2001-09-07 08:45:55 +00:00
Guido van Rossum 8bce4acb17 Rename 'getset' to 'property'. 2001-09-06 21:56:42 +00:00
Martin v. Löwis 36546db750 Patch #455231: Support ELF properly on OpenBSD. 2001-09-05 14:24:43 +00:00
Guido van Rossum b3a639ed7d builtin_execfile(): initialize another local that the GCC on leroy
found it necessary to warn about.
2001-09-05 13:37:47 +00:00
Tim Peters 7eea37e831 At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
__builtin__.dir().  Moved the guts from bltinmodule.c to object.c.
2001-09-04 22:08:56 +00:00
Neil Schemenauer 6c0f20088f Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
way it's called each time a generator is resumed.  The tracing of normal
functions should be unaffected by this change.
2001-09-04 19:03:35 +00:00
Tim Peters 37a309db70 builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
of PyMapping_Keys because we know we have a real dict.  Tolerate that
objects may have an attr named "__dict__" that's not a dict (Py_None
popped up during testing).

test_descr.py, test_dir():  Test the new classic-class behavior; beef up
the new-style class test similarly.

test_pyclbr.py, checkModule():  dir(C) is no longer a synonym for
C.__dict__.keys() when C is a classic class (looks like the same thing
that burned distutils! -- should it be *made* a synoym again?  Then it
would be inconsistent with new-style class behavior.).
2001-09-04 01:20:04 +00:00
Tim Peters 5d2b77cf31 Make dir() wordier (see the new docstring). The new behavior is a mixed
bag.  It's clearly wrong for classic classes, at heart because a classic
class doesn't have a __class__ attribute, and I'm unclear on whether
that's feature or bug.  I'll repair this once I find out (in the
meantime, dir() applied to classic classes won't find the base classes,
while dir() applied to a classic-class instance *will* find the base
classes but not *their* base classes).

Please give the new dir() a try and see whether you love it or hate it.
The new dir([]) behavior is something I could come to love.  Here's
something to hate:

>>> class C:
...     pass
...
>>> c = C()
>>> dir(c)
['__doc__', '__module__']
>>>

The idea that an instance has a __doc__ attribute is jarring (of course
it's really c.__class__.__doc__ == C.__doc__; likewise for __module__).

OTOH, the code already has too many special cases, and dir(x) doesn't
have a compelling or clear purpose when x isn't a module.
2001-09-03 05:47:38 +00:00
Jack Jansen fabd00fa91 Added glue routine for PyMac_BuildFSSpec, PyMac_GetFSRef and PyMac_BuildFSRef.
Moved the declarations to pymactoolbox.h.
2001-09-01 23:39:58 +00:00
Guido van Rossum 393661d15f Add warning mode for classic division, almost exactly as specified in
PEP 238.  Changes:

- add a new flag variable Py_DivisionWarningFlag, declared in
  pydebug.h, defined in object.c, set in main.c, and used in
  {int,long,float,complex}object.c.  When this flag is set, the
  classic division operator issues a DeprecationWarning message.

- add a new API PyRun_SimpleStringFlags() to match
  PyRun_SimpleString().  The main() function calls this so that
  commands run with -c can also benefit from -Dnew.

- While I was at it, I changed the usage message in main() somewhat:
  alphabetized the options, split it in *four* parts to fit in under
  512 bytes (not that I still believe this is necessary -- doc strings
  elsewhere are much longer), and perhaps most visibly, don't display
  the full list of options on each command line error.  Instead, the
  full list is only displayed when -h is used, and otherwise a brief
  reminder of -h is displayed.  When -h is used, write to stdout so
  that you can do `python -h | more'.

Notes:

- I don't want to use the -W option to control whether the classic
  division warning is issued or not, because the machinery to decide
  whether to display the warning or not is very expensive (it involves
  calling into the warnings.py module).  You can use -Werror to turn
  the warnings into exceptions though.

- The -Dnew option doesn't select future division for all of the
  program -- only for the __main__ module.  I don't know if I'll ever
  change this -- it would require changes to the .pyc file magic
  number to do it right, and a more global notion of compiler flags.

- You can usefully combine -Dwarn and -Dnew: this gives the __main__
  module new division, and warns about classic division everywhere
  else.
2001-08-31 17:40:15 +00:00
Fred Drake 14ef244dfe When re-writing a factor containing a unary negation of a literal, only
affect nodes without another operator.  This was causing negated
exponentiations to drop the exponentiation.  This closes SF bug #456756.
2001-08-30 18:53:25 +00:00
Guido van Rossum 46add98758 Do the int inlining only if the type is really an int, not whenever
PyInt_Check() succeeds.  That returns true for subtypes of int, which
may override __add__ or __sub__.
2001-08-30 16:06:23 +00:00
Michael W. Hudson 8019913e4a fix for part of bug #453523: disable unmarshalling of code objects in
restricted execution mode.
2001-08-30 14:50:20 +00:00
Sjoerd Mullender a2c2ae62df Removed unreachable goto statement to silence SGI compiler. 2001-08-30 14:06:45 +00:00
Sjoerd Mullender 2f38f81fec Removed some unreachable break statements to silence SGI compiler. 2001-08-30 14:05:20 +00:00
Tim Peters 692323488b Add a new function imp.lock_held(), and use it to skip test_threaded_import
when that test is doomed to deadlock.
2001-08-30 05:16:13 +00:00
Tim Peters 79248aa1e4 SF bug [#456252] Python should never stomp on [u]intptr_t.
pyport.h:  typedef a new Py_intptr_t type.
    DELICATE ASSUMPTION:  That HAVE_UINTPTR_T implies intptr_t is
    available as well as uintptr_t.  If that turns out not to be
    true, things must get uglier (C99 wants both, so I think it's
    an assumption we're *likely* to get away with).
thread_nt.h, PyThread_start_new_thread:  MS _beginthread is documented
    as returning unsigned long; no idea why uintptr_t was being used.
Others:  Always use Py_[u]intptr_t, never [u]intptr_t directly.
2001-08-29 21:37:10 +00:00
Jack Jansen c51395d797 GUSI on the Mac creates threads with a default stack size of 20KB, which is
not enough for Python. Increased the stacksize to a (somewhat arbitrary)
64KB.
2001-08-29 15:24:53 +00:00
Tim Peters 8211237db8 marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
ints, convert to PyLong (rather than throwing away the high-order 32 bits).
2001-08-29 02:28:42 +00:00
Guido van Rossum cbfc855f57 The "O!" format code should implement an isinstance() test
rather than a type equality test.
2001-08-28 16:37:51 +00:00
Jeremy Hylton 71b6af91d3 If an integer constant can't be generated from an integer literal
because of overflow, generate a long instead.
2001-08-27 19:45:25 +00:00
Jack Jansen 06bd3234cb Refer to the toolbox modules by their official name (Carbon.AE), not the internal name (_AE). This can slow things down (once) but it's the only way I can get things to work on OSX, OS9 dynamically loaded and OS9 frozen. 2001-08-27 14:01:05 +00:00
Barry Warsaw 876c8cb597 PyErr_Format(): Factor out most of this code into
PyString_FromFormat() since it's much more generally useful than
    just for exceptions.
2001-08-24 18:35:23 +00:00
Guido van Rossum f5cb357468 Add 'super' builtin type. 2001-08-24 16:52:18 +00:00
Guido van Rossum 29a62dd6eb Add new built-in type 'getset' (PyGetSet_Type).
This implements the 'getset' class from test_binop.py.
2001-08-23 21:40:38 +00:00
Jack Jansen 3cbf6d9d6e Mac toolbox modules have gotten an _ prepended to their name. 2001-08-23 13:53:34 +00:00
Guido van Rossum 87780dfa97 When an inlined operation on two small ints causes overflow, don't
raise the exception here -- call the generic function (which may
convert the arguments to long and try again).
2001-08-23 02:58:07 +00:00
Guido van Rossum ae347b33be Introduce OverflowWarning -- to be issued when short int operations
are overflowing and a long int operation is substituted.
2001-08-23 02:56:07 +00:00
Jeremy Hylton 1e35ce58e8 Fix SF bug [ #450245 ] Error in parsing future stmts
Check return value from future_parse() in for loop for file_input to
accomodate multiple future statements on separate lines.

Add several comments explaining how the code works.

Remove out-dated XXX comment.
2001-08-20 20:32:33 +00:00
Guido van Rossum 50d756e262 Fix SF bug #443600:
Change to get/set/del slice operations so that if the object doesn't
support slicing, *or* if either of the slice arguments is not an int
or long, we construct a slice object and call the get/set/del item
operation instead.  This makes it possible to design classes that
support slice arguments of non-integral types.
2001-08-18 17:43:36 +00:00
Tim Peters 9fa96bed6f Fix for bug [#452230] future division isn't propagated.
builtin_eval wasn't merging in the compiler flags from the current frame;
I suppose we never noticed this before because future division is the
first future-feature that can affect expressions (nested_scopes and
generators had only statement-level effects).
2001-08-17 23:04:59 +00:00
Tim Peters 6cd6a82db9 A fiddled version of the rest of Michael Hudson's SF patch
#449043 supporting __future__ in simulated shells
which implements PEP 264.
2001-08-17 22:11:27 +00:00
Tim Peters e2c18e90da ceval, PyEval_MergeCompilerFlags: wasn't merging in the
CO_FUTURE_DIVISION flag.  Redid this to use Jeremy's PyCF_MASK #define
instead, so we dont have to remember to fiddle individual feature names
here again.

pythonrun.h:  Also #define a PyCF_MASK_OBSOLETE mask.  This isn't used
yet, but will be as part of the PEP 264 implementation (compile() mustn't
raise an error just because old code uses a flag name that's become
obsolete; a warning may be appropriate, but not an error; so compile() has
to know about obsolete flags too, but nobody is going to remember to
update compile() with individual obsolete flag names across releases either
-- i.e., this is the flip side of PyEval_MergeCompilerFlags's oversight).
2001-08-17 20:47:47 +00:00
Martin v. Löwis 339d0f720e Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.
2001-08-17 18:39:25 +00:00
Martin v. Löwis e3eb1f2b23 Patch #427190: Implement and use METH_NOARGS and METH_O. 2001-08-16 13:15:00 +00:00
Guido van Rossum f6309e8ecf Oops. Two fixes for SF bug #422004 are not needed. :-) 2001-08-16 08:24:00 +00:00
Guido van Rossum 70d893a6aa Bunchathings:
- initsigs(): Ignore SIGXFZ so writing files beyond the file system
  size limit won't kill us.

- Py_Initialize(): call _Py_ReadyTypes() instead of readying types
  here.

- Py_Initialize(): call _PyImport_FixupExtension() for module
  "extensions".  (SF bug #422004.)
2001-08-16 08:21:42 +00:00
Jeremy Hylton 481081e369 Fix SF bug [ #450909 ] __future__.division fails at prompt
When code is compiled and compiler flags are passed in, be sure to
update cf_flags with any features defined by future statements in the
compiled code.
2001-08-14 20:01:59 +00:00
Barry Warsaw 928833891a Fixed typo in comment leading up to _PyImport_FixupExtension(). 2001-08-13 23:05:44 +00:00
Barry Warsaw 5821bc5145 Py_Initialize(): Apply patch by Jürgen Hermann to call
_PyImport_FixupExtension() on the exceptions module.  Now
    reload(exceptions) acts just like reload(sys) instead of raising
    an ImportError.

    This closes SF bug #422004.
2001-08-13 23:04:56 +00:00
Jeremy Hylton 910d7d46dc Remove much dead code from ceval.c
The descr changes moved the dispatch for calling objects from
call_object() in ceval.c to PyObject_Call() in abstract.c.
call_object() and the many functions it used in ceval.c were no longer
used, but were not removed.

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

Also, fix error message that referred to PyEval_EvalCodeEx() by its
old name eval_code2().  (I'll probably refer to it by its old name,
too.)
2001-08-12 21:52:24 +00:00
Jeremy Hylton d5e5a2aa28 SF Patch [ 429024 ] deal with some unary ops at compile time
Revised version of Fred's patch, including support for ~ operator.

If the unary +, -, or ~ operator is applied to a constant, don't
generate a UNARY_xxx opcode. Just store the approriate value as a
constant.  If the value is negative, extend the string containing the
constant and insert a negative in the 0th position.

For ~, compute the inverse of int and longs and use them directly, but
be prepared to generate code for all other possibilities (invalid
numbers, floats, complex).
2001-08-12 01:54:38 +00:00
Jack Jansen abce416e16 Patch by Jonathan Wight (slightly reformatted) to forestall loading the
same module twice, which apparently crashes Python. I could not test the
error condition, but in normal life it seems to have no adverse effects.

Also removed an unsued variable, and corrected 2 glaring errors (missing
'case' in front of a label).
2001-08-11 21:54:11 +00:00
Jeremy Hylton 1abf610b15 Remove st_nested_scopes from struct symtable,
because nested scopes are always enabled.

(Accidentally checked in one small change along this path yesterday,
wreaking havoc in the Windows build.)
2001-08-11 21:51:24 +00:00
Tim Peters ff1f8521ac st_nested_scopes was uninitialized trash. Jeremy should fix in a better
way; see code comments.
2001-08-11 01:06:35 +00:00
Jeremy Hylton b857ba261f Refactor future feature handling
Replace uses of PyCF_xxx with CO_xxx.

Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.

When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.
2001-08-10 21:41:33 +00:00
Guido van Rossum 92e2d5c7ae Apply SF patch #424554: check for PYTHONDUMPREFS to be set instead of
asking to print the references.
2001-08-09 16:37:16 +00:00
Jack Jansen d844a5f428 Got rid of unused includes. 2001-08-08 15:28:03 +00:00
Jack Jansen 94bebc0381 Split macglue.c into two: a new mactoolboxglue.c (in ./Python)
with functionality needed for both unix-Python and MacPython and a
new smaller ./Mac/Python/macglue.c which contains MacPython stuff only.

pymactoolbox.h has moved to ./Include from ./Mac/Include and now also
contains the relevant stuff from macglue.h.

The net effect of this is that the ./Mac subdirectory is not needed
anymore for building the unix-Python core on MacOSX (it is needed
for building the extension modules).
2001-08-08 13:17:31 +00:00
Martin v. Löwis 11d03c57de Put conditional S_IFMT definition into pyport.h. 2001-08-08 12:54:28 +00:00
Martin v. Löwis f9836ba4fe Put conditional S_ISDIR definition(s) into pyport.h. 2001-08-08 10:28:06 +00:00
Tim Peters 257b3bfa76 Repair the Windows build (S_ISDIR() macro doesn't exist).
Somebody else should feel free to repair this a different way; see Python-
Dev for discussion.
2001-08-08 06:24:48 +00:00
Martin v. Löwis 6b3a2c4a48 Patch #448227: Raise an exception when a directory is passed to execfile. 2001-08-08 05:30:36 +00:00
Guido van Rossum 4668b000a1 Implement PEP 238 in its (almost) full glory.
This introduces:

- A new operator // that means floor division (the kind of division
  where 1/2 is 0).

- The "future division" statement ("from __future__ import division)
  which changes the meaning of the / operator to implement "true
  division" (where 1/2 is 0.5).

- New overloadable operators __truediv__ and __floordiv__.

- New slots in the PyNumberMethods struct for true and floor division,
  new abstract APIs for them, new opcodes, and so on.

I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.

Not yet implemented are warnings (default off) when / is used with int
or long arguments.

This has been on display since 7/31 as SF patch #443474.

Flames to /dev/null.
2001-08-08 05:00:18 +00:00
Guido van Rossum 528b7eb0b0 - Rename PyType_InitDict() to PyType_Ready().
- Add an explicit call to PyType_Ready(&PyList_Type) to pythonrun.c
  (just for the heck of it, really -- we should either explicitly
  ready all types, or none).
2001-08-07 17:24:28 +00:00
Jeremy Hylton 6a53bd8582 Another bug fix for recent import * warning (caught by Thomas Wouters)
Only return if symtable_warn() returns -1, indicating that the warning
was turned into an error.
2001-08-06 20:34:25 +00:00
Jeremy Hylton ba591bf3bd Fix error message for import * in function/class scope 2001-08-06 19:55:17 +00:00
Jeremy Hylton 8a6f295303 Fix SF bug [ #445474 ] warn about import * inside functions
Reported by the Man himself.
2001-08-06 19:45:40 +00:00
Tim Peters c173137391 Derived from SF patch #446899 Permit import of .pyw under Windows, from
David Bolen.
2001-08-04 08:12:36 +00:00
Fred Drake 289898cdbb Plug a memory leak in Py_InitModule4(): when PyDict_SetItemString() failed,
the object being inserted was not being DECREFed.

This closes SF bug #444486.
2001-08-04 03:11:25 +00:00
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Tim Peters aa6111fc93 Add mysnprintf.c to Windows build, + squash compiler wngs in mysnprintf.c. 2001-07-31 22:10:29 +00:00
Marc-André Lemburg e5006ebc9d This patch turns the Python API mismatch notice into a standard
Python warning which can be catched by means of the Python warning
framework.

It also adds two new APIs which hopefully make it easier for Python
to switch to buffer overflow safe [v]snprintf() APIs for error
reporting et al. The two new APIs are PyOS_snprintf() and
PyOS_vsnprintf() and work just like the standard ones in many
C libs. On platforms which have snprintf(), the native APIs are used,
on all other an emulation with snprintf() tries to do its best.
2001-07-31 13:24:44 +00:00
Jeremy Hylton 302b54acd9 Do for hasattr() what was done for getattr()
Namely, an exception is raised if the second arg to hasattr() is not a
string or Unicode.
2001-07-30 22:45:19 +00:00
Jeremy Hylton 0eb1115f44 Fix for SF byg [ #420304 ] getattr function w/ default
Fix suggested by Michael Hudson: Raise TypeError if attribute name
passed to getattr() is not a string or Unicode.  There is some
unfortunate duplication of code between builtin_getattr() and
PyObject_GetAttr(), but it appears to be unavoidable.
2001-07-30 22:39:31 +00:00
Jeremy Hylton 3ce45389bd Add _PyUnicode_AsDefaultEncodedString to unicodeobject.h.
And remove all the extern decls in the middle of .c files.
Apparently, it was excluded from the header file because it is
intended for internal use by the interpreter.  It's still intended for
internal use and documented as such in the header file.
2001-07-30 22:34:24 +00:00
Jeremy Hylton 15c1c4f6d2 Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
If the code object has free variables, raise TypeError.
2001-07-30 21:50:55 +00:00
Tim Peters 76f373d081 Repair more now-obsolete references to config.h. 2001-07-26 21:34:59 +00:00
Marc-André Lemburg ae21df59c3 Undoing the UCS-4 patch addition which caused unichr() to return
surrogates for Unicode code points outside range(0x10000) on narrow
Python builds.
2001-07-26 16:29:25 +00:00
Martin v. Löwis 4f1cd8bdcb Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774. 2001-07-26 13:41:06 +00:00
Neil Schemenauer 7d4bb9f179 Add -E command line switch (ignore environment variables like PYTHONHOME
and PYTHONPATH).
2001-07-23 16:30:27 +00:00
Moshe Zadka 03897ea1f7 Patch number #422106 by Greg Ball, to fix segmentation
fault in sys.displayhook.

Please check this in on the 2.2a1 branch (or whatever is necessary
to get it working next release)
2001-07-23 13:32:43 +00:00
Guido van Rossum f48f11cd79 SF Patch #441791, with changes: when "import foo.bar" fails with an
exception in the execution of bar, ensure that foo.bar exists.
(Previously, while sys.modules['foo.bar'] would exist, foo.bar would
only be created upon successful execution of bar.  This is
inconvenient; some would say wrong. :-)
2001-07-23 13:27:49 +00:00
Guido van Rossum f5df46d701 Add a low-level API to access interpreters, for David Beazley.
SF patch #436376.
2001-07-19 12:19:27 +00:00
Martin v. Löwis f0473d511b Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Add dlopenflags to PyInterpreterState, and use it in dlopen calls.
2001-07-18 16:17:16 +00:00
Guido van Rossum b1a77dd248 Deleting zombies 2001-07-17 15:45:08 +00:00
Guido van Rossum e16c7aee4b jcompile(): inherit the CO_GENERATOR_ALLOWED flag from the 'base'
compiling struct.
2001-07-16 16:53:08 +00:00
Guido van Rossum a1b3a47406 PyRun_StringFlags(): forgot to pass the flags on to
PyParser_SimpleParseString().  Now calls
PyParser_SimpleParseStringFlags() with the correct flag.
2001-07-16 16:51:33 +00:00
Tim Peters fe2127d3cb Ugly. A pile of new xxxFlags() functions, to communicate to the parser
that 'yield' is a keyword.  This doesn't help test_generators at all!  I
don't know why not.  These things do work now (and didn't before this
patch):

1. "from __future__ import generators" now works in a native shell.

2. Similarly "python -i xxx.py" now has generators enabled in the
   shell if xxx.py had them enabled.

3. This program (which was my doctest proxy) works fine:

from __future__ import generators

source = """\
def f():
    yield 1
"""

exec compile(source, "", "single") in globals()
print type(f())
2001-07-16 05:37:24 +00:00
Tim Peters 51d76f1f75 future.c: insert a cosmetic space.
pythonrun.c, run_pyc_file():  repair semantic error wrt CO_GENERATOR vs
CO_GENERATOR_ALLOWED.
2001-07-16 03:11:48 +00:00
Tim Peters 5ba5866281 Part way to allowing "from __future__ import generators" to communicate
that info to code dynamically compiled *by* code compiled with generators
enabled.  Doesn't yet work because there's still no way to tell the parser
that "yield" is OK (unlike nested_scopes, the parser has its fingers in
this too).
Replaced PyEval_GetNestedScopes by a more-general
PyEval_MergeCompilerFlags.  Perhaps I should not have?  I doubted it was
*intended* to be part of the public API, so just did.
2001-07-16 02:29:45 +00:00
Guido van Rossum b09f7ed623 Preliminary support for "from __future__ import generators" to enable
the yield statement.  I figure we have to have this in before I can
release 2.2a1 on Wednesday.

Note: test_generators is currently broken, I'm counting on Tim to fix
this.
2001-07-15 21:08:29 +00:00
Neil Schemenauer f8c7c20ba5 GC for generator objects. 2001-07-12 13:27:49 +00:00
Thomas Wouters efafcea280 Re-add 'advanced' xrange features, adding DeprecationWarnings as discussed
on python-dev. The features will still vanish, however, just one release
later.
2001-07-09 12:30:54 +00:00
Guido van Rossum cfd829eefc Complete the xrange-simplification checkins: call PyRange_New() with
fewer arguments.
2001-07-05 14:44:41 +00:00
Tim Peters 0f9431fb18 SF bug #438295: [Windows] __init__.py cause strange behavior
Probable fix (the bug report doesn't have enough info to say for sure).
find_init_module():  Insist on a case-sensitive match for __init__ files.
Given __INIT__.PY instead, find_init_module() thought that was fine, but
the later attempt to do find_module("__INIT__.PY") didn't and its caller
silently suppressed the resulting ImportError.  Now find_init_module()
refuses to accept __INIT__.PY to begin with.
Bugfix candidate; specific to platforms with case-insensitive filesystems.
2001-07-05 03:47:53 +00:00
Fred Drake 9e3ad78444 This change adjusts the profiling/tracing support so that the common
path (with no profile/trace function) through eval_code2() and
eval_frame() avoids several checks.

In the common cases of calls, returns, and exception propogation,
eval_code2() and eval_frame() used to test two values in the
thread-state: the profiling function and the tracing function.  With
this change, a flag is set in the thread-state if either of these is
active, allowing a single check to suffice when both are NULL.  This
also simplifies the code needed when either function is in use but is
already active (to avoid profiling/tracing the profiler/tracer); the
flag is set to 0 when the profile/trace code is entered, allowing the
same check to suffice for "already in the tracer" for call/return/
exception events.
2001-07-03 23:39:52 +00:00
Tim Peters 08a898f85d Another "if 0:" hack, this time to complain about otherwise invisible
"return expr" instances in generators (which latter may be generators
due to otherwise invisible "yield" stmts hiding in "if 0" blocks).
This was fun the first time, but this has gotten truly ugly now.
2001-06-28 01:52:22 +00:00
Fred Drake 5755ce693d Revise the interface to the profiling and tracing support for the
Python interpreter.

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

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

As a side effect, SF bug #436058 is fixed; there is no longer a
_PyTrace_Init() function to declare.
2001-06-27 19:19:46 +00:00
Fredrik Lundh 8f4558583f use Py_UNICODE_WIDE instead of USE_UCS4_STORAGE and Py_UNICODE_SIZE
tests.
2001-06-27 18:59:43 +00:00
Martin v. Löwis ce9b5a55e1 Encode surrogates in UTF-8 even for a wide Py_UNICODE.
Implement sys.maxunicode.
Explicitly wrap around upper/lower computations for wide Py_UNICODE.
When decoding large characters with UTF-8, represent expected test
results using the \U notation.
2001-06-27 06:28:56 +00:00
Guido van Rossum 236d8b7974 Cosmetic changes to MvL's change to unichr():
- the correct range for the error message is range(0x110000);

- put the 4-byte Unicode-size code inside the same else branch as the
  2-byte code, rather generating unreachable code in the 2-byte case.

- Don't hide the 'else' behine the '}'.

(I would prefer that in 4-byte mode, any value should be accepted, but
reasonable people can argue about that, so I'll put that off.)
2001-06-26 23:12:25 +00:00
Tim Peters e77f2e2798 gen_getattr: make the gi_running and gi_frame members discoverable (but
not writable -- too dangerous!) from Python code.
2001-06-26 22:24:51 +00:00
Martin v. Löwis 0ba70cc3c8 Support using UCS-4 as the Py_UNICODE type:
Add configure option --enable-unicode.
Add config.h macros Py_USING_UNICODE, PY_UNICODE_TYPE, Py_UNICODE_SIZE,
                    SIZEOF_WCHAR_T.
Define Py_UCS2.
Encode and decode large UTF-8 characters into single Py_UNICODE values
for wide Unicode types; likewise for UTF-16.
Remove test whether sizeof Py_UNICODE is two.
2001-06-26 22:22:37 +00:00
Tim Peters d8e1c9e177 Add "gi_" (generator-iterator) prefix to names of genobject members.
Makes it much easier to find references via dumb editor search (former
"frame" in particular was near-hopeless).
2001-06-26 20:58:58 +00:00
Fredrik Lundh 0dcf67e56d more unicode tweaks: make unichr(0xdddddddd) behave like u"\Udddddddd"
wrt surrogates.  (this extends the valid range from 65535 to 1114111)
2001-06-26 20:01:56 +00:00
Fredrik Lundh 5b97935604 experimental UCS-4 support: don't assume that MS_WIN32 implies
HAVE_USABLE_WCHAR_T
2001-06-26 17:46:10 +00:00
Tim Peters b6c3ceae79 SF bug #436207: "if 0: yield x" is ignored.
Not anymore <wink>.  Pure hack.  Doesn't fix any other "if 0:" glitches.
2001-06-26 03:36:28 +00:00
Tim Peters ad1a18b78e Change the semantics of "return" in generators, as discussed on the
Iterators list and Python-Dev; e.g., these all pass now:

def g1():
    try:
        return
    except:
        yield 1
assert list(g1()) == []

def g2():
    try:
        return
    finally:
        yield 1
assert list(g2()) == [1]

def g3():
    for i in range(3):
        yield None
    yield None
assert list(g3()) == [None] * 4

compile.c:  compile_funcdef and com_return_stmt:  Just van Rossum's patch
to compile the same code for "return" regardless of function type (this
goes back to the previous scheme of returning Py_None).

ceval.c:  gen_iternext:  take a return (but not a yield) of Py_None as
meaning the generator is exhausted.
2001-06-23 06:19:16 +00:00
Tim Peters 5eb4b87ae6 gen_iternext(): Don't assume that the current thread state's frame is
not NULL.  I don't think it can be NULL from Python code, but if using
generators via the C API I expect a NULL frame is possible.
2001-06-23 05:47:56 +00:00
Tim Peters 8c96369513 PyFrameObject: rename f_stackbottom to f_stacktop, since it points to
the next free valuestack slot, not to the base (in America, stacks push
and pop at the top -- they mutate at the bottom in Australia <winK>).
eval_frame():  assert that f_stacktop isn't NULL upon entry.
frame_delloc():  avoid ordered pointer comparisons involving f_stacktop
when f_stacktop is NULL.
2001-06-23 05:26:56 +00:00
Tim Peters 95c80f8439 Disallow 'yield' in a 'try' block when there's a 'finally' clause.
Derived from Thomas Wouters's patch on the Iterators list, but doesn't
try to read c->c_block[c->c_nblocks].
2001-06-23 02:07:08 +00:00
Tim Peters d6d010b874 Teach the UNPACK_SEQUENCE opcode how to tease an iterable object into
giving up the goods.
NEEDS DOC CHANGES
2001-06-21 02:49:55 +00:00
Neil Schemenauer 2b13ce8317 Try to avoid creating reference cycles involving generators. Only keep a
reference to f_back when its really needed.  Do a little whitespace
normalization as well.  This whole file is a big war between tabs and spaces
but now is probably not the time to reindent everything.
2001-06-21 02:41:10 +00:00
Tim Peters 6302ec63fc gen_iternext(): repair subtle refcount problem.
NeilS, please check!  This came from staring at your genbug.py, but I'm
not sure it plugs all possible holes.  Without this, I caught a
frameobject refcount going negative, and it was also the cause (in debug
build) of _Py_ForgetReference's attempt to forget an object with already-
NULL _ob_prev and _ob_next pointers -- although I'm still not entirely
sure how!  Part of the difficulty is that frameobjects are stored on a
free list that gets recycled very quickly, so if there's a stray pointer
to one of them it never looks like an insane frameobject (never goes
trough the free() mangling MS debug forces, etc).
2001-06-20 06:57:32 +00:00
Neil Schemenauer 43afb24c30 Remove unused code. 2001-06-20 00:39:28 +00:00
Tim Peters 5ca576ed0a Merging the gen-branch into the main line, at Guido's direction. Yay!
Bugfix candidate in inspect.py:  it was referencing "self" outside of
a method.
2001-06-18 22:08:13 +00:00
Fred Drake d083839fb4 Instead of initializing & interning the strings passed to the profile
and trace functions lazily, which incurs extra argument pushing and checks
in the C overhead for profiling/tracing, create the strings semi-lazily
when the Python code first registers a profile or trace function.  This
simplifies the trampoline into the profile/trace functions.
2001-06-16 21:02:31 +00:00
Tim Peters 239508cd10 SF bug 433228: repr(list) woes when len(list) big
call_object:  If the object isn't callable, display its type in the error
msg rather than its repr.
Bugfix candidate.
2001-06-16 00:09:28 +00:00
Marc-André Lemburg 464fe3aa7b Temporarily disable the message to stderr. Jeremy will know what to do
about this...
2001-06-13 17:18:06 +00:00
Tim Peters 2a7f384122 SF bug 430991: wrong co_lnotab
Armin Rigo pointed out that the way the line-# table got built didn't work
for lines generating more than 255 bytes of bytecode.  Fixed as he
suggested, plus corresponding changes to pyassem.py, plus added some
long overdue docs about this subtle table to compile.c.

Bugfix candidate (line numbers may be off in tracebacks under -O).
2001-06-09 09:26:21 +00:00
Fred Drake 904aa7bb00 call_trace(): Add an additional parameter -- pointer to a PyObject*
that should be used to cache an interned version of the event
    string passed to the profile/trace function.  call_trace() will
    create interned strings and cache them in using the storage
    specified by this additional parameter, avoiding a lot of string
    object creation at runtime when using the profiling or tracing
    functions.

All call sites are modified to pass the additional parameter, and four
static PyObject* variables are allocated to cache the interned string
objects.

This closes SF patch #431257.
2001-06-08 04:33:09 +00:00
Tim Peters 024da3545b PyErr_Occurred(): Use PyThreadState_GET(), which saves a tiny function call
in release builds.  Suggested by Martin v. Loewis.

I'm half tempted to macroize PyErr_Occurred too, as the whole thing could
collapse to just
     _PyThreadState_Current->curexc_type
2001-05-30 06:09:50 +00:00
Jeremy Hylton 25916bdc11 Change cascaded if stmts to switch stmt in vgetargs1().
In the default branch, keep three ifs that are used if level == 0, the
most common case.  Note that first if here is a slight optimization
for the 'O' format.

Second part of SF patch 426072.
2001-05-29 17:46:19 +00:00
Jeremy Hylton 1cb7aa3e6e Internal refactoring of convertsimple() and friends.
Note that lots of code was re-indented.

Replace two-step of convertsimple() and convertsimple1() with
convertsimple() and helper converterr(), which is called to format
error messages when convertsimple() fails.  The old code did all the
real work in convertsimple1(), but deferred error message formatting
to conversimple().  The result was paying the price of a second
function call on every call just to format error messages in the
failure cases.

Factor out of the buffer-handling code in convertsimple() and package
it as convertbuffer().

Add two macros to ease readability of Unicode coversions,
UNICODE_DEFAULT_ENCODING() and CONV_UNICODE, an error string.

The convertsimple() routine had awful indentation problems, primarily
because there were two tabs between the case line and the body of the
case statements.  This patch reformats the entire function to have a
single tab between case line and case body, which makes the code
easier to read (and consistent with ceval).  The introduction of
converterr() exacerbated the problem and prompted this fix.

Also, eliminate non-standard whitespace after opening paren and before
closing paren in a few if statements.

(This checkin is part of SF patch 426072.)
2001-05-29 17:37:05 +00:00
Jeremy Hylton 4c9dace392 Fix bug reported by Tim Peters on python-dev:
Keyword arguments passed to builtin functions that don't take them are
ignored.

>>> {}.clear(x=2)
>>>

instead of

>>> {}.clear(x=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: clear() takes no keyword arguments
2001-05-29 16:23:26 +00:00
Tim Peters 4324aa3572 Cruft cleanup: Removed the unused last_is_sticky argument from the internal
_PyTuple_Resize().
2001-05-28 22:30:08 +00:00
Tim Peters 3c6b148a67 SF bug #425836: Reference leak in filter().
Mark Hammond claimed that the iterized filter() forgot to decref the
iterator upon return.  He was right!
2001-05-21 08:07:05 +00:00
Fred Drake d657303910 Fix whitespace botch. 2001-05-18 21:03:40 +00:00
Jeremy Hylton 0f8117f14a vgetargs1() and vgetargskeywords(): Replace uses of PyTuple_Size() and
PyTuple_GetItem() with PyTuple_GET_SIZE() and PyTuple_GET_ITEM().
    The code has already done a PyTuple_Check().
2001-05-18 20:57:38 +00:00
Jeremy Hylton da20fce9c3 Add a second special case to the inline function call code in eval_code2().
If we have a PyCFunction (builtin) and it is METH_VARARGS only, load
the args and dispatch to call_cfunction() directly.  This provides a
small speedup for perhaps the most common function calls -- builtins.
2001-05-18 20:53:14 +00:00
Mark Hammond 26cffde4c2 Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule. 2001-05-14 12:17:34 +00:00
Mark Hammond ef8b654bbe Add support for Windows using "mbcs" as the default Unicode encoding when dealing with the file system. As discussed on python-dev and in patch 410465. 2001-05-13 08:04:26 +00:00
Tim Peters 5ac946c697 SF patch #416249, from Mark Favas: 2.1c1 compile: unused vrbl cleanup 2001-05-09 18:53:51 +00:00
Mark Hammond fb1f68ed7c Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev 2001-05-09 00:50:59 +00:00
Tim Peters 72f98e9b83 SF bug #422177: Results from .pyc differs from .py
Store floats and doubles to full precision in marshal.
Test that floats read from .pyc/.pyo closely match those read from .py.
Declare PyFloat_AsString() in floatobject header file.
Add new PyFloat_AsReprString() API function.
Document the functions declared in floatobject.h.
2001-05-08 15:19:57 +00:00
Jeremy Hylton 9c90105cb0 Several small changes. Mostly reformatting, adding parens.
Check for free in class and method only if nested scopes are enabled.

Add assertion to verify that no free variables occur when nested
scopes are disabled.

XXX When should nested scopes by made non-optional on the trunk?
2001-05-08 04:12:34 +00:00
Tim Peters 8572b4fedf Generalize zip() to work with iterators.
NEEDS DOC CHANGES.
More AttributeErrors transmuted into TypeErrors, in test_b2.py, and,
again, this strikes me as a good thing.
This checkin completes the iterator generalization work that obviously
needed to be done.  Can anyone think of others that should be changed?
2001-05-06 01:05:02 +00:00
Tim Peters f4848dac41 Make PyIter_Next() a little smarter (wrt its knowledge of iterator
internals) so clients can be a lot dumber (wrt their knowledge).
2001-05-05 00:14:56 +00:00
Tim Peters 15d81efb8a Generalize reduce() to work with iterators.
NEEDS DOC CHANGES.
2001-05-04 04:39:21 +00:00
Tim Peters 4e9afdca39 Generalize map() to work with iterators.
NEEDS DOC CHANGES.
Possibly contentious:  The first time s.next() yields StopIteration (for
a given map argument s) is the last time map() *tries* s.next().  That
is, if other sequence args are longer, s will never again contribute
anything but None values to the result, even if trying s.next() again
could yield another result.  This is the same behavior map() used to have
wrt IndexError, so it's the only way to be wholly backward-compatible.
I'm not a fan of letting StopIteration mean "try again later" anyway.
2001-05-03 23:54:49 +00:00
Tim Peters c307453162 Generalize max(seq) and min(seq) to work with iterators.
NEEDS DOC CHANGES.
2001-05-03 07:00:32 +00:00
Marc-André Lemburg 6f15e5796e Added new parser markers 'et' and 'et#' which do not recode string
objects but instead assume that they use the requested encoding.

This is needed on Windows to enable opening files by passing in
Unicode file names.
2001-05-02 17:16:16 +00:00
Tim Peters 0e57abf0cd Generalize filter(f, seq) to work with iterators. This also generalizes
filter() to no longer insist that len(seq) be defined.
NEEDS DOC CHANGES.
2001-05-02 07:39:38 +00:00
Tim Peters cab3f68f61 SF bug #417093: Case sensitive import: dir and .py file w/ same name
Directory containing
    Spam.py
    spam/__init__.py
Then "import Spam" caused a SystemError, because code checking for
the existence of "Spam/__init__.py" finds it on a case-insensitive
filesystem, but then bails because the directory it finds it in
doesn't match case, and then old code assumed that was still an error
even though it isn't anymore.  Changed the code to just continue
looking in this case (instead of calling it an error).  So
    import Spam
and
    import spam
both work now.
2001-04-29 22:21:25 +00:00
Tim Peters 748b8bbe02 Fix buglet reported on c.l.py: map(fnc, file.xreadlines()) blows up.
Also a 2.1 bugfix candidate (am I supposed to do something with those?).
Took away map()'s insistence that sequences support __len__, and cleaned
up the convoluted code that made it *look* like it really cared about
__len__ (in fact the old ->len field was only *used* as a flag bit, as
the main loop only looked at its sign bit, setting the field to -1 when
IndexError got raised; renamed the field to ->saw_IndexError instead).
2001-04-28 08:20:22 +00:00
Jeremy Hylton ddc4fd03b1 Fix 2.1 nested scopes crash reported by Evan Simpson
The new test case demonstrates the bug.  Be more careful in
symtable_resolve_free() to add a var to cells or frees only if it
won't be added under some other rule.

XXX Add new assertion that will catch this bug.
2001-04-27 02:29:40 +00:00
Jeremy Hylton 960d948e7c improved error message-- names the type of the unexpected object 2001-04-27 02:25:33 +00:00
Guido van Rossum 213c7a6aa5 Mondo changes to the iterator stuff, without changing how Python code
sees it (test_iter.py is unchanged).

- Added a tp_iternext slot, which calls the iterator's next() method;
  this is much faster for built-in iterators over built-in types
  such as lists and dicts, speeding up pybench's ForLoop with about
  25% compared to Python 2.1.  (Now there's a good argument for
  iterators. ;-)

- Renamed the built-in sequence iterator SeqIter, affecting the C API
  functions for it.  (This frees up the PyIter prefix for generic
  iterator operations.)

- Added PyIter_Check(obj), which checks that obj's type has a
  tp_iternext slot and that the proper feature flag is set.

- Added PyIter_Next(obj) which calls the tp_iternext slot.  It has a
  somewhat complex return condition due to the need for speed: when it
  returns NULL, it may not have set an exception condition, meaning
  the iterator is exhausted; when the exception StopIteration is set
  (or a derived exception class), it means the same thing; any other
  exception means some other error occurred.
2001-04-23 14:08:49 +00:00
Tim Peters cf96de052f SF but #417587: compiler warnings compiling 2.1.
Repaired *some* of the SGI compiler warnings Sjoerd Mullender reported.
2001-04-21 02:46:11 +00:00
Guido van Rossum 59d1d2b434 Iterators phase 1. This comprises:
new slot tp_iter in type object, plus new flag Py_TPFLAGS_HAVE_ITER
new C API PyObject_GetIter(), calls tp_iter
new builtin iter(), with two forms: iter(obj), and iter(function, sentinel)
new internal object types iterobject and calliterobject
new exception StopIteration
new opcodes for "for" loops, GET_ITER and FOR_ITER (also supported by dis.py)
new magic number for .pyc files
new special method for instances: __iter__() returns an iterator
iteration over dictionaries: "for x in dict" iterates over the keys
iteration over files: "for x in file" iterates over lines

TODO:

documentation
test suite
decide whether to use a different way to spell iter(function, sentinal)
decide whether "for key in dict" is a good idea
use iterators in map/filter/reduce, min/max, and elsewhere (in/not in?)
speed tuning (make next() a slot tp_next???)
2001-04-20 19:13:02 +00:00
Guido van Rossum f68d8e52e7 Make some private symbols static. 2001-04-14 17:55:09 +00:00
Jeremy Hylton 37832f0c8d split long line 2001-04-13 17:50:20 +00:00
Jeremy Hylton c76770c68c Change error message raised when free variable is not yet bound. It
now raises NameError instead of UnboundLocalError, because the var in
question is definitely not local.  (This affects test_scope.py)

Also update the recent fix by Ping using get_func_name().  Replace
tests of get_func_name() return value with call to get_func_desc() to
match all the other uses.
2001-04-13 16:51:46 +00:00