summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* _Py_GetObjects(): GCC suggests to add () around && within || for someGuido van Rossum2001-07-141-1/+1
| | | | code only compiled in debug mode, and I dutifully comply.
* Patch #424475: Speed-up tp_compare usage, by special-casing the commonMartin v. Löwis2001-06-091-20/+49
| | | | | | case of objects with equal types which support tp_compare. Give type objects a tp_compare function. Also add c<0 tests before a few PyErr_Occurred tests.
* Cosmetic: code under "else" clause was missing indent.Tim Peters2001-05-111-1/+1
|
* SF bug #422108 - Error in rich comparisons.Tim Peters2001-05-071-1/+7
| | | | | | 2.1.1 bugfix candidate too. Fix a bad (albeit unlikely) return value in try_rich_to_3way_compare(). Also document do_cmp()'s return values.
* Make 'x in y' and 'x not in y' (PySequence_Contains) play nice w/ iterators.Tim Peters2001-05-051-0/+1
| | | | | | | | | | | | | NEEDS DOC CHANGES A few more AttributeErrors turned into TypeErrors, but in test_contains this time. The full story for instance objects is pretty much unexplainable, because instance_contains() tries its own flavor of iteration-based containment testing first, and PySequence_Contains doesn't get a chance at it unless instance_contains() blows up. A consequence is that some_complex_number in some_instance dies with a TypeError unless some_instance.__class__ defines __iter__ but does not define __getitem__.
* The weakref support in PyObject_InitVar() as well; this should have come outFred Drake2001-05-031-4/+0
| | | | at the same time as it did from PyObject_Init() .
* Remove unnecessary intialization for the case of weakly-referencable objects;Fred Drake2001-05-031-4/+0
| | | | | | | the code necessary to accomplish this is simpler and faster if confined to the object implementations, so we only do this there. This causes no behaviorial changes beyond a (very slight) speedup.
* Printing objects to a real file still wasn't done right: if theGuido van Rossum2001-05-011-32/+14
| | | | | | | | | | | | | | | | | | | object's type didn't define tp_print, there were still cases where the full "print uses str() which falls back to repr()" semantics weren't honored. This resulted in >>> print None <None object at 0x80bd674> >>> print type(u'') <type object at 0x80c0a80> Fixed this by always using the appropriate PyObject_Repr() or PyObject_Str() call, rather than trying to emulate what they would do. Also simplified PyObject_Str() to always fall back on PyObject_Repr() when tp_str is not defined (rather than making an extra check for instances with a __str__ method). And got rid of the special case for strings.
* (Adding this to the trunk as well.)Guido van Rossum2001-04-271-1/+4
| | | | | | | | Fix a very old flaw in PyObject_Print(). Amazing! When an object type defines tp_str but not tp_repr, 'print x' to a real file object would not call the tp_str slot but rather print a default style representation: <foo object at 0x....>. This even though 'print x' to a file-like-object would correctly call the tp_str slot.
* Fixed ref count bug. Patch #411191. Found by Walter Dörwald.Marc-André Lemburg2001-03-251-1/+3
|
* Add Vladimir Marangozov's object allocator. It is disabled by default. ThisNeil Schemenauer2001-02-271-0/+4
| | | | closes SF patch #401229.
* The return value from PyObject_ClearWeakRefs() is no longer meaningful,Fred Drake2001-02-261-3/+3
| | | | so make it void.
* _PyObject_Dump(): If argument is NULL, print "NULL" instead ofBarry Warsaw2001-02-221-3/+7
| | | | crashing.
* In try_3way_to_rich_compare(), swap the call to default_3way_compare()Guido van Rossum2001-02-221-2/+2
| | | | | | and the test for errors, so that an error in the default compare doesn't go undetected. This fixes SF Bug #132933 (submitted by effbot) -- list.sort doesn't detect comparision errors.
* PEP 205, Weak References -- initial checkin.Fred Drake2001-02-011-0/+23
|
* Check the Py_TPFLAGS_HAVE_RICHCOMPARE flag before using theGuido van Rossum2001-01-241-7/+9
| | | | | tp_richcompare field! (Hopefully this will make Python 2.1 binary compatible with certain Zope extensions. :-)
* PyObject_Dump() -> _PyObject_Dump()Barry Warsaw2001-01-241-3/+3
| | | | PyGC_Dump() -> _PyGC_Dump()
* PyObject_Dump(): Use %p format to print the address of the pointer.Barry Warsaw2001-01-231-2/+4
| | | | PyGC_Dump(): Wrap this in a #ifdef WITH_CYCLE_GC.
* A few miscellaneous helpers.Barry Warsaw2001-01-231-2/+26
| | | | | | | | | | | | | | | | PyObject_Dump(): New function that is useful when debugging Python's C runtime. In something like gdb it can be a pain to get some useful information out of PyObject*'s. This function prints the str() of the object to stderr, along with the object's refcount and hex address. PyGC_Dump(): Similar to PyObject_Dump() but knows how to cast from the garbage collector prefix back to the PyObject* structure. [See Misc/gdbinit for some useful gdb hooks] none_dealloc(): Rather than SEGV if we accidentally decref None out of existance, we assign None's and NotImplemented's destructor slot to this function, which just calls abort().
* New special case in comparisons: None is smaller than any other objectGuido van Rossum2001-01-221-0/+6
| | | | (unless the object's type overrides this comparison).
* Once again, numeric-smelling objects compare smaller than non-numericGuido van Rossum2001-01-221-2/+17
| | | | ones.
* Remove a smelly export.Neil Schemenauer2001-01-211-1/+1
|
* Tim chastens:Barry Warsaw2001-01-201-1/+5
| | | | | | | | | | | | | | Barry, that comment belongs in the code, not in the checkin msg. The code *used* to do this correctly (as you well know, since you & I went thru considerable pain to fix this the first time). However, because the *reason* for the convolution wasn't recorded in the code as a comment, somebody threw it all away the first time it got reworked. c-code-isn't-often-self-explanatory-ly y'rs - tim default_3way_compare(): Stick the checkin message from 2.110 in a comment.
* default_3way_compare(): When comparing the pointers, they must be castBarry Warsaw2001-01-201-2/+2
| | | | | | | to integer types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t). ANSI specifies that pointer compares other than == and != to non-related structures are undefined. This quiets an Insure portability warning.
* Rich comparisons fallout: PyObject_Hash() should check for bothGuido van Rossum2001-01-181-1/+1
| | | | | tp_compare and tp_richcompare NULL before deciding to do a quickie based on the object address. (Tim Peters discovered this.)
* Changes to recursive-object comparisons, having to do with a test caseGuido van Rossum2001-01-181-107/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I found where rich comparison of unequal recursive objects gave unintuituve results. In a discussion with Tim, where we discovered that our intuition on when a<=b should be true was failing, we decided to outlaw ordering comparisons on recursive objects. (Once we have fixed our intuition and designed a matching algorithm that's practical and reasonable to implement, we can allow such orderings again.) - Refactored the recursive-object comparison framework; more is now done in the support routines so less needs to be done in the calling routines (even at the expense of slowing it down a bit -- this should normally never be invoked, it's mostly just there to avoid blowing up the interpreter). - Changed the framework so that the comparison operator used is also stored. (The dictionary now stores triples (v, w, op) instead of pairs (v, w).) - Changed the nesting limit to a more reasonable small 20; this only slows down comparisons of very deeply nested objects (unlikely to occur in practice), while speeding up comparisons of recursive objects (previously, this would first waste time and space on 500 nested comparisons before it would start detecting recursion). - Changed rich comparisons for recursive objects to raise a ValueError exception when recursion is detected for ordering oprators (<, <=, >, >=). Unrelated change: - Moved PyObject_Unicode() to just under PyObject_Str(), where it belongs. MAL's patch must've inserted in a random spot between two functions in the file -- between two helpers for rich comparison...
* Deal properly (?) with comparing recursive datastructures.Guido van Rossum2001-01-171-62/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Use the compare nesting level and in-progress dictionary properly in PyObject_RichCompare(). - Change the in-progress code to use static variables instead of globals (both the nesting level and the key for the thread dict were globals but have no reason to be globals; the key can even be a function-static variable in get_inprogress_dict()). - Rewrote try_rich_to_3way_compare() to benefit from the similarity of the three cases, making it table-driven. - In try_rich_to_3way_compare(), test for EQ before LT and GT. This turns out essential when comparing recursive UserList instances; with the old code, these would recurse into rich comparison three times for each nesting level up to NESTING_LIMIT/2, making the total number of calls in the order of 3**(NESTING_LIMIT/2)! NOTE: I'm not 100% comfortable with this. It works for the standard test suite (which compares a few trivial recursive data structures only), but I'm not sure that the in-progress dictionary is used properly by the rich comparison code. Jeremy suggested that maybe the operation should be included in the dict. Currently I presume that objects in the dict are equal unless proven otherwise, and I set the outcome for the rich comparison accordingly: true for operators EQ, LE, GE, and false for the other three. But Jeremy seems to think that there may be counter-examples where this doesn't do the right thing.
* This patch adds a new builtin unistr() which behaves like str()Marc-André Lemburg2001-01-171-0/+47
| | | | | | | | | | except that it always returns Unicode objects. A new C API PyObject_Unicode() is also provided. This closes patch #101664. Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
* Rich comparisons. Refactored internal routine do_cmp() and added APIsGuido van Rossum2001-01-171-74/+293
| | | | | | | | PyObject_RichCompare() and PyObject_RichCompareBool(). XXX Note: the code that checks for deeply nested rich comparisons is bogus -- it assumes the two objects are always identical, rather than using the same logic as PyObject_Compare(). I'll fix that later.
* Changes for PEP 208. PyObject_Compare has been rewritten. Instances noNeil Schemenauer2001-01-041-118/+139
| | | | longer get special treatment. The Py_NotImplemented type is here as well.
* Ka-Ping Yee <ping@lfw.org>:Fred Drake2000-10-241-2/+2
| | | | | | Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
* Rationalize use of limits.h, moving the inclusion to Python.h.Fred Drake2000-09-261-3/+0
| | | | | | | | Add definitions of INT_MAX and LONG_MAX to pyport.h. Remove includes of limits.h and conditional definitions of INT_MAX and LONG_MAX elsewhere. This closes SourceForge patch #101659 and bug #115323.
* As suggested by Toby Dickenson, setting ob_type to NULL inGuido van Rossum2000-09-211-4/+0
| | | | _Py_Dealloc(), is a bad idea (and always was!). So let's drop it.
* PyObject_SetAttr() and PyObject_GetAttr() now also accept UnicodeMarc-André Lemburg2000-09-181-11/+37
| | | | | | | | | | | | | | | objects for the attribute name. Unicode objects are converted to a string using the default encoding before trying the lookup. Note that previously it was allowed to pass arbitrary objects as attribute name in case the tp_getattro/setattro slots were defined. This patch fixes this by applying an explicit string check first: all uses of these slots expect string objects and do not check for the type resulting in a core dump. The tp_getattro/setattro are still useful as optimization for lookups using interned string objects though. This patch fixes bug #113829.
* REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum2000-09-011-9/+0
| | | | This should match the situation in the 1.6b1 tree.
* PyOS_CheckStack() returns 1 when failing, not -1.Guido van Rossum2000-08-301-1/+1
|
* Added PyOS_CheckStack call to PyObject_CompareJack Jansen2000-08-221-0/+13
| | | | | Lowered the recursion limit on compares to 60 (one recursion depth can take a whopping 2K of stack space when running test_b1!)
* make_pair(): When comparing the pointers, they must be cast to integerBarry Warsaw2000-08-181-2/+6
| | | | | | types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t). ANSI specifies that pointer compares other than == and != to non-related structures are undefined. This quiets an Insure portability warning.
* Updated commentAndrew M. Kuchling2000-08-161-1/+1
|
* Fix for http://sourceforge.net/bugs/?func=detailbug&bug_id=111866&group_id=5470.Tim Peters2000-08-151-15/+55
| | | | | | | | | | | This was a misleading bug -- the true "bug" was that hash(x) gave an error return when x is an infinity. Fixed that. Added new Py_IS_INFINITY macro to pyport.h. Rearranged code to reduce growing duplication in hashing of float and complex numbers, pushing Trent's earlier stab at that to a logical conclusion. Fixed exceedingly rare bug where hashing of floats could return -1 even if there wasn't an error (didn't waste time trying to construct a test case, it was simply obvious from the code that it *could* happen). Improved complex hash so that hash(complex(x, y)) doesn't systematically equal hash(complex(y, x)) anymore.
* Fix missing decrements of the recursive counter in PyObject_Compare().Vladimir Marangozov2000-08-111-6/+12
| | | | Closes Patch #101065.
* Removing warnings found by gcc -WallMoshe Zadka2000-08-041-0/+4
|
* merge Include/my*.h into Include/pyport.hPeter Schneider-Kamp2000-07-311-2/+0
| | | | marked my*.h as obsolete
* Use 'void' directly instead of the ANY #define, now that all code is ANSI C.Thomas Wouters2000-07-251-8/+8
| | | | Leave the actual #define in for API compatibility.
* Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in eitherThomas Wouters2000-07-161-1/+1
| | | | | | | | | | comments, docstrings or error messages. I fixed two minor things in test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't"). There is a minor style issue involved: Guido seems to have preferred English grammar (behaviour, honour) in a couple places. This patch changes that to American, which is the more prominent style in the source. I prefer English myself, so if English is preferred, I'd be happy to supply a patch myself ;)
* Propagate the current exception in get_inprogress_dict() -- it doesn'tVladimir Marangozov2000-07-121-1/+0
| | | | need to be cleared.
* change abstract size functions PySequence_Size &c.Jeremy Hylton2000-07-121-1/+1
| | | | add macros for backwards compatibility with C source
* Include macglue.h on the macintosh, so function prototypes are in scope.Jack Jansen2000-07-111-0/+4
|
* ANSI-fication of the sources.Fred Drake2000-07-091-105/+46
|
* Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.Tim Peters2000-07-091-1/+1
|