Commit Graph

771 Commits

Author SHA1 Message Date
Tim Peters c2e7da9859 Somebody started playing with const, so of course the outcome
was cascades of warnings about mismatching const decls.  Overall,
I think const creates lots of headaches and solves almost
nothing.  Added enough consts to shut up the warnings, but
this did require casting away const in one spot too (another
usual outcome of starting down this path):  the function
mymemreplace can't return const char*, but sometimes wants to
return its first argument as-is, which latter must be declared
const char* in order to avoid const warnings at mymemreplace's
call sites.  So, in the case the function wants to return the
first arg, that arg's declared constness must be subverted.
2000-07-09 08:02:21 +00:00
Fred Drake ba09633e1e ANSI-fication of the sources. 2000-07-09 07:04:36 +00:00
Fred Drake 45cfbcccc2 ANSI-fication of the sources. 2000-07-09 06:21:27 +00:00
Fred Drake ee238b977f ANSI-fication of the sources. 2000-07-09 06:03:25 +00:00
Fred Drake 1b190b4636 ANSI-fication of the sources. 2000-07-09 05:40:56 +00:00
Fred Drake 1f0968c5f8 Remove legacy use of __SC__; no longer needed now that ANSI source is
the standard for Python implementation.
2000-07-09 05:31:24 +00:00
Fred Drake fd99de6470 ANSI-fication of the sources. 2000-07-09 05:02:18 +00:00
Fred Drake 4288c80599 ANSI-fication of the sources. 2000-07-09 04:36:04 +00:00
Fred Drake 4201b9e420 type_error(): Added "const" to signature to eliminate warning with -Wall. 2000-07-09 04:34:13 +00:00
Fred Drake 3be9a8a5ed ANSI-fication of the source.
Make the indentation and brace placement internally consistent.
2000-07-09 04:14:42 +00:00
Fred Drake 799124718d ANSI-fication of the sources. 2000-07-09 04:06:11 +00:00
Tim Peters dbd9ba6a6c Nuke all remaining occurrences of Py_PROTO and Py_FPROTO. 2000-07-09 03:09:57 +00:00
Fredrik Lundh 2a1e060619 - changed __repr__ to use "unicode escape" encoding for unicode
strings, instead of the default encoding.
  (see "minidom" thread for discussion, and also patch #100706)
2000-07-08 17:43:32 +00:00
Skip Montanaro 4cbc9f7650 delete unused local variable from _PyTrash_deposit_object 2000-07-08 12:06:36 +00:00
Skip Montanaro 4ca150bdb2 _Py_RefTotal should only be declared here when Py_TRACE_REFS are #define'd 2000-07-08 12:04:57 +00:00
Tim Peters 7d3a511a40 Cray J90 fixes for long ints.
This was a convenient excuse to create the pyport.h file recently
discussed!
Please use new Py_ARITHMETIC_RIGHT_SHIFT when right-shifting a
signed int and you *need* sign-extension.  This is #define'd in
pyport.h, keying off new config symbol SIGNED_RIGHT_SHIFT_ZERO_FILLS.
If you're running on a platform that needs that symbol #define'd,
the std tests never would have worked for you (in particular,
at least test_long would have failed).
The autoconfig stuff got added to Python after my Unix days, so
I don't know how that works.  Would someone please look into doing
& testing an auto-config of the SIGNED_RIGHT_SHIFT_ZERO_FILLS
symbol?  It needs to be defined if & only if, e.g., (-1) >> 3 is
not -1.
2000-07-08 04:17:21 +00:00
Tim Peters 43f04a36cf The tail end of x_sub implicitly assumed that an unsigned short
contains 16 bits.  Not true on Cray J90.
2000-07-08 02:26:47 +00:00
Tim Peters 9ace6bc7ef Got RID of redundant coercions in longobject.c (as spotted by Greg
Stein -- thanks!).  Incidentally removed all the Py_PROTO macros
from object.h, as they prevented my editor from magically finding
the definitions of the "coercion", "cmpfunc" and "reprfunc"
typedefs that were being redundantly applied in longobject.c.
2000-07-08 00:32:04 +00:00
Marc-André Lemburg e12896ec98 New surrogate support in the UTF-8 codec. By Bill Tutt. 2000-07-07 17:51:08 +00:00
Tim Peters 9f688bf9d2 Some cleanup of longs in prepartion for Cray J90 fixes: got
rid of Py_PROTO, switched to ANSI function decls, and did some
minor fiddling.
2000-07-07 15:53:28 +00:00
Marc-André Lemburg 5a5c81a0e9 Added new API PyUnicode_FromEncodedObject() which supports decoding
objects including instance objects.

The old API PyUnicode_FromObject() is still available as shortcut.
2000-07-07 13:46:42 +00:00
Marc-André Lemburg 063e0cb4c6 Fix to bug #393 (UTF16 codec didn't like empty strings) and
corrected some usage of 'unsigned long' where Py_UNICODE
should have been used.
2000-07-07 11:27:45 +00:00
Sjoerd Mullender 2629bd5a33 Two more places where long should be used instead of int. Especially
true after revision 2.36 was checked in...
2000-07-07 09:47:24 +00:00
Marc-André Lemburg 449c325303 Fixed some code that used 'short' to use 'long' instead. 2000-07-06 20:13:23 +00:00
Marc-André Lemburg 85cc4d8940 Fixed a couple of places where 'int' was used where 'long'
should have been used.
2000-07-06 19:43:31 +00:00
Jack Jansen 56cdce3070 Conditionally (currently on ifdef macintosh) break the large switch up
into 1000-case smaller ones.
2000-07-06 13:57:38 +00:00
Marc-André Lemburg 63f3d17418 Added new codec APIs and a new interface method .encode() which
works just like the Unicode one. The C APIs match the ones in the Unicode
implementation, but were extended to be able to reuse the existing
Unicode codecs for string purposes too.

Conversions from string to Unicode and back are done using the
default encoding.
2000-07-06 11:29:01 +00:00
Marc-André Lemburg 1f46860a29 Fix to bug #389:
Full_Name: Bastian Kleineidam
Version: 2.0b1 CVS 5.7.2000
OS: Debian Linux 2.2
Submission from: earth.cs.uni-sb.de (134.96.252.92)
2000-07-05 15:32:40 +00:00
Marc-André Lemburg a7acf425f6 Added new .isalpha() and .isalnum() methods which provide interfaces
to the new alphabetic lookup APIs in unicodectype.c.
2000-07-05 09:49:44 +00:00
Marc-André Lemburg f3938f55c7 Added new lookup API which matches all alphabetic Unicode characters,
i.e the ones with category 'Ll','Lu','Lt','Lo','Lm'.
2000-07-05 09:48:59 +00:00
Marc-André Lemburg 4027f8f4b3 Added new .isalpha() and .isalnum() methods to match the same
ones on the Unicode objects. Note that the string versions use
the (locale aware) C lib APIs isalpha() and isalnum().
2000-07-05 09:47:46 +00:00
Tim Peters 1f5871e834 Removed Py_PROTO and switched to ANSI C declarations in the dict
implementation.  This was really to test whether my new CVS+SSH
setup is more usable than the old one -- and turns out it is (for
whatever reason, it was impossible to do a commit before that
involved more than one directory).
2000-07-04 17:44:48 +00:00
Marc-André Lemburg 1e7205a62a Bill Tutt:
Make unicode_compare a true UTF-16 compare function (includes
support for surrogates).
2000-07-04 09:51:07 +00:00
Marc-André Lemburg 891bc65486 If auto-conversion fails, the Unicode codecs will return NULL.
This is now checked and the error passed on to the caller.
2000-07-03 09:57:53 +00:00
Fredrik Lundh efecc7d05b changed repr and str to always convert unicode strings
to 8-bit strings, using the default encoding.
2000-07-01 14:31:09 +00:00
Guido van Rossum 4cc6ac7b87 Neil Schemenauer: small fixes for GC 2000-07-01 01:00:38 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Guido van Rossum 9a15c211cf Fix an error on AIX by using a proper cast. 2000-06-30 22:46:04 +00:00
Fred Drake a44d353e2b Trent Mick <trentm@activestate.com>:
The common technique for printing out a pointer has been to cast to a long
and use the "%lx" printf modifier. This is incorrect on Win64 where casting
to a long truncates the pointer. The "%p" formatter should be used instead.

The problem as stated by Tim:
> Unfortunately, the C committee refused to define what %p conversion "looks
> like" -- they explicitly allowed it to be implementation-defined. Older
> versions of Microsoft C even stuck a colon in the middle of the address (in
> the days of segment+offset addressing)!

The result is that the hex value of a pointer will maybe/maybe not have a 0x
prepended to it.


Notes on the patch:

There are two main classes of changes:
- in the various repr() functions that print out pointers
- debugging printf's in the various thread_*.h files (these are why the
patch is large)


Closes SourceForge patch #100505.
2000-06-30 15:01:00 +00:00
Marc-André Lemburg d49e5b4667 Marc-Andre Lemburg <mal@lemburg.com>:
A previous patch by Jack Jansen was accidently reverted.
2000-06-30 14:58:20 +00:00
Marc-André Lemburg f28dd83b86 Marc-Andre Lemburg <mal@lemburg.com>:
New buffer overflow checks for formatting strings.

By Trent Mick.
2000-06-30 10:29:57 +00:00
Jeremy Hylton c5007aa5c3 final patches from Neil Schemenauer for garbage collection 2000-06-30 05:02:53 +00:00
Fred Drake 13634cf7a4 This patch addresses two main issues: (1) There exist some non-fatal
errors in some of the hash algorithms. For exmaple, in float_hash and
complex_hash a certain part of the value is not included in the hash
calculation. See Tim's, Guido's, and my discussion of this on
python-dev in May under the title "fix float_hash and complex_hash for
64-bit *nix"

(2) The hash algorithms that use pointers (e.g. func_hash, code_hash)
are universally not correct on Win64 (they assume that sizeof(long) ==
sizeof(void*))

As well, this patch significantly cleans up the hash code. It adds the
two function _Py_HashDouble and _PyHash_VoidPtr that the various
hashing routine are changed to use.

These help maintain the hash function invariant: (a==b) =>
(hash(a)==hash(b))) I have added Lib/test/test_hash.py and
Lib/test/output/test_hash to test this for some cases.
2000-06-29 19:17:04 +00:00
Guido van Rossum 4f4b799b33 Jack Jansen: Use include "" instead of <>; and staticforward declarations 2000-06-29 00:06:39 +00:00
Guido van Rossum d7823f2645 Vladimir Marangozov:
Avoid calling the dealloc function, previously triggered with
DECREF(inst).  This caused a segfault in PyDict_GetItem, called with a
NULL dict, whenever inst->in_dict fails under low-memory conditions.
2000-06-28 23:46:07 +00:00
Guido van Rossum ad89bbcd88 Trent Mick: change a few casts for Win64 compatibility. 2000-06-28 21:57:18 +00:00
Guido van Rossum eceebb87d9 Jack Jansen: Moved includes to the top, removed think C support 2000-06-28 20:57:07 +00:00
Marc-André Lemburg 0f774e3987 Marc-Andre Lemburg <mal@lemburg.com>:
Patch to the standard unicode-escape codec which dynamically
loads the Unicode name to ordinal mapping from the module
ucnhash.

By Bill Tutt.
2000-06-28 16:43:35 +00:00
Marc-André Lemburg 7c014684c2 Marc-Andre Lemburg <mal@lemburg.com>:
Better error message for "1 in unicodestring". Submitted
by Andrew Kuchling.
2000-06-28 08:11:47 +00:00
Jeremy Hylton d08b4c4524 part 2 of Neil Schemenauer's GC patches:
This patch modifies the type structures of objects that
participate in GC.  The object's tp_basicsize is increased when
GC is enabled.  GC information is prefixed to the object to
maintain binary compatibility.  GC objects also define the
tp_flag Py_TPFLAGS_GC.
2000-06-23 19:37:02 +00:00
Jeremy Hylton d22162bac7 traverse functions should return 0 on success 2000-06-23 17:14:56 +00:00
Jeremy Hylton 99a8f90874 raise TypeError when PyObject_Get/SetAttr called with non-string name 2000-06-23 14:36:32 +00:00
Jeremy Hylton 8caad49c30 Round 1 of Neil Schemenauer's GC patches:
This patch adds the type methods traverse and clear necessary for GC
implementation.
2000-06-23 14:18:11 +00:00
Fred Drake 396f6e0d6a Fredrik Lundh <effbot@telia.com>:
Simplify find code; this is a performance improvement on at least some
platforms.
2000-06-20 15:47:54 +00:00
Marc-André Lemburg 49ef6dc1f4 Marc-Andre Lemburg <mal@lemburg.com>:
Fixed a bug in PyUnicode_Count() which would have caused a
core dump in case of substring coercion failure.

Synchronized .count() with the string method of the same name
to return len(s)+1 for s.count('').
2000-06-18 22:25:22 +00:00
Andrew M. Kuchling 74042d6e5d Patch from /F:
this patch introduces PySequence_Fast and PySequence_Fast_GET_ITEM,
and modifies the list.extend method to accept any kind of sequence.
2000-06-18 18:43:14 +00:00
Marc-André Lemburg bea47e768d Vladimir MARANGOZOV <Vladimir.Marangozov@inrialpes.fr>:
This patch fixes an optimisation mystery in _PyUnicodeNew causing segfaults
on AIX when the interpreter is compiled with -O.
2000-06-17 20:31:17 +00:00
Marc-André Lemburg 29dc381ce0 Michael Hudson <mwh21@cam.ac.uk>:
The error message refers to "append", yet the operation in
question is "concat".
2000-06-16 17:05:57 +00:00
Fred Drake 56780257c6 Thomas Wouters <thomas@xs4all.net>:
The following patch adds "sq_contains" support to rangeobject, and enables
the already-written support for sq_contains in listobject and tupleobject.

The rangeobject "contains" code should be a bit more efficient than the
current default "in" implementation ;-) It might not get used much, but it's
not that much to add.

listobject.c and tupleobject.c already had code for sq_contains, and the
proper struct member was set, but the PyType structure was not extended to
include tp_flags, so the object-specific code was not getting called (Go
ahead, test it ;-). I also did this for the immutable_list_type in
listobject.c, eventhough it is probably never used. Symmetry and all that.
2000-06-15 14:50:20 +00:00
Marc-André Lemburg 60bc809d9a Marc-Andre Lemburg <mal@lemburg.com>:
Added code so that .isXXX() testing returns 0 for emtpy strings.
2000-06-14 09:18:32 +00:00
Marc-André Lemburg 07ceb67d9c Marc-Andre Lemburg <mal@lemburg.com>:
Fixed a typo and removed a debug printf(). Thanks to Finn Bock
for finding these.
2000-06-10 09:32:51 +00:00
Jeremy Hylton a251ea0680 the PyDict_SetItem does not borrow a reference, so we need to decref
reported by Mark Hammon
2000-06-09 16:20:39 +00:00
Andrew M. Kuchling cb95a1470a Patch from Michael Hudson: improve unclear error message 2000-06-09 14:04:53 +00:00
Marc-André Lemburg d4ab4a5905 Marc-Andre Lemburg <mal@lemburg.com>:
Fixed %c formatting to check for one character arguments. Thanks
to Finn Bock for finding this bug.

Added a fix for bug PR#348 which originated from not resetting
the globals correctly in _PyUnicode_Fini().
2000-06-08 17:54:00 +00:00
Marc-André Lemburg 90e8147118 Marc-Andre Lemburg <mal@lemburg.com>:
Change the default encoding to 'ascii' (it was previously
defined as UTF-8).

Note: The implementation still uses UTF-8 to implement
the buffer protocol, so C APIs will still see UTF-8. This
is on purpose: rather than fixing the Unicode implementation,
the C APIs should be made Unicode aware.
2000-06-07 09:13:21 +00:00
Fred Drake 4c7fdfc35b Trent Mick <trentm@ActiveState.com>:
This patch correct bounds checking in PyLong_FromLongLong. Currently, it does
not check properly for negative values when checking to see if the incoming
value fits in a long or unsigned long. This results in possible silent
truncation of the value for very large negative values.
2000-06-01 18:37:36 +00:00
Fred Drake 914a2edb24 Improve TypeError exception message for list catenation. 2000-06-01 14:31:03 +00:00
Fred Drake b6a9ada757 Michael Hudson <mwh21@cam.ac.uk>:
Removed PyErr_BadArgument() calls and replaced them with more useful
error messages.
2000-06-01 03:12:13 +00:00
Fred Drake 785d14f965 Minimal change so I can add the rest of MAL's checkin message:
M.-A. Lemburg <mal@lemburg.com>:
Fixed a core dump in PyUnicode_Format().
2000-05-09 19:54:43 +00:00
Fred Drake e4315f58d2 M.-A. Lemburg <mal@lemburg.com>:
Added support for user settable default encodings. The
current implementation uses a per-process global which
defines the value of the encoding parameter in case it
is set to NULL (meaning: use the default encoding).
2000-05-09 19:53:39 +00:00
Guido van Rossum c18a6f466a Replace PyErr_BadArgument() error in PyInt_AsLong() with "an integer
is required" (we can't say more because we don't know in which context
it is called).
2000-05-09 14:27:48 +00:00
Guido van Rossum b8872e61c6 Trent Mick:
Fix the string methods that implement slice-like semantics with
optional args (count, find, endswith, etc.) to properly handle
indeces outside [INT_MIN, INT_MAX]. Previously the "i" formatter
for PyArg_ParseTuple was used to get the indices. These could overflow.

This patch changes the string methods to use the "O&" formatter with
the slice_index() function from ceval.c which is used to do the same
job for Python code slices (e.g. 'abcabcabc'[0:1000000000L]).
2000-05-09 14:14:27 +00:00
Guido van Rossum c682140de7 Trent Mick:
Fix the string methods that implement slice-like semantics with
optional args (count, find, endswith, etc.) to properly handle
indeces outside [INT_MIN, INT_MAX]. Previously the "i" formatter
for PyArg_ParseTuple was used to get the indices. These could overflow.

This patch changes the string methods to use the "O&" formatter with
the slice_index() function from ceval.c which is used to do the same
job for Python code slices (e.g. 'abcabcabc'[0:1000000000L]). slice_index()
is renamed _PyEval_SliceIndex() and is now exported. As well, the return
values for success/fail were changed to make slice_index directly
usable as required by the "O&" formatter.

[GvR: shouldn't a similar patch be applied to unicodeobject.c?]
2000-05-08 14:08:05 +00:00
Guido van Rossum b8f820c5a9 The methods islower(), isupper(), isspace(), isdigit() and istitle()
gave bogus results for chars in the range 128-255, because their
implementation was using signed characters.  Fixed this by using
unsigned character pointers (as opposed to using Py_CHARMASK()).
2000-05-05 20:44:24 +00:00
Guido van Rossum 03e29f1ae9 Mark Hammond should get his act into gear (his words :-). Zero length
strings _are_ valid!
2000-05-04 15:52:20 +00:00
Guido van Rossum 42c29aaeb5 Fix warning detected by VC++ on assignment of Py_UNICODE to char. 2000-05-03 23:58:29 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Guido van Rossum 4e751c3d12 Mark Hammond withdraws his fix -- the size includes the trailing 0 so
a size of 0 *is* illegal.
2000-05-03 12:27:22 +00:00
Guido van Rossum a6edfd9737 Mark Hammond:
Fixes the MBCS codec to work correctly with zero length strings.
2000-05-03 11:03:24 +00:00
Barry Warsaw ee98e4e75d Ignore a bunch of generated files. 2000-05-02 18:34:30 +00:00
Guido van Rossum 0e4f657a50 Marc-Andre Lemburg:
Fixed \OOO interpretation for Unicode objects. \777 now
correctly produces the Unicode character with ordinal 511.
2000-05-01 21:27:20 +00:00
Jeremy Hylton 37b1a26c89 add list_contains and tuplecontains: efficient implementations of tp_contains 2000-04-27 21:41:03 +00:00
Guido van Rossum ec5b776998 Marc-Andre Lemburg:
Doc strings can now be given as Unicode strings.
2000-04-27 20:14:13 +00:00
Guido van Rossum 3c1bb8043f Marc-Andre Lemburg:
Fixed a reference leak in the allocator.

Renamed utf8_string to _PyUnicode_AsUTF8String() and made
it external for use by other parts of the interpreter.
2000-04-27 20:13:50 +00:00
Jeremy Hylton 9e392e2412 potentially useless optimization
The previous checkin (2.84) added a PyErr_Format call that made the
cost of raising an AttributeError much more expensive.  In general
this doesn't matter, except that checks for __init__ and
__del__ methods, where exceptions are caught and cleared in C, also
got much more expensive.

The fix is to split instance_getattr1 into two calls:

instance_getattr2 checks the instance and the class for the attribute
and returns it or returns NULL on error.  It does not raise an
exception.

instance_getattr1 does rexec checks, then calls instance_getattr2.  It
raises an exception if instance_getattr2 returns NULL.

PyInstance_New and instance_dealloc now call instance_getattr2
directly.
2000-04-26 20:39:20 +00:00
Guido van Rossum e92e610a9e Christian Tismer -- total rewrite on trashcan code.
Improvements:
- does no longer need any extra memory
- has no relationship to tstate
- works in debug mode
- can easily be modified for free threading (hi Greg:)

Side effects:
Trashcan does change the order of object destruction.
Prevending that would be quite an immense effort, as
my attempts have shown. This version works always
the same, with debug mode or not. The slightly
changed destruction order should therefore be no problem.

Algorithm:
While the old idea of delaying the destruction of some
obejcts at a certain recursion level was kept, we now
no longer aloocate an object to hold these objects.
The delayed objects are instead chained together
via their ob_type field. The type is encoded via
ob_refcnt. When it comes to the destruction of the
chain of waiting objects, the topmost object is popped
off the chain and revived with type and refcount 1,
then it gets a normal Py_DECREF.

I am confident that this solution is near optimum
for minimizing side effects and code bloat.
2000-04-24 15:40:53 +00:00
Guido van Rossum 5ce78f8e4e Patch by Charles G Waldman to avoid a sneaky memory leak in
_PyTuple_Resize().  In addition, a change suggested by Jeremy Hylton
to limit the size of the free lists is also merged into this patch.

Charles wrote initially:

"""
Test Case:  run the following code:

class Nothing:
    def __len__(self):
        return 5
    def __getitem__(self, i):
        if i < 3:
            return i
        else:
            raise IndexError, i

def g(a,*b,**c):
    return

for x in xrange(1000000):
    g(*Nothing())


and watch Python's memory use go up and up.


Diagnosis:

The analysis begins with the call to PySequence_Tuple at line 1641 in
ceval.c - the argument to g is seen to be a sequence but not a tuple,
so it needs to be converted from an abstract sequence to a concrete
tuple.  PySequence_Tuple starts off by creating a new tuple of length
5 (line 1122 in abstract.c).  Then at line 1149, since only 3 elements
were assigned, _PyTuple_Resize is called to make the 5-tuple into a
3-tuple.  When we're all done the 3-tuple is decrefed, but rather than
being freed it is placed on the free_tuples cache.

The basic problem is that the 3-tuples are being added to the cache
but never picked up again, since _PyTuple_Resize doesn't make use of
the free_tuples cache.  If you are resizing a 5-tuple to a 3-tuple and
there is already a 3-tuple in free_tuples[3], instead of using this
tuple, _PyTuple_Resize will realloc the 5-tuple to a 3-tuple.  It
would more efficient to use the existing 3-tuple and cache the
5-tuple.

By making _PyTuple_Resize aware of the free_tuples (just as
PyTuple_New), we not only save a few calls to realloc, but also
prevent this misbehavior whereby tuples are being added to the
free_tuples list but never properly "recycled".
"""

And later:

"""
This patch replaces my submission of Sun, 16 Apr and addresses Jeremy
Hylton's suggestions that we also limit the size of the free tuple
list.  I chose 2000 as the maximum number of tuples of any particular
size to save.

There was also a problem with the previous version of this patch
causing a core dump if Python was built with Py_TRACE_REFS.  This is
fixed in the below version of the patch, which uses tupledealloc
instead of _Py_Dealloc.
"""
2000-04-21 21:15:05 +00:00
Jeremy Hylton 4a3dd2dcc2 Fix PR#7 comparisons of recursive objects
Note that comparisons of deeply nested objects can still dump core in
extreme cases.
2000-04-14 19:13:24 +00:00
Guido van Rossum f0b7b04ae8 Marc-Andre Lemburg:
The maxsplit functionality in .splitlines() was replaced by the keepends
functionality which allows keeping the line end markers together
with the string.

Added support for '%r' % obj: this inserts repr(obj) rather
than str(obj).
2000-04-11 15:39:26 +00:00
Guido van Rossum dc742b3184 Marc-Andre Lemburg:
Added a few missing whitespace Unicode char mappings.
Thanks to Brian Hooper.
2000-04-11 15:39:02 +00:00
Guido van Rossum 86662914be Marc-Andre Lemburg:
The maxsplit functionality in .splitlines() was replaced by the keepends
functionality which allows keeping the line end markers together
with the string.
2000-04-11 15:38:46 +00:00
Guido van Rossum ba71a247ac Simple optimization by Christian Tismer, who gives credit to Lenny
Kneler for reporting this issue: long_mult() is faster when the
smaller argument is on the left.  Swap the arguments accordingly.
2000-04-10 17:31:58 +00:00
Guido van Rossum fd4b957b06 Marc-Andre Lemburg:
* New exported API PyUnicode_Resize()

* The experimental Keep-Alive optimization was turned back
  on after some tweaks to the implementation. It should now
  work without causing core dumps... this has yet to tested
  though (switching it off is easy: see the unicodeobject.c
  file for details).

* Fixed a memory leak in the Unicode freelist cleanup code.

* Added tests to correctly process the return code from
  _PyUnicode_Resize().

* Fixed a bug in the 'ignore' error handling routines
  of some builtin codecs. Added test cases for these to
  test_unicode.py.
2000-04-10 13:51:10 +00:00
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