Commit Graph

301 Commits

Author SHA1 Message Date
Armin Rigo 51fc8c456e Fix and test for an infinite C recursion. 2006-08-09 14:55:26 +00:00
Martin v. Löwis ab2f8f7bd5 __hash__ may now return long int; the final hash
value is obtained by invoking hash on the long int.
Fixes #1536021.
2006-08-09 07:57:39 +00:00
Fred Drake 7a36f5f344 SF patch #1534048 (bug #1531003): fix typo in error message 2006-08-04 05:17:21 +00:00
Neal Norwitz e1fdb32ff2 Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
2006-07-21 05:32:28 +00:00
Neal Norwitz b114984225 Fix refleak 2006-06-23 03:32:44 +00:00
Armin Rigo 53c1692f6a Fix for an obscure bug introduced by revs 46806 and 46808, with a test.
The problem of checking too eagerly for recursive calls is the
following: if a RuntimeError is caused by recursion, and if code needs
to normalize it immediately (as in the 2nd test), then
PyErr_NormalizeException() needs a call to the RuntimeError class to
instantiate it, and this hits the recursion limit again...  causing
PyErr_NormalizeException() to never finish.

Moved this particular recursion check to slot_tp_call(), which is not
involved in instantiating built-in exceptions.

Backport candidate.
2006-06-21 21:58:50 +00:00
Georg Brandl ccff785258 Patch #1507676: improve exception messages in abstract.c, object.c and typeobject.c. 2006-06-18 22:17:29 +00:00
Georg Brandl 684fd0c8ec Replace PyObject_CallFunction calls with only object args
with PyObject_CallFunctionObjArgs, which is 30% faster.
2006-05-25 19:15:31 +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
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
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 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 ee36d650bb Correct casts to char*. 2006-04-11 09:08:02 +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
Armin Rigo 314861c568 Minor bugs in the __index__ code (PEP 357), with tests. 2006-03-30 14:04:02 +00:00
Georg Brandl 347b30042b Remove unnecessary casts in type object initializers. 2006-03-30 11:57:00 +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 692cdbc5d6 Fix three nits found by Coverity, adding null checks and comments. 2006-03-10 02:04:28 +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 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
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +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 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 2c95cc6d72 Support %zd in PyErr_Format and PyString_FromFormat. 2006-02-16 06:54:25 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Neal Norwitz 50bf51a3a9 Fix ref/memory leak introduced in rev 41845. 2006-01-02 02:46:54 +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
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
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
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
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
Anthony Baxter 5661699995 fix object.__divmod__.__doc__
backport candidate
2005-06-03 14:12:21 +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 b67cc80bb9 SF bug #1155938: Missing None check for __init__(). 2005-03-03 16:45:19 +00:00
Tim Peters f4aca755bc A static swapped_op[] array was defined in 3 different C files, & I think
I need to define it again.  Bite the bullet and define it once as an
extern, _Py_SwappedOp[].
2004-09-23 02:39:37 +00:00
Martin v. Löwis bf608750ad Patch #980082: Missing INCREF in PyType_Ready. 2004-08-18 13:16:54 +00:00
Michael W. Hudson 3f3b66823f Repair the same thinko in two places about handling of _Py_RefTotal in
the case of __del__ resurrecting an object.
This makes the apparent reference leaks in test_descr go away (which I
expected) and also kills off those in test_gc (which is more surprising
but less so once you actually think about it a bit).
2004-08-03 10:21:03 +00:00
Raymond Hettinger 8d726eef96 Cosmetic spacing fix. 2004-06-25 22:24:35 +00:00
Raymond Hettinger d56cbe57b8 Fix leak found by Eric Huss. 2004-06-25 22:17:39 +00:00
Anthony Baxter 3ecdb250af Fix for bug #966623 - classes created with type() in an exec(, {}) don't
have a __module__. Test for this case.

Bugfix candidate, will backport.
2004-06-11 14:41:18 +00:00
Hye-Shik Chang ff365c931b Get rid of gcc warning. 2004-03-25 16:37:03 +00:00
Phillip J. Eby 91a968af76 Ensure super() lookup of descriptor from classmethod works (SF #743627) 2004-03-25 02:19:34 +00:00
Jim Fulton 8a1a594590 Fixed a bug in object.__reduce_ex__ (reduce_2) when using protocol
2.  Failure to clear the error when attempts to get the __getstate__
  attribute fail caused intermittent errors and odd behavior.
2004-02-08 04:21:26 +00:00
Raymond Hettinger 6a8bbdbe7b Improve argument checking speed. 2003-12-13 15:21:55 +00:00
Raymond Hettinger 8f5cdaa784 * Added a new method flag, METH_COEXIST.
* Used the flag to optimize set.__contains__(), dict.__contains__(),
  dict.__getitem__(), and list.__getitem__().
2003-12-13 11:26:12 +00:00
Tim Peters 0bd743cee1 subtype_dealloc(): Simplified overly contorted retracking logic. With
this change, I think subtype_dealloc is actually a smidgen less obscure
than it was in 2.3 -- we got rid of a negation in an "if" <wink>.
2003-11-13 22:50:00 +00:00
Tim Peters f7f9e9966b subtype_dealloc(): A more complete fix for critical bug 840829 +
expanded the test case with a piece that needs the more-complete fix.

I'll backport this to 2.3 maint.
2003-11-13 21:59:32 +00:00
Tim Peters add09b4149 SF bug 840829: weakref callbacks and gc corrupt memory.
subtype_dealloc():  This left the dying object exposed to gc, so that
if cyclic gc triggered during the weakref callback, gc tried to delete
the dying object a second time.  That's a disaster.  subtype_dealloc()
had a (I hope!) unique problem here, as every normal dealloc routine
untracks the object (from gc) before fiddling with weakrefs etc.  But
subtype_dealloc has obscure technical reasons for re-registering the
dying object with gc (already explained in a large comment block at
the bottom of the function).

The fix amounts to simply refraining from reregistering the dying object
with gc until after the weakref callback (if any) has been called.

This is a critical bug (hard to predict, and causes seemingly random
memory corruption when it occurs).  I'll backport it to 2.3 later.
2003-11-12 20:43:28 +00:00