Skip to content

Commit 5db05a2

Browse files
Issue #304: add two new functions to test external lib version
1 parent 5e2da83 commit 5db05a2

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

setup.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def which(bin_exe):
264264
pkgconf = False
265265

266266
#if SUP_EXTERNAL:
267-
if platform.system() == "Linux" and "build_ext" in sys.argv or "build" in sys.argv or "bdist_wheel" in sys.argv:
267+
if platform.system() == "Linux" and "build_ext" in sys.argv or "build" in sys.argv or "bdist_wheel" in sys.argv or "test" in sys.argv:
268268
# You should add external library by option: --libraries zstd
269269
# And probably include paths by option: --include-dirs /usr/include/zstd
270270
# And probably library paths by option: --library-dirs /usr/lib/i386-linux-gnu
@@ -521,7 +521,7 @@ def build_extensions(self):
521521
'compress/zstd_preSplit.c',
522522
'compress/zstdmt_compress.c',
523523
'compress/zstd_fast.c',
524-
'compress/zstd_double_fast.c',
524+
# 'compress/zstd_double_fast.c',
525525
'compress/zstd_lazy.c',
526526
'compress/zstd_opt.c',
527527
'compress/zstd_ldm.c',
@@ -550,10 +550,16 @@ def build_extensions(self):
550550
]:
551551
zstdFiles.append('zstd/lib/'+f)
552552

553+
# files needed always, even for external
553554
zstdFiles.append('src/debug.c')
554555
zstdFiles.append('src/util.c')
555556
zstdFiles.append('src/python-zstd.c')
556557

558+
#for f in [
559+
# 'decompress/zstd_decompress.c',
560+
# 'decompress/zstd_ddict.c',
561+
# ]:
562+
# zstdFiles.append('zstd/lib/'+f)
557563

558564
# Another dirty hack
559565
def my_test_suite():
@@ -580,6 +586,8 @@ def my_test_suite():
580586
ld=f.read()
581587
f.close()
582588

589+
if SUP_DEBUG:
590+
print("debug: ext_libraries:%r" % (ext_libraries))
583591
setup(
584592
name='zstd',
585593
version=PKG_VERSION_STR,

src/python-zstd.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,24 @@ static PyObject *py_zstd_module_version(PyObject* self, PyObject *args)
329329
}
330330

331331
/**
332-
* Returns ZSTD library version as string
332+
* Returns ZSTD library version as string - compiled with
333333
*/
334-
static PyObject *py_zstd_library_version(PyObject* self, PyObject *args)
334+
static PyObject *py_zstd_library_version_compiled(PyObject* self, PyObject *args)
335+
{
336+
UNUSED(self);
337+
UNUSED(args);
338+
339+
#if PY_MAJOR_VERSION >= 3
340+
return PyUnicode_FromFormat("%s", ZSTD_VERSION_STRING);
341+
#else
342+
return PyString_FromFormat("%s", ZSTD_VERSION_STRING);
343+
#endif
344+
}
345+
346+
/**
347+
* Returns ZSTD library version as string - loaded with
348+
*/
349+
static PyObject *py_zstd_library_version_loaded(PyObject* self, PyObject *args)
335350
{
336351
UNUSED(self);
337352
UNUSED(args);
@@ -545,7 +560,9 @@ static PyMethodDef ZstdMethods[] = {
545560
{"dumps", py_zstd_compress_mt, METH_VARARGS, COMPRESS_DOCSTRING},
546561
{"loads", py_zstd_uncompress, METH_VARARGS, UNCOMPRESS_DOCSTRING},
547562
{"version", py_zstd_module_version, METH_NOARGS, VERSION_DOCSTRING},
548-
{"ZSTD_version", py_zstd_library_version, METH_NOARGS, ZSTD_VERSION_DOCSTRING},
563+
{"ZSTD_version", py_zstd_library_version_compiled, METH_NOARGS, ZSTD_VERSION_DOCSTRING},
564+
{"ZSTD_version_compiled", py_zstd_library_version_compiled, METH_NOARGS, NULL},
565+
{"ZSTD_version_loaded", py_zstd_library_version_loaded, METH_NOARGS, NULL},
549566
{"ZSTD_version_number", py_zstd_library_version_int, METH_NOARGS, ZSTD_INT_VERSION_DOCSTRING},
550567
{"ZSTD_threads_count", py_zstd_threads_count, METH_NOARGS, ZSTD_THREADS_COUNT_DOCSTRING},
551568
{"ZSTD_max_threads_count", py_zstd_max_threads_count, METH_NOARGS, ZSTD_MAX_THREADS_COUNT_DOCSTRING},

src/python-zstd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static PyObject *py_zstd_compress_mt(PyObject* self, PyObject *args);
9696
static PyObject *py_zstd_uncompress(PyObject* self, PyObject *args);
9797
static PyObject *py_zstd_check(PyObject* self, PyObject *args);
9898
static PyObject *py_zstd_module_version(PyObject* self, PyObject *args);
99-
static PyObject *py_zstd_library_version(PyObject* self, PyObject *args);
99+
static PyObject *py_zstd_library_version_compiled(PyObject* self, PyObject *args);
100+
static PyObject *py_zstd_library_version_loaded(PyObject* self, PyObject *args);
100101
static PyObject *py_zstd_library_version_int(PyObject* self, PyObject *args);
101102
static PyObject *py_zstd_library_external(PyObject* self, PyObject *args);
102103
static PyObject *py_zstd_with_threads(PyObject* self, PyObject *args);

tests/base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ def raise_skip(msg):
2222
log = logging.getLogger('ZSTD')
2323
log.info("Python version: %s" % sys.version)
2424
log.info("Machine:%s; processor:%s; system:%r; release:%r" % ( platform.machine(), platform.processor(), platform.system(), platform.release()))
25-
log.info("Module exported interface:%r"% dir(zstd))
26-
log.info("libzstd linked external:%r"% zstd.ZSTD_external())
27-
log.info("libzstd built with legacy formats support:%r"% zstd.ZSTD_legacy_support())
28-
log.info("zstd max number of threads:%r"% zstd.ZSTD_max_threads_count())
29-
log.info("zstd found CPU cores :%r"% zstd.ZSTD_threads_count())
30-
log.info("zstd default compression level:%r"% zstd.ZSTD_default_compression_level())
31-
log.info("zstd max compression level:%r"% zstd.ZSTD_max_compression_level())
32-
log.info("zstd min compression level:%r"% zstd.ZSTD_min_compression_level())
25+
log.info("Module exported interfac e:%r"% dir(zstd))
26+
log.info("libzstd linked external: %r"% zstd.ZSTD_external())
27+
log.info("libzstd built with legacy formats support: %r"% zstd.ZSTD_legacy_support())
28+
log.info("zstd max number of threads: %r"% zstd.ZSTD_max_threads_count())
29+
log.info("zstd found CPU cores : %r"% zstd.ZSTD_threads_count())
30+
log.info("zstd default compression level: %r"% zstd.ZSTD_default_compression_level())
31+
log.info("zstd max compression level: %r"% zstd.ZSTD_max_compression_level())
32+
log.info("zstd min compression level: %r"% zstd.ZSTD_min_compression_level())
3333
log.info("pyzstd module version: %r"% zstd.version())
3434
log.info("libzstd version: %r"% zstd.ZSTD_version())
35+
log.info("Compiled with libzstd version: %r"% zstd.ZSTD_version_compiled())
36+
log.info("Loaded with libzstd version: %r"% zstd.ZSTD_version_loaded())
3537

3638

3739
# Classic lorem ipsum

0 commit comments

Comments
 (0)