summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Rich comparisons.Guido van Rossum2001-01-171-146/+278
| | | | | | | | | | | | | | | | - Got rid of instance_cmp(); refactored instance_compare(). - Added instance_richcompare() which calls __lt__() etc. Some unrelated stuff mixed in: - Aligned comments in various large struct initializers. - Better test to avoid recursion if __coerce__ returns self as the first argument (this is an unrelated fix by Neil Schemenauer!). - Style nit: don't use Py_DECREF(Py_NotImplemented); use Py_DECREF(result) -- it just looks better. :-)
* Committing PEP 232, function attribute feature, approved by Guido.Barry Warsaw2001-01-151-4/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Closes SF patch #103123. funcobject.h: PyFunctionObject: add the func_dict slot. funcobject.c: PyFunction_New(): Initialize the func_dict slot to NULL. func_getattr(): Rename to func_getattro() and change the signature. It's more efficient to use attro methods and dig the C string out than it is to re-convert a C string to a PyString. Also, add support for getting the __dict__ (a.k.a. func_dict) attribute, and for getting an arbitrary function attribute. func_setattr(): Rename to func_setattro() and change the signature for the same reason. Also add support for setting __dict__ (a.k.a. func_dict) and any arbitrary function attribute. func_dealloc(): Be sure to DECREF the func_dict slot. func_traverse(): Be sure to traverse func_dict too. PyFunction_Type: make the necessary func_?etattro() changes. classobject.c: instancemethod_memberlist: Add __dict__ instancemethod_setattro(): New method to set arbitrary attributes on methods (really the underlying im_func). Raise TypeError when the instance is bound or when you're trying to set one of the reserved im_* attributes. instancemethod_getattr(): Renamed to instancemethod_getattro() since that's what it really is. Also, added support fo getting arbitrary attributes through the im_func. PyMethod_Type: Do the ?etattr{,o} dance.
* Make instances a new style number type. See PEP 208 for details. InstanceNeil Schemenauer2001-01-041-184/+268
| | | | | types no longer get special treatment from abstract.c so more number number methods have to be implemented.
* Ka-Ping Yee <ping@lfw.org>:Fred Drake2000-10-241-6/+12
| | | | | | Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
* - fix a GC bug caused by malloc() failingNeil Schemenauer2000-10-041-1/+1
|
* Fix for SF bug 110688: Instance deallocation neglected to account forTim Peters2000-09-171-12/+28
| | | | | | | | | | that Py_INCREF boosts global _Py_RefTotal when Py_REF_DEBUG is defined but Py_TRACE_REFS isn't. There are, IMO, way too many preprocessor gimmicks in use for refcount debugging (at least 3 distinct true/false symbols, but not all 8 combos are supported by the code, etc etc), and no coherent documentation of this stuff -- 'twas too painful to track this one down.
* Don't remove instance objects from the GC container set until we areNeil Schemenauer2000-09-151-2/+1
| | | | they are dead. Fixes bug #113812.
* 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.
* refactor __del__ exception handler into PyErr_WriteUnraisableJeremy Hylton2000-09-011-20/+1
| | | | | add sanity check to gc: if an exception occurs during GC, call PyErr_WriteUnraisable and then call Py_FatalEror.
* Call PyErr_Clear() to clear the AttributeError raised by GetAttr.Thomas Wouters2000-08-251-0/+1
|
* Support for the in-place operations introduced by augmented assignment. OnlyThomas Wouters2000-08-241-11/+45
| | | | | the list object supports this currently, but other candidates are gladly accepted (like arraymodule and such.)
* PyInstance_DoBinOp(): When comparing the pointers, they must be castBarry Warsaw2000-08-181-1/+4
| | | | | | | 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.
* Apply SF patch #101029: call __getitem__ with a proper slice object if thereThomas Wouters2000-08-171-9/+60
| | | | | | | | is no __getslice__ available. Also does the same for C extension types. Includes rudimentary documentation (it could use a cross reference to the section on slice objects, I couldn't figure out how to do that) and a test suite for all Python __hooks__ I could think of, including the new behaviour.
* ANSIfy functions that were hiding inside a macro.Thomas Wouters2000-07-231-1/+1
|
* Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in eitherThomas Wouters2000-07-161-2/+2
| | | | | | | | | | 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 ;)
* ANSI-fication of the sources.Fred Drake2000-07-091-142/+56
|
* Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.Tim Peters2000-07-091-8/+8
|
* _Py_RefTotal should only be declared here when Py_TRACE_REFS are #define'dSkip Montanaro2000-07-081-0/+2
|
* Neil Schemenauer: small fixes for GCGuido van Rossum2000-07-011-0/+4
|
* Change copyright notice - 2nd try.Guido van Rossum2000-06-301-6/+0
|
* Change copyright notice.Guido van Rossum2000-06-301-22/+7
|
* Trent Mick <trentm@activestate.com>:Fred Drake2000-06-301-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | The common technique for printing out a pointer has been to cast to a long and use the "%lx" printf modifier. This is incorrect on Win64 where casting to a long truncates the pointer. The "%p" formatter should be used instead. The problem as stated by Tim: > Unfortunately, the C committee refused to define what %p conversion "looks > like" -- they explicitly allowed it to be implementation-defined. Older > versions of Microsoft C even stuck a colon in the middle of the address (in > the days of segment+offset addressing)! The result is that the hex value of a pointer will maybe/maybe not have a 0x prepended to it. Notes on the patch: There are two main classes of changes: - in the various repr() functions that print out pointers - debugging printf's in the various thread_*.h files (these are why the patch is large) Closes SourceForge patch #100505.
* final patches from Neil Schemenauer for garbage collectionJeremy Hylton2000-06-301-4/+13
|
* This patch addresses two main issues: (1) There exist some non-fatalFred Drake2000-06-291-4/+1
| | | | | | | | | | | | | | | | | | | | 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.
* Vladimir Marangozov:Guido van Rossum2000-06-281-3/+3
| | | | | | Avoid calling the dealloc function, previously triggered with DECREF(inst). This caused a segfault in PyDict_GetItem, called with a NULL dict, whenever inst->in_dict fails under low-memory conditions.
* Trent Mick: change a few casts for Win64 compatibility.Guido van Rossum2000-06-281-1/+1
|
* part 2 of Neil Schemenauer's GC patches:Jeremy Hylton2000-06-231-6/+6
| | | | | | | | 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.
* traverse functions should return 0 on successJeremy Hylton2000-06-231-2/+2
|
* Round 1 of Neil Schemenauer's GC patches:Jeremy Hylton2000-06-231-1/+87
| | | | | This patch adds the type methods traverse and clear necessary for GC implementation.
* Vladimir Marangozov's long-awaited malloc restructuring.Guido van Rossum2000-05-031-7/+6
| | | | | | | | | | For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
* potentially useless optimizationJeremy Hylton2000-04-261-11/+20
| | | | | | | | | | | | | | | | | | | | The previous checkin (2.84) added a PyErr_Format call that made the cost of raising an AttributeError much more expensive. In general this doesn't matter, except that checks for __init__ and __del__ methods, where exceptions are caught and cleared in C, also got much more expensive. The fix is to split instance_getattr1 into two calls: instance_getattr2 checks the instance and the class for the attribute and returns it or returns NULL on error. It does not raise an exception. instance_getattr1 does rexec checks, then calls instance_getattr2. It raises an exception if instance_getattr2 returns NULL. PyInstance_New and instance_dealloc now call instance_getattr2 directly.
* Mark Hammond:Guido van Rossum2000-04-101-1/+4
| | | | | | | | In line with a similar checkin to object.c a while ago, this patch gives a more descriptive error message for an attribute error on a class instance. The message now looks like: AttributeError: 'Descriptor' instance has no attribute 'GetReturnType'
* Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This addsGuido van Rossum2000-02-281-0/+56
| | | | | | an instance method instance_contains as sq_contains. It looks for __contains__ and if not found falls back to previous behaviour. Done.
* The rest of the changes by Trent Mick and Dale Nagata for warning-freeGuido van Rossum2000-01-201-3/+3
| | | | compilation on NT Alpha. Mostly added casts etc.
* Fix for PR#98 (Adrian Eyre) -- in instancemethod_repr, the funcnameGuido van Rossum1999-10-111-1/+1
| | | | object is DECREFed too early.
* Fix a memory leak -- the cached values of __getattr__ etc. were neverGuido van Rossum1998-08-041-0/+3
| | | | freed.
* Move the definition of PyMethodObject to classobject.h, so it can defineGuido van Rossum1998-07-101-8/+0
| | | | macros for more efficient access to the fields.
* Marc-Andre Lemburg's patch to support instance methods with otherGuido van Rossum1998-07-081-16/+21
| | | | callable objects than regular Pythonm functions as their im_func.
* Recompute the special getattr/setattr/delattr cache slots afterGuido van Rossum1998-07-081-7/+13
| | | | changing __dict__ *or* __bases__.
* Keep Microsoft's compiler happy.Guido van Rossum1998-06-121-4/+1
|
* Allow assignments to special class attributes -- with typechecks, andGuido van Rossum1998-05-291-12/+87
| | | | | | | | | | | | | | | | | | | not in restricted mode. __dict__ can be set to any dictionary; the cl_getattr, cl_setattr and cl_delattr slots are refreshed. __name__ can be set to any string. __bases__ can be set to to a tuple of classes, provided they are not subclasses of the class whose attribute is being assigned. __getattr__, __setattr__ and __delattr__ can be set to anything, or deleted; the appropriate slot (cl_getattr, cl_setattr, cl_delattr) is refreshed. (Note: __name__ really doesn't need to be a special attribute, but that would be more work.)
* Uses PyErr_ExceptionMatches() instead of comparing PyErr_Occurred().Guido van Rossum1998-05-281-1/+1
|
* Remove a redundant statement from halfbinop().Guido van Rossum1998-05-131-1/+0
|
* Change the default repr() and str() of class instance objects to lookGuido van Rossum1997-12-031-1/+9
| | | | | like <modulename.classname instance at ...> (to match the repr() of class objects.
* Undo another glitch of the automatic not-so-Grand Renaming; some localGuido van Rossum1997-11-181-10/+10
| | | | | variables called 'coerce' were accidentally renamed to 'PyNumber_Coerce'. Rename them back to coercefunc.
* Write a str() function for class objects that returnsGuido van Rossum1997-10-201-2/+36
| | | | "modulename.classname" instead of returning the same as repr().
* Check that all base classes are indeed class objects, rather thanGuido van Rossum1997-10-071-5/+30
| | | | expecting the caller to do so.
* When creating a class, set its __module__ attribute to the moduleGuido van Rossum1997-09-121-1/+22
| | | | | whose name is in the current globals' __name__ variable. If __name__ is not set, ignore this.
* Allow assignments to instance.__dict__ and instance.__class__. TheGuido van Rossum1997-08-251-17/+57
| | | | | | | | | | | | former lets you give an instance a set of new instance vars. The latter lets you give it a new class. Both are typechecked and disallowed in restricted mode. For classes, the check for read-only special attributes is tightened so that only assignments to __dict__, __bases__, __name__, __getattr__, __setattr__, and __delattr__ (these could be made to work as well, but I don't know if that's useful -- let's see first whether mucking with instances will help).
* Added separate free list for instance method objects, for a fewGuido van Rossum1997-08-051-4/+28
| | | | percent speed up. Also add PyMethod_Fini() to discard it.