summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
Commit message (Collapse)AuthorAgeFilesLines
* SF patch #664192 bug #661913: inconsistent error messages between stringRaymond Hettinger2003-01-151-2/+2
| | | | | | and unicode Patch by Christopher Blunck.
* GvR's idea to use memset() for the most common special case of repeatingRaymond Hettinger2003-01-061-1/+5
| | | | | a single character. Shaves another 10% off the running time by avoiding the lg2(N) loops and cache effects for the other cases.
* Optimize string_repeat.Raymond Hettinger2003-01-061-2/+11
| | | | | | | | | | | Christian Tismer pointed out the high cost of the loop overhead and function call overhead for 'c' * n where n is large. Accordingly, the new code only makes lg2(n) loops. Interestingly, 'c' * 1000 * 1000 ran a bit faster with old code. At some point, the loop and function call overhead became cheaper than invalidating the cache with lengthy memcpys. But for more typical sizes of n, the new code runs much faster and for larger values of n it runs only a bit slower.
* Patch for bug #659709: bogus computation of float lengthMarc-André Lemburg2002-12-291-6/+16
| | | | | Python 2.2.x backport candidate. (This bug has been around since Python 1.6.)
* SF patch #659536: Use PyArg_UnpackTuple where possible.Raymond Hettinger2002-12-291-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.
* Patch #650653: Raise always value error if the table is not 256 bytes long.Martin v. Löwis2002-12-121-6/+6
|
* Patch #614055: Support OpenVMS.Martin v. Löwis2002-12-061-1/+5
|
* Add nb_remainder (i.e. __mod__) slot to str type. Fixes SF bug #615506.Neil Schemenauer2002-11-181-2/+22
|
* Fix SF # 635969, No error "not all arguments converted"Neal Norwitz2002-11-121-1/+2
| | | | | | | | | When mwh added extended slicing, strings and unicode became mappings. Thus, dict was set which prevented an error when doing: newstr = 'format without a percent' % string_value This fix raises an exception again when there are no formats and % with a string value.
* Back out #479898.Martin v. Löwis2002-10-111-69/+15
|
* Fix a nasty endcase reported by Armin Rigo in SF bug 618623:Guido van Rossum2002-10-111-2/+6
| | | | | | | | | | | | | '%2147483647d' % -123 segfaults. This was because an integer overflow in a comparison caused the string resize to be skipped. After fixing the overflow, this could call _PyString_Resize() with a negative size, so I (1) test for that and raise MemoryError instead; (2) also added a test for negative newsize to _PyString_Resize(), raising SystemError as for all bad arguments. An identical bug existed in unicodeobject.c, of course. Will backport to 2.2.2.
* Undo this part of the previous checkin:Guido van Rossum2002-10-091-3/+4
| | | | | | | | | Also fixed an error message -- %s argument has non-string str() doesn't make sense for %r, so the error message now differentiates between %s and %r. because PyObject_Repr() and PyObject_Str() ensure that this can never happen. Added a helpful comment instead.
* The string formatting code has a test to switch to Unicode when %sGuido van Rossum2002-10-091-2/+5
| | | | | | | | | | | | | | sees a Unicode argument. Unfortunately this test was also executed for %r, because %s and %r share almost all of their code. This meant that, if u is a unicode object while repr(u) is an 8-bit string containing ASCII characters, '%r' % u is a *unicode* string containing only ASCII characters! Fixed by executing the test only for %s. Also fixed an error message -- %s argument has non-string str() doesn't make sense for %r, so the error message now differentiates between %s and %r.
* Include wctype.h.Martin v. Löwis2002-10-071-1/+2
|
* Patch #479898: Use multibyte C library for printing strings if available.Martin v. Löwis2002-10-071-15/+68
|
* Fix warnings on 64-bit platforms about casts from pointers to ints.Guido van Rossum2002-09-121-1/+2
| | | | Two of these were real bugs.
* Fix escaping of non-ASCII characters.Martin v. Löwis2002-09-091-2/+4
|
* Check whether a string resize is necessary at the endWalter Dörwald2002-09-031-3/+4
| | | | | | | | | of PyString_DecodeEscape(). This prevents a call to _PyString_Resize() for the empty string, which would result in a PyErr_BadInternalCall(), because the empty string has more than one reference. This closes SF bug http://www.python.org/sf/603937
* PEP 293 implemention (from SF patch http://www.python.org/sf/432401)Walter Dörwald2002-09-021-2/+6
|
* string_contains(): speed up by avoiding function calls whereGuido van Rossum2002-08-241-9/+12
| | | | | | possible. This always called PyUnicode_Check() and PyString_Check(), at least one of which would call PyType_IsSubtype(). Also, this would call PyString_Size() on known string objects.
* Code by Inyeol Lee, submitted to SF bug 595350, to implementGuido van Rossum2002-08-231-24/+33
| | | | | the string/unicode method .replace() with a zero-lengt first argument. Inyeol contributed tests for this too.
* Fix some endcase bugs in unicode rfind()/rindex() and endswith().Guido van Rossum2002-08-201-1/+1
| | | | | | These were reported and fixed by Inyeol Lee in SF bug 595350. The endswith() bug was already fixed in 2.3, but this adds some more test cases.
* SF patch 576101, by Oren Tirosh: alternative implementation ofGuido van Rossum2002-08-191-71/+108
| | | | | | | | 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.
* Call me anal, but there was a particular phrase that was speading toGuido van Rossum2002-08-191-3/+3
| | | | | | | comments everywhere that bugged me: /* Foo is inlined */ instead of /* Inline Foo */. Somehow the "is inlined" phrase always confused me for half a second (thinking, "No it isn't" until I added the missing "here"). The new phrase is hopefully unambiguous.
* Get this to compile again if Py_USING_UNICODE is not defined.Neal Norwitz2002-08-161-1/+1
| | | | com_error() is static in Python/compile.c.
* More changes of DeprecationWarning to FutureWarning.Guido van Rossum2002-08-141-1/+1
|
* Check for trailing backslash. Fixes #593656.Martin v. Löwis2002-08-141-5/+8
|
* Patch #505705: Remove eval in pickle and cPickle.Martin v. Löwis2002-08-141-3/+157
|
* Implement stage B0 of PEP 237: add warnings for operations thatGuido van Rossum2002-08-111-0/+6
| | | | | | | | | | currently return inconsistent results for ints and longs; in particular: hex/oct/%u/%o/%x/%X of negative short ints, and x<<n that either loses bits or changes sign. (No warnings for repr() of a long, though that will also change to lose the trailing 'L' eventually.) This introduces some warnings in the test suite; I'll take care of those later.
* Committing patch #591250 which provides "str1 in str2" when str1 is aBarry Warsaw2002-08-061-9/+16
| | | | string of longer than 1 character.
* SF 582071 clarified the .split() method's docstring to note that sep=NoneRaymond Hettinger2002-08-051-2/+2
| | | | will trigger splitting on any whitespace.
* Fix the problem of not raising a TypeError exception when doing:Neal Norwitz2002-07-281-8/+8
| | | | | | | | '%g' % '1' '%d' % '1' Add a test for these conditions Fix the test so that if not exception is raise, this is a failure
* SF patch #577031, remove PyArg_Parse() since it's deprecatedNeal Norwitz2002-07-281-2/+8
|
* Patch #554716: Use __va_copy where available.Martin v. Löwis2002-07-281-0/+4
|
* staticforward bites the dust.Jeremy Hylton2002-07-171-1/+1
| | | | | | | | | | | | | | | The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) I'm leaving staticforward and statichere defined in object.h as static. This is only for backwards compatibility with C extensions that might still use it. XXX I haven't updated the documentation.
* object.h special-build macro minefield: renamed all the new lexicalTim Peters2002-07-111-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* SF bug # 493951 string.{starts,ends}with vs slicesNeal Norwitz2002-06-141-45/+36
| | | | Handle negative indices similar to slices.
* Patch #568124: Add doc string macros.Martin v. Löwis2002-06-131-72/+72
|
* This is my nearly two year old patchMichael W. Hudson2002-06-111-2/+62
| | | | | | | | | [ 400998 ] experimental support for extended slicing on lists somewhat spruced up and better tested than it was when I wrote it. Includes docs & tests. The whatsnew section needs expanding, and arrays should support extended slices -- later.
* Change name from string to basestringNeal Norwitz2002-05-311-3/+3
|
* - A new type object, 'string', is added. This is a common base typeGuido van Rossum2002-05-241-1/+55
| | | | | | | for 'str' and 'unicode', and can be used instead of types.StringTypes, e.g. to test whether something is "a string": isinstance(x, string) is True for Unicode and 8-bit strings. This is an abstract base class and cannot be instantiated directly.
* Patch 549187. Improve string formatting error message.Raymond Hettinger2002-05-211-2/+2
|
* Add #ifdef PY_USING_UNICODE sections, so thatWalter Dörwald2002-05-131-0/+6
| | | | | | stringobject.c compiles again with --disable-unicode. Fixes SF bug http://www.python.org/sf/554912
* Repair widespread misuse of _PyString_Resize. Since it's clear peopleTim Peters2002-04-271-3/+10
| | | | | | | | | | | | | | | | | | | | | | 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.
* Apply patch diff.txt from SF feature requestWalter Dörwald2002-04-221-12/+28
| | | | | | | | | 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.
* Return the orginal string only if it's a real str or unicodeWalter Dörwald2002-04-151-2/+9
| | | | 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-151-0/+40
| | | | | | | | | | 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)
* 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.
* Remove PyMalloc_New, _PyMalloc_MALLOC, and PyMalloc_Del.Neil Schemenauer2002-04-121-7/+7
|