Change cypclass reference counting convention
This changes the reference counting convention for passing cyobjects as arguments in a function call. Before this commit, cyobjects used the same convention as pyobjects: - The function borrows a reference on the argument from the caller and the caller keeps ownership of the object passed as argument, and must eventually decref it, even if it is a temporary rvalue that will not be reachable in the caller's scope after the call. - If the function needs to take ownership of the argument, e.g. to store it, it must increment its reference count first, at which point the caller and callee both own a reference to the object. - If the callee does not take ownership of the argument, it should not decrement its reference count at any point. After this commit, the convention for cyobjects is as follows: - The function steals the reference on the argument from the caller, and the caller should not decrement its reference count after the call. - If the object will still be reachable in the caller's scope after the call the caller must increment its reference count __before__ the call to retain ownership of its reference after the call. - The function has ownership of the reference received as argument, and must decref it when if goes out of scope. The main reason for this change is to make it possible to 'consume' an argument from within a function. Before this change there was no reliable way to determine from within the function whether the caller would retain a reference on the argument after the call, which is required when the 'consume' operation needs a runtime check. The 'self' argument in a cypclass method is currently still an exception to this change: it still follows the previous convention.
Showing with 110 additions and 85 deletions