Commit Graph

136 Commits

Author SHA1 Message Date
Christian Heimes 074ebced1b PyTuple_Pack() was missing va_end() in its error branch which lead to a resource leak. 2012-09-10 02:54:51 +02:00
Petri Lehtinen 3b9d92aefe Revert "Accept None as start and stop parameters for list.index() and tuple.index()"
Issue #13340.
2011-11-06 20:59:01 +02:00
Petri Lehtinen 819d8d447d Accept None as start and stop parameters for list.index() and tuple.index()
Closes #13340.
2011-11-05 23:18:06 +02:00
Antoine Pitrou c83ea137d7 Untabify C files. Will watch buildbots. 2010-05-09 14:46:46 +00:00
Brett Cannon fee3acb082 Remove an unneeded variable assignment.
Found using Clang's static analyzer.
2010-05-05 20:18:23 +00:00
Ezio Melotti fb501123e3 #8030: more docstring fix for builtin types. 2010-02-28 23:59:00 +00:00
Antoine Pitrou c169c781a8 Issue #7466: segmentation fault when the garbage collector is called
in the middle of populating a tuple.  Patch by Florent Xicluna.

(note: no NEWS entry for trunk since the bug was introduced in 2.7/3.1)
2009-12-12 19:13:08 +00:00
Antoine Pitrou 1fba62427c The tracking statistics were actually too pessimistic 2009-03-23 19:17:00 +00:00
Antoine Pitrou f8387af262 Issue #4688: Add a heuristic so that tuples and dicts containing only
untrackable objects are not tracked by the garbage collector. This can
reduce the size of collections and therefore the garbage collection overhead
on long-running programs, depending on their particular use of datatypes.

(trivia: this makes the "binary_trees" benchmark from the Computer Language
Shootout 40% faster)
2009-03-23 18:41:45 +00:00
Benjamin Peterson 1706c644ae fix tuple.index() error message #5495 2009-03-15 14:38:55 +00:00
Martin v. Löwis b90304acb9 Issue #4850: Change COUNT_ALLOCS variables to Py_ssize_t. 2009-01-07 18:40:40 +00:00
Andrew M. Kuchling b15d6fb9a7 Docstring change: Specify exception raised 2008-10-04 01:03:42 +00:00
Neal Norwitz e7d8be80ba Security patches from Apple: prevent int overflow when allocating memory 2008-07-31 17:17:14 +00:00
Robert Schuppenies 73e9ffc811 Fixed: sys.getsizeof does not take the actual length of the tuples into account. 2008-06-13 13:29:37 +00:00
Gregory P. Smith dd96db63f6 This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html

Python 2.6 should stick with PyString_* in its codebase.  The PyBytes_* names
in the spirit of 3.0 are available via a #define only.  See the email thread.
2008-06-09 04:58:54 +00:00
Christian Heimes 593daf545b Renamed PyString to PyBytes 2008-05-26 12:51:38 +00:00
Christian Heimes 3b718a79af Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation. 2008-02-14 12:47:33 +00:00
Raymond Hettinger 55285ef44c Return ints instead of longs for tuple.count() and tuple.index(). 2008-02-07 02:12:52 +00:00
Raymond Hettinger 5b07ebce86 Issue 2025: Add tuple.count() and tuple.index() to follow the ABC in collections.Sequence. 2008-02-07 00:54:20 +00:00
Christian Heimes 5b970ad483 Unified naming convention for free lists and their limits. All free lists
in Object/ are named ``free_list``, the counter ``numfree`` and the upper
limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block.

The chances should make it easier to adjust Python for platforms with
less memory, e.g. mobile phones.
2008-02-06 13:33:44 +00:00
Christian Heimes e93237dfcc #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available. 2007-12-19 02:37:44 +00:00
Brett Cannon 31ba8480d8 Fix error introduced by r58288; if a tuple is length 0 return its repr and
don't worry about any self-referring tuples.
2007-09-30 20:37:19 +00:00
Brett Cannon 0b14f243c4 tuple.__repr__ did not consider a reference loop as it is not possible from
Python code; but it is possible from C.  object.__str__ had the issue of not
expecting a type to doing something within it's tp_str implementation that
could trigger an infinite recursion, but it could in C code..  Both found
thanks to BaseException and how it handles its repr.

Closes issue #1686386.  Thanks to Thomas Herve for taking an initial stab at
coming up with a solution.
2007-09-30 19:45:10 +00:00
Brett Cannon 0153159e67 Add a bunch of GIL release/acquire points in tp_print implementations and for
PyObject_Print().

Closes issue #1164.
2007-09-17 03:28:34 +00:00
Thomas Wouters 3ccec68a05 Improve extended slicing support in builtin types and classes. Specifically:
- Specialcase extended slices that amount to a shallow copy the same way as
   is done for simple slices, in the tuple, string and unicode case.

 - Specialcase step-1 extended slices to optimize the common case for all
   involved types.

 - For lists, allow extended slice assignment of differing lengths as long
   as the step is 1. (Previously, 'l[:2:1] = []' failed even though
   'l[:2] = []' and 'l[:2:None] = []' do not.)

 - Implement extended slicing for buffer, array, structseq, mmap and
   UserString.UserString.

 - Implement slice-object support (but not non-step-1 slice assignment) for
   UserString.MutableString.

 - Add tests for all new functionality.
2007-08-28 15:28:19 +00:00
Martin v. Löwis 6819210b9e PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
2007-07-21 06:55:02 +00:00
Neal Norwitz ee3a1b5244 Variation of patch # 1624059 to speed up checking if an object is a subclass
of some of the common builtin types.

Use a bit in tp_flags for each common builtin type.  Check the bit
to determine if any instance is a subclass of these common types.
The check avoids a function call and O(n) search of the base classes.
The check is done in the various Py*_Check macros rather than calling
PyType_IsSubtype().

All the bits are set in tp_flags when the type is declared
in the Objects/*object.c files because PyType_Ready() is not called
for all the types.  Should PyType_Ready() be called for all types?
If so and the change is made, the changes to the Objects/*object.c files
can be reverted (remove setting the tp_flags).  Objects/typeobject.c
would also have to be modified to add conditions
for Py*_CheckExact() in addition to each the PyType_IsSubtype check.
2007-02-25 19:44:48 +00:00
Georg Brandl 283a1353a0 Patch [ 1586791 ] better error msgs for some TypeErrors 2006-11-19 08:48:30 +00:00
Neal Norwitz 8a87f5d37e Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments.  This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward.  I don't want this to hold up release if possible.
2006-08-12 17:03:09 +00:00
Thomas Wouters c6e55068ca Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
using a custom, nearly-identical macro. This probably changes how some of
these functions are compiled, which may result in fractionally slower (or
faster) execution. Considering the nature of traversal, visiting much of the
address space in unpredictable patterns, I'd argue the code readability and
maintainability is well worth it ;P
2006-04-15 21:47:09 +00:00
Martin v. Löwis 72d206776d Remove "static forward" declaration. Move constructors
after the type objects.
2006-04-11 09:04:12 +00:00
Anthony Baxter a62862120d More low-hanging fruit. Still need to re-arrange some code (or find a better
solution) in the same way as listobject.c got changed. Hoping for a better
solution.
2006-04-11 07:42:36 +00:00
Georg Brandl 5c170fd4a9 Fix some missing checks after PyTuple_New, PyList_New, PyDict_New 2006-03-17 19:03:25 +00:00
Guido van Rossum 38fff8c4e4 Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
2006-03-07 18:50:55 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis eb079f1c25 Use Py_ssize_t for counts and sizes.
Convert Py_ssize_t using PyInt_FromSsize_t
2006-02-16 14:32:27 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Armin Rigo f5b3e36493 Renamed _length_cue() to __length_hint__(). See:
http://mail.python.org/pipermail/python-dev/2006-February/060524.html
2006-02-11 21:32:43 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Raymond Hettinger 57c2d930f6 Add a final permutation step to the tuple hash function.
Prevents a collision pattern that occurs with nested tuples.
(Yitz Gale provided code that repeatably demonstrated the weakness.)
2004-06-10 18:42:15 +00:00
Raymond Hettinger 4ec44e851d Replaced arbitrary addend in tuple_hash with one that is known to generate
many more prime multipliers and that performs well on collision tests.
2004-06-04 06:35:20 +00:00
Raymond Hettinger 41bd02256f SF bug #942952: Weakness in tuple hash
(Basic approach and test concept by Tim Peters.)

* Improved the hash to reduce collisions.
* Added the torture test to the test suite.
2004-06-01 06:36:24 +00:00
Armin Rigo 6fce78e07f Restored revision 2.87. 2004-03-21 22:29:05 +00:00
Tim Peters 1c3fd875b9 PyTuple_New(): vrbl i no longer referenced, so removed it (which kills
off a new compiler wng under MSVC6).
2004-03-21 21:35:41 +00:00
Armin Rigo 56716150e6 This is the fastest I could get on Intel GCC. I kept the memset() in to clear
the newly created tuples, but tuples added in the freelist are now cleared in
tupledealloc already (which is very cheap, because we are already
Py_XDECREF'ing all elements anyway).

Python should have a standard Py_ZAP macro like ZAP in pystate.c.
2004-03-21 20:27:49 +00:00
Armin Rigo 7cdf3e8a8a memset() hunt continuing. This is a net win. 2004-03-20 21:35:09 +00:00
Raymond Hettinger 435bf58b7b Make iterators length transparent where possible. 2004-03-18 22:43:10 +00:00
Raymond Hettinger 325d169a54 Eliminate an unnecessary test on a common code path. 2004-03-15 00:16:34 +00:00
Raymond Hettinger a6366fe085 Optimize inner loops for subscript, repeat, and concat. 2004-03-09 13:05:22 +00:00