summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-64/+64
| | | | | | | | | | | | | PEP 285. Everything described in the PEP is here, and there is even some documentation. I had to fix 12 unit tests; all but one of these were printing Boolean outcomes that changed from 0/1 to False/True. (The exception is test_unicode.py, which did a type(x) == type(y) style comparison. I could've fixed that with a single line using issubtype(x, type(y)), but instead chose to be explicit about those places where a bool is expected. Still to do: perhaps more documentation; change standard library modules to return False/True from predicates.
* Eliminate DONT_SHARE_SHORT_STRINGS.Tim Peters2002-03-301-12/+2
|
* Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.Tim Peters2002-03-291-33/+0
|
* Use pymalloc if it's enabled.Neil Schemenauer2002-03-221-7/+7
|
* %#x/%#X format conversion cleanup (see patch #450267):Andrew MacIntyre2002-02-281-29/+35
| | | | | | Objects/ stringobject.c unicodeobject.c
* OS/2 EMX port changes (Objects part of patch #450267):Andrew MacIntyre2002-02-261-0/+9
| | | | | | | | | | | | Objects/ fileobject.c stringobject.c unicodeobject.c This commit doesn't include the cleanup patches for stringobject.c and unicodeobject.c which are shown separately in the patch manager. Those patches will be regenerated and applied in a subsequent commit, so as to preserve a fallback position (this commit to those files).
* Updated patch #487906: Revise inline docs.Martin v. Löwis2002-01-161-28/+25
|
* SF patch #491049 (David Jacobs): Small PyString_FromString optimizationGuido van Rossum2001-12-101-1/+1
| | | | | | PyString_FromString(): Since the length of the string is already being stored in size, changed the strcpy() to a memcpy() for a small speed improvement.
* PyString_FromString: this requires its argument be non-NULL, but doesn'tTim Peters2001-12-061-1/+4
| | | | check it. Added an assert() to that effect.
* Little stuff.Jeremy Hylton2001-12-061-8/+9
| | | | | | | | | | | Add a missing DECREF in an obscure corner. If the str() or repr() of an object passed to a string interpolation -- e.g. "%s" % obj -- returns a non-string, the returned object was leaked. Repair an indentation glitch. Replace a bunch of PyString_AsString() calls (and their ilk) with macros.
* Add more inline documentation, as contributed in #487906.Martin v. Löwis2001-12-031-3/+8
|
* PyString_FromFormatV, string_repr: document why these use sprintfTim Peters2001-12-031-5/+16
| | | | instead of PyOS_snprintf; add some relevant comments and asserts.
* Patch 487906: update inline docs.Martin v. Löwis2001-12-021-13/+21
|
* sprintf -> PyOS_snprintf in some "obviously safe" cases.Tim Peters2001-11-281-4/+8
| | | | | Also changed <>-style #includes to ""-style in some places where the former didn't make sense.
* Make the error message for unsupported operand types cleaner, inGuido van Rossum2001-10-221-1/+1
| | | | | | | | | | | | 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
* SF bug [#468061] __str__ ignored in str subclass.Tim Peters2001-10-161-2/+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.
* Remove extra "]" in splitlines() docstring.Fred Drake2001-10-131-1/+1
| | | | Reported by Neal Norwitz.
* Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum2001-10-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* 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().
* Merge branch changes (coercion, rich comparisons) into trunk.Guido van Rossum2001-09-271-4/+2
|
* 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.
* If interning an instance of a string subclass, intern a real string objectTim Peters2001-09-121-4/+20
| | | | | | with the same value instead. This ensures that a string (or string subclass) object's ob_sinterned pointer is always a str (or NULL), and that the dict of interned strings only has strs as keys.
* str_subtype_new, unicode_subtype_new:Tim Peters2001-09-121-5/+15
| | | | | | | | + These were leaving the hash fields at 0, which all string and unicode routines believe is a legitimate hash code. As a result, hash() applied to str and unicode subclass instances always returned 0, which in turn confused dict operations, etc. + Changed local names "new"; no point to antagonizing C++ compilers.
* More bug 460020: lots of string optimizations inhibited for stringTim Peters2001-09-121-79/+46
| | | | | | | | | subclasses, all "the usual" ones (slicing etc), plus replace, translate, ljust, rjust, center and strip. I don't know how to be sure they've all been caught. Question: Should we complain if someone tries to intern an instance of a string subclass? I hate to slow any code on those paths.
* More on SF bug [#460020] bug or feature: unicode() and subclasses.Tim Peters2001-09-111-1/+1
| | | | | Repaired str(i) to return a genuine string when i is an instance of a str subclass. New PyString_CheckExact() macro.
* Fix a memory leak in str_subtype_new(). (All the otherGuido van Rossum2001-08-311-3/+3
| | | | xxx_subtype_new() functions are OK, but I goofed up in this one. :-( )
* Make str and tuple types subclassable.Guido van Rossum2001-08-301-2/+24
|
* Two improvements suggested by Greg Stein:Barry Warsaw2001-08-271-2/+5
| | | | | | | | | PyString_FromFormatV(): In the final resize at the end, we can use PyString_AS_STRING() since we know the object is a string and can avoid the typechecking. PyString_FromFormat(): GS sez: "For safety/propriety, you should call va_end() on the vargs variable."
* PyString_FromFormatV: Massage platform %p output to match what gcc does,Tim Peters2001-08-251-0/+8
| | | | | | | at least in the first two characters. %p is ill-defined, and people will forever commit bad tests otherwise ("bad" in the sense that they fall over (at least on Windows) for lack of a leading '0x'; 5 of the 7 tests in test_repr.py failed on Windows for that reason this time around).
* PyString_FromFormat() and PyString_FromFormatV(): Largely ripped fromBarry Warsaw2001-08-241-0/+155
| | | | | | | | | | | | | | | | | | | PyErr_Format() these new C API methods can be used instead of sprintf()'s into hardcoded char* buffers. This allows us to fix many situation where long package, module, or class names get truncated in reprs. PyString_FromFormat() is the varargs variety. PyString_FromFormatV() is the va_list variety Original PyErr_Format() code was modified to allow %p and %ld expansions. Many reprs were converted to this, checkins coming soo. Not changed: complex_repr(), float_repr(), float_print(), float_str(), int_repr(). There may be other candidates not yet converted. Closes patch #454743.
* Patch #445762: Support --disable-unicodeMartin v. Löwis2001-08-171-4/+56
| | | | | | | | - Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
* Patch #427190: Implement and use METH_NOARGS and METH_O.Martin v. Löwis2001-08-161-103/+56
|
* Merge of descr-branch back into trunk.Tim Peters2001-08-021-26/+50
|
* Add _PyUnicode_AsDefaultEncodedString to unicodeobject.h.Jeremy Hylton2001-07-301-5/+0
| | | | | | | And remove all the extern decls in the middle of .c files. Apparently, it was excluded from the header file because it is intended for internal use by the interpreter. It's still intended for internal use and documented as such in the header file.
* Reformat decl of new _PyString_Join. Add NEWS blurb about repr() speedup.Tim Peters2001-06-161-1/+2
|
* SF bug 433228: repr(list) woes when len(list) big.Tim Peters2001-06-161-0/+17
| | | | | | | | | | | | Gave Python linear-time repr() implementations for dicts, lists, strings. This means, e.g., that repr(range(50000)) is no longer 50x slower than pprint.pprint() in 2.2 <wink>. I don't consider this a bugfix candidate, as it's a performance boost. Added _PyString_Join() to the internal string API. If we want that in the public API, fine, but then it requires runtime error checks instead of asserts.
* Fix for bug #432384: Recursion in PyString_AsEncodedString?Marc-André Lemburg2001-06-121-1/+1
|
* Patch #424335: Implement string_richcompare, remove string_compare.Martin v. Löwis2001-05-241-12/+77
| | | | Use new _PyString_Eq in lookdict_string.
* This patch changes the way the string .encode() method works slightlyMarc-André Lemburg2001-05-151-20/+90
| | | | | | | | | | | | | | | | | | | | | | | | | and introduces a new method .decode(). The major change is that strg.encode() will no longer try to convert Unicode returns from the codec into a string, but instead pass along the Unicode object as-is. The same is now true for all other codec return types. The underlying C APIs were changed accordingly. Note that even though this does have the potential of breaking existing code, the chances are low since conversion from Unicode previously took place using the default encoding which is normally set to ASCII rendering this auto-conversion mechanism useless for most Unicode encodings. The good news is that you can now use .encode() and .decode() with much greater ease and that the door was opened for better accessibility of the builtin codecs. As demonstration of the new feature, the patch includes a few new codecs which allow string to string encoding and decoding (rot13, hex, zip, uu, base64). Written by Marc-Andre Lemburg. Copyright assigned to the PSF.
* Heh. I need a break. After this: stropmodule & stringobject were moreTim Peters2001-05-101-8/+6
| | | | | | out of synch than I realized, and I managed to break replace's "count" argument when it was 0. All is well again. Maybe. Bugfix candidate.
* Fudge. stropmodule and stringobject both had copies of the buggyTim Peters2001-05-101-32/+41
| | | | | | mymemXXX stuff, and they were already out of synch. Fix the remaining bugs in both and get them back in synch. Bugfix release candidate.
* SF patch #416247 2.1c1 stringobject: unused vrbl cleanup.Tim Peters2001-05-091-2/+0
| | | | Thanks to Mark Favas.
* Sheesh -- repair the dodge around "cast isn't an lvalue" complaints toTim Peters2001-05-091-0/+4
| | | | restore correct semantics.
* Mark Favas reported that gcc caught me using casts as lvalues. Dodge it.Tim Peters2001-05-091-6/+10
|
* Ack! Restore the COUNT_ALLOCS one_strings code.Tim Peters2001-05-091-1/+5
|
* My change to string_item() left an extra reference to each 1-characterTim Peters2001-05-091-4/+3
| | | | | interned string created by "string"[i]. Since they're immortal anyway, this was hard to notice, but it was still wrong <wink>.
* Intern 1-character strings as soon as they're created. As-is, they aren'tTim Peters2001-05-081-15/+12
| | | | | | | | | | | | | | | | | | | interned when created, so the cached versions generally aren't ever interned. With the patch, the Py_INCREF(t); *p = t; Py_DECREF(s); return; indirection block in PyString_InternInPlace() is never executed during a full run of the test suite, but was executed very many times before. So I'm trading more work when creating one-character strings for doing less work later. Note that the "more work" here can happen at most 256 times per program run, so it's trivial. The same reasoning accounts for the patch's simplification of string_item (the new version can call PyString_FromStringAndSize() no more than 256 times per run, so there's no point to inlining that stuff -- if we were serious about saving time here, we'd pre-initialize the characters vector so that no runtime testing at all was needed!).
* Make unicode.join() work nice with iterators. This also required a changeTim Peters2001-05-051-1/+8
| | | | | | | | to string.join(), so that when the latter figures out in midstream that it really needs unicode.join() instead, unicode.join() can actually get all the sequence elements (i.e., there's no guarantee that the sequence passed to string.join() can be iterated over *again* by unicode.join(), so string.join() must not pass on the original sequence object anymore).
* Fix for bug #417030: "print '%*s' fails for unicode string"Marc-André Lemburg2001-05-021-2/+3
|
* Add a proper implementation for the tp_str slot (returning self, ofGuido van Rossum2001-05-011-1/+8
| | | | | course), so I can get rid of the special case for strings in PyObject_Str().