Commit Graph

627 Commits

Author SHA1 Message Date
Guido van Rossum 90daa87569 Marc-Andre Lemburg:
* string_contains now calls PyUnicode_Contains() only when the other
  operand is a Unicode string (not whenever it's not a string).

* New format style '%r' inserts repr(arg) instead of str(arg).

* '...%s...' % u"abc" now coerces to Unicode just like
  string methods. Care is taken not to reevaluate already formatted
  arguments -- only the first Unicode object appearing in the
  argument mapping is looked up twice. Added test cases for
  this to test_unicode.py.
2000-04-10 13:47:21 +00:00
Guido van Rossum b244f6950b Marc-Andre Lemburg:
* TypeErrors during comparing of mixed type arguments including
  a Unicode object are now masked (just like they are for all
  other combinations).
2000-04-10 13:42:33 +00:00
Guido van Rossum 5f8b12f27e Mark Hammond:
In line with a similar checkin to object.c a while ago, this patch
gives a more descriptive error message for an attribute error on a
class instance.  The message now looks like:

AttributeError: 'Descriptor' instance has no attribute 'GetReturnType'
2000-04-10 13:03:19 +00:00
Guido van Rossum 5db862dd0c Skip Montanaro: add string precisions to calls to PyErr_Format
to prevent possible buffer overruns.
2000-04-10 12:46:51 +00:00
Guido van Rossum ba47704943 Conrad Huang points out that "if (0 < ch < 256)", while legal C,
doesn't mean what the Python programmer thought...
2000-04-06 18:18:10 +00:00
Guido van Rossum 34888ed689 Fredrik Lundh: eliminate a MSVC compiler warning. 2000-04-05 21:29:50 +00:00
Guido van Rossum 9e896b37c7 Marc-Andre's third try at this bulk patch seems to work (except that
his copy of test_contains.py seems to be broken -- the lines he
deleted were already absent).  Checkin messages:


New Unicode support for int(), float(), complex() and long().

- new APIs PyInt_FromUnicode() and PyLong_FromUnicode()
- added support for Unicode to PyFloat_FromString()
- new encoding API PyUnicode_EncodeDecimal() which converts
  Unicode to a decimal char* string (used in the above new
  APIs)
- shortcuts for calls like int(<int object>) and float(<float obj>)
- tests for all of the above

Unicode compares and contains checks:
- comparing Unicode and non-string types now works; TypeErrors
  are masked, all other errors such as ValueError during
  Unicode coercion are passed through (note that PyUnicode_Compare
  does not implement the masking -- PyObject_Compare does this)
- contains now works for non-string types too; TypeErrors are
  masked and 0 returned; all other errors are passed through

Better testing support for the standard codecs.

Misc minor enhancements, such as an alias dbcs for the mbcs codec.

Changes:
- PyLong_FromString() now applies the same error checks as
  does PyInt_FromString(): trailing garbage is reported
  as error and not longer silently ignored. The only characters
  which may be trailing the digits are 'L' and 'l' -- these
  are still silently ignored.
- string.ato?() now directly interface to int(), long() and
  float(). The error strings are now a little different, but
  the type still remains the same. These functions are now
  ready to get declared obsolete ;-)
- PyNumber_Int() now also does a check for embedded NULL chars
  in the input string; PyNumber_Long() already did this (and
  still does)

Followed by:

Looks like I've gone a step too far there... (and test_contains.py
seem to have a bug too).

I've changed back to reporting all errors in PyUnicode_Contains()
and added a few more test cases to test_contains.py (plus corrected
the join() NameError).
2000-04-05 20:11:21 +00:00
Guido van Rossum 2ea3e143f0 Some blank lines. 2000-03-31 17:24:09 +00:00
Jeremy Hylton a12c7a7620 Add PyDict_Copy() function to C API for dicts. It returns a new
dictionary that contains the same key/value pairs as p.
2000-03-30 22:27:31 +00:00
Guido van Rossum b7a40ba8d3 MBCS codecs. (Win32 only.) By Mark Hammond. 2000-03-28 02:01:52 +00:00
Guido van Rossum 13ff8eb493 Christian Tismer:
Added "better safe than sorry" patch to the new
trashcan code in object.c, to ensure that tstate
is not touched when it might be undefined.
2000-03-25 18:39:19 +00:00
Barry Warsaw 51ac58039f On 17-Mar-2000, Marc-Andre Lemburg said:
Attached you find an update of the Unicode implementation.

    The patch is against the current CVS version. I would appreciate
    if someone with CVS checkin permissions could check the changes
    in.

    The patch contains all bugs and patches sent this week and also
    fixes a leak in the codecs code and a bug in the free list code
    for Unicode objects (which only shows up when compiling Python
    with Py_DEBUG; thanks to MarkH for spotting this one).
2000-03-20 16:36:48 +00:00
Guido van Rossum ee70ad1e52 Checking in the new, improve file.writelines() code.
This (1) avoids thread unsafety whereby another thread could zap the
list while we were using it, and (2) now supports writing arbitrary
sequences of strings.
2000-03-13 16:27:06 +00:00
Guido van Rossum d724b23420 Christian Tismer's "trashcan" patch:
Added wrapping macros to dictobject.c, listobject.c, tupleobject.c,
frameobject.c, traceback.c that safely prevends core dumps
on stack overflow. Macros and functions in object.c, object.h.
The method is an "elevator destructor" that turns cascading
deletes into tail recursive behavior when some limit is hit.
2000-03-13 16:01:29 +00:00
Guido van Rossum 96a45adf80 Fix typo in replace() detected by Mark Hammond and fixed by Marc-Andre. 2000-03-13 15:56:08 +00:00
Guido van Rossum 403d68b484 Add sq_contains implementation. 2000-03-13 15:55:09 +00:00
Guido van Rossum ef93b87f1c Added Christian Tismer's patch to allow list.append(a,b,c) back --
with a twist: you have to define NO_STRICT_LIST_APPEND manually
to enable multi-arg append().
2000-03-13 15:41:59 +00:00
Guido van Rossum 4aa1e63e4c Marc-AAndre Lemburg: add new unicode files 2000-03-10 22:55:40 +00:00
Guido van Rossum 4c08d554b9 Many changes for Unicode, by Marc-Andre Lemburg. 2000-03-10 22:55:18 +00:00
Guido van Rossum d57fd91488 Unicode implementation by Marc-Andre Lemburg based on original code by
Fredrik Lundh.
2000-03-10 22:53:23 +00:00
Guido van Rossum 603484d759 Unicode character type helpers, written by Marc-Andre Lemburg. 2000-03-10 22:52:46 +00:00
Guido van Rossum 9611e0b462 Patch by Moshe Zadka: remove the string special case in
PySequence_Contains() now that string objects have this code in their
tp_contains.
2000-03-07 15:54:45 +00:00
Guido van Rossum 9284a572bc Patch by Moshe Zadka: move the string special case from abstract.c
here.

[Patch modified by GvR to keep the original exception.]
2000-03-07 15:53:43 +00:00
Barry Warsaw bf32583084 string_join(): Fix memory leaks discovered by Charles Waldman (and a
few other paths through the function that leaked).
2000-03-06 14:52:18 +00:00
Guido van Rossum 43713e5a28 Massive patch by Skip Montanaro to add ":name" to as many
PyArg_ParseTuple() format string arguments as possible.
2000-02-29 13:59:29 +00:00
Guido van Rossum ee28c3a5ea Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
an instance method instance_contains as sq_contains.  It looks for
__contains__ and if not found falls back to previous behaviour.
Done.
2000-02-28 15:03:15 +00:00
Guido van Rossum 46c6b20392 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This
patches PySequence_Contains() to check for a valid sq_contains field.
More to follow.
2000-02-28 15:01:46 +00:00
Guido van Rossum c00a938be8 OKOK, Greg's right, I should've used the :name option in the argument
format strings.
2000-02-24 21:48:29 +00:00
Guido van Rossum 4aa24f9979 Made all list methods use PyArg_ParseTuple(), for more accurate
diagnostics.

*** INCOMPATIBLE CHANGE: This changes append(), remove(), index(), and
*** count() to require exactly one argument -- previously, multiple
*** arguments were silently assumed to be a tuple.
2000-02-24 15:23:03 +00:00
Andrew M. Kuchling 0f223d2418 Allow using long integers as arguments to PyObject_GetItem(), _SetItem(),
and _DelItem().
In sequence multiplication by a long, only call PyErr_Occurred() when the
    value returned is -1.
2000-02-23 22:21:50 +00:00
Fred Drake 52fccfda5b dict_has_key(): Accept only one parameter. PR#210 reported by
Andreas Jung <ajung@sz-sb.de>.
2000-02-23 15:47:16 +00:00
Guido van Rossum fb4574e320 In response to one particular complaint on edu-sig, change some error
messages from "OverflowError: integer pow()" to "OverflowError:
integer exponentiation".  (Not that this takes care of the complaint
in general that the error messages could be greatly improved. :-)
2000-02-15 14:51:46 +00:00
Andrew M. Kuchling 1991ddc3e1 Make multiplying a sequence by a long integer (5L * 'b') legal 2000-02-14 22:22:04 +00:00
Guido van Rossum bffd683f73 The rest of the changes by Trent Mick and Dale Nagata for warning-free
compilation on NT Alpha.  Mostly added casts etc.
2000-01-20 22:32:56 +00:00
Guido van Rossum 687ef6e70b On Linux, one sometimes sees spurious errors after interrupting
previous output.  Call clearerr() to prevent past errors affecting our
ferror() test later, in PyObject_Print().  Suggested by Marc Lemburg.
2000-01-12 16:28:58 +00:00
Guido van Rossum 57072eb79f Implement the other easy thing: repr() of a float now uses %.17g,
while str() uses %.12g as before.
1999-12-23 19:00:28 +00:00
Fred Drake 121ee2722e long_format(): Now takes a third parameter, addL; iff true, a
trailing 'L' is appended to the representation,
                otherwise not.

                All existing call sites are modified to pass true for
                addL.

                Remove incorrect statement about external use of this
                function from elsewhere; it's static!

long_str():     Handler for the tp_str slot in the type object.
                Identical to long_repr(), but passes false as the addL
                parameter of long_format().
1999-12-23 15:41:28 +00:00
Barry Warsaw 153a27ceb2 do_strip(): Fixed cut-and-paste error; this function should check for
zero arguments (found by Marc Lemburg).
1999-12-15 02:22:52 +00:00
Barry Warsaw 226ae6ca12 Mainlining the string_methods branch. See branch revision log
messages for specific changes.
1999-10-12 19:54:53 +00:00
Guido van Rossum 2c7b8fe618 Fix PR#66. Solution: add error checking around l_divmod() calls in
long_pow().
1999-10-11 22:34:41 +00:00
Guido van Rossum 42636dc64d Fix for PR#98 (Adrian Eyre) -- in instancemethod_repr, the funcname
object is DECREFed too early.
1999-10-11 14:03:12 +00:00
Guido van Rossum e13ff2e2d6 Patch by Tim Peters fixing PR#88:
Integer division can crash under Windows.
1999-09-27 17:12:47 +00:00
Guido van Rossum 1a23c2484e Patch by Tim Peters fixing PR#89:
long(+/- infinity) returns nonsense.
1999-09-27 17:11:52 +00:00
Guido van Rossum ff7e83d606 Patch by Mark Hammond to avoid certain header files on Windows/CE. 1999-08-27 20:39:37 +00:00
Fred Drake 4574f23115 PyBuffer_New(): Raise ValueError if size is negative (the other
constructors didn't miss this).

		 Raise MemoryError if malloc() fails, instead of just
		 returning NULL.
1999-08-04 13:08:19 +00:00
Guido van Rossum 0eb55ac912 Mark Favas was quick to note that the last checkin divides by zero
when n == 0...  So divide by a->ob_size instead which was already
tested for 0.
1999-07-13 05:41:12 +00:00
Guido van Rossum 5bc51f2f27 Appropriate overflow checks so that things like sys.maxint*(1,) can't
dump core.
1999-07-12 23:06:58 +00:00
Guido van Rossum fa71701d46 When deallocating a list, DECREF the items from the end back to the start. 1999-06-09 15:19:34 +00:00
Guido van Rossum 98c9eba945 Fix bug discovered by John W. Shipman -- when the width of a format
specifier came from an int expression instead of a constant in the
format, a negative width was truncated to zero instead of taken to
mean the same as that negative constant plugged into the format.  E.g.
"(%*s)" % (-5, "foo") yielded "(foo)" while "(%-5s)" yields "(foo  )".
Now both yield the latter -- like sprintf() in C.
1999-06-07 15:12:32 +00:00
Guido van Rossum 9263e78ff2 Tim Peters writes:
1. Fixes float divmod so that the quotient it returns is always an integral
value.

2. Fixes float % and float divmod so that the remainder always gets the
right sign (the current code uses a "are the signs different?" test that
doesn't work half the time <wink> when the product of the divisor and the
remainder underflows to 0).
1999-05-06 14:26:34 +00:00
Guido van Rossum 9bcd1d7931 Improve text of some error messages, as suggested by Sean Reifschneider. 1999-04-19 17:44:39 +00:00
Guido van Rossum ff1ccbfc21 casts for picky compilers. 1999-04-10 15:48:23 +00:00
Guido van Rossum 2bc137909d Vladimir Marangozov contributed updated comments. 1999-03-24 19:06:42 +00:00
Guido van Rossum cd037e7bed Folded long lines. 1999-03-24 19:05:31 +00:00
Guido van Rossum d7b5fb858c Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if
a block cannot be freed, add its free items back to the free list.
This is necessary to avoid leaking when Python is reinitialized later.
1999-03-19 20:59:40 +00:00
Guido van Rossum 51288bce48 Fix a problem with Vladimir's PyInt_Fini code: clear the free list; if
a block cannot be freed, add its free items back to the free list, and
add its valid ints back to the small_ints array if they are in range.
This is necessary to avoid leaking when Python is reinitialized later.
1999-03-19 20:30:39 +00:00
Guido van Rossum 49ded3ec00 Added check for negative offset for PyBuffer_FromObject and check for
negative size for PyBuffer_FromMemory.  Greg Stein.
1999-03-19 19:04:25 +00:00
Guido van Rossum 3fce883922 Vladimir has restructured his code somewhat so that the blocks are now
represented by an explicit structure.  (There are still too many casts
in the code, but that may be unavoidable.)

Also added code so that with -vv it is very chatty about what it does.
1999-03-12 19:43:17 +00:00
Guido van Rossum f61bbc8182 OK, try again. Vladimir gave me a fix for the alignment bus error,
so here's his patch again.  This time it works (at least on Solaris,
Linux and Irix).
1999-03-12 00:12:21 +00:00
Guido van Rossum a060fb2598 Alas, Vladimir's patch caused a bus error (probably double
alignment?), and I didn't test it.  Withdrawing it for now.
1999-03-11 01:47:00 +00:00
Guido van Rossum 881928f7ab Patch by Vladimir Marangoz to allow freeing of the allocated blocks of
floats on finalization.
1999-03-10 22:55:47 +00:00
Guido van Rossum da084edd38 Patch by Vladimir Marangoz to allow freeing of the allocated blocks of
integers on finalization.
1999-03-10 22:55:24 +00:00
Guido van Rossum 98cc19fac6 Patch by Chris Petrilli to display the origin of a module in its
repr() -- either "(builtin)" or "from '<filename>'".
1999-02-15 14:47:16 +00:00
Guido van Rossum 00d225ea6d Correct typo (Py_MethodDef doesn't exist). Reported by Uwe Zessin. 1999-01-29 14:39:12 +00:00
Barry Warsaw b5cebfe164 PyLong_FromString(): Nailed a small memory leak. In the str==start
test, we forgot that z is still pointing to a real live object.
DECREF() it before returning.
1999-01-27 17:48:27 +00:00
Guido van Rossum 3bbef60990 Ai! complex_nonzero() has && which should be ||, else decidedly
non-zero things like 5j and complex(1,0) are considered to be
zero/false.  Tim Peters.
1999-01-25 19:42:19 +00:00
Guido van Rossum 3aa23fdd47 Jim Ahlstrom patch: cutoff should be a long for machines with 16-bit
ints.  (In theory, other variables should be widened to long as well,
but this won't ever be needed, since the len of a list is still an
int.)
1999-01-14 19:01:53 +00:00
Guido van Rossum 3c25904a98 Jim Ahlstrom patch: BIGCHUNK is too large for 16-bit int. 1999-01-14 19:00:14 +00:00
Guido van Rossum 031d0e5feb Patch by Charles Waldman -- remove unneeded and even harmful test for
float to the negative power (which is already and better done in
floatobject.c.)
1999-01-10 16:56:58 +00:00
Guido van Rossum 5dadf7e976 Use 'xrange', not 'range', in error messages. Reported by Nathan Sullivan. 1999-01-09 21:40:35 +00:00
Guido van Rossum 41498435ba Need to include <sys/types.h> for off_t. 1999-01-07 22:09:51 +00:00
Guido van Rossum 3c9fe0cce3 Changes for long file support by Steve Clift.
(This also redoes my previous patch, but better.)
1999-01-06 18:51:17 +00:00
Guido van Rossum cdd9ae00ba Changes for long file support by Steve Clift.
(Really: moved a bunch of defs to longobject.h.)
1999-01-06 18:50:37 +00:00
Guido van Rossum 88303194a5 Fix two places (seek and truncate) where a cascade of PyArg_Parse
calls was used instead of a single PyArg_ParseTuple call with an
optional argument.
1999-01-04 17:22:18 +00:00
Guido van Rossum cada2938f7 As noted by Per Cederqvist, new_buffersize() sometimes returns the
buffer increment, and sometimes the new buffer size.  Make it do what
its name says, and fix the one place where this matters to the caller.

Also add a comment explaining why we call lseek() and then ftell().
1998-12-11 20:44:56 +00:00
Guido van Rossum 68055ce6fe When tracing references, reset the type and size of tuples allocated
from the fast free list -- the type (at least) is reset by
_Py_Dealloc().
1998-12-11 14:56:38 +00:00
Guido van Rossum f5046d1aea Remove prototype for PyOS_strtol -- Chris Herborth. 1998-12-10 16:54:48 +00:00
Guido van Rossum 13fdf5e917 When comparing bound methods, use identity test on the objects,
not equality test.
1998-12-04 18:52:55 +00:00
Guido van Rossum f05fc716d1 Remove dead code discovered by Vladimir Marangozov. 1998-11-16 22:46:30 +00:00
Guido van Rossum 017f7780a8 Make tuples less hungry -- an extra item was allocated but never used.
Tip by Vladimir Marangozov.
1998-11-16 18:56:03 +00:00
Guido van Rossum f61618c98e A Py_DECREF(f) is missing in PyFrame_New for the error case when
the `builtins' initialization fails.  Vladimir Marangozov.
1998-10-19 14:20:20 +00:00
Guido van Rossum 2f3667a7b9 Replace fprintf(stderr, ...) with PySys_WriteStderr(...). 1998-10-12 18:23:55 +00:00
Barry Warsaw dedf6d6804 listextend(): New method which implements L.extend(L2). 1998-10-09 16:37:25 +00:00
Guido van Rossum 3886026bed Remove unreachable code. (Sjoerd) 1998-10-09 13:27:19 +00:00
Guido van Rossum 1db7070217 Greg Stein: Implement the new bf_getcharbuffer function, indicating
that (as far as the data type is concerned!) this is character data.
1998-10-08 02:18:52 +00:00
Guido van Rossum 7148ca9d14 Make gcc -Wall happy. 1998-10-07 16:22:12 +00:00
Guido van Rossum 06c18088d6 Add Greg Stein's buffer object API. 1998-10-07 14:41:13 +00:00
Guido van Rossum 2e19bd7cc7 Add Greg Stein's buffer object API. 1998-10-07 14:36:10 +00:00
Guido van Rossum 2ccaf6f2f9 Remove a redundant check from list_slice() and list_ass_slice().
Noted by Greg Stein.
1998-10-07 13:24:13 +00:00
Guido van Rossum c1c7b1a699 Slight rearrangement of code in lookdict() by Vladimir Marangozov, to
make a common case slightly faster.
1998-10-06 16:01:14 +00:00
Guido van Rossum 9d904b9389 Believe it or not, Solaris 2.6 strtod() can move the end pointer
*beyond* the null byte at the end of the input string, when the input
is inf(inity).  Discovered by Greg Ward.
1998-10-01 20:35:46 +00:00
Guido van Rossum 07d780089d Typo reported by Greg Stein: "modifiable" is the correct spelling. 1998-10-01 15:59:48 +00:00
Guido van Rossum 67906af811 In PyFrame_New(), don't set extras to something derived from code
before code has been checked for validity.  Discovered by Vladimir
Marangozov.
1998-09-25 14:11:46 +00:00
Guido van Rossum 78694d970f Patches from Greg Stein to support 'P' format in struct module's
native format, as void* (translated to Python int or long).
Also adds PyLong_FromVoidPtr and PyLong_AsVoidPtr to longobject.c.
1998-09-18 14:14:13 +00:00
Guido van Rossum 065ce5a4b7 Undo victim of careless global substitute ("long long_hash" was
changed to "LONG_LONG_hash" in the list of forward decls).  Discovered
by Jason Harper.
1998-09-13 15:37:20 +00:00
Guido van Rossum 3293b07df5 Patch by Mark Hammond to support 64-bit ints on MS platforms.
The MS compiler doesn't call it 'long long', it uses __int64,
so a new #define, LONG_LONG, has been added and all occurrences
of 'long long' are replaced with it.
1998-08-25 16:07:15 +00:00
Guido van Rossum 21308243ca Better error messages when a sequence is indexed with a non-integer.
Previously, this said "unsubscriptable object"; in 1.5.1, the reverse
problem existed, where None[''] would complain about a non-integer
index.  This fix does the right thing in all cases (for get, set and
del item).
1998-08-13 16:44:44 +00:00
Guido van Rossum bd3a527f93 Two patches by Jason Harper:
- Faster conversion to string for binary bases: linear instead of quadratic!

- Allocate smaller result for certain masking ops, e.g. (1L<<30000) & 1.
1998-08-11 15:04:47 +00:00
Guido van Rossum 1a8791e0b8 Changes for BeOS, QNX and long long, by Chris Herborth. 1998-08-04 22:46:29 +00:00
Guido van Rossum ac6a37ae55 Fix a potential problem in PyLong_FromString(): could fall through the
for loop with z==NULL but continue to reference z later.
1998-08-04 15:04:06 +00:00