Commit Graph

1734 Commits

Author SHA1 Message Date
Michael W. Hudson 173f11da5d Some days, I think my comment of
/* this is harder to get right than you might think */

angered some God somewhere.  After noticing

    >>> range(5000000)[slice(96360, None, 439)]
    []

I found that my cute test for the slice being empty failed due to
overflow.  Fixed, and added simple test (not the above!).
2002-11-05 15:28:51 +00:00
Guido van Rossum f740bdf337 Since properties are supported here, is possible that
instance_getattr2() raises an exception.  Fix all code that made this
assumption.

Backport candidate.
2002-10-29 18:36:40 +00:00
Martin v. Löwis 8c1402869b Patch #627105: Document that SYSTEM_PAGE_SIZE really should not be
larger than the system page size.
2002-10-26 15:01:53 +00:00
Marc-André Lemburg 9cd87aaa54 Fix for bug #626172: crash using unicode latin1 single char
Python 2.2.3 candidate.
2002-10-23 09:02:46 +00:00
Martin v. Löwis edf368c351 Make lower/upper/title work for non-BMP characters. 2002-10-18 16:40:36 +00:00
Neal Norwitz 673cd824ba Fix SF # 624982, Potential AV in slot_sq_item, by Greg Chapman
Don't crash when getting value of a property raises an exception
2002-10-18 16:33:13 +00:00
Martin v. Löwis 9def6a3a77 Update to Unicode 3.2 database. 2002-10-18 16:11:54 +00:00
Guido van Rossum 617080b6cf Fix (real! :-) memory leaks in half_cmp and half_binop.
Perhaps found by NealN and valgrind.  Will forward port.
2002-10-18 14:15:33 +00:00
Guido van Rossum 3930bc35d0 Sigh. That wasn't a memory leak, that was Guido committing before
running tests.  Withdraw 2.183 and its backport.
2002-10-18 13:51:49 +00:00
Guido van Rossum 72297bb71e Fix memory leak in add_subclass() found by NealN with valgrind.
Will backport.
2002-10-18 13:41:47 +00:00
Martin v. Löwis ceaa77cf85 Add n_unnamed_fields into the type. 2002-10-16 19:10:03 +00:00
Martin v. Löwis f607bdaa77 Add PyStructSequence_UnnamedField. Add stat_float_times.
Use integers in stat tuple, optionally floats in named fields.
2002-10-16 18:27:39 +00:00
Guido van Rossum 6e5680fc83 For some reason (probably cut and paste), __ipow__ for new-style
classes was called with three arguments.  This makes no sense, there's
no way to pass in the "modulo" 3rd argument as for __pow__, and
classic classes don't do this.  [SF bug 620179]

I don't want to backport this to 2.2.2, because it could break
existing code that has developed a work-around.  Code in 2.2.2 that
wants to use __ipow__ and wants to be forward compatible with 2.3
should be written like this:

  def __ipow__(self, exponent, modulo=None):
      ...
2002-10-15 01:01:53 +00:00
Martin v. Löwis 13b1a5cc99 Don't drop old slots if _unicode_to_string did not change anything. 2002-10-14 21:11:34 +00:00
Martin v. Löwis d919a59ab5 Allow Unicode strings in __slots__, converting them to byte strings. 2002-10-14 21:07:28 +00:00
Guido van Rossum bfa5a14adb Darn! Don't divide by zero. Bad fix. :-) 2002-10-11 23:39:35 +00:00
Guido van Rossum a5c0e6d6c8 Add checks for size overflow on list*n, list+list, tuple+tuple.
Will backport.
2002-10-11 21:05:56 +00:00
Guido van Rossum 6e08c1460c PyObject_Init[Var] is almost always called from the PyObject_NEW[_VAR]
macros.  The 'op' argument is then the result from PyObject_MALLOC,
and that can of course be NULL.  In that case, PyObject_Init[Var]
would raise a SystemError with "NULL object passed to
PyObject_Init[Var]".  But there's nothing the caller of the macro can
do about this.  So PyObject_Init[Var] should call just PyErr_NoMemory.

Will backport.
2002-10-11 20:37:24 +00:00
Martin v. Löwis a5f0907d79 Back out #479898. 2002-10-11 05:37:59 +00:00
Guido van Rossum 049cd6b563 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.

Will backport to 2.2.2.
2002-10-11 00:43:48 +00:00
Guido van Rossum 8052f8921e Undo this part of the previous checkin:
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.
2002-10-09 19:14:30 +00:00
Guido van Rossum b00c07f038 The string formatting code has a test to switch to Unicode when %s
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.
2002-10-09 19:07:53 +00:00
Martin v. Löwis bab9559d12 Include wctype.h. 2002-10-07 18:26:16 +00:00
Martin v. Löwis fed2405cb5 Patch #479898: Use multibyte C library for printing strings if available. 2002-10-07 13:55:50 +00:00
Mark Hammond c2e85bd4e2 Patch 594001: PEP 277 - Unicode file name support for Windows NT. 2002-10-03 05:10:39 +00:00
Marc-André Lemburg 24e53b6d91 Add cast to avoid compiler warning. 2002-09-24 09:32:14 +00:00
Neal Norwitz a0378e1eda Fix part of SF bug # 544248 gcc warning in unicodeobject.c
When --enable-unicode=ucs4, need to cast Py_UNICODE to a char
2002-09-13 13:47:06 +00:00
Guido van Rossum efc1188239 Fix warnings on 64-bit platforms about casts from pointers to ints.
Two of these were real bugs.
2002-09-12 14:43:41 +00:00
Michael W. Hudson 5c1ad84d7f Fix for platforms where int != long. 2002-09-12 09:31:30 +00:00
Guido van Rossum 02fe64708f Insert an overflow check when the sequence repetition count is outside
the range of ints.  The old code would pass random truncated bits to
sq_repeat() on a 64-bit machine.

Backport candidate.
2002-09-11 19:00:52 +00:00
Guido van Rossum d4774fb6ef Untested code for 64-bit platforms. range_length() is declared as int
but returns r->len which is a long.  This doesn't even cause a warning
on 32-bit platforms, but can return bogus values on 64-bit platforms
(and should cause a compiler warning).  Fix this by inserting a range
check when LONG_MAX != INT_MAX, and adding an explicit cast to (int)
when the test passes.  When r->len is out of range, PySequence_Size()
and hence len() will report an error (but an iterator will still
work).
2002-09-11 15:55:48 +00:00
Michael W. Hudson 02ff6a9952 A slight change to SET_LINENO-less tracing.
This makes things a touch more like 2.2.  Read the comments in
Python/ceval.c for more details.
2002-09-11 15:36:32 +00:00
Martin v. Löwis 2412853f8e Fix escaping of non-ASCII characters. 2002-09-09 06:17:05 +00:00
Neal Norwitz bb9c5f5032 PyObject_RichCompareBool() already returns -1, 0, or 1, so return its value 2002-09-05 21:32:55 +00:00
Raymond Hettinger bd9adab138 Micro-optimization for list_contains. Factored double if test
out of the loop.
2002-09-05 20:18:08 +00:00
Raymond Hettinger aae5999b44 Micro-optimization for list_contains. Factored double if test
out of the loop.
2002-09-05 14:23:49 +00:00
Walter Dörwald 5c1ee17742 Change the unicode.translate docstring to document that
Unicode strings (with arbitrary length) are allowed
as entries in the unicode.translate mapping.

Add a test case for multicharacter replacements.

(Multicharacter replacements were enabled by the
PEP 293 patch)
2002-09-04 20:31:32 +00:00
Guido van Rossum efae8862fe In doc strings, use 'k in D' rather than D.has_key(k). 2002-09-04 11:29:45 +00:00
Skip Montanaro d581d7792b replace thread state objects' ticker and checkinterval fields with two
globals, _Py_Ticker and _Py_CheckInterval.  This also implements Jeremy's
shortcut in Py_AddPendingCall that zeroes out _Py_Ticker.  This allows the
test in the main loop to only test a single value.

The gory details are at

    http://python.org/sf/602191
2002-09-03 20:10:45 +00:00
Walter Dörwald 8709a420c4 Check whether a string resize is necessary at the end
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
2002-09-03 13:53:40 +00:00
Walter Dörwald 3aeb632c31 PEP 293 implemention (from SF patch http://www.python.org/sf/432401) 2002-09-02 13:14:32 +00:00
Raymond Hettinger 29a6d449ef Added comparison functions to dict proxies.
Now all non-mutating dict methods are in the proxy also.
Inspired by SF bug #602232,
2002-08-31 15:51:04 +00:00
Neal Norwitz d94c28e467 SF #561244: micro optimizations, builtins cannot be NULL, so use Py_INCREF 2002-08-29 20:25:46 +00:00
Raymond Hettinger 604cd6ae79 complex() was the only numeric constructor that created a new instance
when given its own type as an argument.
2002-08-29 14:22:51 +00:00
Guido van Rossum bf935fde15 string_contains(): speed up by avoiding function calls where
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.
2002-08-24 06:57:49 +00:00
Guido van Rossum 6248f441ea Speedup for PyObject_IsTrue(): check for True and False first.
Because all built-in tests return bools now, this is the most common
path!
2002-08-24 06:31:34 +00:00
Guido van Rossum 81912d4764 Speedup for PyObject_RichCompareBool(): PyObject_RichCompare() almost
always returns a bool, so avoid calling PyObject_IsTrue() in that
case.
2002-08-24 05:33:28 +00:00
Guido van Rossum 2023c9b84a 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.

(I wonder how many more of these are lurking?  The unicode code base
is full of wonders.)

Bugfix candidate; this same bug is present in 2.2.1.
2002-08-23 18:50:21 +00:00
Guido van Rossum 8b1a6d694f Code by Inyeol Lee, submitted to SF bug 595350, to implement
the string/unicode method .replace() with a zero-lengt first argument.
Inyeol contributed tests for this too.
2002-08-23 18:21:28 +00:00
Tim Peters 0d2d87d202 long_format(), long_lshift(): Someone on c.l.py is trying to boost
SHIFT and MASK, and widen digit.  One problem is that code of the form

    digit << small_integer

implicitly assumes that the result fits in an int or unsigned int
(platform-dependent, but "int sized" in any case), since digit is
promoted "just" to int or unsigned via the usual integer promotions.
But if digit is typedef'ed as unsigned int, this loses information.
The cure for this is just to cast digit to twodigits first.
2002-08-20 19:00:22 +00:00