Commit Graph

40 Commits

Author SHA1 Message Date
Antoine Pitrou c83ea137d7 Untabify C files. Will watch buildbots. 2010-05-09 14:46:46 +00:00
Benjamin Peterson dc3c239b1e #5037 proxy __unicode__ correctly 2009-11-19 03:00:02 +00:00
Benjamin Peterson 97179b0f58 Fix #3634 invalid return value from _weakref.ref(Exception).__init__
Reviewers: Amaury, Antoine, Benjamin
2008-09-09 20:55:01 +00:00
Amaury Forgeot d'Arc a8919fe631 Issue 3110: Crash with weakref subclass,
seen after a "import multiprocessing.reduction"

An instance of a weakref subclass can have attributes.
If such a weakref holds the only strong reference to the object,
deleting the weakref will delete the object. In this case,
the callback must not be called, because the ref object is being deleted!
2008-06-16 19:12:42 +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
Georg Brandl 88659b0ab2 #2592: delegate nb_index and the floor/truediv slots in weakref.proxy. 2008-05-20 08:40:43 +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
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
Brett Cannon f5bee30e30 Fix crasher for when an object's __del__ creates a new weakref to itself.
Patch only fixes new-style classes; classic classes still buggy.

Closes bug #1377858.  Already backported.
2007-01-23 23:21:22 +00:00
Neal Norwitz c5e060dee6 _PyWeakref_GetWeakrefCount() now returns a Py_ssize_t instead of long. 2006-08-02 06:14:22 +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 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
Georg Brandl 347b30042b Remove unnecessary casts in type object initializers. 2006-03-30 11:57:00 +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 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Neal Norwitz 0c6e2f1640 Remove some shadowed variables 2006-01-08 06:13:44 +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 e6c470f255 SF bug #1770766: weakref proxy has incorrect __nonzero__ behavior. 2005-03-27 03:04:54 +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
Fred Drake 6d3265dab6 Be more careful about maintaining the invariants; it was actually
possible that the callback-less flavors of the ref or proxy could have
been added during GC, so we don't want to replace them.
2004-08-03 14:47:25 +00:00
Neal Norwitz bdcb9410c2 SF bug #978308, Spurious errors taking bool of dead pro
Need to return -1 on error.

Needs backport.
2004-07-08 01:22:31 +00:00
Fred Drake 0a4dd390bf Make weak references subclassable:
- weakref.ref and weakref.ReferenceType will become aliases for each
  other

- weakref.ref will be a modern, new-style class with proper __new__
  and __init__ methods

- weakref.WeakValueDictionary will have a lighter memory footprint,
  using a new weakref.ref subclass to associate the key with the
  value, allowing us to have only a single object of overhead for each
  dictionary entry (currently, there are 3 objects of overhead per
  entry: a weakref to the value, a weakref to the dictionary, and a
  function object used as a weakref callback; the weakref to the
  dictionary could be avoided without this change)

- a new macro, PyWeakref_CheckRefExact(), will be added

- PyWeakref_CheckRef() will check for subclasses of weakref.ref

This closes SF patch #983019.
2004-07-02 18:57:45 +00:00
Fred Drake bc875f5a36 Allocating a new weakref object can cause existing weakref objects for
the same object to be collected by the cyclic GC support if they are
only referenced by a cycle.  If the weakref being collected was one of
the weakrefs without callbacks, some local variables for the
constructor became invalid and have to be re-computed.

The test caused a segfault under a debug build without the fix applied.
2004-02-04 23:14:14 +00:00
Fred Drake 6a2852cd48 Fix bug in interpretation of the "callback" argument in the constructors for
weakref ref and proxy objects; None was not being treated as identical to
NULL, though it was documented as equivalent.
2004-02-03 19:52:56 +00:00
Tim Peters 403a203223 SF bug 839548: Bug in type's GC handling causes segfaults.
Also SF patch 843455.

This is a critical bugfix.
I'll backport to 2.3 maint, but not beyond that.  The bugs this fixes
have been there since weakrefs were introduced.
2003-11-20 21:21:46 +00:00
Fred Drake fe89cc186c Remove proxy_print(), since that caused an inconsistency between
"print repr(proxy(a))" and "proxy(a)" at an interactive prompt.
Closes SF bug #722763.
2003-07-14 21:46:23 +00:00
Raymond Hettinger d693a81595 Fix SF 762891: "del p[key]" on proxy object raises SystemError() 2003-06-30 04:18:48 +00:00
Guido van Rossum c1f6e8cbc1 - The repr() of a weakref object now shows the __name__ attribute of
the referenced object, if it has one.

Also use %p to format pointers consistently, and use <weakproxy ...>
in proxy_repr(), to match the type name.
2003-04-16 21:13:23 +00:00
Fred Drake f16c3dc81b Add support for the iterator protocol to weakref proxy objects.
Part of fixing SF bug #591704.
2002-08-09 18:34:16 +00:00
Neil Schemenauer 38a8916134 Remove weakref free list. This has the side effect of fixing a memory
management bug.  Also, move some duplicated code into the new_weakref
fucntion.
2002-03-27 15:18:21 +00:00
Fred Drake 2a908f6b7b proxy_compare(): Make sure that we unwrap both objects being compared if
both are proxy objects.
2001-12-19 16:44:30 +00:00
Fred Drake ef8ebd1e74 Make sure that when we invoke callback functions associated with weak
references, we do not allow any outstanding exceptions "leak" into the
callback's execution state.
This closes SF bug #478534.
2001-12-10 23:44:54 +00:00
Barry Warsaw d586756dc5 weakref_repr(), proxy_repr(): Conversion of sprintf() to
PyOS_snprintf() for buffer overrun avoidance.
2001-11-28 21:01:56 +00:00
Marc-André Lemburg d4c0a9c59b Fixes for possible buffer overflows in sprintf() usages. 2001-11-28 11:47:00 +00:00
Jeremy Hylton 996fad315c Referencable is not a word, so don't use it in an error message <wink>. 2001-10-22 16:31:40 +00:00
Fred Drake 31f4d1fa4b Remove an unnecessary check for NULL. 2001-10-18 19:21:46 +00:00
Fred Drake 73006d0237 When weakref proxies are involved in binary & ternary slot operations,
the left-hand operand may not be the proxy in all cases.  If it isn't,
we end up doing two things: a) unwrapping something that isn't a
PyWeakReference (later resulting in a core dump) and b) passing a
proxy as the right-hand operand anyway, even though that can't be
handled by the actual handler (maybe eventually causing a core dump).

This is fixed by always unwrapping all the proxies involved before
passing anything to the actual handler.
2001-10-18 18:04:18 +00:00
Fred Drake 8844d5264f The weak reference implementation, separated from the weakref module. 2001-10-05 21:52:26 +00:00