@@ -28,9 +28,28 @@ import_librt_vecs(void)
2828 if (mod == NULL )
2929 return -1 ;
3030 Py_DECREF (mod ); // we import just for the side effect of making the below work.
31- VecApi = PyCapsule_Import ("librt.vecs._C_API" , 0 );
32- if (!VecApi )
31+ VecCapsule * capsule = PyCapsule_Import ("librt.vecs._C_API" , 0 );
32+ if (!capsule )
3333 return -1 ;
34+ if (capsule -> abi_version () != LIBRT_VECS_ABI_VERSION ) {
35+ char err [128 ];
36+ snprintf (err , sizeof (err ),
37+ "ABI version conflict for librt.vecs, expected %d, found %d" ,
38+ LIBRT_VECS_ABI_VERSION ,
39+ capsule -> abi_version ());
40+ PyErr_SetString (PyExc_ValueError , err );
41+ return -1 ;
42+ }
43+ if (capsule -> api_version () < LIBRT_VECS_API_VERSION ) {
44+ char err [128 ];
45+ snprintf (err , sizeof (err ),
46+ "API version conflict for librt.vecs, expected %d or newer, found %d (hint: upgrade librt)" ,
47+ LIBRT_VECS_API_VERSION ,
48+ capsule -> api_version ());
49+ PyErr_SetString (PyExc_ValueError , err );
50+ return -1 ;
51+ }
52+ VecApi = capsule ;
3453 VecI64Api = * VecApi -> i64 ;
3554 VecI32Api = * VecApi -> i32 ;
3655 VecI16Api = * VecApi -> i16 ;
0 commit comments