diff --git a/setup/build.py b/setup/build.py index ce0a585996..bc49cb4303 100644 --- a/setup/build.py +++ b/setup/build.py @@ -162,7 +162,8 @@ def parse_extension(ext): def read_extensions(): if hasattr(read_extensions, 'extensions'): return read_extensions.extensions - ans = read_extensions.extensions = json.load(open(os.path.dirname(os.path.abspath(__file__)) + '/extensions.json', 'rb')) + with open(os.path.dirname(os.path.abspath(__file__)) + '/extensions.json', 'rb') as f: + ans = read_extensions.extensions = json.load(f) return ans diff --git a/src/calibre/db/sqlite_extension.cpp b/src/calibre/db/sqlite_extension.cpp index 7757de6142..660f6a6c7b 100644 --- a/src/calibre/db/sqlite_extension.cpp +++ b/src/calibre/db/sqlite_extension.cpp @@ -5,6 +5,7 @@ * Distributed under terms of the GPL3 license. */ +#define PY_SSIZE_T_CLEAN #define UNICODE #include #include @@ -482,7 +483,7 @@ py_callback(void *ctx, int flags, const char *text, int text_length, int start_o static PyObject* tokenize(PyObject *self, PyObject *args) { - const char *text; int text_length, remove_diacritics = 1, flags = FTS5_TOKENIZE_DOCUMENT; + const char *text; Py_ssize_t text_length, remove_diacritics = 1, flags = FTS5_TOKENIZE_DOCUMENT; if (!PyArg_ParseTuple(args, "s#|pi", &text, &text_length, &remove_diacritics, &flags)) return NULL; const char *targs[2] = {"remove_diacritics", "2"}; if (!remove_diacritics) targs[1] = "0"; @@ -495,7 +496,7 @@ tokenize(PyObject *self, PyObject *args) { static PyObject* stem(PyObject *self, PyObject *args) { - const char *text, *lang = "en"; int text_length; + const char *text, *lang = "en"; Py_ssize_t text_length; if (!PyArg_ParseTuple(args, "s#|s", &text, &text_length, &lang)) return NULL; Stemmer s(lang); if (!s) { @@ -504,8 +505,9 @@ stem(PyObject *self, PyObject *args) { } int sz; const char* result = s.stem(text, text_length, &sz); + Py_ssize_t a = sz; if (!result) return PyErr_NoMemory(); - return Py_BuildValue("s#", result, sz); + return Py_BuildValue("s#", result, a); } static PyMethodDef methods[] = {