1
#include <Python.h>
#include "structmember.h"

typedef struct {
    PyObject_HEAD
    PyObject *first; /* first name */
    PyObject *last;  /* last name */
    int number;
} Noddy;

static void
Noddy_dealloc(Noddy* self)
{
    Py_XDECREF(self->first);
    Py_XDECREF(self->last);
    Py_TYPE(self)->tp_free((PyObject*)self);
}

I am relatively new to building Python-C interface, so can someone please explain what Py_TYPE(self)->tp_free((PyObject*)self); does here?

Source: https://python.readthedocs.io/en/latest/extending/newtypes.html

yin
  • 97
  • 1
  • 4
  • That's not the actual Python docs site, by the way. You're looking at an outdated mirror. The actual docs are at docs.python.org. – user2357112 Apr 30 '20 at 19:22
  • Perhaps you don't know about [function pointers](https://www.geeksforgeeks.org/function-pointer-in-c/)? – MemReflect Apr 30 '20 at 23:34

0 Answers0