Commit Graph

475 Commits

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