I've written up the C level code for this PEP in a python pseudo code to hopefully make it more clear. I have left the explanations out to keep this shorter. Refer to the PEP for the explanations.
I will also post the python level code for the PEP as a separate post.
-bruce
------------- cut here -------------