Commit Graph

2688 Commits

Author SHA1 Message Date
Andrew Dalke b552c4d848 Code had returned an ssize_t, upcast to long, then converted with PyInt_FromLong.
Now using PyInt_FromSsize_t.
2006-05-25 18:03:25 +00:00
Fredrik Lundh af72237abc needforspeed: use "fastsearch" for count. this results in a 3x speedup
for the related stringbench tests.
2006-05-25 17:55:31 +00:00
Andrew Dalke 8c9091074b Fixed problem identified by Georg. The special-case in-place code for replace
made a copy of the string using PyString_FromStringAndSize(s, n) and modify
the copied string in-place.  However, 1 (and 0) character strings are shared
from a cache.  This cause "A".replace("A", "a") to change the cached version
of "A" -- used by everyone.

Now may the copy with NULL as the string and do the memcpy manually.  I've
added regression tests to check if this happens in the future.  Perhaps
there should be a PyString_Copy for this case?
2006-05-25 17:53:00 +00:00
Tim Peters da53afa1b0 A new table to help string->integer conversion was added yesterday to
both mystrtoul.c and longobject.c.  Share the table instead.  Also
cut its size by 64 entries (they had been used for an inscrutable
trick originally, but the code no longer tries to use that trick).
2006-05-25 17:34:03 +00:00
Fredrik Lundh e68955cf32 needforspeed: new replace implementation by Andrew Dalke. replace is
now about 3x faster on my machine, for the replace tests from string-
bench.
2006-05-25 17:08:14 +00:00
Fredrik Lundh 0c71f88fc9 needforspeed: check for overflow in replace (from Andrew Dalke) 2006-05-25 16:46:54 +00:00
Fredrik Lundh dfe503d3f0 needforspeed: _toupper/_tolower is a SUSv2 thing; fall back on ISO C
versions if they're not defined.
2006-05-25 16:10:12 +00:00
Kristján Valur Jónsson f94323fbb4 Added a new macro, Py_IS_FINITE(X). On windows there is an intrinsic for this and it is more efficient than to use !Py_IS_INFINITE(X) && !Py_IS_NAN(X). No change on other platforms 2006-05-25 15:53:30 +00:00
Fredrik Lundh 4b4e33ef14 needforspeed: make new upper/lower work properly for single-character
strings too... (thanks to georg brandl for spotting the exact problem
faster than anyone else)
2006-05-25 15:49:45 +00:00
Fredrik Lundh 39ccef607e needforspeed: speed up upper and lower for 8-bit string objects.
(the unicode versions of these are still 2x faster on windows,
though...)

based on work by Andrew Dalke, with tweaks by yours truly.
2006-05-25 15:22:03 +00:00
Tim Peters 696cf43b58 Heavily fiddled variant of patch #1442927: PyLong_FromString optimization.
``long(str, base)`` is now up to 6x faster for non-power-of-2 bases.  The
largest speedup is for inputs with about 1000 decimal digits.  Conversion
from non-power-of-2 bases remains quadratic-time in the number of input
digits (it was and remains linear-time for bases 2, 4, 8, 16 and 32).

Speedups at various lengths for decimal inputs, comparing 2.4.3 with
current trunk.  Note that it's actually a bit slower for 1-digit strings:

  len  speedup
 ----  -------
   1     -4.5%
   2      4.6%
   3      8.3%
   4     12.7%
   5     16.9%
   6     28.6%
   7     35.5%
   8     44.3%
   9     46.6%
  10     55.3%
  11     65.7%
  12     77.7%
  13     73.4%
  14     75.3%
  15     85.2%
  16    103.0%
  17     95.1%
  18    112.8%
  19    117.9%
  20    128.3%
  30    174.5%
  40    209.3%
  50    236.3%
  60    254.3%
  70    262.9%
  80    295.8%
  90    297.3%
 100    324.5%
 200    374.6%
 300    403.1%
 400    391.1%
 500    388.7%
 600    440.6%
 700    468.7%
 800    498.0%
 900    507.2%
1000    501.2%
2000    450.2%
3000    463.2%
4000    452.5%
5000    440.6%
6000    439.6%
7000    424.8%
8000    418.1%
9000    417.7%
2006-05-24 21:10:40 +00:00
Fredrik Lundh 347ee277aa needforspeed: refactored the replace code slightly; special-case
constant-length changes; use fastsearch to locate the first match.
2006-05-24 16:35:18 +00:00
Fredrik Lundh d5e0dc51cf needforspeedindeed: use fastsearch also for __contains__ 2006-05-24 15:11:01 +00:00
Fredrik Lundh 6471ee4f18 needforspeed: use "fastsearch" for count and findstring helpers. this
results in a 2.5x speedup on the stringbench count tests, and a 20x (!)
speedup on the stringbench search/find/contains test, compared to 2.5a2.

for more on the algorithm, see:

    http://effbot.org/zone/stringlib.htm

if you get weird results, you can disable the new algoritm by undefining
USE_FAST in Objects/unicodeobject.c.

enjoy /F
2006-05-24 14:28:11 +00:00
Fredrik Lundh 240bf2a8e4 use Py_ssize_t for string indexes (thanks, neal!) 2006-05-24 10:20:36 +00:00
Fredrik Lundh 7763351808 return 0 on misses, not -1. 2006-05-23 19:47:35 +00:00
Fredrik Lundh b63588c188 needforspeed: use append+reverse for rsplit, use "bloom filters" to
speed up splitlines and strip with charsets; etc.  rsplit is now as
fast as split in all our tests (reverse takes no time at all), and
splitlines() is nearly as fast as a plain split("\n") in our tests.
and we're not done yet... ;-)
2006-05-23 18:44:25 +00:00
Richard Jones a372711fcc fix broken merge 2006-05-23 18:32:11 +00:00
Richard Jones cebbefc98d Applied patch 1337051 by Neal Norwitz, saving 4 ints on frame objects. 2006-05-23 18:28:17 +00:00
Richard Jones 7c88dcc5ab Merge from rjones-funccall branch.
Applied patch zombie-frames-2.diff from sf patch 876206 with updates for
Python 2.5 and also modified to retain the free_list to avoid the 67%
slow-down in pybench recursion test. 5% speed up in function call pybench.
2006-05-23 10:37:38 +00:00
Fredrik Lundh 833bf9422e needforspeed: fixed unicode "in" operator to use same implementation
approach as find/index
2006-05-23 10:12:21 +00:00
Tim Peters 1bacc641a0 unicode_repeat(): Change type of local to Py_ssize_t,
since that's what it should be.
2006-05-23 05:47:16 +00:00
Tim Peters 286085c781 PyUnicode_Join(): Recent code changes introduced new
compiler warnings on Windows (signed vs unsigned mismatch
in comparisons).  Cleaned that up by switching more locals
to Py_ssize_t.  Simplified overflow checking (it can _be_
simpler because while these things are declared as
Py_ssize_t, then should in fact never be negative).
2006-05-22 19:17:04 +00:00
Fredrik Lundh 8a8e05a2b9 needforspeed: use memcpy for "long" strings; use a better algorithm
for long repeats.
2006-05-22 17:12:58 +00:00
Fredrik Lundh f1d60a5384 needforspeed: speed up unicode repeat, unicode string copy 2006-05-22 16:29:30 +00:00
Fredrik Lundh 763b50f9d9 docstring tweaks: count counts non-overlapping substrings, not
total number of occurences
2006-05-22 15:35:12 +00:00
Georg Brandl 7b90e168f3 Bug #1462152: file() now checks more thoroughly for invalid mode
strings and removes a possible "U" before passing the mode to the
C library function.
2006-05-18 07:01:27 +00:00
Neal Norwitz 1004a5339a Patch #1488312, Fix memory alignment problem on SPARC in unicode. Will backport 2006-05-15 07:17:23 +00:00
Tim Peters 8931ff1f67 Teach PyString_FromFormat, PyErr_Format, and PyString_FromFormatV
about "%u", "%lu" and "%zu" formats.

Since PyString_FromFormat and PyErr_Format have exactly the same rules
(both inherited from PyString_FromFormatV), it would be good if someone
with more LaTeX Fu changed one of them to just point to the other.
Their docs were way out of synch before this patch, and I just did a
mass copy+paste to repair that.

Not a backport candidate (this is a new feature).
2006-05-13 23:28:20 +00:00
Martin v. Löwis 822f34a848 Revert 43315: Printing of %zd must be signed. 2006-05-13 13:34:04 +00:00
Neal Norwitz c6a989ac3a Fix problems found by Coverity.
longobject.c: also fix an ssize_t problem
  <a> could have been NULL, so hoist the size calc to not use <a>.

_ssl.c: under fail: self is DECREF'd, but it would have been NULL.

_elementtree.c: delete self if there was an error.

_csv.c: I'm not sure if lineterminator could have been anything other than
a string.  However, other string method calls are checked, so check this
one too.
2006-05-10 06:57:58 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Neal Norwitz c4edb0ec81 SF #1479181: split open() and file() from being aliases for each other. 2006-05-02 04:43:14 +00:00
Martin v. Löwis 6685128b97 Fix more ssize_t issues. 2006-04-22 11:40:03 +00:00
Thomas Wouters 568f1d0eed Py_ssize_t issue; repr()'ing a very large string would result in a teensy
string, because of a cast to int.
2006-04-21 13:54:43 +00:00
Thomas Wouters 4e908107b0 Fix variable/format-char discrepancy in new-style class __getitem__,
__delitem__, __setslice__ and __delslice__ hooks. This caused test_weakref
and test_userlist to fail in the p3yk branch (where UserList, like all
classes, is new-style) on amd64 systems, with open-ended slices: the
sys.maxint value for empty-endpoint was transformed into -1.
2006-04-21 11:26:56 +00:00
Thomas Wouters dc5f808cbc Make s.replace() work with explicit counts exceeding 2Gb. 2006-04-19 15:38:01 +00:00
Thomas Wouters 4abb3660ca Use Py_ssize_t to hold the 'width' argument to the ljust, rjust, center and
zfill stringmethods, so they can create strings larger than 2Gb on 64bit
systems (even win64.) The unicode versions of these methods already did this
right.
2006-04-19 14:50:15 +00:00
Jeremy Hylton a4ebc135ac Refactor: Move code that uses co_lnotab from ceval to codeobject 2006-04-18 14:47:00 +00:00
Andrew M. Kuchling 2060d1bd27 Comment typo fix 2006-04-18 11:49:53 +00:00
Martin v. Löwis 45294a9562 Remove types from type_list if they have no objects
and unlist_types_without_objects is set.
Give dump_counts a FILE* argument.
2006-04-18 06:24:08 +00:00
Skip Montanaro 429433b30b C++ compiler cleanup: bunch-o-casts, plus use of unsigned loop index var in a couple places 2006-04-18 00:35:43 +00:00
Skip Montanaro 54e964d253 C++ compilation cleanup: Migrate declaration of
_PyObject_Call(Function|Method)_SizeT into Include/abstract.h.  This gets
them under the umbrella of the extern "C" { ... } block in that file.
2006-04-18 00:27:46 +00:00
Neal Norwitz 0e2cbabb8d No need to cast a Py_ssize_t, use %z in PyErr_Format 2006-04-17 05:56:32 +00:00
Thomas Wouters 715a4cdea2 Use %zd instead of %i as format character (in call to PyErr_Format) for
Py_ssize_t argument.
2006-04-16 22:04:49 +00:00
Tim Peters 81b092d0e6 gen_del(): Looks like much this was copy/pasted from
slot_tp_del(), but while the latter had to cater to types
that don't participate in GC, we know that generators do.
That allows strengthing an assert().
2006-04-15 22:59:10 +00:00
Tim Peters ffe2395777 Remove now-unused variables from tp_traverse and tp_clear methods. 2006-04-15 22:51:26 +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
Thomas Wouters 447d095976 - Whitespace normalization
- In functions where we already hold the same object in differently typed
   pointers, use the correctly typed pointer instead of casting the other
   pointer a second time.
2006-04-15 21:41:56 +00:00
Thomas Wouters edf17d8798 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
tp_clear methods.
2006-04-15 17:28:34 +00:00
Martin v. Löwis ed8f783126 Clear dummy and emptyfrozenset, so that we don't have
dangling references in case of a Py_Initialize/Py_Finalize
cycle.
2006-04-15 12:47:23 +00:00
Martin v. Löwis c597d1b446 Unlink the structseq type from the global list of
objects before initializing it. It might be linked
already if there was a Py_Initialize/Py_Finalize
cycle earlier; not unlinking it would break the global
list.
2006-04-15 12:45:05 +00:00
Tim Peters adcd25e7fa frame_clear(): Explain why it's important to make the frame
look dead right at the start.  Use Py_CLEAR for four more
frame members.
2006-04-15 03:30:08 +00:00
Tim Peters de2acf6512 frame_traverse(): Use the standard Py_VISIT macro.
Py_VISIT:  cast the `op` argument to PyObject* when calling
`visit()`.  Else the caller has to pay too much attention to
this silly detail (e.g., frame_traverse needs to traverse
`struct _frame *` and `PyCodeObject *` pointers too).
2006-04-15 03:22:46 +00:00
Tim Peters a13131cf7f Trimmed trailing whitespace. 2006-04-15 03:15:24 +00:00
Phillip J. Eby 8ebb28df3a Fix SF#1470508: crash in generator cycle finalization. There were two
problems: first, PyGen_NeedsFinalizing() had an off-by-one bug that
prevented it from ever saying a generator didn't need finalizing, and
second, frame objects cleared themselves in a way that caused their
owning generator to think they were still executable, causing a double
deallocation of objects on the value stack if there was still a loop
on the block stack.  This revision also removes some unnecessary
close() operations from test_generators that are now appropriately
handled by the cycle collector.
2006-04-15 01:02:17 +00:00
Martin v. Löwis 5cb6936672 Make Py_BuildValue, PyObject_CallFunction and
PyObject_CallMethod aware of PY_SSIZE_T_CLEAN.
2006-04-14 09:08:42 +00:00
Martin v. Löwis 83687c98dc Change more occurrences of maxsplit to Py_ssize_t. 2006-04-13 08:52:56 +00:00
Martin v. Löwis 9c83076b7b Change maxsplit types to Py_ssize_t. 2006-04-13 08:37:17 +00:00
Martin v. Löwis b1ed7fac12 Replace INT_MAX with PY_SSIZE_T_MAX. 2006-04-13 07:52:27 +00:00
Martin v. Löwis 2a19074a9c Replace INT_MAX with PY_SSIZE_T_MAX where string length
are concerned.
2006-04-13 07:37:25 +00:00
Martin v. Löwis f15da6995b Remove another INT_MAX limitation 2006-04-13 07:24:50 +00:00
Martin v. Löwis 8ce358f5fe Replace most INT_MAX with PY_SSIZE_T_MAX. 2006-04-13 07:22:51 +00:00
Martin v. Löwis 412fb67368 Change more ints to Py_ssize_t. 2006-04-13 06:34:32 +00:00
Martin v. Löwis 80d2e591d5 Revert 34153: Py_UNICODE should not be signed. 2006-04-13 06:06:08 +00:00
Anthony Baxter ac6bd46d5c spread the extern "C" { } magic pixie dust around. Python itself builds now
using a C++ compiler. Still lots and lots of errors in the modules built by
setup.py, and a bunch of warnings from g++ in the core.
2006-04-13 02:06:09 +00:00
Anthony Baxter 3109d62da6 Add a cast to make code compile with a C++ compiler. 2006-04-13 01:07:27 +00:00
Phillip J. Eby 8920bf24f8 Don't set gi_frame to Py_None, use NULL instead, eliminating some insane
pointer dereferences.
2006-04-12 19:07:15 +00:00
Armin Rigo e170937af6 Ignore the references to the dummy objects used as deleted keys
in dicts and sets when computing the total number of references.
2006-04-12 17:06:05 +00:00
Neal Norwitz 017749c33d wrap docstrings so they are less than 80 columns. add spaces after commas. 2006-04-12 06:56:56 +00:00
Tim Peters a5a80cb4a4 gen_throw(): The caller doesn't own PyArg_ParseTuple()
"O" arguments, so must not decref them.  This accounts
for why running test_contextlib.test_main() in a loop
eventually tried to deallocate Py_None.
2006-04-12 06:44:36 +00:00
Thomas Wouters 9cb28bea04 Fix int() and long() to repr() their argument when formatting the exception,
to avoid confusing situations like:

>>> int("")
ValueError: invalid literal for int():
>>> int("2\n\n2")
ValueError: invalid literal for int(): 2

2

Also report the base used, to avoid:

ValueError: invalid literal for int(): 2

They now report:

>>> int("")
ValueError: invalid literal for int() with base 10: ''
>>> int("2\n\n2")
ValueError: invalid literal for int() with base 10: '2\n\n2'
>>> int("2", 2)
ValueError: invalid literal for int() with base 2: '2'

(Reporting the base could be avoided when base is 10, which is the default,
but hrm.) Another effect of these changes is that the errormessage can be
longer; before, it was cut off at about 250 characters. Now, it can be up to
four times as long, as the unrepr'ed string is cut off at 200 characters,
instead.

No tests were added or changed, since testing for exact errormsgs is (pardon
the pun) somewhat errorprone, and I consider not testing the exact text
preferable. The actually changed code is tested frequent enough in the
test_builtin test as it is (120 runs for each of ints and longs.)
2006-04-11 23:50:33 +00:00
Tim Peters cbd6f1896d _Py_PrintReferenceAddresses,_Py_PrintReferences:
interpolate PY_FORMAT_SIZE_T for refcount display
instead of casting refcounts to long.

I understand that gcc on some boxes delivers
nuisance warnings about this, but if any new ones
appear because of this they'll get fixed by magic
when the others get fixed.
2006-04-11 19:12:33 +00:00
Martin v. Löwis ee36d650bb Correct casts to char*. 2006-04-11 09:08:02 +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
Neal Norwitz 9b26122ec0 Get compiling again 2006-04-11 07:58:54 +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
Anthony Baxter 377be11ee1 More C++-compliance. Note especially listobject.c - to get C++ to accept the
PyTypeObject structures, I had to make prototypes for the functions, and
move the structure definition ahead of the functions. I'd dearly like a better
way to do this - to change this would make for a massive set of changes to
the codebase.

There's still some warnings - this is purely to get rid of errors first.
2006-04-11 06:54:30 +00:00
Martin v. Löwis 0bc2ab9a20 Patch #837242: id() for large ptr should return a long. 2006-04-10 20:28:17 +00:00
Phillip J. Eby 2ba96610bf SF Patch #1463867: Improved generator finalization to allow generators
that are suspended outside of any try/except/finally blocks to be
garbage collected even if they are part of a cycle.  Generators that
suspend inside of an active try/except or try/finally block (including
those created by a ``with`` statement) are still not GC-able if they
are part of a cycle, however.
2006-04-10 17:51:05 +00:00
Neal Norwitz 7e957d38b7 Remove dead code (reported by HP compiler).
Can probably be backported if anyone cares.
2006-04-06 08:17:41 +00:00
Martin v. Löwis c48c8db110 Add PY_SSIZE_T_MIN, as suggested by Ralf W. Grosse-Kunstleve. 2006-04-05 18:21:17 +00:00
Thomas Wouters f4d8f39053 Make xrange more Py_ssize_t aware, by assuming a Py_ssize_t is always at
least as big as a long. I believe this to be a safe assumption that is being
made in many parts of CPython, but a check could be added.

len(xrange(sys.maxint)) works now, so fix the testsuite's odd exception for
64-bit platforms too. It also fixes 'zip(xrange(sys.maxint), it)' as a
portable-ish (if expensive) alternative to enumerate(it); since zip() now
calls len(), this was breaking on (real) 64-bit platforms. No additional
test was added for that behaviour.
2006-04-04 17:28:12 +00:00
Martin v. Löwis 54b42f185e Allow long integers in PySlice_GetIndices. 2006-04-03 11:38:08 +00:00
Neal Norwitz d08eaf4d1b Use Py_ssize_t in slices 2006-04-03 04:46:04 +00:00
Georg Brandl ed02eb6aa9 Bug #1177964: make file iterator raise MemoryError on too big files 2006-03-31 20:31:02 +00:00
Barry Warsaw 176014ffad SF patch #1458476 with modifications based on discussions in python-dev. This
adds the following API calls: PySet_Clear(), _PySet_Next(), and
_PySet_Update().  The latter two are considered non-public.  Tests and
documentation (for the public API) are included.
2006-03-30 22:45:35 +00:00
Armin Rigo 314861c568 Minor bugs in the __index__ code (PEP 357), with tests. 2006-03-30 14:04:02 +00:00
Georg Brandl ecdc0a9f46 That one was a mistake. 2006-03-30 12:19:07 +00:00
Georg Brandl 347b30042b Remove unnecessary casts in type object initializers. 2006-03-30 11:57:00 +00:00
Anthony Baxter 262c00a21e Fixed bug #1459029 - unicode reprs were double-escaped.
Backed out an old patch from 2000.
2006-03-30 10:53:17 +00:00
Armin Rigo 12bec1b985 fix a comment. 2006-03-28 19:27:56 +00:00
Raymond Hettinger 334b5b20f2 Tighten an overbroad and misleading assertion.
(Reported by Jim Jewett.)
2006-03-26 03:11:29 +00:00
Neal Norwitz 7fbd6916b6 Get rid of warnings on some platforms by using %u for a size_t. 2006-03-25 23:55:39 +00:00
Phillip J. Eby bee0712214 Support throw() of string exceptions. 2006-03-25 00:05:50 +00:00
Neal Norwitz badc086543 Stop duplicating code and handle slice indices consistently and correctly
wrt to ssize_t.
2006-03-23 06:03:08 +00:00
Tim Peters 8af92d1f6c Heh -- used the right format for a refcount, but forgot
to stop truncating it.
2006-03-23 05:41:24 +00:00
Tim Peters 4d073bb9a1 _Py_NegativeRefcount(): print the full value of ob_refcnt. 2006-03-23 05:38:33 +00:00
Neal Norwitz 29892cc386 Update function name to reflect params and stop casting to long to avoid losing data 2006-03-20 01:55:26 +00:00
Neal Norwitz 2aa9a5dfdd Use macro versions instead of function versions when we already know the type.
This will hopefully get rid of some Coverity warnings, be a hint to
developers, and be marginally faster.

Some asserts were added when the type is currently known, but depends
on values from another function.
2006-03-20 01:53:23 +00:00
Georg Brandl abd1ff8f1f Previously, Python code had no easy way to access the contents of a
cell object. Now, a ``cell_contents`` attribute has been added
(closes patch #1170323).
2006-03-18 07:59:59 +00:00
Georg Brandl 5c170fd4a9 Fix some missing checks after PyTuple_New, PyList_New, PyDict_New 2006-03-17 19:03:25 +00:00
Tim Peters ae1d0c978d Introduced symbol PY_FORMAT_SIZE_T. See the new comments
in pyport.h.  Changed PyString_FromFormatV() to use it
instead of inlining its own maze of #if'ery.
2006-03-17 03:29:34 +00:00
Tim Peters cf79aace07 Merge the tim-obmalloc branch to the trunk.
This is a heavily altered derivative of SF patch 1123430, Evan
Jones's heroic effort to make obmalloc return unused arenas to
the system free(), with some heuristic strategies to make it
more likley that arenas eventually _can_ be freed.
2006-03-16 01:14:46 +00:00
Neal Norwitz 7580146b5c Fix and test (manually w/xx module) passing NULLs to PyObject_Str() and
PyObject_Unicode().  This problem was originally reported from Coverity
and addresses mail on python-dev "checkin r43015".

This inlines the conversion of the string to unicode and cleans
up/simplifies some code at the end of the PyObject_Unicode().

We really need a complete C API test module for all public APIs
and passing good and bad parameter values.

Will backport.
2006-03-14 06:02:16 +00:00
Georg Brandl 3daf75878d Fix bug found by Coverity: don't allow NULL argument to PyUnicode_CheckExact 2006-03-13 22:22:11 +00:00
Thomas Wouters a96affe1fc - Reindent a confusingly indented piece of code (no intended code changes
there)
 - Add missing DECREFs of inner-scope 'temp' variable
 - Add various missing DECREFs by changing 'return NULL' into 'goto onError'
 - Avoid double DECREF when last _PyUnicode_Resize() fails

Coverity found one of the missing DECREFs, but oddly enough not the others.
2006-03-12 00:29:36 +00:00
Guido van Rossum f669436189 Um, I thought I'd already checked this in.
Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
2006-03-10 02:28:35 +00:00
Guido van Rossum 692cdbc5d6 Fix three nits found by Coverity, adding null checks and comments. 2006-03-10 02:04:28 +00:00
Martin v. Löwis 480f1bb67b Update Unicode database to Unicode 4.1. 2006-03-09 23:38:20 +00:00
Georg Brandl 533ff6fc06 Patch #1434038: property() now uses the getter's docstring if there is
no "doc" argument given. This makes it possible to legitimately use
property() as a decorator to produce a read-only property.
2006-03-08 18:09:27 +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
Hye-Shik Chang 4af5c8cee4 SF #1444030: Fix several potential defects found by Coverity.
(reviewed by Neal Norwitz)
2006-03-07 15:39:21 +00:00
Martin v. Löwis 725507b52e Change int to Py_ssize_t in several places.
Add (int) casts to silence compiler warnings.
Raise Python exceptions for overflows.
2006-03-07 12:08:51 +00:00
Neal Norwitz 84632ee319 Oops, forgot to include this in the last checkin.
Actually define Py_RefTotal as a Py_ssize_t.
2006-03-04 20:00:59 +00:00
Neal Norwitz 1fc4b776d4 Change some sequnce APIs to use Py_ssize_t. 2006-03-04 18:49:58 +00:00
Neal Norwitz 8c49c82889 Use Py_ssize_t for PySet_Size() like all the other Py*_Size() functions. 2006-03-04 18:41:19 +00:00
Thomas Wouters 8b87a0b5fc Use %ld and casts to long for refcount printing, in absense of a universally
available %zd format character. Mark with an XXX comment so we can fix this,
later.
2006-03-01 05:41:20 +00:00
Brett Cannon bf36409e2a PEP 352 implementation. Creates a new base class, BaseException, which has an
added message attribute compared to the previous version of Exception.  It is
also a new-style class, making all exceptions now new-style.  KeyboardInterrupt
and SystemExit inherit from BaseException directly.  String exceptions now
raise DeprecationWarning.

Applies patch 1104669, and closes bugs 1012952 and 518846.
2006-03-01 04:25:17 +00:00
Guido van Rossum 1a5e21e033 Updates to the with-statement:
- New semantics for __exit__() -- it must re-raise the exception
  if type is not None; the with-statement itself doesn't do this.
  (See the updated PEP for motivation.)

- Added context managers to:
  - file
  - thread.LockType
  - threading.{Lock,RLock,Condition,Semaphore,BoundedSemaphore}
  - decimal.Context

- Added contextlib.py, which defines @contextmanager, nested(), closing().

- Unit tests all around; bot no docs yet.
2006-02-28 21:57:43 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Guido van Rossum 4b92a82504 Oops. Fix syntax for C89 compilers. 2006-02-25 23:32:30 +00:00
Guido van Rossum 1968ad32cd - Patch 1433928:
- The copy module now "copies" function objects (as atomic objects).
  - dict.__getitem__ now looks for a __missing__ hook before raising
    KeyError.
  - Added a new type, defaultdict, to the collections module.
    This uses the new __missing__ hook behavior added to dict (see above).
2006-02-25 22:38:04 +00:00
Georg Brandl 418a1ef089 RFE #1436243: make integers in [0..256] preallocated. 2006-02-22 11:30:06 +00:00
Georg Brandl d02db4084e Make staticmethod and classmethod complain about keyword args. 2006-02-21 22:13:44 +00:00
Georg Brandl c255c7bef7 Bug #1086854: Rename PyHeapType members adding ht_ prefix. 2006-02-20 22:27:28 +00:00
Martin v. Löwis dde99d2633 Remove size constraints in SLICE opcodes. 2006-02-17 15:57:41 +00:00
Thomas Wouters 02cbdd3461 Use proper PyArg_Parse format char for Py_ssize_t, instead of 'l', in
buffer_new(). Probably fixes a bug in 'buffer("", 10, 10)' on platforms
where sizeof(Py_ssize_t) != sizeof(long) (Win64?)
2006-02-16 19:44:46 +00:00
Thomas Wouters de01774dae Use correct PyArg_Parse format char for Py_ssize_t in unicode.center().
Fixes:

>>> u"".center(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError

on 64-bit systems.
2006-02-16 19:34:37 +00:00
Thomas Wouters 977485d888 Use Py_ssize_t in helper function between Py_ssize_t-using functions. 2006-02-16 15:59:12 +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
Neal Norwitz 82c5a86d7c Oops, this is supposed to be disabled by default. 2006-02-16 07:30:11 +00:00
Martin v. Löwis e0e89f7920 Revert 42400. 2006-02-16 06:59:22 +00:00
Martin v. Löwis 2c95cc6d72 Support %zd in PyErr_Format and PyString_FromFormat. 2006-02-16 06:54:25 +00:00
Neal Norwitz 26efe402c2 Get rid of compiler warnings (gcc 3.3.4 on x86) 2006-02-16 06:21:57 +00:00
Tim Peters 15231548d2 doubletounicode(), longtounicode():
Py_SAFE_DOWNCAST can evaluate its first argument multiple
times in a debug build.  This caused two distinct assert-
failures in test_unicode run under a debug build.  Rewrote
the code in trivial ways so that multiple evaluation of the
first argument doesn't hurt.
2006-02-16 01:08:01 +00:00
Thomas Wouters 4701af5bf5 Remove two unused Py_ssize_t variables (merge glitches, looks like.) 2006-02-15 23:10:32 +00:00
Thomas Wouters b1410fb433 Avoid unused variables when SIZEOF_SIZE_T == SIZEOF_LONG. Also normalize
whitespace.
2006-02-15 23:08:56 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Armin Rigo 967aa8b349 * Refcount leak. It was just a reference to Py_None, but still.
* Allow the 3rd argument to generator.throw() to be None.
  The 'raise' statement does the same, and anyway it follows the
  general policy that optional arguments of built-ins should, when
  reasonable, have a default value specifiable from Python.
2006-02-14 15:50:44 +00:00
Thomas Wouters c45251a485 SF patch #1397960: When mixing file-iteration and
readline/readlines/read/readinto, loudly break by raising ValueError, rather
than silently deliver data out of order or hitting EOF prematurely.

Probably not a bugfix candidate, even though it affects no 'working' code.
2006-02-12 11:53:32 +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
Thomas Wouters 553489ab1d As discussed on python-dev, silence three gcc-4.0.x warnings, using assert()
to protect against actual uninitialized usage.

Objects/longobject.c: In function ‘PyLong_AsDouble’:
Objects/longobject.c:655: warning: ‘e’ may be used uninitialized in this function

Objects/longobject.c: In function ‘long_true_divide’:
Objects/longobject.c:2263: warning: ‘aexp’ may be used uninitialized in this function
Objects/longobject.c:2263: warning: ‘bexp’ may be used uninitialized in this function
2006-02-01 21:32:04 +00:00
Neal Norwitz bab05c9604 Fix SF #1412837, compile failed with Watcom compiler 2006-01-24 06:06:11 +00:00
Neal Norwitz fc76d633e8 - Patch #1400181, fix unicode string formatting to not use the locale.
This is how string objects work.  u'%f' could use , instead of .
  for the decimal point.  Now both strings and unicode always use periods.

This is the code that would break:

import locale
locale.setlocale(locale.LC_NUMERIC, 'de_DE')
u'%.1f' % 1.0
assert '1.0' == u'%.1f' % 1.0

I couldn't create a test case which fails, but this fixes the problem.

Will backport.
2006-01-10 06:03:13 +00:00
Neal Norwitz 0c6e2f1640 Remove some shadowed variables 2006-01-08 06:13:44 +00:00
Neal Norwitz 76dc081dd9 strlen() returns a size_t, get rid of 64-bit warning 2006-01-08 06:13:13 +00:00
Neal Norwitz d43069ce95 Fix icc warnings: remove (sometimes) unused variable conditionally 2006-01-08 01:12:10 +00:00
Neal Norwitz b2da01b27c Fix icc warnings: remove unused variable 2006-01-08 01:11:25 +00:00
Martin v. Löwis dea59e5755 Stop maintaining the buildno file.
Also, stop determining Unicode sizes with PyString_GET_SIZE.
2006-01-05 10:00:36 +00:00
Neal Norwitz 50bf51a3a9 Fix ref/memory leak introduced in rev 41845. 2006-01-02 02:46:54 +00:00
Tim Peters 60b29961dc Fixed English in a comment; trimmed trailing whitespace;
no code changes.
2006-01-01 01:19:23 +00:00
Armin Rigo 037d1e0ff3 SF bug #1153075: "PyXxx_Check(x) trusts x->ob_type->tp_mro".
A patch by mwh to check that user-defined mro's are reasonable
enough.
2005-12-29 17:07:39 +00:00
Armin Rigo fd163f92ce SF patch #1390657:
* set sq_repeat and sq_concat to NULL for user-defined new-style
  classes, as a way to fix a number of related problems.  See
  test_descr.notimplemented()).  One of these problems was fixed
  in r25556 and r25557 but many more existed; this is a general
  fix and thus reverts r25556-r25557.

* to avoid having PySequence_Repeat()/PySequence_Concat() failing
  on user-defined classes, they now fall back to nb_add/nb_mul if
  sq_concat/sq_repeat are not defined and the arguments appear to
  be sequences.

* added tests.

Backport candidate.
2005-12-29 15:59:19 +00:00
Neal Norwitz 7c460740ed Check return result for error 2005-12-18 08:02:38 +00:00
Hye-Shik Chang 835b243c71 Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
just like string codecs.
2005-12-17 04:38:31 +00:00
Neal Norwitz a716eabca7 Revert r41662 and the part of 41552 that originally caused the problem
(calling ftell(stdin) doesn't seem defined).  So we won't test errors
from ftell unless we can do it portably.
2005-12-15 05:25:09 +00:00
Hye-Shik Chang e237d50390 Add a workaround for file.ftell() to raise IOError for ttys.
ftell(3) on BSD doesn't set errno even for ttys and returns useless
values.
2005-12-13 16:44:02 +00:00
Neal Norwitz ba2fa637d6 en_sit will be freed when en is DECREF'd. Don't double free. 2005-12-11 20:55:10 +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
Michael W. Hudson b78a5fc004 Fix bug
[ 1346144 ] Segfaults from unaligned loads in floatobject.c

by using memcpy and not just blinding casting char* to double*.

Thanks to Rune Holm for the report.
2005-12-05 00:27:49 +00:00
Walter Dörwald d4fff1731c Fix leaked reference to None. 2005-11-28 22:15:56 +00:00
Neal Norwitz e5e5aa4ea6 Do a better job of not inlining Py_ADDRESS_IN_RANGE() for newer gcc's.
Perhaps Py_NO_INLINE should be moved to pyport.h or some other header?
2005-11-13 18:55:39 +00:00
Neal Norwitz 6576bd844f Prevent name pollution by making lots of internal functions static. 2005-11-13 18:41:28 +00:00
Armin Rigo c6686b7c7e Added proper reflection on instances of <type 'method-wrapper'>, e.g.
'[].__add__', to match what the other internal descriptor types provide:
'__objclass__' attribute, '__self__' member, and reasonable repr and
comparison.

Added a test.
2005-11-07 08:38:00 +00:00
Andrew M. Kuchling 8294de5673 Another comment typo fix 2005-11-02 16:36:12 +00:00
Walter Dörwald 2e2c02fedb Fix typo in comment. 2005-11-02 08:57:11 +00:00
Martin v. Löwis ab0f947a21 Remove .cvsignore files, as they live in svn:ignore
properties now.
2005-10-30 22:01:41 +00:00
Fred Drake db390c1ad8 fix typos, mostly in comments 2005-10-28 14:39:47 +00:00
Jeremy Hylton ec97a28b60 Fix a bunch of imports to use code.h instead of compile.h.
Remove duplicate declarations from compile.h
2005-10-21 14:58:06 +00:00
Michael W. Hudson b2308bb9be Fix bug:
[ 1327110 ] wrong TypeError traceback in generator expressions

by removing the code that can stomp on the users' TypeError raised by the
iterable argument to ''.join() -- PySequence_Fast (now?) gives a perfectly
reasonable message itself.  Also, a couple of tests.
2005-10-21 11:45:01 +00:00
Jeremy Hylton 3e0055f8c6 Merge ast-branch to head
This change implements a new bytecode compiler, based on a
transformation of the parse tree to an abstract syntax defined in
Parser/Python.asdl.

The compiler implementation is not complete, but it is in stable
enough shape to run the entire test suite excepting two disabled
tests.
2005-10-20 19:59:25 +00:00
Marc-André Lemburg 2cb94aba12 Enhance the performance of two important Unicode character
type lookups: whitespace and linebreak.

These lookup tables are from the Python 1.6 version with the addition
of the 205F code point which was added as whitespace code point to Unicode
since then.
2005-10-20 19:06:35 +00:00
Neal Norwitz 95c1e5065c SF bug #1331563 ] string_subscript doesn't check for failed PyMem_Malloc. Will backport 2005-10-20 04:15:52 +00:00
Marc-André Lemburg 5c4a9d6591 Whitespace corrections. 2005-10-19 22:39:02 +00:00
Marc-André Lemburg e115ec832c Bug fix for [ 1331062 ] utf 7 codec broken.
Backport candidate.
2005-10-19 22:33:31 +00:00
Walter Dörwald d1c1e10f70 Part of SF patch #1313939: Speedup charmap decoding by extending
PyUnicode_DecodeCharmap() the accept a unicode string as the mapping
argument which is used as a mapping table.

This code isn't used by any of the codecs yet.
2005-10-06 20:29:57 +00:00
Georg Brandl d45014b236 Fix PyString_Format so that the "%s" format works again when Unicode is not
enabled.
2005-10-01 17:06:00 +00:00
Armin Rigo ec862b907a (pedronis, arigo)
segfault when a class contain a non-list value in the (undocumented)
special attribute __slotnames__.
2005-09-24 22:58:41 +00:00
Raymond Hettinger 6b27cda643 Convert iterator __len__() methods to a private API. 2005-09-24 21:23:05 +00:00
Skip Montanaro acb1424106 The key to the various sort columns got lost. Pulled from
http://mail.python.org/pipermail/python-dev/2002-July/026876.html
2005-09-23 17:14:22 +00:00
Guido van Rossum 630db60a55 - On 64-bit platforms, when __len__() returns a value that cannot be
represented as a C int, raise OverflowError.

(Forward port from 2.4.2; the patch to classobject.c was already in
but needed a correction in the error message text.)
2005-09-20 18:49:54 +00:00
Guido van Rossum ba3e6ec0c9 A minor fix for 64-bit platforms: when __len__() returns Python int
containing a value that doesn't fit in a C int, raise OverflowError
rather than truncating silently (and having 50% chance of hitting the
"it should be >= 0" error).
2005-09-19 22:42:41 +00:00
Raymond Hettinger 9bda1d6f64 No longer ignore exceptions raised by comparisons during key lookup.
Inspired by Armin Rigo's suggestion to do the same with dictionaries.
2005-09-16 07:14:21 +00:00
Georg Brandl c404ff2f2d patch [ 1118729 ] Error in representation of complex numbers(again) 2005-09-16 06:42:26 +00:00
Neil Schemenauer ab61923637 Fix bug in last checkin (2.231). To match previous behavior, unicode
subclasses should be substituted as-is and not have tp_str called on
them.
2005-08-31 23:02:05 +00:00
Walter Dörwald a47d1c08d0 SF bug #1251300: On UCS-4 builds the "unicode-internal" codec will now complain
about illegal code points. The codec now supports PEP 293 style error handlers.
(This is a variant of the Nik Haldimann's patch that detects truncated data)
2005-08-30 10:23:14 +00:00
Georg Brandl 02c42871cf Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418)
2005-08-26 06:42:30 +00:00
Raymond Hettinger 9c1491f37c * Add a fast equality check path for frozensets where the hash value has
already been computed.
* Apply a GET_SIZE macro().
2005-08-24 00:24:40 +00:00
Raymond Hettinger a710b331da SF bug #1242657: list(obj) can swallow KeyboardInterrupt
Fix over-aggressive PyErr_Clear().  The same code fragment appears in
various guises in list.extend(), map(), filter(), zip(), and internally
in PySequence_Tuple().
2005-08-21 11:03:59 +00:00
Raymond Hettinger d8e133865d Add shortcuts for a|a and a&a. 2005-08-17 12:27:17 +00:00
Raymond Hettinger f81e45023e Fix nits. 2005-08-17 02:19:36 +00:00
Raymond Hettinger f408ddf4a0 Results of a line-by-line comparison back to dictobject.c.
* set_merge() cannot assume that the table doesn't resize during iteration.

* convert some unnecessary tests to asserts -- they were necessary in
  dictobject.c because PyDict_Next() is a public function.  The same is
  not true for set_next().

* re-arrange the order of functions to more closely match the order
  in dictobject.c.  This makes it must easier to compare the two
  and ought to simplify any issues of maintaining both.
2005-08-17 00:27:42 +00:00
Raymond Hettinger c47e01d020 Numerous fix-ups to C API and docs. Added tests for C API. 2005-08-16 10:44:15 +00:00
Raymond Hettinger 994c2c1c69 DECREF --> XDECREF 2005-08-16 03:54:11 +00:00
Raymond Hettinger beb3101b05 Add a C API for sets and frozensets. 2005-08-16 03:47:52 +00:00
Raymond Hettinger ce8185e642 More function re-ordering (placing like functions together). 2005-08-13 09:28:48 +00:00
Raymond Hettinger ed6c1ef8c3 * Bring lookkey() and lookkey_string() closer to dict version.
* Use set_next() for looping in issubset() and frozenset_hash().
* Re-order the presentation of cmp and hash functions.
2005-08-13 08:28:03 +00:00
Phillip J. Eby 00148226df Fix a too-aggressive assert (see SF#1257960). Previously, gen_iternext
was never called during interpreter shutdown GC, so the f_back!=NULL
assertion was correct.  Now that generators get close()d during GC,
the assertion was being triggered because the generator close() was being
called as the top-level frame.  However, nothing actually is broken by
this; it's just that the condition was unexpected in previous Python
versions.
2005-08-13 03:29:00 +00:00
Raymond Hettinger b02c35e208 * Fix SF #1257731. Make __contains__(), remove(), and discard() only do
a frozenset conversion when the initial search attempt fails with a
  TypeError and the key is some type of set.  Add a testcase.

* Eliminate a duplicate if-stmt.
2005-08-12 20:48:39 +00:00
Neil Schemenauer cf52c07843 Change the %s format specifier for str objects so that it returns a
unicode instance if the argument is not an instance of basestring and
calling __str__ on the argument returns a unicode instance.
2005-08-12 17:34:58 +00:00
Raymond Hettinger c991db240c * Add short-circuit code for in-place operations with self (such as
s|=s, s&=s, s-=s, or s^=s).  Add related tests.

* Improve names for several variables and functions.

* Provide alternate table access functions (next, contains, add, and discard)
  that work with an entry argument instead of just a key.  This improves
  set-vs-set operations because we already have a hash value for each key
  and can avoid unnecessary calls to PyObject_Hash().  Provides a 5% to 20%
  speed-up for quick hashing elements like strings and integers.  Provides
  much more substantial improvements for slow hashing elements like tuples
  or objects defining a custom __hash__() function.

* Have difference operations resize() when 1/5 of the elements are dummies.
  Formerly, it was 1/6.  The new ratio triggers less frequently and only
  in cases that it can resize quicker and with greater benefit.  The right
  answer is probably either 1/4, 1/5, or 1/6.  Picked the middle value for
  an even trade-off between resize time and the space/time costs of dummy
  entries.
2005-08-11 07:58:45 +00:00
Raymond Hettinger bc841a1464 * Bring in INIT_NONZERO_SET_SLOTS macro from dictionary code.
* Bring in free list from dictionary code.
* Improve several comments.
* Differencing can leave many dummy entries.  If more than
  1/6 are dummies, then resize them away.
* Factor-out common code with new macro, PyAnySet_CheckExact.
2005-08-07 13:02:53 +00:00
Raymond Hettinger 99220fabb1 * Removed checked_error flag which no longer provides any benefit.
* Have issubset() control its own loop instead of using set_next_internal().
2005-08-06 18:57:13 +00:00
Raymond Hettinger 5ba0cbe392 * set_new() doesn't need to zero the structure a second time after tp_alloc
has already done the job.
* Use a macro form of PyErr_Occurred() inside the set_lookkey() function.
2005-08-06 18:31:24 +00:00
Raymond Hettinger fe889f3c62 Factor away a redundant clear() function. 2005-08-06 05:43:39 +00:00
Raymond Hettinger a580c47c6d * Improve a variable name: entry0 --> table.
* Give set_lookkey_string() a fast alternate path when no dummy entries
  are present.
* Have set_swap_bodies() reset the hash field to -1 whenever either of
  bodies is not a frozenset.  Maintains the invariant of regular sets
  always having -1 in the hash field; otherwise, any mutation would make
  the hash value invalid.
* Use an entry pointer to simplify the code in frozenset_hash().
2005-08-05 17:19:54 +00:00
Raymond Hettinger a9d9936d10 * Move copyright notice to top and indicate derivation from sets.py and
dictobject.c.
* Have frozenset_hash() use entry->hash instead of re-computing each
  individual hash with PyObject_Hash(o);
* Finalize the dummy entry before a system exit.
2005-08-05 00:01:15 +00:00
Raymond Hettinger 67962ab1bb Model set.pop() after dict.popitem(). 2005-08-02 03:45:16 +00:00
Phillip J. Eby 0d6615fd29 PEP 342 implementation. Per Guido's comments, the generator throw()
method still needs to support string exceptions, and allow None for the
third argument.  Documentation updates are needed, too.
2005-08-02 00:46:46 +00:00
Raymond Hettinger d794666048 * Improve code for the empty frozenset singleton:
- Handle both frozenset() and frozenset([]).
  - Do not use singleton for frozenset subclasses.
  - Finalize the singleton.
  - Add test cases.
* Factor-out set_update_internal() from set_update().  Simplifies the
  code for several internal callers.
* Factor constant expressions out of loop in set_merge_internal().
* Minor comment touch-ups.
2005-08-01 21:39:29 +00:00
Hye-Shik Chang e295676c87 Fix build on gcc: PySetIter_Type should be static in definition
part also.
2005-08-01 05:26:41 +00:00
Raymond Hettinger 06d8cf8ceb Improve variable names. 2005-07-31 15:36:06 +00:00
Raymond Hettinger 9dcb17cb1a Fix frozenset() ref count and a comment typo. 2005-07-31 13:09:28 +00:00
Raymond Hettinger 934d63eb40 Comment on the set_swap_bodies() helper function. 2005-07-31 01:33:10 +00:00
Raymond Hettinger 9f1a6796eb Revised the set() and frozenset() implementaion to use its own internal
data structure instead of using dictionaries.  Reduces memory consumption
by 1/3 and provides modest speed-ups for most set operations.
2005-07-31 01:16:36 +00:00
Tim Peters de7990b8af SF bug #1238681: freed pointer is used in longobject.c:long_pow().
In addition, long_pow() skipped a necessary (albeit extremely unlikely
to trigger) error check when converting an int modulus to long.

Alas, I was unable to write a test case that crashed due to either
cause.

Bugfix candidate.
2005-07-17 23:45:23 +00:00
Michael W. Hudson 0edc7a03e2 Fix:
[ 1229429 ] missing Py_DECREF in PyObject_CallMethod

Add a test in test_enumerate, which is a bit random, but suffices
(reversed_new calls PyObject_CallMethod under some circumstances).
2005-07-12 10:21:19 +00:00
Tim Peters ecc6e6a54e SF bug 1185883: PyObject_Realloc can't safely take over a block currently
managed by C, because it's possible for the block to be smaller than the
new requested size, and at the end of allocated VM.  Trying to copy over
nbytes bytes to a Python small-object block can segfault then, and there's
no portable way to avoid this (we would have to know how many bytes
starting at p are addressable, and std C has no means to determine that).

Bugfix candidate.  Should be backported to 2.4, but I'm out of time.
2005-07-10 22:30:55 +00:00
Michael W. Hudson 3095ad0650 Apparently some compiler gives a warning on
float y = x;

when x is a double.  Go figure.
2005-06-30 00:02:26 +00:00
Raymond Hettinger 3296e696db SF bug #1224347: int/long unification and hex()
Hex longs now print with lowercase letters like their int counterparts.
2005-06-29 23:29:56 +00:00
Raymond Hettinger bff60aeb93 Insert missing flag. 2005-06-19 08:42:20 +00:00
Raymond Hettinger bb999b5925 SF patch #1200018: Restore GC support to set objects
Reverts 1.26 and 1.27.
And adds cycle testing.
2005-06-18 21:00:26 +00:00
Anthony Baxter 5661699995 fix object.__divmod__.__doc__
backport candidate
2005-06-03 14:12:21 +00:00
Michael W. Hudson ba283e2b7f This is my patch:
[ 1181301 ] make float packing copy bytes when they can

which hasn't been reviewed, despite numerous threats to check it in
anyway if noone reviews it.  Please read the diff on the checkin list,
at least!

The basic idea is to examine the bytes of some 'probe values' to see if
the current platform is a IEEE 754-ish platform, and if so
_PyFloat_{Pack,Unpack}{4,8} just copy bytes around.

The rest is hair for testing, and tests.
2005-05-27 15:23:20 +00:00
Skip Montanaro bbf12ba7b2 Disallow opening files with modes 'aU' or 'wU' as specified by PEP
278. Closes bug 967182.
2005-05-20 03:07:06 +00:00
Armin Rigo 7726dc0a8e Fixed a quite misleading comment: a "not" should not have been there. 2005-05-15 15:32:08 +00:00
Raymond Hettinger 186e739d29 SF patch #1200051: Small optimization for PyDict_Merge()
(Contributed by Barry Warsaw and Matt Messier.)
2005-05-14 18:08:25 +00:00
Brett Cannon c3647ac93e Make subclasses of int, long, complex, float, and unicode perform type
conversion using the proper magic slot (e.g., __int__()).  Also move conversion
code out of PyNumber_*() functions in the C API into the nb_* function.

Applied patch #1109424.  Thanks Walter Doewald.
2005-04-26 03:45:26 +00:00
Barry Warsaw c8d907c60b As per discussion on python-dev, descriptors defined in C with a NULL setter
now raise AttributeError instead of TypeError, for consistency with their
pure-Python equivalent.
2005-04-19 23:43:40 +00:00
Raymond Hettinger 1356f785c1 SF bug #1183742: PyDict_Copy() can return non-NULL value on error 2005-04-15 15:58:42 +00:00
Michael W. Hudson e2749cb264 Fix for rather inaccurately titled bug
[ 1165306 ] Property access with decorator makes interpreter crash

Don't allow the creation of unbound methods with NULL im_class, because
attempting to call such crashes.

Backport candidate.
2005-03-30 16:32:10 +00:00
Raymond Hettinger e6c470f255 SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior. 2005-03-27 03:04:54 +00:00
Raymond Hettinger b67cc80bb9 SF bug #1155938: Missing None check for __init__(). 2005-03-03 16:45:19 +00:00
Martin v. Löwis 6ce7ed23d0 Revert previous checkin on getargs 'L' code. Try to convert all
numbers in PyLong_AsLongLong, and update test suite accordingly.
Backported to 2.4.
2005-03-03 12:26:35 +00:00
Raymond Hettinger 57e7447c44 * Beef-up tests for str.count().
* Speed-up str.count() by using memchr() to fly between first char matches.
2005-02-20 09:54:53 +00:00
Raymond Hettinger 7cbf1bcb3e * Beef-up testing of str.__contains__() and str.find().
* Speed-up "x in y" where x has more than one character.

The existing code made excessive calls to the expensive memcmp() function.
The new code uses memchr() to rapidly find a start point for memcmp().
In addition to knowing that the first character is a match, the new code
also checks that the last character is a match.  This significantly reduces
the incidence of false starts (saving memcmp() calls and making quadratic
behavior less likely).

Improves the timings on:
    python -m timeit -r7 -s"x='a'*1000" "'ab' in x"
    python -m timeit -r7 -s"x='a'*1000" "'bc' in x"

Once this code has proven itself, then string_find_internal() should refer
to it rather than running its own version.  Also, something similar may
apply to unicode objects.
2005-02-20 04:07:08 +00:00
Michael W. Hudson ee319f66ab Fix
[ 1124295 ] Function's __name__ no longer accessible in restricted mode

which I introduced with a bit of mindless copy-paste when making
__name__ writable.  You can't assign to __name__ in restricted mode,
which I'm going to pretend was intentional :)
2005-02-17 10:37:21 +00:00
Raymond Hettinger 07ead17318 Code simplification -- eliminate lookup when value is known in advance. 2005-02-05 23:42:57 +00:00
Michael W. Hudson faa7648ffe More bug #1077106 stuff, sorry -- modem induced impatiece!
This should go on whatever bugfix branches the other fetches up on.
2005-01-31 17:09:25 +00:00
Armin Rigo a174813113 Dima Dorfman's patch for coercion/comparison of C types (patch #995939), with
a minor change after the coercion, to accept two objects not necessarily of
the same type but with the same tp_compare.
2004-12-23 22:13:13 +00:00
Raymond Hettinger 5d01aa4f6a Bug #1079011: Incorrect error message (somewhat) 2004-12-19 20:45:20 +00:00
Raymond Hettinger 193814c308 Small boost to PySequence_Fast(). Lists build faster than tuples for
unsized iterable inputs.
2004-12-18 19:00:59 +00:00
Raymond Hettinger e6bdb37e5b Add missing decref. 2004-12-16 15:10:21 +00:00
Raymond Hettinger 4d01259fb2 SF bug #1085744: Performance issues with PySequence_Tuple()
* Added missing error checks.
* Fixed O(n**2) growth pattern.  Modeled after lists to achieve linear
  amortized resizing.  Improves construction of "tuple(it)" when "it" is
  large and does not have a __len__ method.  Other cases are unaffected.
2004-12-16 10:38:38 +00:00
Raymond Hettinger 665174834a Remove PyRange_New(). 2004-12-03 11:45:13 +00:00
Marc-André Lemburg a9cadcd41b Correct the handling of 0-termination of PyUnicode_AsWideChar()
and its usage in PyLocale_strcoll().

Clarify the documentation on this.

Thanks to Andreas Degert for pointing this out.
2004-11-22 13:02:31 +00:00
Raymond Hettinger 15056a5202 SF 1062353: set pickling problems
Support automatic pickling of dictionaries in instance of set subclasses.
2004-11-09 07:25:31 +00:00
Peter Astrand f8e74b12b0 If close() fails in file_dealloc, then print an error message to
stderr. close() can fail if the user is out-of-quota, for example.
Fixes #959379.
2004-11-07 14:15:28 +00:00
Tim Peters ead8b7ab30 SF 1055820: weakref callback vs gc vs threads
In cyclic gc, clear weakrefs to unreachable objects before allowing any
Python code (weakref callbacks or __del__ methods) to run.

This is a critical bugfix, affecting all versions of Python since weakrefs
were introduced.  I'll backport to 2.3.
2004-10-30 23:09:22 +00:00