#include "Python.h" #include "stdio.h" int main() { // Start Python. Py_Initialize(); // Get the builtins module. PyObject* builtins = PyImport_ImportModule("builtins"); if (builtins == NULL) { fprintf(stderr, "Could not load the built-ins module.\n"); return -1; } // Get 'super' from the builtins. PyObject* super = PyObject_GetAttrString(builtins, "super"); if (super == NULL) { fprintf(stderr, "No attribute super.\n"); return -1; } Py_DECREF(builtins); // Invoke super with no arguments. // Empty tuple for args // Empty dict for kwargs PyObject* args = PyTuple_New(0); if (args == NULL) { fprintf(stderr, "Error creating empty tuple.\n"); return -1; } PyObject* kwargs = PyDict_New(); if (kwargs == NULL) { fprintf(stderr, "Error creating empty dict.\n"); return -1; } fprintf(stdout, "Call super with no arguments...\n"); PyObject* result = PyObject_Call(super, args, kwargs); fprintf(stdout, "Call has finished.\n"); // clean-up Py_XDECREF(super); Py_XDECREF(args); Py_XDECREF(kwargs); // The call should have failed. // The result from invoking super should be null. if (result != NULL) { fprintf(stdout, "The call to super with no arguments succeeded.\n"); Py_DECREF(result); } // Stop Python. Py_Finalize(); return 0; }