summaryrefslogtreecommitdiffstats
path: root/Include/object.h
Commit message (Collapse)AuthorAgeFilesLines
* Patch #1538606, Patch to fix __index__() clipping.Neal Norwitz2006-08-121-1/+1
| | | | | | | I modified this patch some by fixing style, some error checking, and adding XXX comments. This patch requires review and some changes are to be expected. I'm checking in now to get the greatest possible review and establish a baseline for moving forward. I don't want this to hold up release if possible.
* Remove types from type_list if they have no objectsMartin v. Löwis2006-04-181-1/+3
| | | | | and unlist_types_without_objects is set. Give dump_counts a FILE* argument.
* There were no comments explaining what Py_CLEAR() did orTim Peters2006-04-151-0/+34
| | | | | | | why it's important. Now there are ;-) If someone else hasn't already, I'll add a Py_CLEAR cleanup task to the TODO Wiki next.
* Ignore the references to the dummy objects used as deleted keysArmin Rigo2006-04-121-0/+3
| | | | in dicts and sets when computing the total number of references.
* Checking in the code for PEP 357.Guido van Rossum2006-03-071-1/+8
| | | | | | This was mostly written by Travis Oliphant. I've inspected it all; Neal Norwitz and MvL have also looked at it (in an earlier incarnation).
* Use Py_ssize_t for _Py_RefTotal.Neal Norwitz2006-03-041-1/+1
| | | | I tried to handle Win64 properly, but please review.
* Make ob_refcnt and tp_maxalloc (and friends) Py_ssize_t.Martin v. Löwis2006-03-011-4/+4
|
* Revert backwards-incompatible const changes.Martin v. Löwis2006-02-271-4/+4
|
* Bug #1086854: Rename PyHeapType members adding ht_ prefix.Georg Brandl2006-02-201-3/+3
|
* Use Py_ssize_t for field sizes and offsets.Martin v. Löwis2006-02-161-3/+3
|
* Merge ssize_t branch.Martin v. Löwis2006-02-151-17/+31
|
* Add const to several API functions that take char *.Jeremy Hylton2005-12-101-7/+7
| | | | | | | | | | | | | | | | | | | In C++, it's an error to pass a string literal to a char* function without a const_cast(). Rather than require every C++ extension module to put a cast around string literals, fix the API to state the const-ness. I focused on parts of the API where people usually pass literals: PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type slots, etc. Predictably, there were a large set of functions that needed to be fixed as a result of these changes. The most pervasive change was to make the keyword args list passed to PyArg_ParseTupleAndKewords() to be a const char *kwlist[]. One cast was required as a result of the changes: A type object mallocs the memory for its tp_doc slot and later frees it. PyTypeObject says that tp_doc is const char *; but if the type was created by type_new(), we know it is safe to cast to char *.
* Change the %s format specifier for str objects so that it returns aNeil Schemenauer2005-08-121-0/+1
| | | | | unicode instance if the argument is not an instance of basestring and calling __str__ on the argument returns a unicode instance.
* A static swapped_op[] array was defined in 3 different C files, & I thinkTim Peters2004-09-231-0/+5
| | | | | I need to define it again. Bite the bullet and define it once as an extern, _Py_SwappedOp[].
* SF patch #1020188: Use Py_CLEAR where necessary to avoid crashesRaymond Hettinger2004-09-011-1/+1
| | | | (Contributed by Dima Dorfman)
* SF bug 994255: Py_RETURN_NONE causes too much warningsTim Peters2004-07-221-1/+1
| | | | | | | | | | Rewrote Py_RETURN_{NONE, TRUE, FALSE} to expand to comma expressions rather than "do {} while(0)" thingies. The OP complained because he likes using MS /W4 sometimes, and then all his uses of these things generate nuisance warnings about testing a constant expression (in the "while(0)" part). Comma expressions don't have this problem (although it's a lucky accident that comma expressions suffice for these macros!).
* Implemented a new Py_CLEAR macro. This macro should be used whenJim Fulton2004-07-141-0/+9
| | | | | decrementing the refcount of variables that might be accessed as a result of calling Python
* Two new public API functions, Py_IncRef and Py_DecRef. Useful forThomas Heller2004-04-221-0/+7
| | | | dynamic embedders of Python.
* fixed buggy comment as per SF bug #827856Alex Martelli2003-11-091-7/+7
| | | | (same as commit of Sun Nov 2 to the release23-maint branch)
* Modify the Py_RETURN_* macros to be of the form ``do {...} while (0)`` in orderBrett Cannon2003-10-191-1/+1
| | | | to handle situations like ``if (foo) Py_RETURN_NONE else ...``.
* Modified the Py_RETURN_* macros by having the statements surrounded by {} inBrett Cannon2003-10-191-1/+1
| | | | | order to prevent any unexpected surprises from someone using them in a conditional without using curly braces (e.g., ``if (foo) Py_RETURN_TRUE``.
* Defined macros Py_RETURN_(TRUE|FALSE|NONE) as helper functions for returningBrett Cannon2003-10-191-0/+3
| | | | the specified value. All three Py_INCREF the singleton and then return it.
* After Raymond's remark, I changed the Stackless bits toChristian Tismer2003-05-231-2/+2
| | | | | two fixed bits, position 15 and 16. It is right, why should these be elsewhere.
* Generalized my type flags structure extension without being specific aboutChristian Tismer2003-05-231-4/+4
| | | | | | the purpose. Increased my claim to two bits, hoping that nobody will complain about it. I'm taking the highest two bits, whatever the integer word size may be.
* Preserved one bit in type objects for Stackless.Christian Tismer2003-05-201-0/+8
| | | | | The presence of this bit controls, whether there are special fields for non-recursive calls.
* _Py_PrintReferences(): Changed to print object address at start of eachTim Peters2003-04-171-0/+1
| | | | | | | | | | | | | | | 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().
* Improved new Py_TRACE_REFS gimmicks.Tim Peters2003-03-231-1/+1
| | | | | | | | | | | 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-0/+1
| | | | | | | _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.
* 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/+1
| | | | Factors out the common case of returning self.
* - The extended type structure used for heap types (new-styleGuido van Rossum2003-03-071-0/+22
| | | | | classes defined by Python code using a class statement) is now exported from object.h as PyHeapTypeObject. (SF patch #696193.)
* Remove _Py_ResetReferences. Fixes bug #529750 "Circular reference makesNeil Schemenauer2002-11-171-1/+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.
* A modest speedup of object deallocation. call_finalizer() did ratherGuido van Rossum2002-08-081-0/+1
| | | | | | | | | | | | | | | a lot of work: it had to save and restore the current exception around a call to lookup_maybe(), because that could fail in rare cases, and most objects don't have a __del__ method, so the whole exercise was usually a waste of time. Changed this to cache the __del__ method in the type object just like all other special methods, in a new slot tp_del. So now subtype_dealloc() can test whether tp_del is NULL and skip the whole exercise if it is. The new slot doesn't need a new flag bit: subtype_dealloc() is only called if the type was dynamically allocated by type_new(), so it's guaranteed to have all current slots. Types defined in C cannot fill in tp_del with a function of their own, so there's no corresponding "wrapper". (That functionality is already available through tp_dealloc.)
* Added info about the right way to leave the body of a trashcan-protectedTim Peters2002-08-071-0/+5
| | | | destructor early.
* Excise DL_IMPORT/EXPORT from object.h, and related files. This patchMark Hammond2002-07-291-51/+51
| | | | | also adds 'extern' to PyAPI_DATA rather than at each declaration, as discussed with Tim and Guido.
* staticforward bites the dust.Jeremy Hylton2002-07-171-18/+9
| | | | | | | | | | | | | | | The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) I'm leaving staticforward and statichere defined in object.h as static. This is only for backwards compatibility with C extensions that might still use it. XXX I haven't updated the documentation.
* object.h special-build macro minefield: renamed all the new lexicalTim Peters2002-07-111-60/+40
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Uglified the new Py_REF_DEBUG (etc) lexical helper macro definitions soTim Peters2002-07-101-21/+25
| | | | | | | that their uses can be prettier. I've come to despise the names I picked for these things, though, and expect to change all of them -- I changed a bunch of other files to use them (replacing #ifdef blocks), but the names were so obscure out of context that I backed that all out again.
* The Py_REF_DEBUG/COUNT_ALLOCS/Py_TRACE_REFS macro minefield: addedTim Peters2002-07-091-27/+35
| | | | | | | | | | | | | | | | | | | | | 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.
* Rearranged and added comments to object.h, to clarify many thingsTim Peters2002-07-071-74/+120
| | | | | | | | | | | 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.
* Trashcan cleanup: Now that cyclic gc is always there, the trashcanTim Peters2002-07-071-50/+53
| | | | | | | | | | | | | | | | | | | 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-4/+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.
* Change the type of the tp_free from 'destructor' to 'freefunc'.Neil Schemenauer2002-04-121-1/+2
|
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-2/+2
| | | | | | | | | | | | | 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.
* Patch supplied by Burton Radons for his own SF bug #487390: ModifyingGuido van Rossum2001-12-081-1/+1
| | | | | | | | | | | | | type.__module__ behavior. This adds the module name and a dot in front of the type name in every type object initializer, except for built-in types (and those that already had this). Note that it touches lots of Mac modules -- I have no way to test these but the changes look right. Apologies if they're not. This also touches the weakref docs, which contains a sample type object initializer. It also touches the mmap test output, because the mmap type's repr is included in that output. It touches object.h to put the correct description in a comment.
* SF bug #475327: type() produces incorrect error msgTim Peters2001-10-271-0/+1
| | | | | | | | | | | | | object.h: Added PyType_CheckExact macro. typeobject.c, type_new(): + Use the new macro. + Assert that the arguments have the right types rather than do incomplete runtime checks "sometimes". + If this isn't the 1-argument flavor() of type, and there aren't 3 args total, produce a "types() takes 1 or 3 args" msg before PyArg_ParseTupleAndKeywords produces a "takes exactly 3" msg.
* Get rid of __defined__ and tp_defined -- there's no need toGuido van Rossum2001-10-151-1/+1
| | | | | distinguish __dict__ and __defined__ any more. In the C structure, tp_cache takes its place -- but this hasn't been implemented yet.
* Completely get rid of __dynamic__ and the correspondingGuido van Rossum2001-10-151-3/+0
| | | | | Py_TPFLAGS_DYNAMICTYPE bit. There is no longer a performance benefit, and I don't really see the use case any more.
* Keep track of a type's subclasses (subtypes), in tp_subclasses, whichGuido van Rossum2001-10-081-0/+2
| | | | | | | | | | | | | | | | is a list of weak references to types (new-style classes). Make this accessible to Python as the function __subclasses__ which returns a list of types -- we don't want Python programmers to be able to manipulate the raw list. In order to make this possible, I also had to add weak reference support to type objects. This will eventually be used together with a trap on attribute assignment for dynamic classes for a major speed-up without losing the dynamic properties of types: when a __foo__ method is added to a class, the class and all its subclasses will get an appropriate tp_foo slot function.
* PyObject_ClearWeakRefs() is now a real function instead of a function pointer;Fred Drake2001-10-051-1/+1
| | | | the implementation is in Objects/weakrefobject.c.