0

Trying to harness the feature of public functions and classes in cython I immediately ran into a problem with simplest things. Two days of googling and reading the forums yielded no result. Documentation says kinda: "just use it, and it will work". Ok.

public.pxd:

# cython: language_level=3

public.pyx:

cdef public void Qu():
    print("Qu!")

public_c.c:

#include <Python.h>
#include "public.h"

int main() {
    Py_Initialize();
    PyInit_public();

    printf("Init\n");

    Qu();

    printf("Finalize\n");

    Py_Finalize();
}

compile.sh:

#!/bin/bash

cython public.pyx
gcc -fPIC $(python3-config --cflags) -c public.c -o public.o
gcc -fPIC $(python3-config --cflags) -c public_c.c -o public_c.o
gcc public_c.o public.o $(python3-config --ldflags) -lpython3.9 -o public_c

No errors or warnings during compilation. Cython generated .c and .h files look ok. But...

$ ./public_c
Init
Segmentation fault

Even this simplest try fails. What am I doing wrong?

m0Ray
  • 1
  • Documentation says "In Python 3.x, calling the module init function directly should be avoided" and recommends the initab mechanism – DavidW Jun 23 '22 at 17:59
  • Thanks. I missed that part of documentation. Inittab procedure solved the problem. – m0Ray Jun 24 '22 at 19:00

0 Answers0