Open SnarkBoojum opened 9 months ago
There seems to be a conflict between Cython < 3 and Cython 3 on how this function should be declared:
I have no good idea how to handle this? Anyone got any ideas?
Well, Debian wants to package a newer version of cython -- that's why I'm looking into this. That might get around the issue...
@malb The issue is that the cdef public...
function declaration introduces a definition (and hence also a declaration) into the program from the perspective of the C++ compiler (this is basically why we get the "duplicate declaration" error in the logs above: it's already declared). Looking at the error logs, it looks like this used to be a C declaration, but now (for some reason) it's a C++ declaration, and so they don't always line up correctly. For example, if I extract everything out into its own file, I get:
// callback_func.h
#ifdef CYTHON_EXTERN_C
#undef __PYX_EXTERN_C
#define __PYX_EXTERN_C CYTHON_EXTERN_C
#elif defined(__PYX_EXTERN_C)
#ifdef _MSC_VER
#pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
#else
#warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
#endif
#else
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#endif
__PYX_EXTERN_C bool evaluator_callback_call_obj(PyObject *, int, double *);
I think the best thing to do is just to extract the callback function into its own .pyx
file:
# callback_func.pyx
from libcpp cimport bool
cdef public bool evaluator_callback_call_obj(obj, int n, double *new_sol_coord):
cdef list new_sol_coord_ = []
for i in range(n):
new_sol_coord_.append(new_sol_coord[i])
return obj(new_sol_coord_);
And then just include the resulting header in callback_helper.h
:
#include "callback_func.h"
This is basically what's described here.
That way, we don't need to worry about the linkage type, because it should always be correct. You might need to play around with the include paths, though, since callback_func.h
is auto-generated.
I wanted to update the Debian package for fpylll to the latest version because we want to transition to Python 3.12 ; unfortunately during the transition that means we compile for 3.11 and 3.12.
And with 3.11 I get a failure:
My first idea is "why two declarations?", but I haven't dug to see if that was indeed the problem.