python-Levenshtein icon indicating copy to clipboard operation
python-Levenshtein copied to clipboard

Fixes needed in Termux

Open Manamama opened this issue 1 year ago • 1 comments

Quick FYI, that on Termux, Android this:

add_definitions(-D_GNU_SOURCE)
include(CheckIncludeFile)
check_include_file("limits.h" HAVE_LIMITS_H)
add_compile_definitions(-DSSIZE_MAX=9223372036854775807)

added to:

/data/data/com.termux/files/home/downloads/Levenshtein-0.24.0/src/Levenshtein

was needed to fix:

.0:23: error: 'SSIZE_MAX' was not declared in this scope; did you mean 'SIZE_MAX'?
 5750 |         if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos))
      |                       ^~~~~~~~~~~~~~
/data/data/com.termux/files/home/downloads/Levenshtein-0.24.0/src/Levenshtein/levenshtein_cpp.cxx:1456:43: note: in definition of macro 'unlikely'
 1456 |   #define unlikely(x) __builtin_expect(!!(x), 0)
      |                                           ^
/data/data/com.termux/files/home/downloads/Levenshtein-0.24.0/src/Levenshtein/levenshtein_cpp.cxx: In function 'Py_ssize_t __Pyx_ssize_strlen(const char*)':
/data/data/com.termux/files/home/downloads/Levenshtein-0.24.0/src/Levenshtein/levenshtein_cpp.cxx:9131:33: error: 'SSIZE_MAX' was not declared in this scope; did you mean 'SIZE_MAX'?
 9131 |     if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) {
      |                                 ^~~~~~~~~~~~~~
/data/data/com.termux/files/home/downloads/Levenshtein-0.24.0/src/Levenshtein/levenshtein_cpp.cxx:1456:43: note: in definition of macro 'unlikely'
 1456 |   #define unlikely(x) __builtin_expect(!!(x), 0)
      |                                           ^
make[2]: *** [src/Levenshtein/CMakeFiles/levenshtein_cpp.dir/build.make:76: src/Levenshtein/CMakeFiles/levenshtein_cpp.dir/levenshtein_cpp.cxx.o] Error 1

Manamama avatar Feb 11 '24 10:02 Manamama

I am honestly confused by this. This is something we pull in from CPython:

/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
 * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an
 * unsigned integral type).  See PEP 353 for details.
 * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
 */
#ifdef HAVE_PY_SSIZE_T

#elif HAVE_SSIZE_T
typedef ssize_t         Py_ssize_t;
#   define PY_SSIZE_T_MAX SSIZE_MAX
#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
typedef Py_intptr_t     Py_ssize_t;
#   define PY_SSIZE_T_MAX INTPTR_MAX
#else
#   error "Python needs a typedef for Py_ssize_t in pyport.h."
#endif

The error means that in you environment you have ssize_t but not SSIZE_MAX. Wouldn't this cause problems with virtually any compiled C module? To me this sounds very much like an issue with your / the termux environment.

Edit: I just gave this a test on termux on my Android phone. For me it appears to build fine. It fails to import due to some missing symbol in Cpython though. Maybe linked to it absolutely wanting to use the gold linker for some reason. Idk how to get rid of this behavior.

maxbachmann avatar Feb 11 '24 14:02 maxbachmann