Commit Graph

2023 Commits

Author SHA1 Message Date
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