File: issue_cpython.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (37 lines) | stat: -rw-r--r-- 857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

#include "test.h"

typedef struct { int dummy; } PyObject;

static inline void hmacmodule_clear(PyObject *mod) {
    (void)mod; 
    printf("hmacmodule_clear called\n");
}

static inline void hmacmodule_free(void *mod) {
    // call clear but cast to PyObject*
    (void)hmacmodule_clear((PyObject *)mod);
}

struct PyModuleDef {
    const char *m_name;
    int m_size;
    void (*m_traverse)(void);
    void (*m_clear)(void *);
    void (*m_free)(void *);
};

static struct PyModuleDef _hmacmodule = {
    .m_name = "_hmac",
    .m_size = sizeof(PyObject),
    .m_traverse = NULL,
    .m_clear = (void (*)(void *))hmacmodule_clear,
    .m_free = hmacmodule_free,  // <-- inline function assigned directly
};

int main() {
    PyObject obj;
    if (_hmacmodule.m_free)
        _hmacmodule.m_free(&obj);  // will try to call hmacmodule_free
    return 0;
}