fix python3.8+ use py_ssize_t type

This commit is contained in:
wu-leilei 2022-05-07 11:10:22 +08:00
parent bc3a40e95d
commit d34faabadd
2 changed files with 110 additions and 2 deletions

View File

@ -0,0 +1,102 @@
From 8242ae139f70a228bbcd8e7ca28f235ec0654180 Mon Sep 17 00:00:00 2001
From: Sergey Dryabzhinsky <sergey.dryabzhinsky@gmail.com>
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 <stdlib.h>
#include <stddef.h>
+
+/* Since 3.8 it is mandatory to use proper type for # formats */
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
+
#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

View File

@ -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 <wulei80@h-partners.com> 1.4.8.1-2
- Fix python3.8+ use py_ssize_t type
* Tue Feb 23 2021 wangxiyuan <wangxiyuan1007@gmail.com>
- Package Spec Init