Is one correct in stating the following:
- If a Python object is created in a C function, but the function doesn't return it, no - INCREFis needed, but a- DECREFis.
- [false]If the function does return it, you do need to - INCREF, in the function that receives the return value.[/false]
- When assigning C typed variables as attributes, like - double,- intetc., to the Python object, no- INCREFor- DECREFis needed.
- Is the following safe to use? Assigning Python objects as attributes to your other Python objects goes like this: - PyObject *foo; foo = bar; // A Python object tmp = self->foo; Py_INCREF(foo); self->foo = foo; Py_XDECREF(tmp); // taken from the manual, but it is unclear if this works in every situation
- Deallocation of a Python object needs to - DECREFfor every other Python object that it has as an attribute, but not for attributes that are C types.
EDIT:
With regards to 'C type as an attribute', I mean bar and baz:
typedef struct {
    PyObject_HEAD
    PyObject *foo;
    int bar;
    double baz;
} FooBarBaz;
 
     
    