[Python-Dev] PySet API (original) (raw)
Alex Martelli aleaxit at gmail.com
Sun Mar 26 18:55:03 CEST 2006
- Previous message: [Python-Dev] PySet API
- Next message: [Python-Dev] PySet API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mar 26, 2006, at 8:43 AM, Raymond Hettinger wrote:
[Aahz]
Speaking as a person who does relatively little C programming, I don't see much difference between them. The first example is more Pythonic -- for Python. I agree with Barry that it's not much of a virtue for C code. It was a trick question. Everyone is supposed to be attracted to the next version because it is shorter, faster, and takes less ref counting management. However, the next version has a hard-to-find bug. The call to PyObjectHash() can trigger arbitrary Python code and possibly mutate the table, leaving pointers to invalid memory addresses. It would likely take Armin less than five minutes to write a pure Python crasher for the code. And THAT is why PySetNext() should never come into being.
Sure, accidentally mutating underlying iterables is a subtle (but
alas frequent) bug, but I don't see why it should be any harsher when
the loop is using a hypothetical PySet_Next than when it is using
PyIter_Next -- whatever precautions the latter takes to detect the
bug and raise an exception instead of crashing, wouldn't it be at
least as feasible for PySet_Next to take similar precautions
(probably easier, since PySet_Next need only worry about one concrete
case rather than an arbitrary variety)? What does PyDict_Next do in
similar cases, and why couldn't PySet_Next behave similarly? (Yes, I
could/should look it up myself, but I'm supposed to be working on the
2nd Ed of the Nutshell, whose deadline is getting worryingly
close...;-).
Alex
- Previous message: [Python-Dev] PySet API
- Next message: [Python-Dev] PySet API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]