summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.Guido van Rossum2001-09-051-0/+30
| | | | | | While not even documented, they were clearly part of the C API, there's no great difficulty to support them, and it has the cool effect of not requiring any changes to ExtensionClass.c.
* Use new GC API.Neil Schemenauer2001-08-291-22/+19
|
* Improve the error message issued when an unbound method is called withGuido van Rossum2001-08-241-3/+49
| | | | | | an inappropriate first argument. Now that there are more ways for this to fail, make sure to report the name of the class of the expected instance and of the actual instance.
* repr's converted to using PyString_FromFormat() instead of sprintf'ingBarry Warsaw2001-08-241-19/+14
| | | | | | into a hardcoded char* buffer. Closes patch #454743.
* Fix core dump in repr() of instancemethod whose class==NULL.Guido van Rossum2001-08-171-7/+11
|
* instance_getattr2(): rewritten to remove unnecessary stuff andGuido van Rossum2001-08-171-24/+13
| | | | | | | streamlined a bit. instancemethod_descr_get(): don't bind an unbound method of a class that's not a base class of the argument class.
* Instance methods: allow a NULL value for im_class.Guido van Rossum2001-08-171-2/+2
|
* classobject.c:instancemethod_descr_get(): when a bound method isGuido van Rossum2001-08-161-0/+5
| | | | | | | assigned to a class variable and then accessed via an instance, it should not be rebound. test_descr.py:methods(): test for the condition above.
* PyMethod_Type: add a tp_descr_get slot function to ensure properGuido van Rossum2001-08-151-1/+19
| | | | binding of unbound methods.
* Implement PEP 238 in its (almost) full glory.Guido van Rossum2001-08-081-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix the test_weakref.py failure. Introduced by resolving "a conflict"Tim Peters2001-08-021-7/+0
| | | | (which didn't actually exist!) incorrectly.
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-74/+161
|
* init_name_op(): add (void) to the argument list to make it a validGuido van Rossum2001-05-221-1/+1
| | | | prototype, for gcc -Wstrict-prototypes.
* Variant of SF patch 423181Jeremy Hylton2001-05-111-21/+51
| | | | | | | For rich comparisons, use instance_getattr2() when possible to avoid the expense of setting an AttributeError. Also intern the name_op[] table and use the interned strings rather than creating a new string and interning it each time through.
* Reimplement PySequence_Contains() and instance_contains(), so they workTim Peters2001-05-051-37/+30
| | | | | | | | | safely together and don't duplicate logic (the common logic was factored out into new private API function _PySequence_IterContains()). Visible change: some_complex_number in some_instance no longer blows up if some_instance has __getitem__ but neither __contains__ nor __iter__. test_iter changed to ensure that remains true.
* Since Py_TPFLAGS_HAVE_WEAKREFS is set in Py_TPFLAGS_DEFAULT, it does notFred Drake2001-05-031-1/+1
| | | | | | | need to be specified in the type structures independently. The flag exists only for binary compatibility. This is a "source cleanliness" issue and introduces no behavioral changes.
* Well darnit! The innocuous fix I made to PyObject_Print() causedGuido van Rossum2001-04-301-1/+20
| | | | printing of instances not to look for __str__(). Fix this.
* Mondo changes to the iterator stuff, without changing how Python codeGuido van Rossum2001-04-231-2/+38
| | | | | | | | | | | | | | | | | | | | | | | | 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-2/+29
| | | | | | | | | | | | | | | | | | | | | | 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???)
* Add support for weak references to the function and method types.Fred Drake2001-03-231-1/+6
|
* A small change to the C API for weakly-referencable types: Such typesFred Drake2001-03-221-0/+1
| | | | | | | | must now initialize the extra field used by the weak-ref machinery to NULL themselves, to avoid having to require PyObject_INIT() to check if the type supports weak references and do it there. This causes less work to be done for all objects (the type object does not need to be consulted to check for the Py_TPFLAGS_HAVE_WEAKREFS bit).
* The return value from PyObject_ClearWeakRefs() is no longer meaningful,Fred Drake2001-02-261-2/+1
| | | | so make it void.
* instancemethod_setattro(): Raise TypeError if an attempt is made toBarry Warsaw2001-02-261-15/+2
| | | | | | set a function attribute on a method (either bound or unbound). This reverts to Python 2.0 behavior that no attributes of the method are writable, but provides a more informative error message.
* PEP 205, Weak References -- initial checkin.Fred Drake2001-02-011-0/+5
|
* Rename dubiously named local variable 'cmpfunc' -- this is also aGuido van Rossum2001-01-291-5/+5
| | | | | | typedef, and at least one compiler choked on this. (SF patch #103457, by bquinlan)
* fix indentation glitchJeremy Hylton2001-01-291-1/+1
|
* Re-factored PyInstance_New() into PyInstance_New() and PyInstance_NewRaw().Fred Drake2001-01-281-13/+34
|
* Rich comparisons fallout: instance_hash() should check for bothGuido van Rossum2001-01-181-7/+14
| | | | | __cmp__ and __eq__ absent before deciding to do a quickie based on the object address. (Tim Peters discovered this.)
* Fix a leak in instance_coerce(). This was introduced by Neil'sGuido van Rossum2001-01-171-2/+0
| | | | | | | | | earlier coercion changes, not by rich comparisons. When a coercion function returns 1 (meaning it cannot do it), it should not INCREF the arguments. When no __coerce__() method was found, instance_coerce() originally returned 0, pretending it did it. Neil changed the return value to 1, more accurately reflecting that it didn't do anything, but forgot to take out the two INCREF calls.
* 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
|