summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
Commit message (Collapse)AuthorAgeFilesLines
* _Py_PrintReferenceAddresses(): also print the type name. In real useTim Peters2003-04-181-1/+2
| | | | | | | | | I'm finding some pretty baffling output, like reprs consisting entirely of three left parens. At least this will let us know what type the object is (it's not str -- there's no quote character in the repr). New tool combinerefs.py, to combine the two output blocks produced via PYTHONDUMPREFS.
* _Py_PrintReferences(): Changed to print object address at start of eachTim Peters2003-04-171-1/+16
| | | | | | | | | | | | | | | new line. New pvt API function _Py_PrintReferenceAddresses(): Prints only the addresses and refcnts of the live objects. This is always safe to call, because it has no dependence on Python's C API. Py_Finalize(): If envar PYTHONDUMPREFS is set, call (the new) _Py_PrintReferenceAddresses() right before dumping final pymalloc stats. We can't print the reprs of the objects here because too much of the interpreter has been shut down. You need to correlate the addresses displayed here with the object reprs printed by the earlier PYTHONDUMPREFS call to _Py_PrintReferences().
* - pythunrun.c, Py_Finalize(): move the call to _Py_PrintReferences()Guido van Rossum2003-04-151-1/+1
| | | | | | | | | | | | | | | | | | | even farther down, to just before the call to _PyObject_DebugMallocStats(). This required the following changes: - pystate.c, PyThreadState_GetDict(): changed not to raise an exception or issue a fatal error when no current thread state is available, but simply return NULL without raising an exception (ever). - object.c, Py_ReprEnter(): when PyThreadState_GetDict() returns NULL, don't raise an exception but return 0. This means that when printing a container that's recursive, printing will go on and on and on. But that shouldn't happen in the case we care about (see first bullet). - Updated Misc/NEWS and Doc/api/init.tex to reflect changes to PyThreadState_GetDict() definition.
* Typo in comment.Tim Peters2003-03-231-1/+1
|
* Improved new Py_TRACE_REFS gimmicks.Tim Peters2003-03-231-14/+36
| | | | | | | | | | | Arranged that all the objects exposed by __builtin__ appear in the list of all objects. I basically peed away two days tracking down a mystery leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because the object leaking the references didn't appear in the sys.getobjects(0) list. The object happened to be False. Now False is in the list, along with other popular & previously missing leak candidates (like None). Alas, we still don't have a choke point covering *all* Python objects, so the list of all objects may still be incomplete.
* Refactored some of the Py_TRACE_REFS code. New private API functionTim Peters2003-03-231-10/+14
| | | | | | | _Py_AddToAllObjects() that simply inserts an object at the front of the doubly-linked list of all objects. Changed PyType_Ready() (the closest thing we've got to a choke point for type objects) to call that.
* Oops! Used a wrong preprocessor symbol.Tim Peters2003-03-231-1/+1
|
* When Py_TRACE_REFS is defined, a list of all live objects is maintained inTim Peters2003-03-231-2/+15
| | | | | | | | | | | a doubly-linked list, exposed by sys.getobjects(). Unfortunately, it's not really all live objects, and it seems my fate to bump into programs where sys.gettotalrefcount() keeps going up but where the reference leaks aren't accounted for by anything in the list of all objects. This patch helps a little: if COUNT_ALLOCS is also defined, from now on type objects will also appear in this list, provided at least one object of a type has been allocated.
* Renamed PyObject_GenericGetIter to PyObject_SelfIterRaymond Hettinger2003-03-171-1/+1
| | | | | | to more accurately describe what the function does. Suggested by Thomas Wouters.
* Created PyObject_GenericGetIter().Raymond Hettinger2003-03-171-0/+7
| | | | Factors out the common case of returning self.
* PyObject_Generic{Get,Set}Attr:Guido van Rossum2003-02-191-2/+4
| | | | | | | | | | Don't access tp_descr_{get,set} of a descriptor without checking the flag bits of the descriptor's type. While we know that the main type (the type of the object whose attribute is being accessed) has all the right flag bits (or else PyObject_Generic{Get,Set}Attr wouldn't be called), we don't know that for its class attributes! Will backport to 2.2.
* default_3way_compare(): use PyNumber_Check(), rather than testing forGuido van Rossum2003-02-181-3/+3
| | | | tp_as_number directly.
* SF bug 681122: Built-in function dir() causes refcount leak in baseclasses.Tim Peters2003-02-051-1/+4
| | | | | | merge_class_dict(): This was missing a decref. Bugfix candidate.
* Recursive compare machinery: The code that intended to exempt tuplesTim Peters2003-01-201-9/+14
| | | | | | | | | | | | was broken because new-in-2.3 code added a tp_as_mapping slot to tuples. Repaired that. Added basic docs to check_recursion(). The code that intended to exempt tuples and strings was also broken here, and in 2.2: these should use PyXYZ_CheckExact(), not PyXYZ_Check() -- we can't know whether subclass instances are immutable. This part (and this part alone) is a bugfix candidate.
* Fix SF bug #667147, Segmentation fault printing str subclassNeal Norwitz2003-01-131-3/+16
| | | | | | | Fix infinite recursion which occurred when printing an object whose __str__() returned self. Will backport
* Remove _Py_ResetReferences. Fixes bug #529750 "Circular reference makesNeil Schemenauer2002-11-171-7/+0
| | | | | | Py_Init crash". refchain cannot be cleared because objects can live across Py_Finalize() and Py_Initialize() if they are kept alive by circular references.
* PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR]Guido van Rossum2002-10-111-10/+4
| | | | | | | | | | macros. The 'op' argument is then the result from PyObject_MALLOC, and that can of course be NULL. In that case, PyObject_Init[Var] would raise a SystemError with "NULL object passed to PyObject_Init[Var]". But there's nothing the caller of the macro can do about this. So PyObject_Init[Var] should call just PyErr_NoMemory. Will backport.
* Speedup for PyObject_IsTrue(): check for True and False first.Guido van Rossum2002-08-241-0/+4
| | | | | Because all built-in tests return bools now, this is the most common path!
* Speedup for PyObject_RichCompareBool(): PyObject_RichCompare() almostGuido van Rossum2002-08-241-1/+4
| | | | | always returns a bool, so avoid calling PyObject_IsTrue() in that case.
* Another modest speedup in PyObject_GenericGetAttr(): inline the callGuido van Rossum2002-08-191-2/+26
| | | | to _PyType_Lookup().
* Inline call to _PyObject_GetDictPtr() in PyObject_GenericGetAttr().Guido van Rossum2002-08-191-3/+20
| | | | This causes a modest speedup.
* Replace abort with Py_FatalError.Martin v. Löwis2002-08-071-1/+1
|
* Excise DL_IMPORT/EXPORT from object.h, and related files. This patchMark Hammond2002-07-291-2/+2
| | | | | also adds 'extern' to PyAPI_DATA rather than at each declaration, as discussed with Tim and Guido.
* object.h special-build macro minefield: renamed all the new lexicalTim Peters2002-07-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | helper macros to something saner, and used them appropriately in other files too, to reduce #ifdef blocks. classobject.c, instance_dealloc(): One of my worst Python Memories is trying to fix this routine a few years ago when COUNT_ALLOCS was defined but Py_TRACE_REFS wasn't. The special-build code here is way too complicated. Now it's much simpler. Difference: in a Py_TRACE_REFS build, the instance is no longer in the doubly-linked list of live objects while its __del__ method is executing, and that may be visible via sys.getobjects() called from a __del__ method. Tough -- the object is presumed dead while its __del__ is executing anyway, and not calling _Py_NewReference() at the start allows enormous code simplification. typeobject.c, call_finalizer(): The special-build instance_dealloc() pain apparently spread to here too via cut-'n-paste, and this is much simpler now too. In addition, I didn't understand why this routine was calling _PyObject_GC_TRACK() after a resurrection, since there's no plausible way _PyObject_GC_UNTRACK() could have been called on the object by this point. I suspect it was left over from pasting the instance_delloc() code. Instead asserted that the object is still tracked. Caution: I suspect we don't have a test that actually exercises the subtype_dealloc() __del__-resurrected-me code.
* The Py_REF_DEBUG/COUNT_ALLOCS/Py_TRACE_REFS macro minefield: addedTim Peters2002-07-091-0/+15
| | | | | | | | | | | | | | | | | | | | | more trivial lexical helper macros so that uses of these guys expand to nothing at all when they're not enabled. This should help sub- standard compilers that can't do a good job of optimizing away the previous "(void)0" expressions. Py_DECREF: There's only one definition of this now. Yay! That was that last one in the family defined multiple times in an #ifdef maze. Py_FatalError(): Changed the char* signature to const char*. _Py_NegativeRefcount(): New helper function for the Py_REF_DEBUG expansion of Py_DECREF. Calling an external function cuts down on the volume of generated code. The previous inline expansion of abort() didn't work as intended on Windows (the program often kept going, and the error msg scrolled off the screen unseen). _Py_NegativeRefcount calls Py_FatalError instead, which captures our best knowledge of how to abort effectively across platforms.
* SF bug 578752: COUNT_ALLOCS vs heap typesTim Peters2002-07-081-0/+9
| | | | | | | Repair segfaults and infinite loops in COUNT_ALLOCS builds in the presence of new-style (heap-allocated) classes/types. Bugfix candidate. I'll backport this to 2.2. It's irrelevant in 2.1.
* Rearranged and added comments to object.h, to clarify many thingsTim Peters2002-07-071-6/+2
| | | | | | | | | | | that have taken me "too long" to reverse-engineer over the years. Vastly reduced the nesting level and redundancy of #ifdef-ery. Took a light stab at repairing comments that are no longer true. sys_gettotalrefcount(): Changed to enable under Py_REF_DEBUG. It was enabled under Py_TRACE_REFS, which was much heavier than necessary. sys.gettotalrefcount() is now available in a Py_REF_DEBUG-only build.
* Removed 3 unlikely #includes that were only needed for the non-gc flavorTim Peters2002-07-071-5/+0
| | | | of the trashcan code.
* Trashcan cleanup: Now that cyclic gc is always there, the trashcanTim Peters2002-07-071-50/+40
| | | | | | | | | | | | | | | | | | | mechanism is no longer evil: it no longer plays dangerous games with the type pointer or refcounts, and objects in extension modules can play along too without needing to edit the core first. Rewrote all the comments to explain this, and (I hope) give clear guidance to extension authors who do want to play along. Documented all the functions. Added more asserts (it may no longer be evil, but it's still dangerous <0.9 wink>). Rearranged the generated code to make it clearer, and to tolerate either the presence or absence of a semicolon after the macros. Rewrote _PyTrash_destroy_chain() to call tp_dealloc directly; it was doing a Py_DECREF again, and that has all sorts of obscure distorting effects in non-release builds (Py_DECREF was already called on the object!). Removed Christian's little "embedded change log" comments -- that's what checkin messages are for, and since it was impossible to correlate the comments with the code that changed, I found them merely distracting.
* Removed WITH_CYCLE_GC #ifdef-ery. Holes:Tim Peters2002-07-071-43/+0
| | | | | | + I'm not sure what to do about configure.in. Left it alone. + Ditto pyexpat.c. Fred or Martin will know what to do.
* SF # 533070 Silence AIX C Compiler WarningsNeal Norwitz2002-06-131-1/+1
| | | | Warning caused by using &func. & is not necessary.
* SF # 561244 Micro optimizationsNeal Norwitz2002-06-131-5/+3
| | | | Cleanup code a bit and return as early as possible.
* Fix typoNeal Norwitz2002-05-311-1/+1
|
* Implement the intention of SF patch 472523 (but coded differently).Guido van Rossum2002-05-311-15/+67
| | | | | | | | | | | | | | | | | | In the past, an object's tp_compare could return any value. In 2.2 the docs were tightened to require it to return -1, 0 or 1; and -1 for an error. We now issue a warning if the value is not in this range. When an exception is raised, we allow -1 or -2 as return value, since -2 will the recommended return value for errors in the future. (Eventually tp_compare will also be allowed to return +2, to indicate NotImplemented; but that can only be implemented once we know all extensions return a value in [-2...1]. Or perhaps it will require the type to set a flag bit.) I haven't decided yet whether to backport this to 2.2.x. The patch applies fine. But is it fair to start warning in 2.2.2 about code that worked flawlessly in 2.2.1?
* - A new type object, 'string', is added. This is a common base typeGuido van Rossum2002-05-241-0/+3
| | | | | | | for 'str' and 'unicode', and can be used instead of types.StringTypes, e.g. to test whether something is "a string": isinstance(x, string) is True for Unicode and 8-bit strings. This is an abstract base class and cannot be instantiated directly.
* Jim Fulton reported a segfault in dir(). A heavily proxied objectGuido van Rossum2002-05-131-7/+15
| | | | | | | | returned a proxy for __class__ whose __bases__ was also a proxy. The merge_class_dict() helper for dir() assumed incorrectly that __bases__ would always be a tuple and used the in-line tuple API on the proxy. I will backport this to 2.2 as well.
* PyNumber_CoerceEx: this took a shortcut (not doing anything) when theGuido van Rossum2002-04-261-1/+4
| | | | | | | | | | | | | | | | | | | | | left and right type were of the same type and not classic instances. This shortcut is dangerous for proxy types, because it means that coerce(Proxy(1), Proxy(2.1)) leaves Proxy(1) unchanged rather than turning it into Proxy(1.0). In an ever-so-slight change of semantics, I now only take the shortcut when the left and right types are of the same type and don't have the CHECKTYPES feature. It so happens that classic instances have this flag, so the shortcut is still skipped in this case (i.e. nothing changes for classic instances). Proxies also have this flag set (otherwise implementing numeric operations on proxies would become nightmarish) and this means that the shortcut is also skipped there, as desired. It so happens that int, long and float also have this flag set; that means that e.g. coerce(1, 1) will now invoke int_coerce(). This is fine: int_coerce() can deal with this, and I'm not worried about the performance; int_coerce() is only invoked when the user explicitly calls coerce(), which should be rarer than rare.
* First stab at rationalizing the PyMem_ API. Mixing PyObject_xyz withTim Peters2002-04-121-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | PyMem_{Del, DEL} doesn't work yet (compilation problems). pyport.h: _PyMem_EXTRA is gone. pmem.h: Repaired comments. PyMem_{Malloc, MALLOC} and PyMem_{Realloc, REALLOC} now make the same x-platform guarantees when asking for 0 bytes, and when passing a NULL pointer to the latter. object.c: PyMem_{Malloc, Realloc} just call their macro versions now, since the latter take care of the x-platform 0 and NULL stuff by themselves now. pypcre.c, grow_stack(): So sue me. On two lines, this called PyMem_RESIZE to grow a "const" area. It's not legit to realloc a const area, so the compiler warned given the new expansion of PyMem_RESIZE. It would have gotten the same warning before if it had used PyMem_Resize() instead; the older macro version, but not the function version, silently cast away the constness. IMO that was a wrong thing to do, and the docs say the macro versions of PyMem_xyz are deprecated anyway. If somebody else is resizing const areas with the macro spelling, they'll get a warning when they recompile now too.
* Move PyObject_Malloc and PyObject_Free to obmalloc.c.Neil Schemenauer2002-04-121-21/+2
|
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-0/+3
| | | | | | | | | | | | | PEP 285. Everything described in the PEP is here, and there is even some documentation. I had to fix 12 unit tests; all but one of these were printing Boolean outcomes that changed from 0/1 to False/True. (The exception is test_unicode.py, which did a type(x) == type(y) style comparison. I could've fixed that with a single line using issubtype(x, type(y)), but instead chose to be explicit about those places where a bool is expected. Still to do: perhaps more documentation; change standard library modules to return False/True from predicates.
* If the GC is enabled then don't use the ob_type pointer to create a listNeil Schemenauer2002-03-291-1/+12
| | | | of trash objects. Use the gc_prev pointer instead.
* Build obmalloc.c directly instead of #include'ing from object.c.Tim Peters2002-03-231-43/+0
| | | | | | | | Also move all _PyMalloc_XXX entry points into obmalloc.c. The Windows build works fine. The Unix build is changed here (Makefile.pre.in), but not tested. No other platform's build process has been fiddled.
* Add pymalloc object memory management functions. These must beNeil Schemenauer2002-03-221-0/+24
| | | | | available even if pymalloc is disabled since extension modules might use them.
* Drop the PyCore_* memory API.Neil Schemenauer2002-03-181-1/+16
|
* Patch #517521: Consider byte strings before Unicode stringsMartin v. Löwis2002-03-151-52/+60
| | | | in PyObject_Get/SetAttr.
* Whether platform malloc(0) returns NULL has nothing to do with whetherTim Peters2002-03-021-5/+2
| | | | | | | | | | | platform realloc(p, 0) returns NULL, so MALLOC_ZERO_RETURNS_NULL can be correctly undefined yet realloc(p, 0) can return NULL anyway. Prevent realloc(p, 0) doing free(p) and returning NULL via a different hack. Would probably be better to get rid of MALLOC_ZERO_RETURNS_NULL entirely. Bugfix candidate.
* SF patch 514641 (Naofumi Honda) - Negative ob_size of LongObjectsGuido van Rossum2002-03-011-2/+8
| | | | | | | | | | 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.
* PyObject_Generic{Get,Set}Attr(): ensure that the attribute name is aGuido van Rossum2001-12-041-20/+72
| | | | | | | string object (or a Unicode that's trivially converted to ASCII). PyObject_GetAttr(): add an 'else' to the Unicode test like PyObject_SetAttr() already has.
* Rehabilitated the fast-path richcmp code, and sped it up. It wasn'tTim Peters2001-11-041-31/+35
| | | | | | | | | | | | | | | helping for types that defined tp_richcmp but not tp_compare, although that's when it's most valuable, and strings moved into that category since the fast path was first introduced. Now it helps for same-type non-Instance objects that define rich or 3-way compares. For all the edits here, the rest just amounts to moving the fast path from do_richcmp into PyObject_RichCompare, saving a layer of function call (measurable on my box!). This loses when NESTING_LIMIT is exceeded, but I don't care about that (fast-paths are for normal cases, not pathologies). Also added a tasteful <wink> label to get out of PyObject_RichCompare, as the if/else nesting in this routine was getting incomprehensible.
* No code change -- just trying to document the return conditions for allTim Peters2001-11-041-17/+43
| | | | the internal comparison routines.