summaryrefslogtreecommitdiffstats
path: root/Include/object.h
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Add Garbage Collection support to new-style classes (not yet to theirGuido van Rossum2001-10-021-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | instances). Also added GC support to various auxiliary types: super, property, descriptors, wrappers, dictproxy. (Only type objects have a tp_clear field; the other types are.) One change was necessary to the GC infrastructure. We have statically allocated type objects that don't have a GC header (and can't easily be given one) and heap-allocated type objects that do have a GC header. Giving these different metatypes would be really ugly: I tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new invent a new name for the new metatype and make it a built-in, change affected tests... In short, a mess. So instead, we add a new type slot tp_is_gc, which is a simple Boolean function that determines whether a particular instance has GC headers or not. This slot is only relevant for types that have the (new) GC flag bit set. If the tp_is_gc slot is NULL (by far the most common case), all instances of the type are deemed to have GC headers. This slot is called by the PyObject_IS_GC() macro (which is only used twice, both times in gcmodule.c). I also changed the extern declarations for a bunch of GC-related functions (_PyObject_GC_Del etc.): these always exist but objimpl.h only declared them when WITH_CYCLE_GC was defined, but I needed to be able to reference them without #ifdefs. (When WITH_CYCLE_GC is not defined, they do the same as their non-GC counterparts anyway.)
* Add optional docstrings to getset descriptors. Fortunately, there'sGuido van Rossum2001-09-201-1/+1
| | | | | | | | | | no backwards compatibility to worry about, so I just pushed the 'closure' struct member to the back -- it's never used in the current code base (I may eliminate it, but that's more work because the getter and setter signatures would have to change.) As examples, I added actual docstrings to the getset attributes of a few types: file.closed, xxsubtype.spamdict.state.
* Add optional docstrings to member descriptors. For backwardsGuido van Rossum2001-09-201-1/+1
| | | | | | | | | | | | | | | compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
* Hopefully fix 3-way comparisons. This unfortunately adds yet anotherGuido van Rossum2001-09-181-0/+4
| | | | | | | | hack, and it's even more disgusting than a PyInstance_Check() call. If the tp_compare slot is the slot used for overrides in Python, it's always called. Add some tests that show what should work too.
* At Guido's suggestion, here's a new C API function, PyObject_Dir(), likeTim Peters2001-09-041-0/+8
| | | | __builtin__.dir(). Moved the guts from bltinmodule.c to object.c.
* Change the GC type flag since the API has changed. Allow types usingNeil Schemenauer2001-08-291-6/+10
| | | | the old flag to still compile.
* Add decl of PySuper_Type; fixup comments for the two other types.Guido van Rossum2001-08-241-2/+3
|
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-0/+2
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* Added comments before recently added/assigned slots in the type object,Fred Drake2001-08-151-0/+6
| | | | | so the backward compatibility issues will be easier to understand. I only added comments indicating additions and assignments back to Python 2.0.
* Add new flags for PyType_Ready(): READY to explicitly indicate theGuido van Rossum2001-08-101-0/+6
| | | | | | type is ready, and READYING to indicate that it is busy with the type. A recursive call is a fatal error.
* Implement PEP 238 in its (almost) full glory.Guido van Rossum2001-08-081-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | This introduces: - A new operator // that means floor division (the kind of division where 1/2 is 0). - The "future division" statement ("from __future__ import division) which changes the meaning of the / operator to implement "true division" (where 1/2 is 0.5). - New overloadable operators __truediv__ and __floordiv__. - New slots in the PyNumberMethods struct for true and floor division, new abstract APIs for them, new opcodes, and so on. I emphasize that without the future division statement, the semantics of / will remain unchanged until Python 3.0. Not yet implemented are warnings (default off) when / is used with int or long arguments. This has been on display since 7/31 as SF patch #443474. Flames to /dev/null.
* - Rename PyType_InitDict() to PyType_Ready().Guido van Rossum2001-08-071-1/+1
| | | | | | - Add an explicit call to PyType_Ready(&PyList_Type) to pythonrun.c (just for the heck of it, really -- we should either explicitly ready all types, or none).
* Patch #448194: Debuging negative reference counts.Martin v. Löwis2001-08-051-5/+6
|
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-6/+58
|
* Mondo changes to the iterator stuff, without changing how Python codeGuido van Rossum2001-04-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | sees it (test_iter.py is unchanged). - Added a tp_iternext slot, which calls the iterator's next() method; this is much faster for built-in iterators over built-in types such as lists and dicts, speeding up pybench's ForLoop with about 25% compared to Python 2.1. (Now there's a good argument for iterators. ;-) - Renamed the built-in sequence iterator SeqIter, affecting the C API functions for it. (This frees up the PyIter prefix for generic iterator operations.) - Added PyIter_Check(obj), which checks that obj's type has a tp_iternext slot and that the proper feature flag is set. - Added PyIter_Next(obj) which calls the tp_iternext slot. It has a somewhat complex return condition due to the need for speed: when it returns NULL, it may not have set an exception condition, meaning the iterator is exhausted; when the exception StopIteration is set (or a derived exception class), it means the same thing; any other exception means some other error occurred.
* Iterators phase 1. This comprises:Guido van Rossum2001-04-201-4/+10
| | | | | | | | | | | | | | | | | | | | | | new slot tp_iter in type object, plus new flag Py_TPFLAGS_HAVE_ITER new C API PyObject_GetIter(), calls tp_iter new builtin iter(), with two forms: iter(obj), and iter(function, sentinel) new internal object types iterobject and calliterobject new exception StopIteration new opcodes for "for" loops, GET_ITER and FOR_ITER (also supported by dis.py) new magic number for .pyc files new special method for instances: __iter__() returns an iterator iteration over dictionaries: "for x in dict" iterates over the keys iteration over files: "for x in file" iterates over lines TODO: documentation test suite decide whether to use a different way to spell iter(function, sentinal) decide whether "for key in dict" is a good idea use iterators in map/filter/reduce, min/max, and elsewhere (in/not in?) speed tuning (make next() a slot tp_next???)
* The return value from PyObject_ClearWeakRefs() is no longer meaningful,Fred Drake2001-02-261-1/+1
| | | | so make it void.
* Use a type flag to determine the applicability of the tp_weaklistoffsetFred Drake2001-02-021-0/+7
| | | | | field. This should avoid binary incompatibility problems with older modules that have not been recompiled.
* Undo recent change that banned using import to bind a global, as perJeremy Hylton2001-02-011-0/+3
| | | | | | | | | | | discussion on python-dev. 'from mod import *' is still banned except at the module level. Fix value for special NOOPT entry in symtable. Initialze to 0 instead of None, so that later uses of PyInt_AS_LONG() are valid. (Bug reported by Donn Cave.) replace local REPR macros with PyObject_REPR in object.h
* PEP 205, Weak References -- initial checkin.Fred Drake2001-02-011-3/+5
|
* Add a flag to indicate the presence of the tp_richcompare field, andGuido van Rossum2001-01-241-2/+7
| | | | add it to the default flags.
* PyObject_Dump() -> _PyObject_Dump()Barry Warsaw2001-01-241-1/+1
|
* Add prototype for PyObject_Dump().Barry Warsaw2001-01-231-0/+1
|
* Get rid of the declaration for _PyCompareState_Key.Guido van Rossum2001-01-171-3/+0
|
* This patch adds a new builtin unistr() which behaves like str()Marc-André Lemburg2001-01-171-0/+1
| | | | | | | | | | 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.
* Introduction to rich comparisons:Guido van Rossum2001-01-171-12/+22
| | | | | | | | | | | | | | - Removed the nb_add slot from the PyNumberMethods struct. - Renamed Py_TPFLAGS_NEWSTYLENUMBER to Py_TPFLAGS_CHECKTYPES. - Added typedef richcmpfunc. - Added tp_richcompare slot to PyTypeObject (replacing spare tp_xxx7). - Added APIs PyObject_RichCompare() and PyObject_RichCompareBool(). - Added rich comparison operators Py_LT through Py_GE.
* - Add nb_cmp slot for new style nubmers.Neil Schemenauer2001-01-041-0/+22
| | | | | - Define type flag for new style numbers. - Add Py_NotImplemented.
* Close SF bug 110826: a complaint about the way Python #define'd NULL.Tim Peters2000-09-101-7/+0
| | | | | | | | | | | | | | | It's hard to sort out what the bug was, exactly. So, Big Hammer: 1. Python shouldn't be in the business of #define'ing NULL, period. 2. Users of the Python C API shouldn't be in the business of not including Python.h, period. Hence: 1. Removed all #define's of NULL in Python source code (pyport.h and object.h). 2. Since we're *relying* on stdio.h defining NULL, put an #error in Python.h after its #include of stdio.h if NULL isn't defined then.
* 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.
* The real suport for augmented assignment: new opcodes, new PyNumber andThomas Wouters2000-08-241-1/+18
| | | | PySequence methods and functions, new tokens.
* Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in eitherThomas Wouters2000-07-161-3/+3
| | | | | | | | | | 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 ;)
* Remove legacy use of __SC__; no longer needed now that ANSI source isFred Drake2000-07-091-4/+0
| | | | the standard for Python implementation.
* One of the new prototypes was missing the "void" args.Greg Stein2000-07-081-1/+1
|
* Got RID of redundant coercions in longobject.c (as spotted by GregTim Peters2000-07-081-54/+54
| | | | | | | Stein -- thanks!). Incidentally removed all the Py_PROTO macros from object.h, as they prevented my editor from magically finding the definitions of the "coercion", "cmpfunc" and "reprfunc" typedefs that were being redundantly applied in longobject.c.
* Change copyright notice - 2nd try.Guido van Rossum2000-06-301-6/+0
|
* Change copyright notice.Guido van Rossum2000-06-301-22/+7
|
* This patch addresses two main issues: (1) There exist some non-fatalFred Drake2000-06-291-0/+4
| | | | | | | | | | | | | | | | | | | | errors in some of the hash algorithms. For exmaple, in float_hash and complex_hash a certain part of the value is not included in the hash calculation. See Tim's, Guido's, and my discussion of this on python-dev in May under the title "fix float_hash and complex_hash for 64-bit *nix" (2) The hash algorithms that use pointers (e.g. func_hash, code_hash) are universally not correct on Win64 (they assume that sizeof(long) == sizeof(void*)) As well, this patch significantly cleans up the hash code. It adds the two function _Py_HashDouble and _PyHash_VoidPtr that the various hashing routine are changed to use. These help maintain the hash function invariant: (a==b) => (hash(a)==hash(b))) I have added Lib/test/test_hash.py and Lib/test/output/test_hash to test this for some cases.
* part 2 of Neil Schemenauer's GC patches:Jeremy Hylton2000-06-231-0/+7
| | | | | | | | This patch modifies the type structures of objects that participate in GC. The object's tp_basicsize is increased when GC is enabled. GC information is prefixed to the object to maintain binary compatibility. GC objects also define the tp_flag Py_TPFLAGS_GC.
* Round 1 of Neil Schemenauer's GC patches:Jeremy Hylton2000-06-231-2/+8
| | | | | This patch adds the type methods traverse and clear necessary for GC implementation.
* Christian Tismer -- total rewrite on trashcan code.Guido van Rossum2000-04-241-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improvements: - does no longer need any extra memory - has no relationship to tstate - works in debug mode - can easily be modified for free threading (hi Greg:) Side effects: Trashcan does change the order of object destruction. Prevending that would be quite an immense effort, as my attempts have shown. This version works always the same, with debug mode or not. The slightly changed destruction order should therefore be no problem. Algorithm: While the old idea of delaying the destruction of some obejcts at a certain recursion level was kept, we now no longer aloocate an object to hold these objects. The delayed objects are instead chained together via their ob_type field. The type is encoded via ob_refcnt. When it comes to the destruction of the chain of waiting objects, the topmost object is popped off the chain and revived with type and refcount 1, then it gets a normal Py_DECREF. I am confident that this solution is near optimum for minimizing side effects and code bloat.
* Fix PR#7 comparisons of recursive objectsJeremy Hylton2000-04-141-0/+3
| | | | | Note that comparisons of deeply nested objects can still dump core in extreme cases.
* Updated comment: in PyTypeObject:Fred Drake2000-03-211-1/+1
| | | | | | | | | | /* More standard operations (at end for binary compatibility) */ should now be: /* More standard operations (here for binary compatibility) */ since they're no longer at the end!
* Christian Tismer's "trashcan" patch:Guido van Rossum2000-03-131-0/+47
| | | | | | | | Added wrapping macros to dictobject.c, listobject.c, tupleobject.c, frameobject.c, traceback.c that safely prevends core dumps on stack overflow. Macros and functions in object.c, object.h. The method is an "elevator destructor" that turns cascading deletes into tail recursive behavior when some limit is hit.
* Got rid of silly "123456789-..." lines in comments.Guido van Rossum2000-03-011-12/+0
|