From d34faabaddac959d1a613fcb89c85dda65bb4fdc Mon Sep 17 00:00:00 2001 From: wu-leilei Date: Sat, 7 May 2022 11:10:22 +0800 Subject: [PATCH] fix python3.8+ use py_ssize_t type --- fix-python3.8+-use-py_ssize_t-type.patch | 102 +++++++++++++++++++++++ python-zstd.spec | 10 ++- 2 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 fix-python3.8+-use-py_ssize_t-type.patch diff --git a/fix-python3.8+-use-py_ssize_t-type.patch b/fix-python3.8+-use-py_ssize_t-type.patch new file mode 100644 index 0000000..b3f1766 --- /dev/null +++ b/fix-python3.8+-use-py_ssize_t-type.patch @@ -0,0 +1,102 @@ +From 8242ae139f70a228bbcd8e7ca28f235ec0654180 Mon Sep 17 00:00:00 2001 +From: Sergey Dryabzhinsky +Date: Fri, 16 Apr 2021 21:40:23 +0300 +Subject: [PATCH] fix python3.8+ use py_ssize_t type + +--- + src/python-zstd.c | 23 ++++++++++++++--------- + 1 file changed, 14 insertions(+), 9 deletions(-) + +diff --git a/src/python-zstd.c b/src/python-zstd.c +index 1cf7b61..9ce1577 100644 +--- a/src/python-zstd.c ++++ b/src/python-zstd.c +@@ -29,13 +29,16 @@ + + #include + #include ++ ++/* Since 3.8 it is mandatory to use proper type for # formats */ ++#define PY_SSIZE_T_CLEAN + #include ++ + #include "bytesobject.h" + #include "zstd.h" + #include "util.h" + #include "python-zstd.h" + +- + /** + * New function for multi-threaded compression. + * Uses origin zstd header, nothing more. +@@ -47,12 +50,13 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args) + + PyObject *result; + const char *source; +- uint32_t source_size; ++ Py_ssize_t source_size; + char *dest; +- uint32_t dest_size; ++ Py_ssize_t dest_size; + size_t cSize; + int32_t level = ZSTD_CLEVEL_DEFAULT; + int32_t threads = 0; ++ ZSTD_CCtx* cctx = 0; + + #if PY_MAJOR_VERSION >= 3 + if (!PyArg_ParseTuple(args, "y#|ii", &source, &source_size, &level, &threads)) +@@ -87,7 +91,7 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args) + return NULL; + } + +- dest_size = ZSTD_compressBound(source_size); ++ dest_size = (Py_ssize_t)ZSTD_compressBound(source_size); + result = PyBytes_FromStringAndSize(NULL, dest_size); + if (result == NULL) { + return NULL; +@@ -96,12 +100,13 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args) + if (source_size > 0) { + dest = PyBytes_AS_STRING(result); + +- ZSTD_CCtx* cctx = ZSTD_createCCtx(); ++ cctx = ZSTD_createCCtx(); ++ + ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, level); + ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, threads); + + Py_BEGIN_ALLOW_THREADS +- cSize = ZSTD_compress2(cctx, dest, dest_size, source, source_size); ++ cSize = ZSTD_compress2(cctx, dest, (size_t)dest_size, source, (size_t)source_size); + Py_END_ALLOW_THREADS + + ZSTD_freeCCtx(cctx); +@@ -126,7 +131,7 @@ static PyObject *py_zstd_uncompress(PyObject* self, PyObject *args) + + PyObject *result; + const char *source; +- uint32_t source_size; ++ Py_ssize_t source_size; + uint64_t dest_size; + char error = 0; + size_t cSize; +@@ -233,7 +238,7 @@ static PyObject *py_zstd_compress_old(PyObject* self, PyObject *args) { + + PyObject *result; + const char *source; +- uint32_t source_size; ++ Py_ssize_t source_size; + char *dest; + uint32_t dest_size; + size_t cSize; +@@ -289,7 +294,7 @@ static PyObject *py_zstd_uncompress_old(PyObject* self, PyObject *args) { + + PyObject *result; + const char *source; +- uint32_t source_size; ++ Py_ssize_t source_size; + uint32_t dest_size; + size_t cSize; + +-- +2.27.0 + diff --git a/python-zstd.spec b/python-zstd.spec index ac8664d..712e8b6 100644 --- a/python-zstd.spec +++ b/python-zstd.spec @@ -1,11 +1,14 @@ Name: python-zstd Version: 1.4.8.1 -Release: 1 +Release: 2 Summary: ZSTD Bindings for Python License: BSD URL: https://github.com/sergey-dryabzhinsky/python-zstd Source0: https://files.pythonhosted.org/packages/92/bc/6bc155c61db55d5b3111a8afc76aaec084372bde89a82ecd4f5fd96c639a/zstd-1.4.8.1.tar.gz +# https://github.com/sergey-dryabzhinsky/python-zstd/commit/428a31edcde94d2908aa8ca3439ca01a797de3a4 +Patch1: fix-python3.8+-use-py_ssize_t-type.patch + BuildRequires: gcc BuildRequires: python3-devel BuildRequires: python3-setuptools @@ -22,7 +25,7 @@ Provides: python3-zstd Simple Python bindings for the Zstd compression library. %prep -%autosetup -n zstd-1.4.8.1 +%autosetup -n zstd-1.4.8.1 -p1 %build %py3_build @@ -39,6 +42,9 @@ Simple Python bindings for the Zstd compression library. %{python3_sitearch}/zstd*.so %changelog +* Sat May 07 2022 wulei 1.4.8.1-2 +- Fix python3.8+ use py_ssize_t type + * Tue Feb 23 2021 wangxiyuan - Package Spec Init