Commit Graph

1465 Commits

Author SHA1 Message Date
Guido van Rossum e027d9818f Add Raymond Hettinger's d.pop(). See SF patch 539949. 2002-04-12 15:11:59 +00:00
Tim Peters 85cc1c4368 _PyObject_DebugRealloc(): rewritten to let the underlying realloc do
most of the work.  In particular, if the underlying realloc is able to
grow the memory block in place, great (this routine used to do a fresh
malloc + memcpy every time a block grew).  BTW, I'm not so keen here on
avoiding possible quadratic-time realloc patterns as I am on making
the debug pymalloc more invisible (the more it uses memory "just like"
the underlying allocator, the better the chance that a suspected memory
corruption bug won't vanish when the debug malloc is turned on).
2002-04-12 08:52:50 +00:00
Tim Peters f539c68ccd _PyObject_DebugDumpAddress(): clarify an output message. 2002-04-12 07:43:07 +00:00
Tim Peters f6fb501c57 PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
prefix.  These symbols are private to the file, and the PYMALLOC_ gets
in the way (overly long code lines, comments, and error messages).
2002-04-12 07:38:53 +00:00
Tim Peters af3e8de580 First stab at rationalizing the PyMem_ API. Mixing PyObject_xyz with
PyMem_{Del, DEL} doesn't work yet (compilation problems).

pyport.h:  _PyMem_EXTRA is gone.

pmem.h:  Repaired comments.  PyMem_{Malloc, MALLOC} and
PyMem_{Realloc, REALLOC} now make the same x-platform guarantees when
asking for 0 bytes, and when passing a NULL pointer to the latter.

object.c:  PyMem_{Malloc, Realloc} just call their macro versions
now, since the latter take care of the x-platform 0 and NULL stuff
by themselves now.

pypcre.c, grow_stack():  So sue me.  On two lines, this called
PyMem_RESIZE to grow a "const" area.  It's not legit to realloc a
const area, so the compiler warned given the new expansion of
PyMem_RESIZE.  It would have gotten the same warning before if it
had used PyMem_Resize() instead; the older macro version, but not the
function version, silently cast away the constness.  IMO that was a wrong
thing to do, and the docs say the macro versions of PyMem_xyz are
deprecated anyway.  If somebody else is resizing const areas with the
macro spelling, they'll get a warning when they recompile now too.
2002-04-12 07:22:56 +00:00
Neil Schemenauer d2560cd37c Move PyObject_Malloc and PyObject_Free here from object.c. Remove
PyMalloc_ prefix and use PyObject_ instead.  I'm not sure about the
debugging functions.  Perhaps they should stay as PyMalloc_.
2002-04-12 03:10:20 +00:00
Neil Schemenauer bdf0eedb68 Move PyObject_Malloc and PyObject_Free to obmalloc.c. 2002-04-12 03:08:42 +00:00
Neil Schemenauer 58aa861fa2 Remove PyMalloc_*. 2002-04-12 03:07:20 +00:00
Neil Schemenauer 09a2ae5882 Change signature of _PyObject_GC_Malloc to match PyObject_MALLOC.
PyObject_Del and PyObject_GC_Del can now be used as a function
designators.
2002-04-12 03:06:53 +00:00
Neil Schemenauer 626d774df6 PyObject_GC_Del can now be used as a function designator. 2002-04-12 03:05:52 +00:00
Neil Schemenauer 7465ad2fc9 Remove PyMalloc_New and PyMalloc_Del. 2002-04-12 03:05:37 +00:00
Neil Schemenauer 510492e985 Remove PyMalloc_New, _PyMalloc_MALLOC, and PyMalloc_Del. 2002-04-12 03:05:19 +00:00
Neil Schemenauer 9acae5a0a6 Remove PyMalloc_New and PyMalloc_Del. 2002-04-12 02:44:55 +00:00
Neil Schemenauer 99b5d28467 PyObject_GC_Del can now be used as a function designator. 2002-04-12 02:44:22 +00:00
Neil Schemenauer aa769ae468 PyObject_Del can now be used as a function designator. 2002-04-12 02:44:10 +00:00
Neil Schemenauer 6189b89cc5 PyObject_GC_Del and PyObject_Del can now be used as a function
designators.

Remove PyMalloc_New.
2002-04-12 02:43:00 +00:00
Tim Peters 52aefc8a7b SF bug 542181: Realloc behavior
The bug report pointed out a bogosity in the comment block explaining
thread safety for arena management.  Repaired that comment, repaired a
couple others while I was at it, and added an assert.

_PyMalloc_DebugRealloc:  If this needed to get more memory, but couldn't,
it erroneously freed the original memory.  Repaired that.

This is for 2.3 only (unless we decide to backport the new pymalloc).
2002-04-11 06:36:45 +00:00
Marc-André Lemburg 68e69338ae Bug fix for UTF-8 encoding bug (buffer overrun) #541828. 2002-04-10 20:36:13 +00:00
Marc-André Lemburg ce0b664af2 Added test case for UTF-8 encoding bug #541828. 2002-04-10 17:18:02 +00:00
Tim Peters 2ea9111cf1 SF bug 538827: Python open w/ MSVC6: bad error msgs.
open_the_file:  Some (not all) flavors of Windows set errno to EINVAL
when passed a syntactically invalid filename.  Python turned that into an
incomprehensible complaint about the mode string.  Fixed by special-casing
MSVC.
2002-04-08 04:13:12 +00:00
Guido van Rossum 0986d8250f - A type can now inherit its metatype from its base type. Previously,
when PyType_Ready() was called, if ob_type was found to be NULL, it
  was always set to &PyType_Type; now it is set to base->ob_type,
  where base is tp_base, defaulting to &PyObject_Type.

- PyType_Ready() accidentally did not inherit tp_is_gc; now it does.

Bugfix candidate.
2002-04-08 01:38:42 +00:00
Guido van Rossum 7f7666ff43 isatty() should return a bool. 2002-04-07 06:28:00 +00:00
Tim Peters 49f26817eb Minor improvements to the stats output dump, including adding commas to
the big numbers.
2002-04-06 01:45:35 +00:00
Guido van Rossum 8ace1ab53a - Changed new-style class instantiation so that when C's __new__
method returns something that's not a C instance, its __init__ is
  not called.  [SF bug #537450]
2002-04-06 01:05:01 +00:00
Guido van Rossum 6b8ab74c8a Don't inherit tp_new! This is a retraction of half of the previous
checkin.  And since that one was, this one is also a:

Bugfix candidate.
2002-04-05 22:04:18 +00:00
Guido van Rossum cc8fe0407a Inherit tp_new and tp_is_gc.
Bugfix candidate.
2002-04-05 17:10:16 +00:00
Tim Peters ffdd22f1af Repair an incomprehensible comment. 2002-04-05 06:24:54 +00:00
Tim Peters 16bcb6b1af _PyMalloc_DebugDumpStats(): vastly improved the output, and it now
accounts for every byte.
2002-04-05 05:45:31 +00:00
Tim Peters e70ddf3a99 Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
runtime multiplications and divisions, via the scheme developed with
Vladimir Marangozov on Python-Dev.  The pool_header struct loses its
capacity member, but gains nextoffset and maxnextoffset members; this
still leaves it at 32 bytes on a 32-bit box (it has to be padded to a
multiple of 8 bytes).
2002-04-05 04:32:29 +00:00
Guido van Rossum c334df5727 A much revised version of SF patch 514662, by Naofumi Honda. This
speeds up __getitem__ and __setitem__ in subclasses of built-in
sequences.

It's much revised because I took the opportunity to refactor the code
somewhat (moving a large section of duplicated code to a helper
function) and added comments to a series of functions.
2002-04-04 23:44:47 +00:00
Guido van Rossum bfc2e5ee8e Clarifying code rearrangement and comments by David Abrahams. I've
got to admit that I haven't reviewed this carefully, but it looks okay
from 30,000 views, and doesn't break anything.  (SF patch 536407.)
2002-04-04 17:50:54 +00:00
Tim Peters b7265dbe3e _PyMalloc_Realloc(): removed a now-pointless cast. 2002-04-04 05:08:31 +00:00
Tim Peters 84c1b97467 _PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
what these do given a 0 size argument.  This is so that when pymalloc
is enabled, we don't need to wrap pymalloc calls in goofy little
routines special-casing 0.  Note that it's virtually impossible to meet
the doc's promise that malloc(0) will never return NULL; this makes a
best effort, but not an insane effort.  The code does promise that
realloc(not-NULL, 0) will never return NULL (malloc(0) is much harder).

_PyMalloc_Realloc:  Changed to take over all requests for 0 bytes, and
rearranged to be a little quicker in expected cases.

All over the place:  when resorting to the platform allocator, call
free/malloc/realloc directly, without indirecting thru macros.  This
should avoid needing a nightmarish pile of #ifdef-ery if PYMALLOC_DEBUG
is changed so that pymalloc takes over all Py(Mem, Object} memory
operations (which would add useful debugging info to PyMem_xyz
allocations too).
2002-04-04 04:44:32 +00:00
Guido van Rossum 645a22e007 As Neal pointed out, bool_print was an order of magnitude too complex. 2002-04-04 01:00:42 +00:00
Guido van Rossum 5f8203679d Oops. Here are the new files. My apologies. 2002-04-03 23:01:45 +00:00
Guido van Rossum 77f6a65eb0 Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285.  Everything described in the PEP is here, and there is even
some documentation.  I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison.  I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.

Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
2002-04-03 22:41:51 +00:00
Fred Drake cd874edaaa Fix the names of the classmethod and staticmethod constructors as passed to
PyArg_ParseTuple() as part of the format string.
2002-04-03 21:42:45 +00:00
Guido van Rossum d464107ecf Fold some long lines. Delete blank initial line. 2002-04-03 02:13:37 +00:00
Guido van Rossum 155db9aa22 SF patch 537536 by Phillip J. Eby, fix for SF bug 535444, super()
broken w/ classmethods.

Bugfix candidate.
2002-04-02 17:53:47 +00:00
Tim Peters 6169f09d64 Fixed errors in two comments. 2002-04-01 20:12:59 +00:00
Tim Peters 338e010b45 Restructured my pool-management overview in terms of the three
possible pool states.  I think it's much clearer now.

Added a new long overdue block-management overview comment block.

I believe the comments are in good shape now.

Added two comments about possible small optimizations (one getting rid
of runtime multiplications at the cost of a new pool_header member; the
other getting rid of runtime divisions and the pool_header capacity
member, at the cost of a static const vector of 32 uints).
2002-04-01 19:23:44 +00:00
Tim Peters 7ccfadf3a8 New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
This displays stats about the # of arenas, pools, blocks and bytes, to
stderr, both used and reserved but unused.

CAUTION:  Because PYMALLOC_DEBUG is on, the debug malloc routine adds
16 bytes to each request.  This makes each block appear two size classes
higher than it would be if PYMALLOC_DEBUG weren't on.

So far, playing with this confirms the obvious:  there's a lot of activity
in the "small dict" size class, but nothing in the core makes any use of
the 8-byte or 16-byte classes.
2002-04-01 06:04:21 +00:00
Neal Norwitz 62f5a9d6c2 Convert file.readinto() to stop using METH_OLDARGS & PyArg_Parse.
Add test for file.readinto().
2002-04-01 00:09:00 +00:00
Neal Norwitz 93c1e23667 Use METH_VARARGS rather than METH_OLDARGS implicitly (args are ignored) 2002-03-31 16:06:11 +00:00
Tim Peters 57b17ad6ae Add one more assert that indirectly interlocking conditions are consistent
with each other.
2002-03-31 02:59:48 +00:00
Tim Peters 4c5be0ce09 Fixed an error in a new assert. 2002-03-31 02:52:29 +00:00
Tim Peters b1da050131 Fixed a typo in a new comment. 2002-03-31 02:51:40 +00:00
Tim Peters 2c95c99a64 _PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
the code so that the most frequent cases come first.  Added comments.
Found a hidden assumption that a pool contains room for at least two
blocks, and added an assert to catch a violation if it ever happens in
a place where that matters.  Gave the normal "I allocated this block"
case a longer basic block to work with before it has to do its first
branch (via breaking apart an embedded assignment in an "if", and
hoisting common code out of both branches).
2002-03-31 02:18:01 +00:00
Tim Peters 1e16db6d3b Added a long-overdue comment block giving an overview of pool operations
and terminology, plus explanation of some extreme obscurities.
2002-03-31 01:05:22 +00:00
Tim Peters c2ce91af5f It's once again thought safe to call the pymalloc free/realloc with an
address obtained from system malloc/realloc without holding the GIL.

When the vector of arena base addresses has to grow, the old vector is
deliberately leaked.  This makes "stale" x-thread references safe.
arenas and narenas are also declared volatile, and changed in an order
that prevents a thread from picking up a value of narenas too large
for the value of arenas it sees.

Added more asserts.

Fixed an old inaccurate comment.

Added a comment explaining why it's safe to call pymalloc free/realloc
with an address obtained from system malloc/realloc even when arenas is
still NULL (this is obscure, since the ADDRESS_IN_RANGE macro
appears <wink> to index into arenas).
2002-03-30 21:36:04 +00:00