File feature-detection.patch of Package python-zstandard
---
c-ext/backend_c.c | 14 ++++++++++++++
setup_zstd.py | 1 +
tests/test_module_attributes.py | 10 +++++++++-
3 files changed, 24 insertions(+), 1 deletion(-)
Index: zstandard-0.24.0/c-ext/backend_c.c
===================================================================
--- zstandard-0.24.0.orig/c-ext/backend_c.c 2025-08-17 01:50:50.000000000 +0200
+++ zstandard-0.24.0/c-ext/backend_c.c 2025-09-16 16:15:10.125710215 +0200
@@ -210,6 +210,20 @@
Py_DECREF(feature);
#endif
+#ifdef SYSTEM_ZSTD
+ feature = PyUnicode_FromString("system_zstd");
+ if (NULL == feature) {
+ PyErr_SetString(PyExc_ImportError, "could not create feature string");
+ return;
+ }
+
+ if (PySet_Add(features, feature) == -1) {
+ return;
+ }
+
+ Py_DECREF(feature);
+#endif
+
if (PyObject_SetAttrString(m, "backend_features", features) == -1) {
return;
}
Index: zstandard-0.24.0/setup_zstd.py
===================================================================
--- zstandard-0.24.0.orig/setup_zstd.py 2025-08-17 02:20:18.000000000 +0200
+++ zstandard-0.24.0/setup_zstd.py 2025-09-16 16:15:10.125758965 +0200
@@ -79,6 +79,7 @@
if system_zstd:
extra_args.append("-DZSTD_MULTITHREAD")
+ extra_args.append("-DSYSTEM_ZSTD")
else:
extra_args.append("-DZSTD_SINGLE_FILE")
extra_args.append("-DZSTDLIB_VISIBLE=")
Index: zstandard-0.24.0/tests/test_module_attributes.py
===================================================================
--- zstandard-0.24.0.orig/tests/test_module_attributes.py 2025-08-17 19:03:17.000000000 +0200
+++ zstandard-0.24.0/tests/test_module_attributes.py 2025-09-16 16:15:10.125970238 +0200
@@ -26,7 +26,15 @@
},
}[zstd.backend]
- self.assertEqual(zstd.backend_features, expected)
+ # The following features are available only with
+ # statically linked version of the module.
+ available_features = set(zstd.backend_features)
+ if 'system_zstd' in available_features:
+ available_features.remove('system_zstd')
+ expected.discard('multi_compress_to_buffer')
+ expected.discard('multi_decompress_to_buffer')
+
+ self.assertEqual(available_features, expected)
def test_constants(self):
self.assertEqual(zstd.MAX_COMPRESSION_LEVEL, 22)