summaryrefslogtreecommitdiffstats
path: root/Objects
Commit message (Collapse)AuthorAgeFilesLines
* Remove old deprecated features from the xrange object.Fred Drake2002-05-021-273/+40
|
* Fix attribute access for the xrange objects. The tp_getattr and tp_getattroFred Drake2002-05-021-31/+38
| | | | | | handlers were both set, but were not compatible. This change uses only the tp_getattro handler with a more "modern" approach. This fixes SF bug #551285.
* clarify message when raising TypeError to indicate that float() acceptsSkip Montanaro2002-05-021-1/+1
| | | | strings or numbers
* Just added comments, and cleared some XXX questions, related to intTim Peters2002-04-281-3/+12
| | | | memory management.
* _PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,Tim Peters2002-04-281-18/+25
| | | | | display a msg warning that the count of bytes requested may be bogus, and that a segfault may happen next.
* Repair widespread misuse of _PyString_Resize. Since it's clear peopleTim Peters2002-04-273-32/+19
| | | | | | | | | | | | | | | | | | | | | | don't understand how this function works, also beefed up the docs. The most common usage error is of this form (often spread out across gotos): if (_PyString_Resize(&s, n) < 0) { Py_DECREF(s); s = NULL; goto outtahere; } The error is that if _PyString_Resize runs out of memory, it automatically decrefs the input string object s (which also deallocates it, since its refcount must be 1 upon entry), and sets s to NULL. So if the "if" branch ever triggers, it's an error to call Py_DECREF(s): s is already NULL! A correct way to write the above is the simpler (and intended) if (_PyString_Resize(&s, n) < 0) goto outtahere; Bugfix candidate.
* SF patch 549375: Compromise PyUnicode_EncodeUTF8Tim Peters2002-04-271-108/+70
| | | | | | | | | | | | | | | | | | | | This implements ideas from Marc-Andre, Martin, Guido and me on Python-Dev. "Short" Unicode strings are encoded into a "big enough" stack buffer, then exactly as much string space as they turn out to need is allocated at the end. This should have speed benefits akin to Martin's "measure once, allocate once" strategy, but without needing a distinct measuring pass. "Long" Unicode strings allocate as much heap space as they could possibly need (4 x # Unicode chars), and do a realloc at the end to return the untouched excess. Since the overallocation is likely to be substantial, this shouldn't burden the platform realloc with unusably small excess blocks. Also simplified uses of the PyString_xyz functions. Also added a release- build check that 4*size doesn't overflow a C int. Sooner or later, that's going to happen.
* - New builtin function enumerate(x), from PEP 279. Example:Guido van Rossum2002-04-261-0/+139
| | | | | enumerate("abc") is an iterator returning (0,"a"), (1,"b"), (2,"c"). The argument can be an arbitrary iterable object.
* PyNumber_CoerceEx: this took a shortcut (not doing anything) when theGuido van Rossum2002-04-261-1/+4
| | | | | | | | | | | | | | | | | | | | | left and right type were of the same type and not classic instances. This shortcut is dangerous for proxy types, because it means that coerce(Proxy(1), Proxy(2.1)) leaves Proxy(1) unchanged rather than turning it into Proxy(1.0). In an ever-so-slight change of semantics, I now only take the shortcut when the left and right types are of the same type and don't have the CHECKTYPES feature. It so happens that classic instances have this flag, so the shortcut is still skipped in this case (i.e. nothing changes for classic instances). Proxies also have this flag set (otherwise implementing numeric operations on proxies would become nightmarish) and this means that the shortcut is also skipped there, as desired. It so happens that int, long and float also have this flag set; that means that e.g. coerce(1, 1) will now invoke int_coerce(). This is fine: int_coerce() can deal with this, and I'm not worried about the performance; int_coerce() is only invoked when the user explicitly calls coerce(), which should be rarer than rare.
* Make sure that tp_free frees the int the same way as tp_dealloc would.Guido van Rossum2002-04-261-0/+8
| | | | | | | | | This fixes the problem that Barry reported on python-dev: >>> 23000 .__class__ = bool crashes in the deallocator. This was because int inherited tp_free from object, which uses the default allocator. 2.2. Bugfix candidate.
* Clean up the layout of the bool_as_number struct initializer.Guido van Rossum2002-04-251-38/+38
|
* abstract_get_bases(): Clarify exactly what the return values andBarry Warsaw2002-04-231-9/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | states can be for this function, and ensure that only AttributeErrors are masked. Any other exception raised via the equivalent of getattr(cls, '__bases__') should be propagated up. abstract_issubclass(): If abstract_get_bases() returns NULL, we must call PyErr_Occurred() to see if an exception is being propagated, and return -1 or 0 as appropriate. This is the specific fix for a problem whereby if getattr(derived, '__bases__') raised an exception, an "undetected error" would occur (under a debug build). This nasty situation was uncovered when writing a security proxy extension type for the Zope3 project, where the security proxy raised a Forbidden exception on getattr of __bases__. PyObject_IsInstance(), PyObject_IsSubclass(): After both calls to abstract_get_bases(), where we're setting the TypeError if the return value is NULL, we must first check to see if an exception occurred, and /not/ mask an existing exception. Neil Schemenauer should double check that these changes don't break his ExtensionClass examples (there aren't any test cases for those examples and abstract_get_bases() was added by him in response to problems with ExtensionClass). Neil, please add test cases if possible! I belive this is a bug fix candidate for Python 2.2.2.
* Clarify return value of PyLong_AsLongLong().Jeremy Hylton2002-04-231-1/+1
| | | | | | The function is documented to return -1 on error. If res was < 0, it returned res. It wasn't clear that the invariant was res < 0 iff res == -1.
* unicode_memchr(): Squashed gratuitous int-vs-size_t mismatch (whichTim Peters2002-04-221-3/+3
| | | | | gives a compiler wng under MSVC because of the resulting signed-vs- unsigned comparison).
* Apply patch diff.txt from SF feature requestWalter Dörwald2002-04-222-70/+191
| | | | | | | | | http://www.python.org/sf/444708 This adds the optional argument for str.strip to unicode.strip too and makes it possible to call str.strip with a unicode argument and unicode.strip with a str argument.
* Py_UniversalNewlineFread(): small speed boost on non-Windows boxes.Tim Peters2002-04-211-3/+3
|
* PyUnicode_EncodeUTF8(): tightened the memory asserts a bit, and at leastTim Peters2002-04-211-12/+20
| | | | tried to catch some possible arithmetic overflows in the debug build.
* Back out 2.140.Martin v. Löwis2002-04-211-43/+55
|
* Py_UniversalNewlineFread(): Many changes.Tim Peters2002-04-211-37/+47
| | | | | | | | | | | | | | | | | | | | + Continued looping until n bytes in the buffer have been filled, not just when n bytes have been read from the file. This repairs the bug that f.readlines() only sucked up the first 8192 bytes of the file on Windows when universal newlines was enabled and f was opened in U mode (see Python-Dev -- this was the ultimate cause of the test_inspect.py failure). + Changed prototye to take a char* buffer (void* doesn't make much sense). + Squashed size_t vs int mismatches (in particular, besides the unsigned vs signed distinction, size_t may be larger than int). + Gets out under all error conditions now (it's possible for fread() to suffer an error even if it returns a number larger than 0 -- any "short read" is an error or EOF condition). + Rearranged and simplified declarations.
* PyUnicode_EncodeUTF8: squash compiler wng. The difference of twoTim Peters2002-04-211-4/+5
| | | | | | pointers is a signed type. Changing "allocated" to a signed int makes undetected overflow more likely, but there was no overflow detection before either.
* Patch #495401: Count number of required bytes for encoding UTF-8 beforeMartin v. Löwis2002-04-201-54/+43
| | | | allocating the target buffer.
* Fix SF bug #505315: Make free and cell vars show up consistently in locals().Jeremy Hylton2002-04-201-6/+7
| | | | | | | | | | PyFrame_FastToLocals() and PyFrame_LocalsToFast() had a return if f_nlocals was 0. I think this was a holdover from the pre 2.1 days when regular locals were the only kind of local variables. The change makes it possible to use a free variable in eval or exec if it the variable is also used elsewhere in the same block, which is what the documentation says.
* _PyObject_DebugMallocStats(): Added some potentially expensive internalTim Peters2002-04-181-5/+41
| | | | | | consistency checks, enabled only in a debug (Py_DEBUG) build. Note that this never gets called automatically unless PYMALLOC_DEBUG is #define'd too, and the envar PYTHONMALLOCSTATS exists.
* PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)Tim Peters2002-04-181-2/+9
| | | | | | doesn't return NULL. PyObject_Realloc: better comment for why we don't call PyObject_Malloc(0).
* Remove some long-disabled debugging boilerplate.Tim Peters2002-04-181-26/+0
|
* type_get_doc(): Squash compiler wng about incompatible ptr types.Tim Peters2002-04-181-1/+2
|
* SF bug 542984.Guido van Rossum2002-04-181-7/+11
| | | | | | | | | | | Change type_get_doc (the get function for __doc__) to look in tp_dict more often, and if it finds a descriptor in tp_dict, to call it (with a NULL instance). This means you can add a __doc__ descriptor to a new-style class that returns instance docs when called on an instance, and class docs when called on a class -- or the same docs in either case, but lazily computed. I'll also check this into the 2.2 maintenance branch.
* SF bug 544647.Guido van Rossum2002-04-161-2/+6
| | | | | | | | | PyNumber_InPlaceMultiply insisted on calling sq_inplace_repeat if it existed, even if nb_inplace_multiply also existed and the arguments weren't right for sq_inplace_repeat. Change this to only use sq_inplace_repeat if nb_inplace_multiply isn't defined. Bugfix candidate.
* Whitespace normalization and fold some long lines.Guido van Rossum2002-04-161-20/+19
|
* Return the orginal string only if it's a real str or unicodeWalter Dörwald2002-04-152-4/+18
| | | | instance, otherwise make a copy.
* Remove 'const' from local variable declaration in string_zfill() -- itGuido van Rossum2002-04-151-71/+80
| | | | | | | | isn't constant, so why bother. Folded long lines. Whitespace normalization.
* Apply the second version of SF patch http://www.python.org/sf/536241Walter Dörwald2002-04-152-3/+44
| | | | | | | | | | Add a method zfill to str, unicode and UserString and change Lib/string.py accordingly. This activates the zfill version in unicodeobject.c that was commented out and implements the same in stringobject.c. It also adds the test for unicode support in Lib/string.py back in and uses repr() instead() of str() (as it was before Lib/string.py 1.62)
* Deprecate % as well. The message for deprecation of //, % and divmodGuido van Rossum2002-04-151-1/+6
| | | | is the same in all three cases (mostly because // calls divmod :-).
* SF bug #543387.Guido van Rossum2002-04-151-0/+5
| | | | | | | | | Complex numbers implement divmod() and //, neither of which makes one lick of sense. Unfortunately this is documented, so I'm adding a deprecation warning now, so we can delete this silliness, oh, around 2005 or so. Bugfix candidate (At least for 2.2.2, I think.)
* SF bug #541883 (Vincent Fiack).Guido van Rossum2002-04-151-0/+5
| | | | | | | A stupid bug in object_set_class(): didn't check for value==NULL before checking its type. Bugfix candidate.
* SF bug 543840: complex(string) accepts strings with \0Tim Peters2002-04-141-1/+1
| | | | | | | complex_subtype_from_string(): this stopped parsing at the first 0 byte, as if that were the end of the input string. Bugfix candidate.
* Mass checkin of universal newline support.Jack Jansen2002-04-141-17/+294
| | | | | | | | Highlights: import and friends will understand any of \r, \n and \r\n as end of line. Python file input will do the same if you use mode 'U'. Everything can be disabled by configuring with --without-universal-newlines. See PEP278 for details.
* Fold long lines. (Walter, please take note! :-)Guido van Rossum2002-04-131-9/+18
|
* _PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.Tim Peters2002-04-131-4/+8
| | | | | | Added code to call this when PYMALLOC_DEBUG is enabled, and envar PYTHONMALLOCSTATS is set, whenever a new arena is obtained and once late in the Python shutdown process.
* SF bug 543148: Memory leak with stackframes + inspect.Tim Peters2002-04-131-2/+17
| | | | | | | | Put a bound on the number of frameobjects that can live in the frameobject free_list. Am also backporting to 2.2. I don't intend to backport to 2.1 (too much work -- lots of cyclic structures leak there, and the GC API).
* Partially implement SF feature request 444708.Guido van Rossum2002-04-131-15/+86
| | | | | | | | | | | | | Add optional arg to string methods strip(), lstrip(), rstrip(). The optional arg specifies characters to delete. Also for UserString. Still to do: - Misc/NEWS - LaTeX docs (I did the docstrings though) - Unicode methods, and Unicode support in the string methods.
* Small anal correctness tweaks:Tim Peters2002-04-121-2/+2
| | | | | | | | | | _PyObject_DebugMalloc: explicitly cast PyObject_Malloc's result to the target pointer type. _PyObject_DebugDumpStats: change decl of arena_alignment from unsigned int to unsigned long. This is for the 2.3 release only (it's new code).
* Add Raymond Hettinger's d.pop(). See SF patch 539949.Guido van Rossum2002-04-121-0/+38
|
* _PyObject_DebugRealloc(): rewritten to let the underlying realloc doTim Peters2002-04-121-27/+30
| | | | | | | | | | most of the work. In particular, if the underlying realloc is able to grow the memory block in place, great (this routine used to do a fresh malloc + memcpy every time a block grew). BTW, I'm not so keen here on avoiding possible quadratic-time realloc patterns as I am on making the debug pymalloc more invisible (the more it uses memory "just like" the underlying allocator, the better the chance that a suspected memory corruption bug won't vanish when the debug malloc is turned on).
* _PyObject_DebugDumpAddress(): clarify an output message.Tim Peters2002-04-121-1/+1
|
* PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_Tim Peters2002-04-121-34/+39
| | | | | prefix. These symbols are private to the file, and the PYMALLOC_ gets in the way (overly long code lines, comments, and error messages).
* First stab at rationalizing the PyMem_ API. Mixing PyObject_xyz withTim Peters2002-04-121-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | PyMem_{Del, DEL} doesn't work yet (compilation problems). pyport.h: _PyMem_EXTRA is gone. pmem.h: Repaired comments. PyMem_{Malloc, MALLOC} and PyMem_{Realloc, REALLOC} now make the same x-platform guarantees when asking for 0 bytes, and when passing a NULL pointer to the latter. object.c: PyMem_{Malloc, Realloc} just call their macro versions now, since the latter take care of the x-platform 0 and NULL stuff by themselves now. pypcre.c, grow_stack(): So sue me. On two lines, this called PyMem_RESIZE to grow a "const" area. It's not legit to realloc a const area, so the compiler warned given the new expansion of PyMem_RESIZE. It would have gotten the same warning before if it had used PyMem_Resize() instead; the older macro version, but not the function version, silently cast away the constness. IMO that was a wrong thing to do, and the docs say the macro versions of PyMem_xyz are deprecated anyway. If somebody else is resizing const areas with the macro spelling, they'll get a warning when they recompile now too.
* Move PyObject_Malloc and PyObject_Free here from object.c. RemoveNeil Schemenauer2002-04-121-61/+33
| | | | | PyMalloc_ prefix and use PyObject_ instead. I'm not sure about the debugging functions. Perhaps they should stay as PyMalloc_.
* Move PyObject_Malloc and PyObject_Free to obmalloc.c.Neil Schemenauer2002-04-121-21/+2
|
* Remove PyMalloc_*.Neil Schemenauer2002-04-121-5/+5
|