Use Python memory allocation API correctly so that e.g. memory allocated by PyObject_New is deallocated by PyObject_Del. Also, use the function based API instead of the macros.