Commit Graph

1714 Commits

Author SHA1 Message Date
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
Guido van Rossum 76afbd9aa4 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 was already fixed in 2.3, but this adds some more test
cases.
2002-08-20 17:29:29 +00:00
Tim Peters 75585d4ec1 getinstclassname(): Squash new compiler wng in assert (comparison of
signed vs unsigned).
2002-08-20 14:31:35 +00:00
Guido van Rossum 45ec02aed1 SF patch 576101, by Oren Tirosh: alternative implementation of
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.
2002-08-19 21:43:18 +00:00
Guido van Rossum e3a8e7ed1d Call me anal, but there was a particular phrase that was speading to
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.
2002-08-19 19:26:42 +00:00
Guido van Rossum 056fbf422d Another modest speedup in PyObject_GenericGetAttr(): inline the call
to _PyType_Lookup().
2002-08-19 19:22:50 +00:00
Guido van Rossum 492b46f29e Make PyDescr_IsData() a macro. It's too simple to be a function.
Should save 4% on slot lookups.
2002-08-19 18:45:37 +00:00
Michael W. Hudson 69734a5272 Check in my ultra-shortlived patch #597220.
Move some debugging checks inside Py_DEBUG.

They were causing cache misses according to cachegrind.
2002-08-19 16:54:08 +00:00
Guido van Rossum c66ff4441e Inline call to _PyObject_GetDictPtr() in PyObject_GenericGetAttr().
This causes a modest speedup.
2002-08-19 16:50:48 +00:00
Guido van Rossum c588e9041a Simple but important optimization for descr_check(): instead of the
expensive and overly general PyObject_IsInstance(), call
PyObject_TypeCheck() which is a macro that often avoids a call, and if
it does make a call, calls the much more efficient PyType_IsSubtype().
This saved 6% on a benchmark for slot lookups.
2002-08-19 16:02:33 +00:00
Neal Norwitz b898d9fc9a Get this to compile again if Py_USING_UNICODE is not defined.
com_error() is static in Python/compile.c.
2002-08-16 23:20:39 +00:00
Guido van Rossum 84b2bed435 Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
-- replace then with slightly faster PyObject_Call(o,a,NULL).  (The
difference is that the latter requires a to be a tuple; the former
allows other values and wraps them in a tuple if necessary; it
involves two more levels of C function calls to accomplish all that.)
2002-08-16 17:01:09 +00:00
Guido van Rossum 8e829200b1 Fix SF bug 595838 -- buffer in type_new() should not be static. Moved
to inner scope, too.
2002-08-16 03:47:49 +00:00
Tim Peters e417de0e56 Illustrating by example one good reason not to trust a proof <wink>. 2002-08-15 20:10:45 +00:00
Tim Peters ab86c2be24 k_mul() comments: In honor of Dijkstra, made the proof that "t3 fits"
rigorous instead of hoping for testing not to turn up counterexamples.
Call me heretical, but despite that I'm wholly confident in the proof,
and have done it two different ways now, I still put more faith in
testing ...
2002-08-15 20:06:00 +00:00
Tim Peters 9973d74b2d long_mul(): Simplified exit code. In particular, k_mul() returns a
normalized result, so no point to normalizing it again.  The number
of test+branches was also excessive.
2002-08-15 19:41:06 +00:00
Michael W. Hudson dd32a91cc0 This is my patch
[ 587993 ] SET_LINENO killer

Remove SET_LINENO.  Tracing is now supported by inspecting co_lnotab.

Many sundry changes to document and adapt to this change.
2002-08-15 14:59:02 +00:00
Jeremy Hylton 8b73542cf5 Reflow long lines. 2002-08-14 21:01:41 +00:00
Guido van Rossum 54df53a352 More changes of DeprecationWarning to FutureWarning. 2002-08-14 18:38:27 +00:00
Guido van Rossum 323a9cfc83 PyType_Ready(): initialize the base class a bit earlier, so that if we
copy the metatype from the base, the base actually has one!
2002-08-14 17:26:30 +00:00
Tim Peters 48d52c0fcc k_mul() comments: Simplified the simplified explanation of why ah*bh and
al*bl "always fit":  it's actually trivial given what came before.
2002-08-14 17:07:32 +00:00