summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Be smarter about clearing the weakref lists for instances, instance methods,Fred Drake2001-10-262-3/+6
| | | | | | 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.
* Added two new functions to conveniently call functions/methods from C.Fred Drake2001-10-261-0/+76
| | | | | | | PyObject_CallFunctionObArgs() and PyObject_CallMethodObArgs() have the advantage that no format strings need to be parsed. The CallMethod variant also avoids creating a new string object in order to retrieve a method from an object as well.
* Generalize dictionary() to accept a sequence of 2-sequences. At theTim Peters2001-10-262-17/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outer level, the iterator protocol is used for memory-efficiency (the outer sequence may be very large if fully materialized); at the inner level, PySequence_Fast() is used for time-efficiency (these should always be sequences of length 2). dictobject.c, new functions PyDict_{Merge,Update}FromSeq2. These are wholly analogous to PyDict_{Merge,Update}, but process a sequence-of-2- sequences argument instead of a mapping object. For now, I left these functions file static, so no corresponding doc changes. It's tempting to change dict.update() to allow a sequence-of-2-seqs argument too. Also changed the name of dictionary's keyword argument from "mapping" to "x". Got a better name? "mapping_or_sequence_of_pairs" isn't attractive, although more so than "mosop" <wink>. abstract.h, abstract.tex: Added new PySequence_Fast_GET_SIZE function, much faster than going thru the all-purpose PySequence_Size. libfuncs.tex: - Document dictionary(). - Fiddle tuple() and list() to admit that their argument is optional. - The long-winded repetitions of "a sequence, a container that supports iteration, or an iterator object" is getting to be a PITA. Many months ago I suggested factoring this out into "iterable object", where the definition of that could include being explicit about generators too (as is, I'm not sure a reader outside of PythonLabs could guess that "an iterator object" includes a generator call). - Please check my curly braces -- I'm going blind <0.9 wink>. abstract.c, PySequence_Tuple(): When PyObject_GetIter() fails, leave its error msg alone now (the msg it produces has improved since PySequence_Tuple was generalized to accept iterable objects, and PySequence_Tuple was also stomping on the msg in cases it shouldn't have even before PyObject_GetIter grew a better msg).
* Allow assignment to newinstance.__dict__.Guido van Rossum2001-10-261-1/+24
|
* complex_subtype_from_string(): move the declaration of s_buffer[] outGuido van Rossum2001-10-251-1/+3
| | | | | | | | of the if block where it was before. The name is only used inside that if block, but the storage is referenced outside it via the 's' variable. (This patch was part of SF patch #474590 -- RISC OS support.)
* SF patch #474590 -- RISC OS supportGuido van Rossum2001-10-241-0/+7
|
* SF patch #474175 (Jay T Miller): file.readinto arg parsing bugGuido van Rossum2001-10-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | The C-code in fileobject.readinto(buffer) which parses the arguments assumes that size_t is interchangeable with int: size_t ntodo, ndone, nnow; if (f->f_fp == NULL) return err_closed(); if (!PyArg_Parse(args, "w#", &ptr, &ntodo)) return NULL; This causes a problem on Alpha / Tru64 / OSF1 v5.1 where size_t is a long and sizeof(long) != sizeof(int). The patch I'm proposing declares ntodo as an int. An alternative might be to redefine w# to expect size_t. [We can't change w# because there are probably third party modules relying on it. GvR]
* Referencable is not a word, so don't use it in an error message <wink>.Jeremy Hylton2001-10-221-2/+2
|
* cleanup indentationJeremy Hylton2001-10-221-1/+1
|
* Make the error message for unsupported operand types cleaner, inGuido van Rossum2001-10-222-8/+28
| | | | | | | | | | | | response to a message by Laura Creighton on c.l.py. E.g. >>> 0+'' TypeError: unsupported operand types for +: 'int' and 'str' (previously this did not mention the operand types) >>> ''+0 TypeError: cannot concatenate 'str' and 'int' objects
* Fix for SF bug #472940: can't getattr() attribute shown by dir()Guido van Rossum2001-10-221-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.
* Methods of built-in types now properly check for keyword argumentsGuido van Rossum2001-10-222-12/+25
| | | | | (formerly these were silently ignored). The only built-in methods that take keyword arguments are __call__, __init__ and __new__.
* Add missing "static" declarations (found by "make smelly").Neil Schemenauer2001-10-212-5/+5
|
* Adding missing "static" declarations (found by "make smelly").Neil Schemenauer2001-10-211-3/+3
|
* Big internal change that should have no external effects: unify theGuido van Rossum2001-10-211-527/+243
| | | | | | | | | 'slotdef' structure typedef and 'struct wrapperbase'. By adding the wrapper docstrings to the slotdef structure, the slotdefs array can serve as the data structure that drives add_operators(); the wrapper descriptor contains a pointer to slotdef structure. This replaces lots of custom code from add_operators() by a loop over the slotdefs array, and does away with all the tab_xxx tables.
* Fix for Bug #216405:Thomas Heller2001-10-191-4/+6
| | | | use the correct base for a buffer object in _PyBuffer_FromObject.
* Additional test and documentation for the unicode() changes.Marc-André Lemburg2001-10-191-2/+3
| | | | This patch should also be applied to the 2.2b1 trunk.
* SF patch #470578: Fixes to synchronize unicode() and str()Guido van Rossum2001-10-192-62/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements what we have discussed on python-dev late in September: str(obj) and unicode(obj) should behave similar, while the old behaviour is retained for unicode(obj, encoding, errors). The patch also adds a new feature with which objects can provide unicode(obj) with input data: the __unicode__ method. Currently no new tp_unicode slot is implemented; this is left as option for the future. Note that PyUnicode_FromEncodedObject() no longer accepts Unicode objects as input. The API name already suggests that Unicode objects do not belong in the list of acceptable objects and the functionality was only needed because PyUnicode_FromEncodedObject() was being used directly by unicode(). The latter was changed in the discussed way: * unicode(obj) calls PyObject_Unicode() * unicode(obj, encoding, errors) calls PyUnicode_FromEncodedObject() One thing left open to discussion is whether to leave the PyUnicode_FromObject() API as a thin API extension on top of PyUnicode_FromEncodedObject() or to turn it into a (macro) alias for PyObject_Unicode() and deprecate it. Doing so would have some surprising consequences though, e.g. u"abc" + 123 would turn out as u"abc123"... [Marc-Andre didn't have time to check this in before the deadline. I hope this is OK, Marc-Andre! You can still make changes and commit them on the trunk after the branch has been made, but then please mail Barry a context diff if you want the change to be merged into the 2.2b1 release branch. GvR]
* Missing file structseq.c for SF patch #462296Guido van Rossum2001-10-181-0/+284
|
* Remove an unnecessary check for NULL.Fred Drake2001-10-181-4/+3
|
* When weakref proxies are involved in binary & ternary slot operations,Fred Drake2001-10-181-15/+28
| | | | | | | | | | | the left-hand operand may not be the proxy in all cases. If it isn't, we end up doing two things: a) unwrapping something that isn't a PyWeakReference (later resulting in a core dump) and b) passing a proxy as the right-hand operand anyway, even though that can't be handled by the actual handler (maybe eventually causing a core dump). This is fixed by always unwrapping all the proxies involved before passing anything to the actual handler.
* Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)Guido van Rossum2001-10-181-0/+7
| | | | | The fix is a band-aid: type_call() now makes the same exception for a single-argument call to type() as type_new() was already making.
* Fix error checking done by abstract_issubclass and abstract_isinstance.Neil Schemenauer2001-10-181-44/+61
| | | | | | isinstance() now allows any object as the first argument and a class, a type or something with a __bases__ tuple attribute for the second argument. This closes SF patch #464992.
* Protect references to tp_descr_get and tp_dict with the appropriate test:Guido van Rossum2001-10-171-9/+14
| | | | PyType_HasFeature(t, Py_TPFLAGS_HAVE_CLASS).
* Remove a bunch of stuff that's no longer needed now that update_slot()Guido van Rossum2001-10-171-42/+20
| | | | | | and fixup_slot_dispatchers() always select the proper slot dispatcher. This affects slot_sq_item(), slot_tp_getattro(), and slot_tp_getattr_hook().
* slot_sq_item(): ensure that self is an instance of the wrapper'sGuido van Rossum2001-10-171-3/+5
| | | | | | d_type before calling the wrapped function. fixup_slot_dispatchers(): fix indentation.
* SF bug [#468061] __str__ ignored in str subclass.Tim Peters2001-10-162-8/+21
| | | | | | | | | | | | | | | | | object.c, PyObject_Str: Don't try to optimize anything except exact string objects here; in particular, let str subclasses go thru tp_str, same as non-str objects. This allows overrides of tp_str to take effect. stringobject.c: + string_print (str's tp_print): If the argument isn't an exact string object, get one from PyObject_Str. + string_str (str's tp_str): Make a genuine-string copy of the object if it's of a proper str subclass type. str() applied to a str subclass that doesn't override __str__ ends up here. test_descr.py: New str_of_str_subclass() test.
* Refactored the update_slot() code a bit to be hopefully slightly moreGuido van Rossum2001-10-161-57/+61
| | | | | | | | | | | | | efficient: - recurse down subclasses only once rather than for each affected slot; - short-circuit recursing down subclasses when a subclass has its own definition of the name that caused the update_slot() calls in the first place; - inline collect_ptrs().
* Get rid of __defined__ and tp_defined -- there's no need toGuido van Rossum2001-10-151-41/+23
| | | | | 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-101/+21
| | | | | Py_TPFLAGS_DYNAMICTYPE bit. There is no longer a performance benefit, and I don't really see the use case any more.
* Add (void *) casts to solve some problems on HP-UX 11.0, as discussedGuido van Rossum2001-10-151-3/+3
| | | | on SF bug #467145.
* 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
|