summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove some shadowed variablesNeal Norwitz2006-01-081-1/+1
|
* SF patch #1390657:Armin Rigo2005-12-291-6/+45
| | | | | | | | | | | | | | | | | * set sq_repeat and sq_concat to NULL for user-defined new-style classes, as a way to fix a number of related problems. See test_descr.notimplemented()). One of these problems was fixed in r25556 and r25557 but many more existed; this is a general fix and thus reverts r25556-r25557. * to avoid having PySequence_Repeat()/PySequence_Concat() failing on user-defined classes, they now fall back to nb_add/nb_mul if sq_concat/sq_repeat are not defined and the arguments appear to be sequences. * added tests. Backport candidate.
* Convert iterator __len__() methods to a private API.Raymond Hettinger2005-09-241-1/+26
|
* SF bug #1242657: list(obj) can swallow KeyboardInterruptRaymond Hettinger2005-08-211-0/+5
| | | | | | Fix over-aggressive PyErr_Clear(). The same code fragment appears in various guises in list.extend(), map(), filter(), zip(), and internally in PySequence_Tuple().
* Fix:Michael W. Hudson2005-07-121-8/+13
| | | | | | | [ 1229429 ] missing Py_DECREF in PyObject_CallMethod Add a test in test_enumerate, which is a bit random, but suffices (reversed_new calls PyObject_CallMethod under some circumstances).
* Make subclasses of int, long, complex, float, and unicode perform typeBrett Cannon2005-04-261-47/+37
| | | | | | | conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald.
* Small boost to PySequence_Fast(). Lists build faster than tuples forRaymond Hettinger2004-12-181-1/+1
| | | | unsized iterable inputs.
* Add missing decref.Raymond Hettinger2004-12-161-0/+1
|
* SF bug #1085744: Performance issues with PySequence_Tuple()Raymond Hettinger2004-12-161-4/+14
| | | | | | | * Added missing error checks. * Fixed O(n**2) growth pattern. Modeled after lists to achieve linear amortized resizing. Improves construction of "tuple(it)" when "it" is large and does not have a __len__ method. Other cases are unaffected.
* SF bug #1030557: PyMapping_Check crashes when argument is NULLRaymond Hettinger2004-09-191-2/+2
| | | | | | Make PySequence_Check() and PyMapping_Check() handle NULL inputs. This goes beyond what most of the other checks do, but it is nice defensive programming and solves the OP's problem.
* Check the type of values returned by __int__, __float__, __long__,Neil Schemenauer2004-07-191-6/+33
| | | | | | __oct__, and __hex__. Raise TypeError if an invalid type is returned. Note that PyNumber_Int and PyNumber_Long can still return ints or longs. Fixes SF bug #966618.
* SF bug #952866: "can't multiply sequence *by* non-int"Raymond Hettinger2004-05-121-1/+1
| | | | Minor wording fix.
* Improve previous checkin to use a slot check instead of equivalentRaymond Hettinger2004-04-051-1/+2
| | | | attribute name lookup.
* Improve accuracy of sequence and mapping checks.Raymond Hettinger2004-04-041-2/+8
|
* recursive_isinstance(), recursive_issubclass(): New code here returnedTim Peters2004-03-211-2/+2
| | | | | NULL in case of error, but the functions are declared to return int. MSVC 6 properly complains about that. Return -1 on error instead.
* Limit the nesting depth of a tuple passed as the second argument toBrett Cannon2004-03-201-9/+36
| | | | isinstance() or issubclass() to the recursion limit of the interpreter.
* Add missing decrefRaymond Hettinger2004-03-171-0/+1
|
* Eliminate a big block of duplicate code in PySequence_List() byRaymond Hettinger2004-03-111-54/+6
| | | | exposing _PyList_Extend().
* SF Patch #871704: Py_SequenceFast can mask errorsRaymond Hettinger2004-01-111-3/+11
| | | | | | | (Contributed by Greg Chapman.) Since this only changes the error message, I doubt that it should be backported.
* Apply pre-sizing optimization to a broader class of objects.Raymond Hettinger2004-01-041-8/+4
| | | | | Formerly, the length was only fetched from sequence objects. Now, any object that reports its length can benefit from pre-sizing.
* Apply tuple/list pre-sizing optimization to a broader class of objects.Raymond Hettinger2004-01-041-1/+1
| | | | | | | | Formerly, length data fetched from sequence objects. Now, any object that reports its length can benefit from pre-sizing. On one sample timing, it gave a threefold speedup for list(s) where s was a set object.
* Fix Greg Ward's error message nit: PyObject_SetItem and PySequenceSetItemRaymond Hettinger2003-10-271-1/+1
| | | | had slightly different error messages.
* Removed duplicate test from inner loop.Raymond Hettinger2003-03-011-6/+1
| | | | The PyIter_Check is already performed by PyObject_GetIter.
* Make PyNumber_Check() a bit more careful, since all sorts of thingsGuido van Rossum2003-02-181-1/+3
| | | | now have tp_as_number. Check for nb_int or nb_float.
* Add missing cast in previous fix.Guido van Rossum2003-02-121-1/+2
|
* SF #532767: isinstance(x, X) should work when x is a proxy for an XGuido van Rossum2003-02-121-6/+19
| | | | | instance, as long as x.__class__ is X or a subclass thereof. Did a little cleanup of PyObject_IsInstance() too.
* Fold long lines.Guido van Rossum2003-02-101-4/+7
|
* Merge to trunk from release branch:Guido van Rossum2002-12-311-0/+1
| | | | Plug the leak that Tim just reported.
* Always try nb_* slots before trying sq_concat, sq_inplace_concat, sq_repeat,Neil Schemenauer2002-12-301-50/+128
| | | | | | | andsq_inplace_repeat. This fixes a number of corner case bugs (see #624807). Consolidate the int and long sequence repeat code. Before the change, integers checked for integer overflow but longs did not.
* Change issubclass() so that recursive tuples (directly or indirectlyWalter Dörwald2002-12-121-4/+4
| | | | | | containing class objects) are allowed as the second argument. This makes issubclass() more similar to isinstance() where recursive tuples are allowed too.
* Enhance issubclass() and PyObject_IsSubclass() so that a tuple isWalter Dörwald2002-12-121-28/+42
| | | | | | | | | | | 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.
* Fix typo in abstract.c which caused __rpow__ to not be invoked.Raymond Hettinger2002-12-071-1/+1
| | | | | Added related testcase. Closes SF bug #643260.
* Simplify use of NB_BINOP and NB_TERNOP by making them do the pointerNeil Schemenauer2002-11-241-15/+15
| | | | dereference rather than the caller.
* Remove special handling of str and unicode in PyNumber_InPlaceRemainder. TheyNeil Schemenauer2002-11-241-9/+2
| | | | both have a nb_remainer slot.
* str and unicode objects now have a __mod__ slot so don't special case them inNeil Schemenauer2002-11-181-6/+0
| | | | | PyNumber_Remainder(). This fixes SF bug #615506 and allows string and unicode subclasses to override __mod__.
* Use PyList_CheckExact and PyTuple_CheckExact for checking whetherMichael W. Hudson2002-11-051-1/+1
| | | | PySequence_Fast needs to do anything siginificant.
* Squash a few calls to the hideously expensive PyObject_CallObject(o,a)Guido van Rossum2002-08-161-2/+2
| | | | | | | -- replace then with slightly faster PyObject_Call(o,a,NULL). (The difference is that the latter requires a to be a tuple; the former allows other values and wraps them in a tuple if necessary; it involves two more levels of C function calls to accomplish all that.)
* Patch #554716: Use __va_copy where available.Martin v. Löwis2002-07-281-0/+4
|
* Close SF bug 563740. complex() now finds __complex__() in new style classes.Raymond Hettinger2002-06-061-2/+2
| | | | | Made conversion failure error messages consistent between types. Added related unittests.
* Better isinstance error message.Thomas Heller2002-06-051-1/+2
| | | | | | Closes SF patch # 560250. Bugfix candidate IMO.
* abstract_get_bases(): Clarify exactly what the return values andBarry Warsaw2002-04-231-9/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | states can be for this function, and ensure that only AttributeErrors are masked. Any other exception raised via the equivalent of getattr(cls, '__bases__') should be propagated up. abstract_issubclass(): If abstract_get_bases() returns NULL, we must call PyErr_Occurred() to see if an exception is being propagated, and return -1 or 0 as appropriate. This is the specific fix for a problem whereby if getattr(derived, '__bases__') raised an exception, an "undetected error" would occur (under a debug build). This nasty situation was uncovered when writing a security proxy extension type for the Zope3 project, where the security proxy raised a Forbidden exception on getattr of __bases__. PyObject_IsInstance(), PyObject_IsSubclass(): After both calls to abstract_get_bases(), where we're setting the TypeError if the return value is NULL, we must first check to see if an exception occurred, and /not/ mask an existing exception. Neil Schemenauer should double check that these changes don't break his ExtensionClass examples (there aren't any test cases for those examples and abstract_get_bases() was added by him in response to problems with ExtensionClass). Neil, please add test cases if possible! I belive this is a bug fix candidate for Python 2.2.2.
* SF bug 544647.Guido van Rossum2002-04-161-2/+6
| | | | | | | | | PyNumber_InPlaceMultiply insisted on calling sq_inplace_repeat if it existed, even if nb_inplace_multiply also existed and the arguments weren't right for sq_inplace_repeat. Change this to only use sq_inplace_repeat if nb_inplace_multiply isn't defined. Bugfix candidate.
* Whitespace normalization and fold some long lines.Guido van Rossum2002-04-161-20/+19
|
* Fix leak of NotImplemented in previous checkin to PyNumber_Add().Jeremy Hylton2002-03-081-4/+6
| | | | | If result == Py_NotImplemented, always DECREF it before assigning a new value to result.
* Fix for SF bug 516727: MyInt(2) + "3" -> NotImplementedJeremy Hylton2002-03-081-4/+3
| | | | | | PyNumber_Add() tries the nb_add slot first, then falls back to sq_concat. However, tt didn't check the return value of sq_concat. If sq_concat returns NotImplemented, raise the standard TypeError.
* Revert the last odd change to PyNumber_Long: the problem it was tryingTim Peters2002-03-021-10/+2
| | | | to fix was almost certainly a bug in _PyLong_Copy (which I'll fix next).
* SF patch 514641 (Naofumi Honda) - Negative ob_size of LongObjectsGuido van Rossum2002-03-011-2/+10
| | | | | | | | | | Due to the bizarre definition of _PyLong_Copy(), creating an instance of a subclass of long with a negative value could cause core dumps later on. Unfortunately it looks like the behavior of _PyLong_Copy() is quite intentional, so the fix is more work than feels comfortable. This fix is almost, but not quite, the code that Naofumi Honda added; in addition, I added a test case.
* Implement PyObject_DelItemString. Fixes #498915.Martin v. Löwis2002-01-051-0/+18
|
* PyObject_GetItem(), PyObject_SetItem(), PyObject_DelItem(): Fix a fewGuido van Rossum2001-11-241-5/+10
| | | | | | | confusing error messages. If a new-style class has no sequence or mapping behavior, attempting to use the indexing notation with a non-integer key would complain that the sequence index must be an integer, rather than complaining that the operation is not supported.
* Add PyObject_CheckReadBuffer(), which returns true if its argumentJeremy Hylton2001-11-091-29/+35
| | | | | | supports the single-segment readable buffer interface. Add documentation for this and other PyObject_XXXBuffer() calls.