summaryrefslogtreecommitdiff
path: root/Objects/classobject.c
AgeCommit message (Collapse)AuthorLines
2006-10-09Backport rev 51262 from trunk -- squashes a compiler warning on WindowsTim Peters-2/+2
about truly wrong code. Checkin comment from 51262: Can't return NULL from a void function. If there is a memory error, about the best we can do is call PyErr_WriteUnraisable and go on. We won't be able to do the call below either, so verify delstr is valid.
2006-10-05[Backport r51246 | neal.norwitz]Andrew M. Kuchling-30/+110
Handle a whole lot of failures from PyString_FromInternedString(). Should fix most of Klocwork 234-272. [Backport r51400 | neal.norwitz] Move initialization of interned strings to before allocating the object so we don't leak op. (Fixes an earlier patch to this code) Klockwork #350
2006-09-30Patch #1567691: super() and new.instancemethod() now don't acceptGeorg Brandl-0/+2
keyword arguments any more (previously they accepted them, but didn't use them). (backport from rev. 52058)
2006-06-13Classic class that defined ``def __coerce__(self, other): return other, self``Brett Cannon-0/+3
would infinitely recourse and segfault the interpreter. Now a recursion check occurs after a coercion. Backport of fix for bug #992017.
2005-09-20- On 64-bit platforms, when __len__() returns a value that cannot beGuido van Rossum-1/+11
represented as a C int, raise OverflowError. (Will forward-port.)
2005-03-31Backport:Michael W. Hudson-0/+6
Fix for rather inaccurately titled bug [ 1165306 ] Property access with decorator makes interpreter crash Don't allow the creation of unbound methods with NULL im_class, because attempting to call such crashes. Backport candidate.
2004-09-23A static swapped_op[] array was defined in 3 different C files, & I thinkTim Peters-4/+1
I need to define it again. Bite the bullet and define it once as an extern, _Py_SwappedOp[].
2004-08-03Repair the same thinko in two places about handling of _Py_RefTotal inMichael W. Hudson-6/+7
the case of __del__ resurrecting an object. This makes the apparent reference leaks in test_descr go away (which I expected) and also kills off those in test_gc (which is more surprising but less so once you actually think about it a bit).
2003-11-22- When method objects have an attribute that can be satisfied eitherGuido van Rossum-28/+30
by the function object or by the method object, the function object's attribute usually wins. Christian Tismer pointed out that that this is really a mistake, because this only happens for special methods (like __reduce__) where the method object's version is really more appropriate than the function's attribute. So from now on, all method attributes will have precedence over function attributes with the same name.
2003-10-28Deleting cyclic object comparison.Armin Rigo-6/+4
SF patch 825639 http://mail.python.org/pipermail/python-dev/2003-October/039445.html
2003-10-12Simplify and speedup uses of Py_BuildValue():Raymond Hettinger-14/+14
* Py_BuildValue("(OOO)",a,b,c) --> PyTuple_Pack(3,a,b,c) * Py_BuildValue("()",a) --> PyTuple_New(0) * Py_BuildValue("O", a) --> Py_INCREF(a)
2003-09-16Fix leak in classobject.c. The leak surfaced on the error exit whenRaymond Hettinger-0/+1
hashing a class that does not define __hash__ but does define a comparison.
2003-04-09Make it possible to call instancemethod() with 2 arguments.Guido van Rossum-2/+2
2003-04-07New private API function _PyInstance_Lookup. gc will use this to figureTim Peters-0/+21
out whether __del__ exists, without executing any Python-level code.
2003-02-11Refactor instancemethod_descr_get() to (a) be more clear, (b) be safeGuido van Rossum-8/+18
in the light of weird args, and (c) not to expect None (which is now changed to NULL by slot_tp_descr_get()).
2002-12-29SF patch #659536: Use PyArg_UnpackTuple where possible.Raymond Hettinger-1/+1
Obtain cleaner coding and a system wide performance boost by using the fast, pre-parsed PyArg_Unpack function instead of PyArg_ParseTuple function which is driven by a format string.
2002-12-12Change issubclass() so that recursive tuples (directly or indirectlyWalter Dörwald-1/+2
containing class objects) are allowed as the second argument. This makes issubclass() more similar to isinstance() where recursive tuples are allowed too.
2002-12-12Enhance issubclass() and PyObject_IsSubclass() so that a tuple isWalter Dörwald-0/+7
supported as the second argument. This has the same meaning as for isinstance(), i.e. issubclass(X, (A, B)) is equivalent to issubclass(X, A) or issubclass(X, B). Compared to isinstance(), this patch does not search the tuple recursively for classes, i.e. any entry in the tuple that is not a class, will result in a TypeError. This closes SF patch #649608.
2002-10-29Since properties are supported here, is possible thatGuido van Rossum-13/+12
instance_getattr2() raises an exception. Fix all code that made this assumption. Backport candidate.
2002-10-18Fix (real! :-) memory leaks in half_cmp and half_binop.Guido van Rossum-1/+4
Perhaps found by NealN and valgrind. Will forward port.
2002-08-20getinstclassname(): Squash new compiler wng in assert (comparison ofTim Peters-1/+1
signed vs unsigned).
2002-08-19SF patch 576101, by Oren Tirosh: alternative implementation ofGuido van Rossum-20/+24
interning. I modified Oren's patch significantly, but the basic idea and most of the implementation is unchanged. Interned strings created with PyString_InternInPlace() are now mortal, and you must keep a reference to the resulting string around; use the new function PyString_InternImmortal() to create immortal interned strings.
2002-07-11object.h special-build macro minefield: renamed all the new lexicalTim Peters-49/+38
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.
2002-07-07Removed WITH_CYCLE_GC #ifdef-ery. Holes:Tim Peters-3/+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.
2002-06-18About the new but unreferenced new_class, Guido sez:Michael W. Hudson-15/+0
> Looks like an experiment by Oren Tirosh that didn't get nuked. I > think you can safely lose it. It's gone.
2002-06-14SF patch 568629 by Oren Tirosh: types made callable.Guido van Rossum-5/+93
These built-in functions are replaced by their (now callable) type: slice() buffer() and these types can also be called (but have no built-in named function named after them) classobj (type name used to be "class") code function instance instancemethod (type name used to be "instance method") The module "new" has been replaced with a small backward compatibility placeholder in Python. A large portion of the patch simply removes the new module from various platform-specific build recipes. The following binary Mac project files still have references to it: Mac/Build/PythonCore.mcp Mac/Build/PythonStandSmall.mcp Mac/Build/PythonStandalone.mcp [I've tweaked the code layout and the doc strings here and there, and added a comment to types.py about StringTypes vs. basestring. --Guido]
2002-06-13Major cleanup operation: whenever there's a call that looks for anGuido van Rossum-10/+59
optional attribute, only clear the exception when the internal getattr operation raised AttributeError. Many places in this file already had that policy; but just as many didn't, and there didn't seem to be any rhyme or reason to it. Be consistently cautious. Question: should I backport this? On the one hand it's a bugfix. On the other hand it's a change in behavior. Certain forms of buggy or just weird code would work in the past but raise an exception under the new rules; e.g. if you define a __getattr__ method that raises a non-AttributeError exception.
2002-06-13Fix for SF bug 532646. This is a little simpler than what NealGuido van Rossum-1/+17
suggested there, based upon a better analysis (__getattr__ is a red herring). Will backport to 2.2.
2001-10-26Be smarter about clearing the weakref lists for instances, instance methods,Fred Drake-2/+4
and functions: we only need to call PyObject_ClearWeakRefs() if the weakref list is non-NULL. Since these objects are common but weakrefs are still unusual, saving the call at deallocation time makes a lot of sense.
2001-10-22Fix for SF bug #472940: can't getattr() attribute shown by dir()Guido van Rossum-28/+1
There really isn't a good reason for instance method objects to have their own __dict__, __doc__ and __name__ properties that just delegate the request to the function (callable); the default attribute behavior already does this. The test suite had to be fixed because the error changes from TypeError to AttributeError.
2001-10-17Protect references to tp_descr_get and tp_dict with the appropriate test:Guido van Rossum-9/+14
PyType_HasFeature(t, Py_TPFLAGS_HAVE_CLASS).
2001-09-30SF bug [#466173] unpack TypeError unclearTim Peters-1/+1
Replaced 3 instances of "iter() of non-sequence" with "iteration over non-sequence". Restored "unpack non-sequence" for stuff like "a, b = 1".
2001-09-20Add optional docstrings to getset descriptors. Fortunately, there'sGuido van Rossum-4/+4
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.
2001-09-20Add optional docstrings to member descriptors. For backwardsGuido van Rossum-4/+7
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.
2001-09-18Properly repr classes without module names.Martin v. Löwis-1/+1
2001-09-18Redo the PyMethod attributes using a dir()-friendly approach, creatingGuido van Rossum-37/+69
descriptors for each attribute. The getattr() implementation is similar to PyObject_GenericGetAttr(), but delegates to im_self instead of looking in __dict__; I couldn't do this as a wrapper around PyObject_GenericGetAttr(). XXX A problem here is that this is a case of *delegation*. dir() doesn't see exactly the same attributes that are actually defined; e.g. if the delegate is a Python function object, it supports attributes like func_code etc., but these are not visible to dir(); on the other hand, dynamic function attributes (stored in the function's __dict__) *are* visible to dir(). Maybe we need a mechanism to tell dir() about the delegation mechanism? I vaguely recall seeing a request in the newsgroup for a more formal definition of attribute delegation too. Sigh, time for a new PEP.
2001-09-08Generalize operator.indexOf (PySequence_Index) to work with anyTim Peters-1/+2
iterable object. I'm not sure how that got overlooked before! Got rid of the internal _PySequence_IterContains, introduced a new internal _PySequence_IterSearch, and rewrote all the iteration-based "count of", "index of", and "is the object in it or not?" routines to just call the new function. I suppose it's slower this way, but the code duplication was getting depressing.
2001-09-07PyClass_New(): put the extended Don Beaudry hook back in. When one ofGuido van Rossum-4/+14
the base classes is not a classic class, and its class (the metaclass) is callable, call the metaclass to do the deed. One effect of this is that, when mixing classic and new-style classes amongst the bases of a class, it doesn't matter whether the first base class is a classic class or not: you will always get the error "TypeError: metatype conflict among bases". (Formerly, with a classic class first, you'd get "TypeError: PyClass_New: base must be a class".) Another effect is that multiple inheritance from ExtensionClass.Base, with a classic class as the first class, transfers control to the ExtensionClass.Base class. This is what we need for SF #443239 (and also for running Zope under 2.2a4, before ExtensionClass is replaced).
2001-09-05Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.Guido van Rossum-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.
2001-08-29Use new GC API.Neil Schemenauer-22/+19
2001-08-24Improve the error message issued when an unbound method is called withGuido van Rossum-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.
2001-08-24repr's converted to using PyString_FromFormat() instead of sprintf'ingBarry Warsaw-19/+14
into a hardcoded char* buffer. Closes patch #454743.
2001-08-17Fix core dump in repr() of instancemethod whose class==NULL.Guido van Rossum-7/+11
2001-08-17instance_getattr2(): rewritten to remove unnecessary stuff andGuido van Rossum-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.
2001-08-17Instance methods: allow a NULL value for im_class.Guido van Rossum-2/+2
2001-08-16classobject.c:instancemethod_descr_get(): when a bound method isGuido van Rossum-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.
2001-08-15PyMethod_Type: add a tp_descr_get slot function to ensure properGuido van Rossum-1/+19
binding of unbound methods.
2001-08-08Implement PEP 238 in its (almost) full glory.Guido van Rossum-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.
2001-08-02Fix the test_weakref.py failure. Introduced by resolving "a conflict"Tim Peters-7/+0
(which didn't actually exist!) incorrectly.
2001-08-02Merge of descr-branch back into trunk.Tim Peters-74/+161