Commit Graph

74 Commits

Author SHA1 Message Date
Tim Peters 6783070ebf Make PyDict_Next safe to use for loops that merely modify the values
associated with existing dict keys.
This is a variant of part of Michael Hudson's patch #409864 "lazy fix for
Pings bizarre scoping crash".
2001-03-21 19:23:56 +00:00
Guido van Rossum b932420cc7 Rich comparisons:
- Use PyObject_RichCompareBool() when comparing keys; this makes the
  error handling cleaner.

- There were two implementations for dictionary comparison, an old one
  (#ifdef'ed out) and a new one.  Got rid of the old one, which was
  abandoned years ago.

- In the characterize() function, part of dictionary comparison, use
  PyObject_RichCompareBool() to compare keys and values instead.  But
  continue to use PyObject_Compare() for comparing the final
  (deciding) elements.

- Align the comments in the type struct initializer.

Note: I don't implement rich comparison for dictionaries -- there
doesn't seem to be much to be gained.  (The existing comparison
already decides that shorter dicts are always smaller than longer
dicts.)
2001-01-18 00:39:02 +00:00
Jeremy Hylton 1fb6088e86 dict_update has two boundary conditions: a.update(a) and a.update({})
Added test for second one.
2001-01-03 22:34:59 +00:00
Tim Peters f7f88b11e4 Add long-overdue docstrings to dict methods. 2000-12-13 23:18:45 +00:00
Tim Peters f1c7c884b3 Typo repair in comments. Fell for GregS's .popitem() poke. 2000-12-13 19:58:25 +00:00
Tim Peters ea8f2bf9ca Bring comments up to date (e.g., they still said the table had to be
a prime size, which is in fact never true anymore ...).
2000-12-13 01:02:46 +00:00
Guido van Rossum ba6ab84e73 Add popitem() -- SF patch #102733. 2000-12-12 22:02:18 +00:00
Moshe Zadka 5725d1eb03 Backing out my changes.
Improved version coming soon to a Source Forge near you!
2000-11-30 19:30:21 +00:00
Moshe Zadka 1a62750eda Added .first{item,value,key}() to dictionaries.
Complete with docos and tests.
OKed by Guido.
2000-11-30 12:31:03 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Fred Drake 1bff34ab96 Slight performance hack that also avoids requiring the existence of thread
state for dictionaries that have only been indexed by string keys.

See the comments in SourceForge for more.

This closes SourceForge patch #101309.
2000-08-31 19:31:38 +00:00
Fred Drake c88b99ce06 Clear errors raised by PyObject_Compare() without losing any existing
exception context.  This avoids improperly propogating errors raised by
a user-defined __cmp__() by a subsequent lookup operation.

This patch does *not* include the performance enhancement patch for
dictionaries with string keys only; that will be checked in separately.

This closes SourceForge patch #101277 and bug #112558.
2000-08-31 19:04:07 +00:00
Guido van Rossum 164452cec4 Barry's patch to implement the new setdefault() method. 2000-08-08 16:12:54 +00:00
Thomas Wouters 7889010731 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
char**) and return an int even on PC platforms. If not, please fix
PC/utils/makesrc.c ;-P
2000-07-22 19:25:51 +00:00
Thomas Wouters 7e47402264 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
comments, docstrings or error messages. I fixed two minor things in
test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't").

There is a minor style issue involved: Guido seems to have preferred English
grammar (behaviour, honour) in a couple places. This patch changes that to
American, which is the more prominent style in the source. I prefer English
myself, so if English is preferred, I'd be happy to supply a patch myself ;)
2000-07-16 12:04:32 +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
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
Jeremy Hylton c5007aa5c3 final patches from Neil Schemenauer for garbage collection 2000-06-30 05:02:53 +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 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
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
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 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
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 2bc137909d Vladimir Marangozov contributed updated comments. 1999-03-24 19:06:42 +00:00
Guido van Rossum f05fc716d1 Remove dead code discovered by Vladimir Marangozov. 1998-11-16 22:46:30 +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 0fd00334c6 Avoid using calloc(). This triggered an obscure bug on multiprocessor
Sparc Solaris 2.6 (fully patched!) that I don't want to dig into, but
which I suspect is a bug in the multithreaded malloc library that only
shows up when run on a multiprocessor.  (The program wasn't using
threads, it was just using the multithreaded C library.)
1998-07-16 15:06:13 +00:00
Guido van Rossum 474b19e2ab Make sure that PyDict_GetItem[String]() *never* raises an exception.
If the argument is not a dictionary, simply return NULL.  If the
hash() on the key fails, clear the error.
1998-05-14 01:00:51 +00:00
Guido van Rossum 255443b720 Use Py_Repr{Enter,Leave} to display recursive dictionaries in finite space.
(Jeremy will hardly recognize his patch :-)
1998-04-10 22:47:14 +00:00
Guido van Rossum 6fcfa72c63 Correct Barry's fix -- take care of {}.get(0). 1997-10-20 20:10:00 +00:00
Barry Warsaw 320ac331d1 dict_get(): Fixed a couple of stupid mistakes which caused crashes.
Also got rid of some unnecessary code.
1997-10-20 17:26:25 +00:00
Barry Warsaw c38c5da5d0 dict_get(): New method for item access with different semantics than
__getitem__().  This method never raises an exception; if the key is
not in the dictionary, the second (optional) argument is returned.  If
the second argument is not provided and the key is missing, None is
returned.

mapp_methods: added "get" method.
1997-10-06 17:49:20 +00:00
Guido van Rossum 4f3bf1e383 Don't intern the key string for getitem and delitem. 1997-09-29 23:31:11 +00:00
Guido van Rossum fd7a0b871f Made lookdict nearly twice as fast, resulting in a 5% overall
improvement of pystone.  Vladimir Marangozov.
1997-08-18 21:52:47 +00:00
Guido van Rossum 5d8123f34a Reordered list of methods to hopefully put the most frequently used
ones near the front.
1997-07-13 03:58:01 +00:00
Guido van Rossum a8d5131d57 Renamed dict.absorb() (too spungy) to dict.update(). 1997-06-02 17:13:37 +00:00
Guido van Rossum e3f5b9c8d1 Added dict.absorb() and dict.copy(). 1997-05-28 19:15:28 +00:00
Guido van Rossum 5b2121b25f PyObject_Compare can now return an error. Unfortunately, there are a
few places where we don't know how to test for them without losing
speed; don't know yet how to handle that.
1997-05-23 00:01:41 +00:00
Guido van Rossum 037b2205e8 Moved PyObject_{Get,Set}Attr to object.c.
Fixed two 'return NULL' that should be 'return -1'.
1997-05-20 18:35:19 +00:00
Guido van Rossum 3cca24570e Got rid of all the last_name_* bogosities. I don't think the
complexity saved much any more.  A simple benchmark (grail) showed
that there were 3 times as many misses as hits, and the same number of
times again the code was bypassed altogether due to the existence of
setattro/getattro.
1997-05-16 14:23:33 +00:00
Guido van Rossum a9e7a81137 Renamed from mappingobject.c to dictobject.c.
(Sorry Jack, all your projects will have to be changed again. :-( )
1997-05-13 21:02:11 +00:00
Guido van Rossum c0b618a2cc Quickly renamed the last directory. 1997-05-02 03:12:38 +00:00
Guido van Rossum 3648884490 (Jack:) Align mapping entries to 4-words if USE_CACHE_ALIGNED is defined. 1997-04-11 19:14:07 +00:00
Guido van Rossum 2095d24842 Tweaks to keep the Microsoft compiler quiet. 1997-04-09 19:41:24 +00:00
Guido van Rossum fb8f1cadb2 Add clear() method to dictionary objects. 1997-03-21 21:55:12 +00:00
Guido van Rossum efb4609c4a Small lookmapping nits:
- remove bogus initialization using uninitialized i
- derive initial incr from hash
- copy mp->ma_table into a local variable
1997-01-29 15:53:56 +00:00
Guido van Rossum 9e5656ca3f Final three poly table entries corrected by Tim Peters.
Reindented the whole table.
1997-01-29 04:45:16 +00:00