2

I have a really simple cython code, built with python3

python3 setup.py build_ext
cpdef public int say_hello ():
    print("HELLO")
    return 1


Which I call in a C program

#include <Python.h>

Py_Initialize();
PyInit_libwrapper();
int ok = say_hello();


Here's the error i get

#0  0x00007fffeabebb52 in PyTuple_Pack () at /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#1  0x00007fffea7eb8f1 in __Pyx_PrintOne (stream=0x0, o=<optimized out>) at code/cython/wrapper.c:2123
#2  0x00007fffea7eb8f1 in say_hello (__pyx_skip_dispatch=<optimized out>) at code/cython/wrapper.c:1114


If I don't call print function everything works fine, and also if I use python2 (as follows) everything works fine

python2 setup.py build_ext
#include <python2.7/Python.h>

Py_Initialize();
initlibwrapper();
int ok = say_hello();


Where's the problem?

EDIT:
Adding the comment

#cython: language_level=3

I get a different error

say_hello (__pyx_skip_dispatch=0) at code/cython/wrapper.c:1106
1106      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
(gdb) bt
#0  0x00007fffea7eb8cc in say_hello (__pyx_skip_dispatch=0) at code/cython/wrapper.c:1106
user10207893
  • 243
  • 1
  • 2
  • 11

0 Answers0