Commit Graph

717 Commits

Author SHA1 Message Date
Guido van Rossum 13ff8eb493 Christian Tismer:
Added "better safe than sorry" patch to the new
trashcan code in object.c, to ensure that tstate
is not touched when it might be undefined.
2000-03-25 18:39:19 +00:00
Barry Warsaw 51ac58039f On 17-Mar-2000, Marc-Andre Lemburg said:
Attached you find an update of the Unicode implementation.

    The patch is against the current CVS version. I would appreciate
    if someone with CVS checkin permissions could check the changes
    in.

    The patch contains all bugs and patches sent this week and also
    fixes a leak in the codecs code and a bug in the free list code
    for Unicode objects (which only shows up when compiling Python
    with Py_DEBUG; thanks to MarkH for spotting this one).
2000-03-20 16:36:48 +00:00
Guido van Rossum ee70ad1e52 Checking in the new, improve file.writelines() code.
This (1) avoids thread unsafety whereby another thread could zap the
list while we were using it, and (2) now supports writing arbitrary
sequences of strings.
2000-03-13 16:27:06 +00:00
Guido van Rossum d724b23420 Christian Tismer's "trashcan" patch:
Added wrapping macros to dictobject.c, listobject.c, tupleobject.c,
frameobject.c, traceback.c that safely prevends core dumps
on stack overflow. Macros and functions in object.c, object.h.
The method is an "elevator destructor" that turns cascading
deletes into tail recursive behavior when some limit is hit.
2000-03-13 16:01:29 +00:00
Guido van Rossum 96a45adf80 Fix typo in replace() detected by Mark Hammond and fixed by Marc-Andre. 2000-03-13 15:56:08 +00:00
Guido van Rossum 403d68b484 Add sq_contains implementation. 2000-03-13 15:55:09 +00:00
Guido van Rossum ef93b87f1c Added Christian Tismer's patch to allow list.append(a,b,c) back --
with a twist: you have to define NO_STRICT_LIST_APPEND manually
to enable multi-arg append().
2000-03-13 15:41:59 +00:00
Guido van Rossum 4aa1e63e4c Marc-AAndre Lemburg: add new unicode files 2000-03-10 22:55:40 +00:00
Guido van Rossum 4c08d554b9 Many changes for Unicode, by Marc-Andre Lemburg. 2000-03-10 22:55:18 +00:00
Guido van Rossum d57fd91488 Unicode implementation by Marc-Andre Lemburg based on original code by
Fredrik Lundh.
2000-03-10 22:53:23 +00:00
Guido van Rossum 603484d759 Unicode character type helpers, written by Marc-Andre Lemburg. 2000-03-10 22:52:46 +00:00
Guido van Rossum 9611e0b462 Patch by Moshe Zadka: remove the string special case in
PySequence_Contains() now that string objects have this code in their
tp_contains.
2000-03-07 15:54:45 +00:00
Guido van Rossum 9284a572bc Patch by Moshe Zadka: move the string special case from abstract.c
here.

[Patch modified by GvR to keep the original exception.]
2000-03-07 15:53:43 +00:00
Barry Warsaw bf32583084 string_join(): Fix memory leaks discovered by Charles Waldman (and a
few other paths through the function that leaked).
2000-03-06 14:52:18 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Guido van Rossum ee28c3a5ea Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
an instance method instance_contains as sq_contains.  It looks for
__contains__ and if not found falls back to previous behaviour.
Done.
2000-02-28 15:03:15 +00:00
Guido van Rossum 46c6b20392 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This
patches PySequence_Contains() to check for a valid sq_contains field.
More to follow.
2000-02-28 15:01:46 +00:00
Guido van Rossum c00a938be8 OKOK, Greg's right, I should've used the :name option in the argument
format strings.
2000-02-24 21:48:29 +00:00
Guido van Rossum 4aa24f9979 Made all list methods use PyArg_ParseTuple(), for more accurate
diagnostics.

*** INCOMPATIBLE CHANGE: This changes append(), remove(), index(), and
*** count() to require exactly one argument -- previously, multiple
*** arguments were silently assumed to be a tuple.
2000-02-24 15:23:03 +00:00
Andrew M. Kuchling 0f223d2418 Allow using long integers as arguments to PyObject_GetItem(), _SetItem(),
and _DelItem().
In sequence multiplication by a long, only call PyErr_Occurred() when the
    value returned is -1.
2000-02-23 22:21:50 +00:00
Fred Drake 52fccfda5b dict_has_key(): Accept only one parameter. PR#210 reported by
Andreas Jung <ajung@sz-sb.de>.
2000-02-23 15:47:16 +00:00
Guido van Rossum fb4574e320 In response to one particular complaint on edu-sig, change some error
messages from "OverflowError: integer pow()" to "OverflowError:
integer exponentiation".  (Not that this takes care of the complaint
in general that the error messages could be greatly improved. :-)
2000-02-15 14:51:46 +00:00
Andrew M. Kuchling 1991ddc3e1 Make multiplying a sequence by a long integer (5L * 'b') legal 2000-02-14 22:22:04 +00:00
Guido van Rossum bffd683f73 The rest of the changes by Trent Mick and Dale Nagata for warning-free
compilation on NT Alpha.  Mostly added casts etc.
2000-01-20 22:32:56 +00:00
Guido van Rossum 687ef6e70b On Linux, one sometimes sees spurious errors after interrupting
previous output.  Call clearerr() to prevent past errors affecting our
ferror() test later, in PyObject_Print().  Suggested by Marc Lemburg.
2000-01-12 16:28:58 +00:00
Guido van Rossum 57072eb79f Implement the other easy thing: repr() of a float now uses %.17g,
while str() uses %.12g as before.
1999-12-23 19:00:28 +00:00
Fred Drake 121ee2722e long_format(): Now takes a third parameter, addL; iff true, a
trailing 'L' is appended to the representation,
                otherwise not.

                All existing call sites are modified to pass true for
                addL.

                Remove incorrect statement about external use of this
                function from elsewhere; it's static!

long_str():     Handler for the tp_str slot in the type object.
                Identical to long_repr(), but passes false as the addL
                parameter of long_format().
1999-12-23 15:41:28 +00:00
Barry Warsaw 153a27ceb2 do_strip(): Fixed cut-and-paste error; this function should check for
zero arguments (found by Marc Lemburg).
1999-12-15 02:22:52 +00:00
Barry Warsaw 226ae6ca12 Mainlining the string_methods branch. See branch revision log
messages for specific changes.
1999-10-12 19:54:53 +00:00
Guido van Rossum 2c7b8fe618 Fix PR#66. Solution: add error checking around l_divmod() calls in
long_pow().
1999-10-11 22:34:41 +00:00
Guido van Rossum 42636dc64d Fix for PR#98 (Adrian Eyre) -- in instancemethod_repr, the funcname
object is DECREFed too early.
1999-10-11 14:03:12 +00:00
Guido van Rossum e13ff2e2d6 Patch by Tim Peters fixing PR#88:
Integer division can crash under Windows.
1999-09-27 17:12:47 +00:00
Guido van Rossum 1a23c2484e Patch by Tim Peters fixing PR#89:
long(+/- infinity) returns nonsense.
1999-09-27 17:11:52 +00:00
Guido van Rossum ff7e83d606 Patch by Mark Hammond to avoid certain header files on Windows/CE. 1999-08-27 20:39:37 +00:00
Fred Drake 4574f23115 PyBuffer_New(): Raise ValueError if size is negative (the other
constructors didn't miss this).

		 Raise MemoryError if malloc() fails, instead of just
		 returning NULL.
1999-08-04 13:08:19 +00:00
Guido van Rossum 0eb55ac912 Mark Favas was quick to note that the last checkin divides by zero
when n == 0...  So divide by a->ob_size instead which was already
tested for 0.
1999-07-13 05:41:12 +00:00
Guido van Rossum 5bc51f2f27 Appropriate overflow checks so that things like sys.maxint*(1,) can't
dump core.
1999-07-12 23:06:58 +00:00
Guido van Rossum fa71701d46 When deallocating a list, DECREF the items from the end back to the start. 1999-06-09 15:19:34 +00:00
Guido van Rossum 98c9eba945 Fix bug discovered by John W. Shipman -- when the width of a format
specifier came from an int expression instead of a constant in the
format, a negative width was truncated to zero instead of taken to
mean the same as that negative constant plugged into the format.  E.g.
"(%*s)" % (-5, "foo") yielded "(foo)" while "(%-5s)" yields "(foo  )".
Now both yield the latter -- like sprintf() in C.
1999-06-07 15:12:32 +00:00
Guido van Rossum 9263e78ff2 Tim Peters writes:
1. Fixes float divmod so that the quotient it returns is always an integral
value.

2. Fixes float % and float divmod so that the remainder always gets the
right sign (the current code uses a "are the signs different?" test that
doesn't work half the time <wink> when the product of the divisor and the
remainder underflows to 0).
1999-05-06 14:26:34 +00:00
Guido van Rossum 9bcd1d7931 Improve text of some error messages, as suggested by Sean Reifschneider. 1999-04-19 17:44:39 +00:00
Guido van Rossum ff1ccbfc21 casts for picky compilers. 1999-04-10 15:48:23 +00:00
Guido van Rossum 2bc137909d Vladimir Marangozov contributed updated comments. 1999-03-24 19:06:42 +00:00
Guido van Rossum cd037e7bed Folded long lines. 1999-03-24 19:05:31 +00:00
Guido van Rossum d7b5fb858c Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
a block cannot be freed, add its free items back to the free list.
This is necessary to avoid leaking when Python is reinitialized later.
1999-03-19 20:59:40 +00:00
Guido van Rossum 51288bce48 Fix a problem with Vladimir's PyInt_Fini code: clear the free list; if
a block cannot be freed, add its free items back to the free list, and
add its valid ints back to the small_ints array if they are in range.
This is necessary to avoid leaking when Python is reinitialized later.
1999-03-19 20:30:39 +00:00
Guido van Rossum 49ded3ec00 Added check for negative offset for PyBuffer_FromObject and check for
negative size for PyBuffer_FromMemory.  Greg Stein.
1999-03-19 19:04:25 +00:00
Guido van Rossum 3fce883922 Vladimir has restructured his code somewhat so that the blocks are now
represented by an explicit structure.  (There are still too many casts
in the code, but that may be unavoidable.)

Also added code so that with -vv it is very chatty about what it does.
1999-03-12 19:43:17 +00:00
Guido van Rossum f61bbc8182 OK, try again. Vladimir gave me a fix for the alignment bus error,
so here's his patch again.  This time it works (at least on Solaris,
Linux and Irix).
1999-03-12 00:12:21 +00:00
Guido van Rossum a060fb2598 Alas, Vladimir's patch caused a bus error (probably double
alignment?), and I didn't test it.  Withdrawing it for now.
1999-03-11 01:47:00 +00:00
Guido van Rossum 881928f7ab Patch by Vladimir Marangoz to allow freeing of the allocated blocks of
floats on finalization.
1999-03-10 22:55:47 +00:00
Guido van Rossum da084edd38 Patch by Vladimir Marangoz to allow freeing of the allocated blocks of
integers on finalization.
1999-03-10 22:55:24 +00:00
Guido van Rossum 98cc19fac6 Patch by Chris Petrilli to display the origin of a module in its
repr() -- either "(builtin)" or "from '<filename>'".
1999-02-15 14:47:16 +00:00
Guido van Rossum 00d225ea6d Correct typo (Py_MethodDef doesn't exist). Reported by Uwe Zessin. 1999-01-29 14:39:12 +00:00
Barry Warsaw b5cebfe164 PyLong_FromString(): Nailed a small memory leak. In the str==start
test, we forgot that z is still pointing to a real live object.
DECREF() it before returning.
1999-01-27 17:48:27 +00:00
Guido van Rossum 3bbef60990 Ai! complex_nonzero() has && which should be ||, else decidedly
non-zero things like 5j and complex(1,0) are considered to be
zero/false.  Tim Peters.
1999-01-25 19:42:19 +00:00
Guido van Rossum 3aa23fdd47 Jim Ahlstrom patch: cutoff should be a long for machines with 16-bit
ints.  (In theory, other variables should be widened to long as well,
but this won't ever be needed, since the len of a list is still an
int.)
1999-01-14 19:01:53 +00:00
Guido van Rossum 3c25904a98 Jim Ahlstrom patch: BIGCHUNK is too large for 16-bit int. 1999-01-14 19:00:14 +00:00
Guido van Rossum 031d0e5feb Patch by Charles Waldman -- remove unneeded and even harmful test for
float to the negative power (which is already and better done in
floatobject.c.)
1999-01-10 16:56:58 +00:00
Guido van Rossum 5dadf7e976 Use 'xrange', not 'range', in error messages. Reported by Nathan Sullivan. 1999-01-09 21:40:35 +00:00
Guido van Rossum 41498435ba Need to include <sys/types.h> for off_t. 1999-01-07 22:09:51 +00:00
Guido van Rossum 3c9fe0cce3 Changes for long file support by Steve Clift.
(This also redoes my previous patch, but better.)
1999-01-06 18:51:17 +00:00
Guido van Rossum cdd9ae00ba Changes for long file support by Steve Clift.
(Really: moved a bunch of defs to longobject.h.)
1999-01-06 18:50:37 +00:00
Guido van Rossum 88303194a5 Fix two places (seek and truncate) where a cascade of PyArg_Parse
calls was used instead of a single PyArg_ParseTuple call with an
optional argument.
1999-01-04 17:22:18 +00:00
Guido van Rossum cada2938f7 As noted by Per Cederqvist, new_buffersize() sometimes returns the
buffer increment, and sometimes the new buffer size.  Make it do what
its name says, and fix the one place where this matters to the caller.

Also add a comment explaining why we call lseek() and then ftell().
1998-12-11 20:44:56 +00:00
Guido van Rossum 68055ce6fe When tracing references, reset the type and size of tuples allocated
from the fast free list -- the type (at least) is reset by
_Py_Dealloc().
1998-12-11 14:56:38 +00:00
Guido van Rossum f5046d1aea Remove prototype for PyOS_strtol -- Chris Herborth. 1998-12-10 16:54:48 +00:00
Guido van Rossum 13fdf5e917 When comparing bound methods, use identity test on the objects,
not equality test.
1998-12-04 18:52:55 +00:00
Guido van Rossum f05fc716d1 Remove dead code discovered by Vladimir Marangozov. 1998-11-16 22:46:30 +00:00
Guido van Rossum 017f7780a8 Make tuples less hungry -- an extra item was allocated but never used.
Tip by Vladimir Marangozov.
1998-11-16 18:56:03 +00:00
Guido van Rossum f61618c98e A Py_DECREF(f) is missing in PyFrame_New for the error case when
the `builtins' initialization fails.  Vladimir Marangozov.
1998-10-19 14:20:20 +00:00
Guido van Rossum 2f3667a7b9 Replace fprintf(stderr, ...) with PySys_WriteStderr(...). 1998-10-12 18:23:55 +00:00
Barry Warsaw dedf6d6804 listextend(): New method which implements L.extend(L2). 1998-10-09 16:37:25 +00:00
Guido van Rossum 3886026bed Remove unreachable code. (Sjoerd) 1998-10-09 13:27:19 +00:00
Guido van Rossum 1db7070217 Greg Stein: Implement the new bf_getcharbuffer function, indicating
that (as far as the data type is concerned!) this is character data.
1998-10-08 02:18:52 +00:00
Guido van Rossum 7148ca9d14 Make gcc -Wall happy. 1998-10-07 16:22:12 +00:00
Guido van Rossum 06c18088d6 Add Greg Stein's buffer object API. 1998-10-07 14:41:13 +00:00
Guido van Rossum 2e19bd7cc7 Add Greg Stein's buffer object API. 1998-10-07 14:36:10 +00:00
Guido van Rossum 2ccaf6f2f9 Remove a redundant check from list_slice() and list_ass_slice().
Noted by Greg Stein.
1998-10-07 13:24:13 +00:00
Guido van Rossum c1c7b1a699 Slight rearrangement of code in lookdict() by Vladimir Marangozov, to
make a common case slightly faster.
1998-10-06 16:01:14 +00:00
Guido van Rossum 9d904b9389 Believe it or not, Solaris 2.6 strtod() can move the end pointer
*beyond* the null byte at the end of the input string, when the input
is inf(inity).  Discovered by Greg Ward.
1998-10-01 20:35:46 +00:00
Guido van Rossum 07d780089d Typo reported by Greg Stein: "modifiable" is the correct spelling. 1998-10-01 15:59:48 +00:00
Guido van Rossum 67906af811 In PyFrame_New(), don't set extras to something derived from code
before code has been checked for validity.  Discovered by Vladimir
Marangozov.
1998-09-25 14:11:46 +00:00
Guido van Rossum 78694d970f Patches from Greg Stein to support 'P' format in struct module's
native format, as void* (translated to Python int or long).
Also adds PyLong_FromVoidPtr and PyLong_AsVoidPtr to longobject.c.
1998-09-18 14:14:13 +00:00
Guido van Rossum 065ce5a4b7 Undo victim of careless global substitute ("long long_hash" was
changed to "LONG_LONG_hash" in the list of forward decls).  Discovered
by Jason Harper.
1998-09-13 15:37:20 +00:00
Guido van Rossum 3293b07df5 Patch by Mark Hammond to support 64-bit ints on MS platforms.
The MS compiler doesn't call it 'long long', it uses __int64,
so a new #define, LONG_LONG, has been added and all occurrences
of 'long long' are replaced with it.
1998-08-25 16:07:15 +00:00
Guido van Rossum 21308243ca Better error messages when a sequence is indexed with a non-integer.
Previously, this said "unsubscriptable object"; in 1.5.1, the reverse
problem existed, where None[''] would complain about a non-integer
index.  This fix does the right thing in all cases (for get, set and
del item).
1998-08-13 16:44:44 +00:00
Guido van Rossum bd3a527f93 Two patches by Jason Harper:
- Faster conversion to string for binary bases: linear instead of quadratic!

- Allocate smaller result for certain masking ops, e.g. (1L<<30000) & 1.
1998-08-11 15:04:47 +00:00
Guido van Rossum 1a8791e0b8 Changes for BeOS, QNX and long long, by Chris Herborth. 1998-08-04 22:46:29 +00:00
Guido van Rossum ac6a37ae55 Fix a potential problem in PyLong_FromString(): could fall through the
for loop with z==NULL but continue to reference z later.
1998-08-04 15:04:06 +00:00
Guido van Rossum df3d8756b7 Better error messages when raising ValueError for int and long
literals.  (The previous version of this code would not show the
offending input, even though there was code that attempted this.)
1998-08-04 15:02:01 +00:00
Guido van Rossum 152d8173a3 Fix a memory leak -- the cached values of __getattr__ etc. were never
freed.
1998-08-04 14:59:16 +00:00
Barry Warsaw 52ddc0e756 PyFile_FromString(): If an exception occurs, pass in the filename that
was used so it's reflected in the IOError.  Call
PyErr_SetFromErrnoWithFilename().
1998-07-23 16:07:02 +00:00
Guido van Rossum b4db1944c4 When comparing objects, always check that tp_compare is not NULL
before calling it.  This check was there when the objects were of the
same type *before* coercion, but not if they initially differed but
became the same *after* coercion.
1998-07-21 21:56:41 +00:00
Guido van Rossum 0fd00334c6 Avoid using calloc(). This triggered an obscure bug on multiprocessor
Sparc Solaris 2.6 (fully patched!) that I don't want to dig into, but
which I suspect is a bug in the multithreaded malloc library that only
shows up when run on a multiprocessor.  (The program wasn't using
threads, it was just using the multithreaded C library.)
1998-07-16 15:06:13 +00:00
Guido van Rossum 5dba9e8aef Add special case to PySequence_List() so that list() of a list is
faster (using PyList_GetSlice()).  Also added a test for a NULL
argument, as with PySequence_Tuple().  (Hmm...  Better names for these
two would be PyList_FromSequence() and PyTuple_FromSequence().  Oh well.)
1998-07-10 18:03:50 +00:00
Guido van Rossum bfc725bf64 Changed PySequence_List() and PySequence_Tuple() to support
"indefinite length" sequences.  These should still have a length, but
the length is only used as a hint -- the actual length of the sequence
is determined by the item that raises IndexError, which may be either
smaller or larger than what len() returns.  (This is a novelty; map(),
filter() and reduce() only allow the actual length to be larger than
what len() returns, not shorter.  I'll fix that shortly.)
1998-07-10 16:22:44 +00:00
Guido van Rossum d4ba73c75b Move the definition of PyMethodObject to classobject.h, so it can define
macros for more efficient access to the fields.
1998-07-10 15:46:33 +00:00
Guido van Rossum 9223351617 Marc-Andre Lemburg's patch to move the typedef for PyCFunctionObject
to the .h file and add macros there for inlined access to the fields.
1998-07-10 15:21:55 +00:00
Guido van Rossum 7859f87fdb Marc-Andre Lemburg's patch to support instance methods with other
callable objects than regular Pythonm functions as their im_func.
1998-07-08 14:58:16 +00:00
Guido van Rossum 7ba30431ec Recompute the special getattr/setattr/delattr cache slots after
changing __dict__ *or* __bases__.
1998-07-08 13:34:48 +00:00
Guido van Rossum 3dd7f3fef0 Added doc strings for methods and a new pop() method. 1998-06-30 15:36:32 +00:00
Guido van Rossum 8a92c627d9 New feature: if the object's type has a non-NULL tp_doc field, that
is returned as the object's __doc__ attribute.

(If only the list of methods would be referenced from the type...)
1998-06-27 18:28:59 +00:00
Guido van Rossum 1bb26872f5 Slight rearrangement of some code to make it faster, by Vladimir
Marangozov.
1998-06-26 15:53:50 +00:00
Guido van Rossum e67629774f Add check in long-to-int conversion for at least one digit. 1998-06-22 03:54:46 +00:00
Guido van Rossum 3b2b34790f Fix the tests for various anomalies in the string-to-numbers
conversions.  Formerly, for example, int('-') would return 0 instead
of raising ValueError, and int(' 0') would raise ValueError
(complaining about a null byte!) instead of 0...
1998-06-22 03:54:15 +00:00
Guido van Rossum 4281258b5f Minor cleanup by Tim after my changes:
+ Took the "list" argument out of the other functions that no longer need
it.  This speeds things up a little more.

+ Small comment changes in accord with that.

+ Exploited the now-safe ability to cache values in the partitioning loop.
Makes no timing difference on my flavor of Pentium, but this machine ran out
of registers 12 iterations ago.  It should yield a small speedup on a RISC
machine, and not hurt in any case.
1998-06-17 14:15:44 +00:00
Guido van Rossum 4c4e7df755 Tim's latest, with some of my changes (also a TP suggestion) added:
instead of testing whether the list changed size after each
comparison, temporarily set the type of the list to an immutable list
type.  This should allow continued use of the list for legitimate
purposes but disallows all operations that can change it in any way.
(Changes to the internals of list items are not caught, of cause;
that's not possible to detect, and it's not necessary to protect the
sort code, either.)
1998-06-16 15:18:28 +00:00
Guido van Rossum e0fdf6f1a8 Keep Microsoft's compiler happy. 1998-06-12 15:03:58 +00:00
Guido van Rossum cd5a5f627a When comparing objects of different types (which is done by comparing
the type names), make sure that numeric objects are considered smaller
than all other objects, by forcing their name to "".
1998-06-09 18:58:44 +00:00
Guido van Rossum 4a0144c0de Should check that PyObject_Str() really returned a string! 1998-06-09 15:08:41 +00:00
Guido van Rossum a63eff6e6a Allow assignments to special class attributes -- with typechecks, and
not in restricted mode.

__dict__ can be set to any dictionary; the cl_getattr, cl_setattr and
cl_delattr slots are refreshed.

__name__ can be set to any string.

__bases__ can be set to to a tuple of classes, provided they are not
subclasses of the class whose attribute is being assigned.

__getattr__, __setattr__ and __delattr__ can be set to anything, or
deleted; the appropriate slot (cl_getattr, cl_setattr, cl_delattr) is
refreshed.

(Note: __name__ really doesn't need to be a special attribute, but
that would be more work.)
1998-05-29 21:37:21 +00:00
Guido van Rossum a119c0dd5e Tim's revision of the previous patch. He also added some sparts to
the median-of-three code to get a few percent back.
1998-05-29 17:56:32 +00:00
Guido van Rossum ed6219b116 Fix a whole bunch of error return NULL that should be return -1. 1998-05-29 02:59:33 +00:00
Guido van Rossum ae621ff7b7 Guard against changes in the list size during a compare or sort. 1998-05-28 20:18:46 +00:00
Guido van Rossum 617c1b0116 Uses PyErr_ExceptionMatches() instead of comparing PyErr_Occurred(). 1998-05-28 19:50:02 +00:00
Guido van Rossum 08570decb7 Uses PyErr_ExceptionMatches() instead of comparing PyErr_Occurred(). 1998-05-28 19:24:35 +00:00
Guido van Rossum 9be628338d Tim's quicksort on May 25. 1998-05-26 15:06:32 +00:00
Guido van Rossum f753181272 Subject: Buglet in PyLong_AsLong
From: "Tim Peters" <tim_one@email.msn.com>
To: "Guido van Rossum" <guido@CNRI.Reston.VA.US>
Date: Sat, 23 May 1998 21:45:53 -0400

Guido, the overflow checking in PyLong_AsLong is off a little:

1) If the C in use sign-extends right shifts on signed longs, there's a
spurious overflow error when converting the most-negative int:

Python 1.5.1 (#0, Apr 13 1998, 20:22:04) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x = -1L << 31
>>> x
-2147483648L
>>> int(x)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: long int too long to convert
>>>

2) If C does not sign-extend, some genuine overflows won't be caught.

The attached should repair both, and, because I installed a new disk and a C
compiler today, it's even been compiled this time <wink>.

Python 1.5.1 (#0, May 23 1998, 20:24:58) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x = -1L << 31
>>> x
-2147483648L
>>> int(x)
-2147483648
>>> int(-x)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: long int too long to convert
>>> int(-x-1)
2147483647
>>> int(x-1)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: long int too long to convert
>>>

end-casing-ly y'rs  - tim
1998-05-26 14:33:37 +00:00
Guido van Rossum fa0b6ab01a Address some gcc -Wall warnings (e.g. include <ctype.h>).
Make sure that no tp_as_numbers->nb_<whatever> function is called
without checking for a NULL pointer.  Marc-Andre Lemburg will love it!
(Except that he's just rewritten all this code for a different
approach to coercions ;-( )
1998-05-22 15:23:36 +00:00
Guido van Rossum 0dabacee16 Make function objects somewhat mutable -- the members func_code,
func_defaults and func_doc (alias __doc__) may be assigned to.  For
the first two, there's a type restriction to code object and tuple,
respectively.
1998-05-22 00:55:34 +00:00
Guido van Rossum 1c4f458099 In PyObject_IsTrue(), don't call function pointers that are NULL
(nb_nonzero, mp_length, sq_length).
1998-05-22 00:53:24 +00:00
Guido van Rossum cea1c8ca22 Completely reformatted, standardizing indentation as well as
programming style.

Recoded many routines to incorporate better error checking, and/or
better versions of the same function found elsewhere
(e.g. bltinmodule.c or ceval.c).  In particular,
Py_Number_{Int,Long,Float}() now convert from strings, just like the
built-in functions int(), long() and float().

Sequences and mappings are now safe to have NULL function pointers
anywhere in their tp_as_sequence or tp_as_mapping fields.  (A few
places in other files need to be checked in too.)

Renamed PySequence_In() to PySequence_Contains().
1998-05-22 00:47:05 +00:00
Guido van Rossum e23eb57f08 Since PyDict_GetItem() can't raise an exception any more, there's no
need to cxall PyErr_Clear() when it returns NULL.
1998-05-14 01:49:48 +00:00
Guido van Rossum 474b19e2ab Make sure that PyDict_GetItem[String]() *never* raises an exception.
If the argument is not a dictionary, simply return NULL.  If the
hash() on the key fails, clear the error.
1998-05-14 01:00:51 +00:00
Guido van Rossum 4180cf1649 Remove a redundant statement from halfbinop(). 1998-05-13 22:02:16 +00:00
Guido van Rossum ed7adcff73 Tim's quicksort on May 13. 1998-05-13 21:21:24 +00:00
Guido van Rossum b7057640d1 Tim's quicksort on May 10. 1998-05-13 21:20:49 +00:00
Guido van Rossum 8530ef625a Add check to conjugate() that there are no excess arguments. 1998-05-07 16:29:10 +00:00
Guido van Rossum 91aaa92c88 Ugly band-aid to work around a bug in Linux ftell(). 1998-05-05 22:21:35 +00:00
Guido van Rossum e32907df67 Get rid of the unused ifdefed-out old sort code. 1998-04-28 17:54:03 +00:00
Guido van Rossum 9b00dfae75 If USE_STACKCHECK is defined use PyOS_CheckStack() in the repr and str
routines. This catches a slightly different set of crashes than the
recursive-repr fix.
(Jack)
1998-04-28 16:06:54 +00:00
Guido van Rossum f2044e1a71 Enable ftruncate() on the Mac.
(Jack)
1998-04-28 16:05:59 +00:00
Guido van Rossum 82e6a8f80d Quicksort retuned by Tim Peters. 1998-04-28 13:17:56 +00:00
Guido van Rossum d30dc0a55e Clear the error condition set by ftell(). 1998-04-27 19:01:08 +00:00
Guido van Rossum 565798d493 Be less naive about null characters in an object's repr(). 1998-04-21 22:25:01 +00:00
Guido van Rossum eb90946978 Some robustness checks in Py_ReprLeave() in the unlikely event someone
has messed with the dictionary or list.
1998-04-11 15:17:34 +00:00
Guido van Rossum fb376dee55 Use Py_Repr{Enter,Leave} to display recursive lists in finite space.
(Jeremy will hardly recognize his patch :-)
1998-04-10 22:47:27 +00:00
Guido van Rossum 255443b720 Use Py_Repr{Enter,Leave} to display recursive dictionaries in finite space.
(Jeremy will hardly recognize his patch :-)
1998-04-10 22:47:14 +00:00
Guido van Rossum 8661036cb8 Add implementations of Py_Repr{Enter,Leave}.
(Jeremy will hardly recognize his patch :-)
1998-04-10 22:32:46 +00:00
Guido van Rossum 1109fbca76 Make new gcc -Wall happy 1998-04-10 22:16:39 +00:00
Guido van Rossum c3d3f9692d Add PyObject_Not(). 1998-04-09 17:53:59 +00:00
Guido van Rossum f7d590c93d This was the reason a numeric array to a real power was not working. 1998-04-03 23:38:59 +00:00
Guido van Rossum 240c35aac0 Subtle fix in the read() code which could cause a read broken up in
several pieces to fail...
1998-03-18 17:59:20 +00:00
Guido van Rossum f8b4de02a4 When we have no setvbuf(), make the file totally unbuffered using
setbuf() if a buffer size of 0 or 1 byte is requested.
1998-03-06 15:32:40 +00:00
Guido van Rossum dcb5e7f389 Of course, I shouldn't have used lseek() to find out the file's
position in new_buffersize(); the correct function to use is ftell().
Thanks to Ben Jackson.
1998-03-03 22:36:10 +00:00
Guido van Rossum 044b9dc1d7 Add back some safeguards on the index elements that were lost in the
last patch.  Dave Ascher found a case that dumps core without these:

def myComparison(x,y):
    return cmp(x%3,y%7)

z = range(12)
z.sort(myComparison)
1998-02-25 17:50:03 +00:00
Guido van Rossum f1dc0615e9 Add internal routine _PyModule_Clear(), which does approximately what
clear_carefully() used to do in import.c.  Differences: leave only
__builtins__ alone in the 2nd pass; and don't clear the dictionary (on
the theory that as long as there are references left to the
dictionary, those might be destructors that might expect __builtins__
to be alive when they run; and __builtins__ can't normally be part of
a cycle).
1998-02-19 20:51:52 +00:00
Guido van Rossum bde6ff7984 Vladimir Marangozov' performance hack: copy f_builtins from ancestor
if the globals are the same.

Also, when creating a dummy builtins dictionary, add "None" to it,
just to be kind.
1998-02-19 20:48:26 +00:00
Guido van Rossum 3da3fcef96 Check ferror(), not errno, for fread() error. 1998-02-19 20:46:48 +00:00
Guido van Rossum db9351643d Instead of "attribute-less object", issue an error message that
contains the type of the object and name of the attribute.
1998-01-19 22:16:36 +00:00
Guido van Rossum 24e62e2c7c Modified quicksort by Raymund Galvin, after studying the GNU libg++
quicksort.  This should be much faster if there are lots of
duplicates, and otherwise at least as good.
1997-12-10 15:14:24 +00:00
Guido van Rossum b7f1afe4a8 Change the default repr() and str() of class instance objects to look
like <modulename.classname instance at ...> (to match the repr() of
class objects.
1997-12-03 00:06:02 +00:00
Guido van Rossum 242c64256c Add a new function PyNumber_CoerceEx() which works just like
PyNumber_Coerce() except that when the coercion can't be done and no
other exceptions happen, it returns 1 instead of raising an
exception.

Use this function in PyObject_Compare() to avoid raising an exception
simply because two objects with numeric behavior can't be coerced to a
common type; instead, proceed with the non-numeric default comparison.

Note that this is a somewhat questionable practice -- comparisons for
numeric objects shouldn't default to random behavior like this, but it
is required for backward compatibility.  (Case in point, it broke
comparison of kjDict objects to integers in Aaron Watters' kjbuckets
extension.)  A correct fix (for python 2.0) should involve a different
definiton of comparison altogether.
1997-11-19 16:03:17 +00:00
Guido van Rossum 3931df9250 Undo another glitch of the automatic not-so-Grand Renaming; some local
variables called 'coerce' were accidentally renamed to
'PyNumber_Coerce'.  Rename them back to coercefunc.
1997-11-18 19:23:07 +00:00
Guido van Rossum f51815426e Fix problem discovered by Barry: if you hit ^C to
sys.stdin.readline(), you get a fatal error (no current thread).  This
is because there was a call to PyErr_CheckSignals() while there was no
current thread.  I wonder how many more of these we find...  I bnetter
go hunting for PyErr_CheckSignals() now...
1997-11-07 19:20:34 +00:00
Guido van Rossum 6345ac6d61 Add cast to realloc/malloc call to shut up AIX compiler. (Vladimir Marangozov) 1997-10-31 20:32:13 +00:00
Guido van Rossum 3c03fa87b6 Hack suggested by Matthias Klose to pull in all relevant entry points
in libmath.a so they are available to mathmodule.so (in case it is
shared).  While this still gets triggered on Solaris 2.x, this appears
to be harmless there.
1997-10-31 17:00:30 +00:00
Guido van Rossum 1f84449fd8 New CObject from Jim Fulton, adds PyCObject_FromVoidPtrAndDesc() and
PyCObject_GetDesc().
1997-10-21 19:48:35 +00:00
Guido van Rossum 4a2a621907 Write a str() function for class objects that returns
"modulename.classname" instead of returning the same as repr().
1997-10-20 23:26:11 +00:00
Guido van Rossum 6fcfa72c63 Correct Barry's fix -- take care of {}.get(0). 1997-10-20 20:10:00 +00:00
Barry Warsaw 320ac331d1 dict_get(): Fixed a couple of stupid mistakes which caused crashes.
Also got rid of some unnecessary code.
1997-10-20 17:26:25 +00:00
Guido van Rossum 04d73c495e Check that all base classes are indeed class objects, rather than
expecting the caller to do so.
1997-10-07 14:54:11 +00:00
Barry Warsaw c38c5da5d0 dict_get(): New method for item access with different semantics than
__getitem__().  This method never raises an exception; if the key is
not in the dictionary, the second (optional) argument is returned.  If
the second argument is not provided and the key is missing, None is
returned.

mapp_methods: added "get" method.
1997-10-06 17:49:20 +00:00
Guido van Rossum 4f3bf1e383 Don't intern the key string for getitem and delitem. 1997-09-29 23:31:11 +00:00
Guido van Rossum 7cc56eb524 When creating a class, set its __module__ attribute to the module
whose name is in the current globals' __name__ variable.  If __name__
is not set, ignore this.
1997-09-12 20:04:46 +00:00
Guido van Rossum 045e688f6f Patch submitted by Brad Howes (with one bug fixed by me): allow
arbitrary nested parens in a %(...)X style format.
#Also folded two lines and added more detail to the error message for
#unsupported format character.
1997-09-08 18:30:11 +00:00
Guido van Rossum b2173c3146 Allow assignments to instance.__dict__ and instance.__class__. The
former lets you give an instance a set of new instance vars.  The
latter lets you give it a new class.  Both are typechecked and
disallowed in restricted mode.

For classes, the check for read-only special attributes is tightened
so that only assignments to __dict__, __bases__, __name__,
__getattr__, __setattr__, and __delattr__ (these could be made to work
as well, but I don't know if that's useful -- let's see first whether
mucking with instances will help).
1997-08-25 21:23:56 +00:00
Guido van Rossum a27d112213 Rename roundup() to roundupsize(), as there's a macro roundup() in the
sys/types.h header on many systems that may get pulled in (through
WANT_SIGFPE_HANDLER which pulls in signal.h).
1997-08-25 18:36:23 +00:00
Guido van Rossum 36f8e2d1db Use lseek instead of ftell; compensate by adding BUFSIZE 1997-08-21 02:31:25 +00:00
Guido van Rossum fd7a0b871f Made lookdict nearly twice as fast, resulting in a 5% overall
improvement of pystone.  Vladimir Marangozov.
1997-08-18 21:52:47 +00:00
Guido van Rossum 787bdd37a0 PyTuple_SetItem should require that the tuple's refcnt is one! 1997-08-17 16:25:45 +00:00
Guido van Rossum ea46e4d93c Fix mixup about PyErr_NoMemory() prototype. 1997-08-12 14:54:54 +00:00
Guido van Rossum 83f9ad8399 Fix bug in comparing function objects detected by Sjoerd:
SystemError: bad argument to internal function

caused by comparing NULL pointer default args.
1997-08-05 16:51:05 +00:00
Guido van Rossum fbbd57e4ca Added _Fini() routines to free up some memory 1997-08-05 02:16:08 +00:00
Guido van Rossum 971a7aaeac Change the Fini function to only remove otherwise unreferenced strings
from the interned table.  There are references in hard-to-find static
variables all over the interpreter, and it's not worth trying to get
rid of all those; but "uninterning" isn't fair either and may cause
subtle failures later -- so we have to keep them in the interned
table.

Also get rid of no-longer-needed insert of None in interned dict.
1997-08-05 02:15:12 +00:00
Guido van Rossum 1f39c5c666 Added separate free list for cfunction (builtin method) objects, for a
few percent speed up.  Also add PyCFunction_Fini() to discard it.
1997-08-05 02:11:41 +00:00
Guido van Rossum 404b95d9ba Provide a dummy empty directory as f_builtins instead of failing, when
no valid directory is passed in.  This prevents __del__ to fail when
invoked after __builtins__ has already been discarded.

Also add PyFrame_Fini() to discard the cache of frames.
1997-08-05 02:09:46 +00:00
Guido van Rossum a0d349f46a Added separate free list for instance method objects, for a few
percent speed up.  Also add PyMethod_Fini() to discard it.
1997-08-05 02:06:53 +00:00
Guido van Rossum e09fb55f29 Added _Py_ResetReferences(), if tracing references.
In _Py_PrintReferences(), no longer suppress once-referenced string.

Add Py_Malloc and friends and PyMem_Malloc and friends (malloc
wrappers for third parties).
1997-08-05 02:04:34 +00:00
Guido van Rossum eb46d67ce5 Avoid function calls to access the current thread state and builtins
-- the thread state is passed in as an argument and the builtins are a
member thereof.
1997-08-02 02:59:08 +00:00
Guido van Rossum 8cf0476474 Added internal routine PyString_Fini() which deletes all interned
strings.  For use in Py_Finalize() only.
1997-08-02 02:57:45 +00:00
Guido van Rossum f6ca6aa869 New build procedure. 1997-07-19 19:39:57 +00:00
Guido van Rossum 5d8123f34a Reordered list of methods to hopefully put the most frequently used
ones near the front.
1997-07-13 03:58:01 +00:00
Guido van Rossum 74ba24758e Reordered list of methods to hopefully put the most frequently used
ones near the front.

Also added a missing "return -1" to PyFile_WriteString.
1997-07-13 03:56:50 +00:00
Guido van Rossum 71160aaffe Use #include "mymath.h" instead of declaring fabs() explicitly.
This should solve a weird problem on the Mac for Jack.
1997-06-03 18:03:18 +00:00
Guido van Rossum a8d5131d57 Renamed dict.absorb() (too spungy) to dict.update(). 1997-06-02 17:13:37 +00:00
Guido van Rossum 80c2a1674e American spelling in doc string. 1997-06-02 14:43:07 +00:00
Guido van Rossum e3f5b9c8d1 Added dict.absorb() and dict.copy(). 1997-05-28 19:15:28 +00:00
Guido van Rossum c8b6df9004 PyObject_Compare can raise an exception now. 1997-05-23 00:06:51 +00:00
Guido van Rossum 5b2121b25f PyObject_Compare can now return an error. Unfortunately, there are a
few places where we don't know how to test for them without losing
speed; don't know yet how to handle that.
1997-05-23 00:01:41 +00:00
Guido van Rossum 27a60b147c PyFile_WriteString now returns an error indicator instead of calling
PyErr_Clear().
1997-05-22 22:25:11 +00:00
Guido van Rossum e9eec54798 Fix typo in error checking spotted by Just... 1997-05-22 14:02:25 +00:00
Guido van Rossum a9040ec5d9 Renamed a local variable from 'PyCFunction' (which is also a typedef
in methodobject.h) to 'func'.  /bin/cc on SunOS 4.x didn't grok this.
1997-05-20 22:09:08 +00:00
Guido van Rossum 037b2205e8 Moved PyObject_{Get,Set}Attr to object.c.
Fixed two 'return NULL' that should be 'return -1'.
1997-05-20 18:35:19 +00:00
Guido van Rossum 98ff96adba Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr. 1997-05-20 18:34:44 +00:00
Guido van Rossum 967839473a Got rid of c_error in favor of errno (and EDOM/ERANGE).
Assume that errno usage is thread-safe -- most vendors do this by
making in a macro that refers to a per-thread storage area.
1997-05-20 18:21:34 +00:00
Guido van Rossum 3cca24570e Got rid of all the last_name_* bogosities. I don't think the
complexity saved much any more.  A simple benchmark (grail) showed
that there were 3 times as many misses as hits, and the same number of
times again the code was bypassed altogether due to the existence of
setattro/getattro.
1997-05-16 14:23:33 +00:00
Guido van Rossum d0c87ee6c4 Oops, another forgotten renaming: varobject -> PyVarObject. 1997-05-15 21:31:03 +00:00
Guido van Rossum e61093c218 Fix reversed test for failure in PySequence_List() and PySequence_Tuple().
This broke cPickle.
1997-05-14 18:43:29 +00:00