Skip to content

Commit 428a31e

Browse files
author
Sergey Dryabzhinsky
committed
New version 1.4.9.1
- fix python3.8+ warnings - use py_ssize_t type - update unittests - use os.environ everywhere
1 parent dacd5e6 commit 428a31e

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

PKG-INFO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Metadata-Version: 1.1
22
Name: zstd
3-
Version: 1.4.9.0
3+
Version: 1.4.9.1
44
Summary: Simple python bindings to Yann Collet ZSTD compression library
55
Home-page: https://github.com/sergey-dryabzhinsky/python-zstd
66
Author: Sergey Dryabzhinsky
77
Author-email: [email protected]
88
License: BSD
9-
Download-URL: https://github.com/sergey-dryabzhinsky/python-zstd/archive/v1.4.9.0.tar.gz
9+
Download-URL: https://github.com/sergey-dryabzhinsky/python-zstd/archive/v1.4.9.1.tar.gz
1010
Description: Simple ZSTandarD bindings for Python
1111
Keywords: zstd,zstandard,compression
1212
Platform: POSIX

setup.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Package version
1515
PKG_VERSION = VERSION
1616
# Minor versions
17-
PKG_VERSION += ("0",)
17+
PKG_VERSION += ("1",)
1818
PKG_VERSION_STR = ".".join([str(x) for x in PKG_VERSION])
1919

2020
###
@@ -161,20 +161,26 @@ def build_extensions(self):
161161
zstdFiles.append('src/util.c')
162162
zstdFiles.append('src/python-zstd.c')
163163

164-
# Python 2.6 compat
165-
os.environ["VERSION"] = VERSION_STR
166-
os.environ["PKG_VERSION"] = PKG_VERSION_STR
167-
if SUP_LEGACY:
168-
os.environ["LEGACY"] = "1"
169-
if SUP_EXTERNAL:
170-
os.environ["ZSTD_EXTERNAL"] = "1"
171-
if SUP_PYZSTD_LEGACY:
172-
os.environ["PYZSTD_LEGACY"] = "1"
164+
165+
def setup_env():
166+
# Python 2.6 compat
167+
os.environ["VERSION"] = VERSION_STR
168+
os.environ["PKG_VERSION"] = PKG_VERSION_STR
169+
os.environ["LEGACY"] = "0"
170+
os.environ["ZSTD_EXTERNAL"] = "0"
171+
os.environ["PYZSTD_LEGACY"] = "0"
172+
if SUP_LEGACY:
173+
os.environ["LEGACY"] = "1"
174+
if SUP_EXTERNAL:
175+
os.environ["ZSTD_EXTERNAL"] = "1"
176+
if SUP_PYZSTD_LEGACY:
177+
os.environ["PYZSTD_LEGACY"] = "1"
173178

174179
# Another dirty hack
175180
def my_test_suite():
176181
import unittest
177182

183+
setup_env()
178184
test_suite = unittest.TestSuite()
179185
for test in os.listdir('tests'):
180186
if test.startswith("test_") and test.endswith(".py"):

src/python-zstd.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929

3030
#include <stdlib.h>
3131
#include <stddef.h>
32+
33+
/* Since 3.8 it is mandatory to use proper type for # formats */
34+
#define PY_SSIZE_T_CLEAN
3235
#include <Python.h>
36+
3337
#include "bytesobject.h"
3438
#include "zstd.h"
3539
#include "util.h"
3640
#include "python-zstd.h"
3741

38-
3942
/**
4043
* New function for multi-threaded compression.
4144
* Uses origin zstd header, nothing more.
@@ -47,12 +50,13 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args)
4750

4851
PyObject *result;
4952
const char *source;
50-
uint32_t source_size;
53+
Py_ssize_t source_size;
5154
char *dest;
52-
uint32_t dest_size;
55+
Py_ssize_t dest_size;
5356
size_t cSize;
5457
int32_t level = ZSTD_CLEVEL_DEFAULT;
5558
int32_t threads = 0;
59+
ZSTD_CCtx* cctx = 0;
5660

5761
#if PY_MAJOR_VERSION >= 3
5862
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)
8791
return NULL;
8892
}
8993

90-
dest_size = ZSTD_compressBound(source_size);
94+
dest_size = (Py_ssize_t)ZSTD_compressBound(source_size);
9195
result = PyBytes_FromStringAndSize(NULL, dest_size);
9296
if (result == NULL) {
9397
return NULL;
@@ -96,12 +100,13 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args)
96100
if (source_size > 0) {
97101
dest = PyBytes_AS_STRING(result);
98102

99-
ZSTD_CCtx* cctx = ZSTD_createCCtx();
103+
cctx = ZSTD_createCCtx();
104+
100105
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, level);
101106
ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, threads);
102107

103108
Py_BEGIN_ALLOW_THREADS
104-
cSize = ZSTD_compress2(cctx, dest, dest_size, source, source_size);
109+
cSize = ZSTD_compress2(cctx, dest, (size_t)dest_size, source, (size_t)source_size);
105110
Py_END_ALLOW_THREADS
106111

107112
ZSTD_freeCCtx(cctx);
@@ -126,7 +131,7 @@ static PyObject *py_zstd_uncompress(PyObject* self, PyObject *args)
126131

127132
PyObject *result;
128133
const char *source;
129-
uint32_t source_size;
134+
Py_ssize_t source_size;
130135
uint64_t dest_size;
131136
char error = 0;
132137
size_t cSize;
@@ -233,7 +238,7 @@ static PyObject *py_zstd_compress_old(PyObject* self, PyObject *args) {
233238

234239
PyObject *result;
235240
const char *source;
236-
uint32_t source_size;
241+
Py_ssize_t source_size;
237242
char *dest;
238243
uint32_t dest_size;
239244
size_t cSize;
@@ -289,7 +294,7 @@ static PyObject *py_zstd_uncompress_old(PyObject* self, PyObject *args) {
289294

290295
PyObject *result;
291296
const char *source;
292-
uint32_t source_size;
297+
Py_ssize_t source_size;
293298
uint32_t dest_size;
294299
size_t cSize;
295300

tests/test_compress.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
class TestZSTD(BaseTestZSTD):
88

99
def setUp(self):
10-
if os.getenv("LEGACY"):
11-
self.LEGACY = True
12-
if os.getenv("PYZSTD_LEGACY"):
13-
self.PYZSTD_LEGACY = True
10+
self.LEGACY = os.environ["LEGACY"] == "1"
11+
self.PYZSTD_LEGACY = os.environ["PYZSTD_LEGACY"] == "1"
1412

1513
def test_compression_random(self):
1614
BaseTestZSTD.helper_compression_random(self)

tests/test_version.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
class TestZSTD(BaseTestZSTD):
88

99
def setUp(self):
10-
if os.getenv("ZSTD_EXTERNAL"):
11-
self.ZSTD_EXTERNAL = True
12-
self.VERSION = os.getenv("VERSION")
13-
self.PKG_VERSION = os.getenv("PKG_VERSION")
10+
self.ZSTD_EXTERNAL = os.environ["ZSTD_EXTERNAL"] == "1"
11+
self.VERSION = os.environ["VERSION"]
12+
self.PKG_VERSION = os.environ["PKG_VERSION"]
1413
v = [int(n) for n in reversed(self.VERSION.split("."))]
1514
self.VERSION_INT = 0
1615
i = 0

0 commit comments

Comments
 (0)