bdiff: add version to help detect breaking binary changes
Previously, we have no way to detect if a compiled .so file could be used or
not, and blindly load it if it exists. Usually we carefully maintain
compatibility of .so and fallback to pure code gracefully. But if we stick
to the rules, certain nice changes will be impossible to make in a clean
way.
This patch adds a "version" constant to the module so we can detect
inconsistency and take appropriate actions (warn, abort, fallback to pure,
run make automatically) in module loader.
--- a/mercurial/bdiff_module.c Sat May 20 03:10:23 2017 +0200
+++ b/mercurial/bdiff_module.c Tue Apr 25 17:34:41 2017 -0700
@@ -192,6 +192,8 @@
{NULL, NULL}
};
+static const int version = 1;
+
#ifdef IS_PY3K
static struct PyModuleDef bdiff_module = {
PyModuleDef_HEAD_INIT,
@@ -203,11 +205,16 @@
PyMODINIT_FUNC PyInit_bdiff(void)
{
- return PyModule_Create(&bdiff_module);
+ PyObject *m;
+ m = PyModule_Create(&bdiff_module);
+ PyModule_AddIntConstant(m, "version", version);
+ return m;
}
#else
PyMODINIT_FUNC initbdiff(void)
{
- Py_InitModule3("bdiff", methods, mdiff_doc);
+ PyObject *m;
+ m = Py_InitModule3("bdiff", methods, mdiff_doc);
+ PyModule_AddIntConstant(m, "version", version);
}
#endif