@@ -138,7 +138,8 @@ void zstd_module_init(PyObject *m) {
138138 PyUnstable_Module_SetGIL (m , Py_MOD_GIL_NOT_USED );
139139#endif
140140
141- /* python-zstandard relies on unstable zstd C API features. This means
141+ /*
142+ python-zstandard relies on unstable zstd C API features. This means
142143 that changes in zstd may break expectations in python-zstandard.
143144
144145 python-zstandard is distributed with a copy of the zstd sources.
@@ -152,19 +153,25 @@ void zstd_module_init(PyObject *m) {
152153
153154 We detect this mismatch here and refuse to load the module if this
154155 scenario is detected.
156+
157+ Historically we required exact matches. But over the years the churn
158+ in libzstd became reasonable and we relaxed this constraint to a minimum
159+ version check. Our assumption going forward is that we will only rely on
160+ unstable C API features that are in reality stable for years.
155161 */
156162 PyObject * features = NULL ;
157163 PyObject * feature = NULL ;
164+ unsigned zstd_version_no = ZSTD_versionNumber ();
158165 unsigned zstd_version_min = 10506 ;
159166 // if either compile-time or runtime version of libzstd is lower than expected, abort initialization
160167 if (ZSTD_VERSION_NUMBER < zstd_version_min ||
161- ZSTD_versionNumber () < zstd_version_min ) {
168+ zstd_version_no < zstd_version_min ) {
162169 PyErr_Format (
163170 PyExc_ImportError ,
164171 "zstd C API versions mismatch; Python bindings were not "
165172 "compiled/linked against expected zstd version (%u returned by the "
166173 "lib, %u hardcoded in zstd headers, %u hardcoded in the cext)" ,
167- ZSTD_versionNumber () , ZSTD_VERSION_NUMBER , zstd_version_min );
174+ zstd_version_no , ZSTD_VERSION_NUMBER , zstd_version_min );
168175 return ;
169176 }
170177
0 commit comments