146 Commits

Author SHA1 Message Date
Jeremy Hylton
886849a282 Backport: Double-fix of crash in Unicode freelist handling. 2003-09-17 03:32:41 +00:00
Neal Norwitz
9976fdf83c Backport:
Fix SF bug #697220, string.strip implementation/doc mismatch

Attempt to make all the various string/unicode *strip methods the same.
 * Doc - add doc for when functions were added
 * UserString
 * string/unicode object methods
 * string module functions
'chars' is used for the last parameter everywhere.
2003-04-11 18:21:22 +00:00
Neal Norwitz
9aa5027699 Backport: Add more missing PyErr_NoMemory() after failled memory allocs 2003-02-11 23:19:35 +00:00
Raymond Hettinger
65b5e1fdbe Backport MAL's patch for bug #659709: bogus computation of float length 2003-01-02 22:08:39 +00:00
Neal Norwitz
c3bb11417f Backport 2.173:
Fix for bug #626172:  crash using unicode latin1 single char
2002-11-07 00:22:53 +00:00
Guido van Rossum
d9ddf59d28 Backport stringobject.c 2.194 and unicodeobject.c 2.172:
Fix a nasty endcase reported by Armin Rigo in SF bug 618623:
'%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.
2002-10-11 00:47:20 +00:00
Michael W. Hudson
d1bb75505f Backport:
2002/08/11 12:23:04 lemburg Python/bltinmodule.c 2.262
2002/08/11 12:23:04 lemburg Objects/unicodeobject.c 2.162
2002/08/11 12:23:03 lemburg Misc/NEWS 1.461
2002/08/11 12:23:03 lemburg Lib/test/test_unicode.py 1.65
2002/08/11 12:23:03 lemburg Include/unicodeobject.h 2.39
Add C API PyUnicode_FromOrdinal() which exposes unichr() at C level.

u'%c' will now raise a ValueError in case the argument is an
integer outside the valid range of Unicode code point ordinals.

Closes SF bug #593581.
2002-10-07 12:32:57 +00:00
Tim Peters
1b3e494a46 unicode_memchr(): Squashed compiler wng (signed-vs-unsigned comparison). 2002-09-24 15:22:30 +00:00
Marc-André Lemburg
1e616dcafb Backport the UTF-8 codec from 2.3 and add a work-around to let the
UTF-8 decoder accept broken UTF-8 sequences which encode lone
high surrogates (the pre-2.2.2 versions forgot to generate the
UTF-8 prefix \xed for these).

Fixes SF bug #610783: Lone surrogates cause bad .pyc files.
2002-09-24 14:06:55 +00:00
Marc-André Lemburg
1b651fcde8 Fix cast from backport. 2002-09-24 09:29:44 +00:00
Guido van Rossum
67c87194fb Backport from trunk:
unicodeobject.c 2.169
stringobject.c 2.189

Fix warnings on 64-bit platforms about casts from pointers to ints.
Two of these were real bugs.
2002-09-23 21:17:27 +00:00
Guido van Rossum
1c4a45761c Backport 2.166 from trunk:
Fix SF bug 599128, submitted by Inyeol Lee: .replace() would do the
wrong thing for a unicode subclass when there were zero string
replacements.  The example given in the SF bug report was only one way
to trigger this; replacing a string of length >= 2 that's not found is
another.  The code would actually write outside allocated memory if
replacement string was longer than the search string.
2002-09-23 20:46:52 +00:00
Guido van Rossum
96303ce055 Fix some endcase bugs in unicode rfind()/rindex() and endswith().
These were reported and fixed by Inyeol Lee in SF bug 595350.  The
endswith() bug is already fixed in 2.3; I'll fix the others in
2.3 next.
2002-08-20 16:57:58 +00:00
Anthony Baxter
3864a45cd3 backport tim_one's patch:
Repair widespread misuse of _PyString_Resize.  Since it's clear people
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.

Original patch(es):
python/dist/src/Objects/fileobject.c:2.161
python/dist/src/Objects/stringobject.c:2.161
python/dist/src/Objects/unicodeobject.c:2.147
2002-04-30 03:41:53 +00:00
Walter Dörwald
aa82bc0817 Backport checkin:
Apply patch diff.txt from SF feature request
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.
2002-04-22 18:42:45 +00:00
Walter Dörwald
1c097b7102 Backport the following changes:
Misc/NEWS 1.387->1.388
Lib/test/string_tests.py 1.10->1.11, 1.12->1.14,
Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56
Lib/test/test_string.py 1.15->1.16
Lib/string.py 1.61->1.63
Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12
Objects/stringobject.c 2.156->2.159
Objects/unicodeobject.c 2.137->2.139
Doc/lib/libstdtypes.tec 1.87->1.88

Add a method zfill to str, unicode and UserString
and change Lib/string.py accordingly
(see SF patch http://www.python.org/sf/536241)

This also adds Guido's fix to test_userstring.py
and the subinstance checks in test_string.py
and test_unicode.py.
2002-04-22 11:57:06 +00:00
Michael W. Hudson
c2a5e3c0f9 Martin's fix for
[ 529104 ] broken error handling in unicode-escape

I presume this will need to be fixed on the trunk, too.

Later.
2002-03-18 12:47:52 +00:00
Michael W. Hudson
36de099f04 Fix
[ 531306 ] ucs4 build horked.

Classic C mistake, I think.

Also squashed a couple of warnings in the ucs4 build.
2002-03-18 12:43:33 +00:00
Tim Peters
f0cd73e215 Move to zlib 1.1.4 on Windows (the new version that squashes the "double
free" glitch).

unicodeobject.c:  squash compiler warnings.

Noting that test_pyclbr currently fails in 2.2.1:

    test_others (__main__.PyclbrTest) ... ??? HTTP11
    FAIL
2002-03-13 23:56:48 +00:00
Marc-André Lemburg
679e4314fd Whitespace normalization and minor cosmetics. 2002-02-25 14:51:00 +00:00
Marc-André Lemburg
d53e226f81 Fix UTF-8 encoder pointer arithmetic and restore 2.2 behaviour. 2002-02-25 14:30:49 +00:00
Michael W. Hudson
6c7078b582 Fix the problem reported in
[ #495401 ] Build troubles: --with-pymalloc

in a slightly different manner to the trunk, as discussed on python-dev.
2002-02-22 13:44:43 +00:00
Guido van Rossum
604ddf80d8 Fix for #489669 (Neil Norwitz): memory leak in test_descr (unicode).
This is best reproduced by

  while 1:
      class U(unicode):
          pass
      U(u"xxxxxx")

The unicode_dealloc() code wasn't properly freeing the str and defenc
fields of the Unicode object when freeing a subtype instance.  Fixed
this by a subtle refactoring that actually reduces the amount of code
slightly.
2001-12-06 20:03:56 +00:00
Barry Warsaw
e5c492d72a formatfloat(), formatint(): Conversion of sprintf() to PyOS_snprintf()
for buffer overrun avoidance.
2001-11-28 21:00:41 +00:00
Marc-André Lemburg
11326de657 Fix for bug #485951: repr diff between string and unicode. 2001-11-28 12:56:20 +00:00