cpython/Misc
Tim Peters f6b8045ca5 Reworked has_finalizer() to use the new _PyObject_Lookup() instead
of PyObject_HasAttr(); the former promises never to execute
arbitrary Python code.  Undid many of the changes recently made to
worm around the worst consequences of that PyObject_HasAttr() could
execute arbitrary Python code.

Compatibility is hard to discuss, because the dangerous cases are
so perverse, and much of this appears to rely on implementation
accidents.

To start with, using hasattr() to check for __del__ wasn't only
dangerous, in some cases it was wrong:  if an instance of an old-
style class didn't have "__del__" in its instance dict or in any
base class dict, but a getattr hook said __del__ existed, then
hasattr() said "yes, this object has a __del__".  But
instance_dealloc() ignores the possibility of getattr hooks when
looking for a __del__, so while object.__del__ succeeds, no
__del__ method is called when the object is deleted.  gc was
therefore incorrect in believing that the object had a finalizer.

The new method doesn't suffer that problem (like instance_dealloc(),
_PyObject_Lookup() doesn't believe __del__ exists in that case), but
does suffer a somewhat opposite-- and even more obscure --oddity:
if an instance of an old-style class doesn't have "__del__" in its
instance dict, and a base class does have "__del__" in its dict,
and the first base class with a "__del__" associates it with a
descriptor (an object with a __get__ method), *and* if that
descriptor raises an exception when __get__ is called, then
(a) the current method believes the instance does have a __del__,
but (b) hasattr() does not believe the instance has a __del__.

While these disagree, I believe the new method is "more correct":
because the descriptor *will* be called when the object is
destructed, it can execute arbitrary Python code at the time the
object is destructed, and that's really what gc means by "has a
finalizer":  not specifically a __del__ method, but more generally
the possibility of executing arbitrary Python code at object
destruction time.  Code in a descriptor's __get__() executed at
destruction time can be just as problematic as code in a
__del__() executed then.

So I believe the new method is better on all counts.

Bugfix candidate, but it's unclear to me how all this differs in
the 2.2 branch (e.g., new-style and old-style classes already
took different gc paths in 2.3 before this last round of patches,
but don't in the 2.2 branch).
2003-04-07 19:21:15 +00:00
..
RPM 2.3b1 patches 2003-02-24 17:55:37 +00:00
ACKS Frank Vercruesse gave an okay on removing the copyright notice: 2003-03-25 10:20:55 +00:00
AIX-NOTES Add some notes that got python to work on the snake farm 2003-02-02 17:10:04 +00:00
BeOS-NOTES Completely revamped BeOS notes, by Donn Cave (SF patch 411834). 2001-04-10 21:51:29 +00:00
BeOS-setup.py SF patch 568629 by Oren Tirosh: types made callable. 2002-06-14 20:41:17 +00:00
cheatsheet Part 3 of Py2.3 update 2003-01-26 03:29:15 +00:00
find_recursionlimit.py script that reports a fairly safe recursionlimit for a specific platform 2000-08-31 19:24:17 +00:00
gdbinit PyObject_Dump() -> _PyObject_Dump() 2001-01-24 04:18:13 +00:00
HISTORY migrate news about 2.1 and earlier releases from NEWS to HISTORY in 2002-09-17 20:55:31 +00:00
indent.pro
NEWS Reworked has_finalizer() to use the new _PyObject_Lookup() instead 2003-04-07 19:21:15 +00:00
NEWS.help Updated (2.3 OK now) 2003-01-03 03:29:58 +00:00
Porting Patch #411138: Rename config.h to pyconfig.h. Closes bug #231774. 2001-07-26 13:41:06 +00:00
PURIFY.README Updated for Python 1.5, including my experiences with Purify on 1997-10-07 15:50:58 +00:00
pymemcompat.h Fix grammatically inept comment. 2002-08-22 13:36:11 +00:00
python-mode.el py-pdbtrack-grub-for-buffer(): Rectified some logic errors i 2003-03-03 17:09:44 +00:00
python.man Document that -u puts stdin, stdout, and stderr in binary mode. 2002-08-09 13:37:31 +00:00
README Note the existence of SpecialBuilds.txt. 2002-07-11 01:01:49 +00:00
RFD
setuid-prog.c correct bogus instructions 'ccoment out' -> 'uncomment' 1998-09-10 20:18:09 +00:00
SpecialBuilds.txt When Py_TRACE_REFS is defined, a list of all live objects is maintained in 2003-03-23 02:51:01 +00:00
vgrindefs Add 'yield' as a keyword 2001-08-06 17:42:53 +00:00

Python Misc subdirectory
========================

This directory contains files that wouldn't fit in elsewhere.  Some
documents are only of historic importance.

Files found here
----------------

ACKS		Acknowledgements
AIX-NOTES	Notes for building Python on AIX
BeOS-NOTES	Notes for building on BeOS
BeOS-setup.py	setup.py replacement for BeOS, see BeOS-NOTES
cheatsheet	Quick summary of Python by Ken Manheimer
find_recursionlimit.py  Script to find a value for sys.maxrecursionlimit
gdbinit		Handy stuff to put in your .gdbinit file, if you use gdb
HISTORY		News from previous releases -- oldest last
HPUX-NOTES	Notes about dynamic loading under HP-UX
indent.pro	GNU indent profile approximating my C style
NEWS		News for this release (for some meaning of "this")
Porting		Mini-FAQ on porting to new platforms
PURIFY.README	Information for Purify users
python.man	UNIX man page for the python interpreter
python-mode.el	Emacs mode for editing Python programs
README		The file you're reading now
RFD		Request For Discussion about a Python newsgroup
RPM		(Old) tools to build RPMs
SpecialBuilds.txt     Describes extra symbols you can set for debug builds
setuid-prog.c	C helper program for set-uid Python scripts
vgrindefs	Python configuration for vgrind (a generic pretty printer)