summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* PyFunction_Call() did not check the result of PyObject_Repr() for NULL, andFred Drake2001-11-011-2/+2
| | | | | | | should just avoid calling it in the first place to avoid waiting for a repr of a large object like a dict or list. The result of PyObject_Repr() was being leaked as well. Bugfix candidate!
* PyObject_CallFunctionObArgs() ---> PyObject_CallFunctionObjArgs()Fred Drake2001-10-281-5/+5
| | | | PyObject_CallMethodObArgs() ---> PyObject_CallMethodObjArgs()
* PyObject_CallFunction(), PyObject_CallMethod(): Make sure we do not touchFred Drake2001-10-271-18/+11
| | | | | | the va_list until we are sure we have a format string and need to use it; this avoid premature initialization and having to finalize it several different places because of error returns.
* Added two new functions to conveniently call functions/methods from C.Fred Drake2001-10-261-0/+76
| | | | | | | PyObject_CallFunctionObArgs() and PyObject_CallMethodObArgs() have the advantage that no format strings need to be parsed. The CallMethod variant also avoids creating a new string object in order to retrieve a method from an object as well.
* Generalize dictionary() to accept a sequence of 2-sequences. At theTim Peters2001-10-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outer level, the iterator protocol is used for memory-efficiency (the outer sequence may be very large if fully materialized); at the inner level, PySequence_Fast() is used for time-efficiency (these should always be sequences of length 2). dictobject.c, new functions PyDict_{Merge,Update}FromSeq2. These are wholly analogous to PyDict_{Merge,Update}, but process a sequence-of-2- sequences argument instead of a mapping object. For now, I left these functions file static, so no corresponding doc changes. It's tempting to change dict.update() to allow a sequence-of-2-seqs argument too. Also changed the name of dictionary's keyword argument from "mapping" to "x". Got a better name? "mapping_or_sequence_of_pairs" isn't attractive, although more so than "mosop" <wink>. abstract.h, abstract.tex: Added new PySequence_Fast_GET_SIZE function, much faster than going thru the all-purpose PySequence_Size. libfuncs.tex: - Document dictionary(). - Fiddle tuple() and list() to admit that their argument is optional. - The long-winded repetitions of "a sequence, a container that supports iteration, or an iterator object" is getting to be a PITA. Many months ago I suggested factoring this out into "iterable object", where the definition of that could include being explicit about generators too (as is, I'm not sure a reader outside of PythonLabs could guess that "an iterator object" includes a generator call). - Please check my curly braces -- I'm going blind <0.9 wink>. abstract.c, PySequence_Tuple(): When PyObject_GetIter() fails, leave its error msg alone now (the msg it produces has improved since PySequence_Tuple was generalized to accept iterable objects, and PySequence_Tuple was also stomping on the msg in cases it shouldn't have even before PyObject_GetIter grew a better msg).
* Make the error message for unsupported operand types cleaner, inGuido van Rossum2001-10-221-7/+27
| | | | | | | | | | | | response to a message by Laura Creighton on c.l.py. E.g. >>> 0+'' TypeError: unsupported operand types for +: 'int' and 'str' (previously this did not mention the operand types) >>> ''+0 TypeError: cannot concatenate 'str' and 'int' objects
* Fix error checking done by abstract_issubclass and abstract_isinstance.Neil Schemenauer2001-10-181-44/+61
| | | | | | isinstance() now allows any object as the first argument and a class, a type or something with a __bases__ tuple attribute for the second argument. This closes SF patch #464992.
* Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,Guido van Rossum2001-10-071-1/+16
| | | | | not other sequences (then we'd have to except strings, and we'd still be susceptible to recursive attacks).
* binary_op1(), ternary_op(): rearrange the code so that slotw is testedGuido van Rossum2001-10-011-14/+14
| | | | | (to see whether __rop__ should go before __op__) only when slotv is set. This saves a test+branch when only slotw is set.