-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Most of this is already in the devguide.
Rules for new API:
Function arguments
Functions must not steal references to their arguments.
IOW, after a function call, the caller still owns the arguments it passed in.
The caller must guarantee that references stay valid for the entire call.
Return values and "output parameters" (*result
)
Functions returning references must return a new reference.
IOW, after a function call, the caller owns (a reference to) the return value.
Same rules apply to filling an output parameter (*result
, #13).
Borrowed references
We're likely to have exceptions to these rules (#4) which create borrowed references.
These must be documented, and the documentation must explicitly state what the reference is borrowed "from" and how long it is valid for. (Even if it's like None
can be borrowed from the interpreter so it's valid until interpreter shutdown.)