summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Redid the slot computation. The initial slot assignments are now doneGuido van Rossum2001-10-131-64/+91
| | | | | | | using the same algorithm as the slot updates. The slotdefs array is now sorted by slot offset and has an interned string object corresponding to the name added to each item. More can be done but I need to commit this first as a working intermediate stage.
* Remove extra "]" in splitlines() docstring.Fred Drake2001-10-131-1/+1
| | | | Reported by Neal Norwitz.
* Band-aid solution to SF bug #470634: readlines() on linux requires 2 ^D's.Guido van Rossum2001-10-121-4/+11
| | | | | | | | | | | | | | | | The problem is that if fread() returns a short count, we attempt another fread() the next time through the loop, and apparently glibc clears or ignores the eof condition so the second fread() requires another ^D to make it see the eof condition. According to the man page (and the C std, I hope) fread() can only return a short count on error or eof. I'm using that in the band-aid solution to avoid calling fread() a second time after a short read. Note that xreadlines() still has this problem: it calls readlines(sizehint) until it gets a zero-length return. Since xreadlines() is mostly used for reading real files, I won't worry about this until we get a bug report.
* Now that COPYBUF is a new local macro, add #undef COPYBUF.Guido van Rossum2001-10-121-0/+1
|
* SF bug [#470040] ParseTuple t# vs subclasses.Tim Peters2001-10-121-1/+11
| | | | | | | inherit_slots(): tp_as_buffer was getting inherited as if it were a method pointer, rather than a pointer to a vector of method pointers. As a result, inheriting from a type that implemented buffer methods was ineffective, leaving all the tp_as_buffer slots NULL in the subclass.
* Another step in the right direction: when a new class's attributeGuido van Rossum2001-10-111-33/+116
| | | | | | | | | corresponding to a dispatch slot (e.g. __getitem__ or __add__) is set, calculate the proper dispatch slot and propagate the change to all subclasses. Because of multiple inheritance, there's no easy way to avoid always recursing down the tree of subclasses. Who cares? (There's more to do, but this works. There's also a test for this now.)
* Rather gross workaround for a bug in the mac GUSI I/O library:Jack Jansen2001-10-101-1/+7
| | | | | | lseek(fp, 0L, SEEK_CUR) can make a filedescriptor unusable. This workaround is expected to last only a few weeks (until GUSI is fixed), but without it test_email fails.
* The slot definition table entry for mp_getitem had a bogus wrapperGuido van Rossum2001-10-091-1/+2
| | | | function, which caused test_minidom to fail. Fixed this.
* Halfway checkin. This is still messy, but it's beginning to addressGuido van Rossum2001-10-091-140/+301
| | | | | | | | | | the problem that slots weren't inherited properly. override_slots() no longer exists; in its place comes fixup_slot_dispatchers() which does more and different work and is table-based. (Eventually I want this table also to replace all the little tab_foo tables.) Also add a wrapper for __delslice__; this required a change in test_descrtut.py.
* It turned out not so difficult to support old-style numbers (thoseGuido van Rossum2001-10-091-7/+24
| | | | | | | without the Py_TPFLAGS_CHECKTYPES flag) in the wrappers. This required a few changes in test_descr.py to cope with the fact that the complex type has __int__, __long__ and __float__ methods that always raise an exception.
* type_subclasses(): debug build was broken due to typo in new assert().Tim Peters2001-10-081-1/+1
|
* Keep track of a type's subclasses (subtypes), in tp_subclasses, whichGuido van Rossum2001-10-081-1/+71
| | | | | | | | | | | | | | | | 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.
* Implement isinstance(x, (A, B, ...)). Note that we only allow tuples,Guido van Rossum2001-10-071-1/+16
| | | | | not other sequences (then we'd have to except strings, and we'd still be susceptible to recursive attacks).
* Guido suggests, and I agree, to insist that SIZEOF_VOID_P be a power of 2.Tim Peters2001-10-072-8/+4
| | | | | | This simplifies the rounding in _PyObject_VAR_SIZE, allows to restore the pre-rounding calling sequence, and allows some nice little simplifications in its callers. I'm still making it return a size_t, though.
* _PyObject_VAR_SIZE: always round up to a multiple-of-pointer-size value.Tim Peters2001-10-062-36/+14
| | | | | | | | | | | | | | | | | As Guido suggested, this makes the new subclassing code substantially simpler. But the mechanics of doing it w/ C macro semantics are a mess, and _PyObject_VAR_SIZE has a new calling sequence now. Question: The PyObject_NEW_VAR macro appears to be part of the public API. Regardless of what it expands to, the notion that it has to round up the memory it allocates is new, and extensions containing the old PyObject_NEW_VAR macro expansion (which was embedded in the PyObject_NEW_VAR expansion) won't do this rounding. But the rounding isn't actually *needed* except for new-style instances with dict pointers after a variable-length blob of embedded data. So my guess is that we do not need to bump the API version for this (as the rounding isn't needed for anything an extension can do unless it's recompiled anyway). What's your guess?
* Repaired the debug Windows deaths in test_descr, by allocating enoughTim Peters2001-10-061-13/+23
| | | | | | | | | | | | | | pad memory to properly align the __dict__ pointer in all cases. gcmodule.c/objimpl.h, _PyObject_GC_Malloc: + Added a "padding" argument so that this flavor of malloc can allocate enough bytes for alignment padding (it can't know this is needed, but its callers do). typeobject.c, PyType_GenericAlloc: + Allocated enough bytes to align the __dict__ pointer. + Sped and simplified the round-up-to-PTRSIZE logic. + Added blank lines so I could parse the if/else blocks <0.7 wink>.
* _PyObject_GetDictPtr():Tim Peters2001-10-061-8/+12
| | | | | | + Use the _PyObject_VAR_SIZE macro to compute object size. + Break the computation into lines convenient for debugger inspection. + Speed the round-up-to-pointer-size computation.
* PyObject_ClearWeakRefs() is now a real function instead of a function pointer;Fred Drake2001-10-051-15/+0
| | | | the implementation is in Objects/weakrefobject.c.
* The weak reference implementation, separated from the weakref module.Fred Drake2001-10-051-0/+715
|
* Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum2001-10-0512-26/+71
| | | | | | | | | | | | | | | | | | | | | | many types were subclassable but had a xxx_dealloc function that called PyObject_DEL(self) directly instead of deferring to self->ob_type->tp_free(self). It is permissible to set tp_free in the type object directly to _PyObject_Del, for non-GC types, or to _PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster, so I'm fearing that our pystone rating is going down again. I'm not sure if doing something like void xxx_dealloc(PyObject *self) { if (PyXxxCheckExact(self)) PyObject_DEL(self); else self->ob_type->tp_free(self); } is any faster than always calling the else branch, so I haven't attempted that -- however those types whose own dealloc is fancier (int, float, unicode) do use this pattern.
* Make new classes dynamic by default.Guido van Rossum2001-10-041-16/+4
|
* type_new(): cast PyObject_MALLOC's result to char*, for clarity.Tim Peters2001-10-041-1/+1
|
* SF bug [#467331] ClassType.__doc__ always None.Tim Peters2001-10-041-1/+24
| | | | | | | | | For a dynamically constructed type object, fill in the tp_doc slot with a copy of the argument dict's "__doc__" value, provided the latter exists and is a string. NOTE: I don't know what to do if it's a Unicode string, so in that case tp_doc is left NULL (which shows up as Py_None if you do Class.__doc__). Note that tp_doc holds a char*, not a general PyObject*.
* typeobject.c, slot_tp_gettattr_hook(): fix the speedup hack -- theGuido van Rossum2001-10-031-0/+12
| | | | | | | | test for getattribute==NULL was bogus because it always found object.__getattribute__. Pick it apart using the trick we learned from slot_sq_item, and if it's just a wrapper around PyObject_GenericGetAttr, zap it. Also added a long XXX comment explaining the consequences.
* *EXPERIMENTAL* speedup of slot_sq_item. This sped up the followingGuido van Rossum2001-10-032-40/+62
| | | | | | | | | | | | | | | | | | | | | | | test dramatically: class T(tuple): __dynamic__ = 1 t = T(range(1000)) for i in range(1000): tt = tuple(t) The speedup was about 5x compared to the previous state of CVS (1.7 vs. 8.8, in arbitrary time units). But it's still more than twice as slow as as the same test with __dynamic__ = 0 (0.8). I'm not sure that I really want to go through the trouble of this kind of speedup for every slot. Even doing it just for the most popular slots will be a major effort (the new slot_sq_item is 40+ lines, while the old one was one line with a powerful macro -- unfortunately the speedup comes from expanding the macro and doing things in a way specific to the slot signature). An alternative that I'm currently considering is sketched in PLAN.txt: trap setattr on type objects. But this will require keeping track of all derived types using weak references.
* call_method(), call_maybe(): fix a performance bug: the argumentGuido van Rossum2001-10-031-8/+3
| | | | | | | pointing to a static variable to hold the object form of the string was never used, causing endless calls to PyString_InternFromString(). One particular test (with lots of __getitem__ calls) became a third faster with this!
* SF bug [#467265] Compile errors on SuSe Linux on IBM/s390.Tim Peters2001-10-021-1/+6
| | | | | | | Unknown whether this fixes it. - stringobject.c, PyString_FromFormatV: don't assume that va_list is of a type that can be copied via an initializer. - errors.c, PyErr_Format: add a va_end() to balance the va_start().
* Add Garbage Collection support to new-style classes (not yet to theirGuido van Rossum2001-10-022-29/+205
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.)
* Miscellaneous code fiddling:Guido van Rossum2001-10-011-28/+41
| | | | | | | | | | | | | | | - SLOT1BINFULL() macro: changed this to check for __rop__ overriding __op__, like binary_op1() in abstract.c -- the latter only calls the slot function once if both types use the same slot function, so the slot function must make both calls -- which it already did for the __op__, __rop__ order, but not yet for the __rop__, __op__ order when B.__class__ is a subclass of A.__class__. - slot_sq_contains(), slot_nb_nonzero(): use lookup_maybe() rather than lookup_method() which sets an exception which we then clear. - slot_nb_coerce(): don't give up when left argument's __coerce__ returns NotImplemented, but give the right argument a chance.
* binary_op1(), ternary_op(): rearrange the code so that slotw is testedGuido van Rossum2001-10-011-14/+14
| | | | | (to see whether __rop__ should go before __op__) only when slotv is set. This saves a test+branch when only slotw is set.
* slot_sq_length(): squash a leak.Guido van Rossum2001-10-011-1/+4
|
* slot_tp_new(): newargs was leaking.Guido van Rossum2001-10-011-0/+1
|
* Fix typo found by doerwalter.Guido van Rossum2001-10-011-1/+1
|
* SF bug [#466173] unpack TypeError unclearTim Peters2001-09-303-3/+3
| | | | | | Replaced 3 instances of "iter() of non-sequence" with "iteration over non-sequence". Restored "unpack non-sequence" for stuff like "a, b = 1".
* SF [#466125] PyLong_AsLongLong works for any integer.Tim Peters2001-09-301-1/+7
| | | | | | Generalize PyLong_AsLongLong to accept int arguments too. The real point is so that PyArg_ParseTuple's 'L' code does too. That code was undocumented (AFAICT), so documented it.
* The changes to ternary_op could cause a core dump. Fix this, andGuido van Rossum2001-09-291-55/+44
| | | | rewrite the code a bit to avoid calling the same slot more than once.
* It's a fact: for binary operators, *under certain circumstances*,Guido van Rossum2001-09-281-28/+48
| | | | | | | | | | | | | __rop__ now takes precendence over __op__. Those circumstances are: - Both arguments are new-style classes - Both arguments are new-style numbers - Their implementation slots for tp_op differ - Their types differ - The right argument's type is a subtype of the left argument's type Also did this for the ternary operator (pow) -- only the binary case is dealt with properly though, since __rpow__ is not supported anyway.
* Ouch. The wrapper for __rpow__ was the same as for __pow__, resultingGuido van Rossum2001-09-281-1/+15
| | | | in bizarre outcomes. Test forthcoming.
* Merge branch changes (coercion, rich comparisons) into trunk.Guido van Rossum2001-09-274-11/+106
|
* add_operators(): the __floordiv__ and __truediv__ descriptors (andGuido van Rossum2001-09-251-0/+10
| | | | | | | their 'i' and 'r' variants) were not being generated if the corresponding nb_ slots were present in the type object. I bet this is because floor and true division were introduced after I last looked at that part of the code.
* - Provisional support for pickling new-style objects. (*)Guido van Rossum2001-09-251-11/+50
| | | | | | | | | | | | | | | | | | | - Made cls.__module__ writable. - Ensure that obj.__dict__ is returned as {}, not None, even upon first reference; it simply springs into life when you ask for it. (*) The pickling support is provisional for the following reasons: - It doesn't support classes with __slots__. - It relies on additional support in copy_reg.py: the C method __reduce__, defined in the object class, really calls calling copy_reg._reduce(obj). Eventually the Python code in copy_reg.py needs to be migrated to C, but I'd like to experiment with the Python implementation first. The _reduce() code also relies on an additional helper function, _reconstructor(), defined in copy_reg.py; this should also be reimplemented in C.
* Change repr() of a new-style class to say <class 'ClassName'> ratherGuido van Rossum2001-09-251-4/+11
| | | | | | than <type 'ClassName'>. Exception: if it's a built-in type or an extension type, continue to call it <type 'ClassName>. Call me a wimp, but I don't want to break more user code than necessary.
* Make __class__ assignment possible, when the object structures are theGuido van Rossum2001-09-251-4/+83
| | | | | | | | | | | | | | same. I hope the test for structural equivalence is stringent enough. It only allows the assignment if the old and new types: - have the same basic size - have the same item size - have the same dict offset - have the same weaklist offset - have the same GC flag bit - have a common base that is the same except for maybe the dict and weaklist (which may have been added separately at the same offsets in both types)
* Make properties discoverable from Python:Tim Peters2001-09-241-25/+56
| | | | | | | | | | | | | - property() now takes 4 keyword arguments: fget, fset, fdel, doc. Note that the real purpose of the 'f' prefix is to make fdel fit in ('del' is a keyword, so can't used as a keyword argument name). - These map to visible readonly attributes 'fget', 'fset', 'fdel', and '__doc__' in the property object. - fget/fset/fdel weren't discoverable from Python before. - __doc__ is new, and allows to associate a docstring with a property.
* Another comparison patch-up: comparing a type with a dynamic metatypeGuido van Rossum2001-09-241-1/+2
| | | | to one with a static metatype raised an obscure error.
* Do the same thing to complex that I did to str: the rich comparisonGuido van Rossum2001-09-241-7/+10
| | | | | function returns NotImplemented when comparing objects whose tp_richcompare slot is not itself.
* Change string comparison so that it applies even when one (or both)Guido van Rossum2001-09-241-3/+4
| | | | | arguments are subclasses of str, as long as they don't override rich comparison.
* Fix the baffler that Tim reported: sometimes the repr() of an objectGuido van Rossum2001-09-241-2/+2
| | | | | looks like <X object at ...>, sometimes it says <X instance at ...>. Make this uniformly say <X object at ...>.
* Generalize file.writelines() to allow iterable objects.Tim Peters2001-09-231-31/+31
|
* Add the __getattr__ hook back. The rules are now:Guido van Rossum2001-09-211-0/+39
| | | | | | | - if __getattribute__ exists, it is called first; if it doesn't exists, PyObject_GenericGetAttr is called first. - if the above raises AttributeError, and __getattr__ exists, it is called.