summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Add PyObject_CheckReadBuffer(), which returns true if its argumentJeremy Hylton2001-11-091-29/+35
| | | | | | supports the single-segment readable buffer interface. Add documentation for this and other PyObject_XXXBuffer() calls.
* open_the_file(): Explicitly set errno to 0 before calling fopen().Tim Peters2001-11-091-0/+1
|
* open_the_file(): this routine has a borrowed reference to the fileTim Peters2001-11-091-1/+0
| | | | | | object, so the "Metroworks only" section should not decref it in case of error (the caller is responsible for decref'ing in case of error -- and does).
* Fix SF buf #476953: Bad more for opening file gives bad msg.Jeremy Hylton2001-11-091-2/+6
| | | | | | If fopen() fails with EINVAL it means that the mode argument is invalid. Return the mode in the error message instead of the filename.
* long_true_divide(): decref its converted arguments. test_long_future.pyTim Peters2001-11-041-2/+5
| | | | | run in an infinite loop no longer grows. Thanks to Neal Norwitz for determining that test leaked!
* Rehabilitated the fast-path richcmp code, and sped it up. It wasn'tTim Peters2001-11-041-31/+35
| | | | | | | | | | | | | | | helping for types that defined tp_richcmp but not tp_compare, although that's when it's most valuable, and strings moved into that category since the fast path was first introduced. Now it helps for same-type non-Instance objects that define rich or 3-way compares. For all the edits here, the rest just amounts to moving the fast path from do_richcmp into PyObject_RichCompare, saving a layer of function call (measurable on my box!). This loses when NESTING_LIMIT is exceeded, but I don't care about that (fast-paths are for normal cases, not pathologies). Also added a tasteful <wink> label to get out of PyObject_RichCompare, as the if/else nesting in this routine was getting incomprehensible.
* No code change -- just trying to document the return conditions for allTim Peters2001-11-041-17/+43
| | | | the internal comparison routines.
* float_divmod(): the code wasn't sick enough to stop the MS optimizerTim Peters2001-11-011-1/+1
| | | | | from optimizing away mod's sign adjustment when mod == 0; so it got the intended result only in the debug build.
* SF bug #477221: abs and divmod act oddly with -0.0Tim Peters2001-11-011-9/+26
| | | | | | | Try to ensure that divmod(-0.0, 1.0) -> (-0.0, +0.0) across platforms. It always did on Windows, and still does. It didn't on Linux. Alas, there's no platform-independent way to write a test case for this. Bugfix candidate.
* float_abs() again: Guido pointed out that this could screw up in theTim Peters2001-11-011-6/+1
| | | | | | presence of NaNs. So pass the issue on to the platform libm fabs(); after all, fabs() is a std C function because you can't implement it correctly in portable C89.
* PyFunction_Call() did not check the result of PyObject_Repr() for NULL, andFred Drake2001-11-011-2/+2
| | | | | | | should just avoid calling it in the first place to avoid waiting for a repr of a large object like a dict or list. The result of PyObject_Repr() was being leaked as well. Bugfix candidate!
* SF bug #477221: abs and divmod act oddly with -0.0.Tim Peters2001-11-011-9/+11
| | | | | | Partial fix. float_abs(): ensure abs(-0.0) returns +0.0. Bugfix candidate.
* fix forMichael W. Hudson2001-10-311-2/+2
| | | | | | [ #476557 ] Wrong error message for file.write(a, b) Makes file.write a METH_VARARGS function.
* Fix bad bug in structseq slicing (NULL pointers in result). Reported byTim Peters2001-10-301-1/+1
| | | | | | Jack Jansen on python-dev. Add simple test case. Move vereq() from test_descr to test_support (it's handy!).
* Add values to tp_getattro and tp_flags so that dir(Ellipsis) willGuido van Rossum2001-10-301-14/+20
| | | | return the same as dir(None).
* Rename "dictionary" (type and constructor) to "dict".Tim Peters2001-10-292-6/+6
|
* Add __del__ callbacks. They are too useful to leave out.Guido van Rossum2001-10-291-0/+74
| | | | | | | | | | | | | | | | XXX Remaining problems: - The GC module doesn't know about these; I think it has its reasons to disallow calling __del__, but for now, __del__ on new-style objects is called when the GC module discards an object, for better or for worse. - The code to call a __del__ handler is really ridiculously complicated, due to all the different debug #ifdefs. I've copied this from the similar code in classobject.c, so I'm pretty sure I did it right, but it's not pretty. :-( - No tests yet.
* When overriding __str__ or __repr__, set the tp_print slot to NULL.Guido van Rossum2001-10-291-0/+2
|
* PyObject_CallFunctionObArgs() ---> PyObject_CallFunctionObjArgs()Fred Drake2001-10-281-5/+5
| | | | PyObject_CallMethodObArgs() ---> PyObject_CallMethodObjArgs()
* SF bug #475327: type() produces incorrect error msgTim Peters2001-10-271-6/+21
| | | | | | | | | | | | | object.h: Added PyType_CheckExact macro. typeobject.c, type_new(): + Use the new macro. + Assert that the arguments have the right types rather than do incomplete runtime checks "sometimes". + If this isn't the 1-argument flavor() of type, and there aren't 3 args total, produce a "types() takes 1 or 3 args" msg before PyArg_ParseTupleAndKeywords produces a "takes exactly 3" msg.
* dictionary() constructor:Tim Peters2001-10-271-7/+5
| | | | | | + Change keyword arg name from "x" to "items". People passing a mapping object can stretch their imaginations <wink>. + Simplify the docstring text.
* PyObject_CallFunction(), PyObject_CallMethod(): Make sure we do not touchFred Drake2001-10-271-18/+11
| | | | | | the va_list until we are sure we have a format string and need to use it; this avoid premature initialization and having to finalize it several different places because of error returns.
* 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().