comparison mercurial/bdiff_module.c @ 32355:4195b84940e9

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.
author Jun Wu <quark@fb.com>
date Tue, 25 Apr 2017 17:34:41 -0700
parents 08ecec297521
children
comparison
equal deleted inserted replaced
32354:f432897a9f49 32355:4195b84940e9
190 {"blocks", blocks, METH_VARARGS, "find a list of matching lines\n"}, 190 {"blocks", blocks, METH_VARARGS, "find a list of matching lines\n"},
191 {"fixws", fixws, METH_VARARGS, "normalize diff whitespaces\n"}, 191 {"fixws", fixws, METH_VARARGS, "normalize diff whitespaces\n"},
192 {NULL, NULL} 192 {NULL, NULL}
193 }; 193 };
194 194
195 static const int version = 1;
196
195 #ifdef IS_PY3K 197 #ifdef IS_PY3K
196 static struct PyModuleDef bdiff_module = { 198 static struct PyModuleDef bdiff_module = {
197 PyModuleDef_HEAD_INIT, 199 PyModuleDef_HEAD_INIT,
198 "bdiff", 200 "bdiff",
199 mdiff_doc, 201 mdiff_doc,
201 methods 203 methods
202 }; 204 };
203 205
204 PyMODINIT_FUNC PyInit_bdiff(void) 206 PyMODINIT_FUNC PyInit_bdiff(void)
205 { 207 {
206 return PyModule_Create(&bdiff_module); 208 PyObject *m;
209 m = PyModule_Create(&bdiff_module);
210 PyModule_AddIntConstant(m, "version", version);
211 return m;
207 } 212 }
208 #else 213 #else
209 PyMODINIT_FUNC initbdiff(void) 214 PyMODINIT_FUNC initbdiff(void)
210 { 215 {
211 Py_InitModule3("bdiff", methods, mdiff_doc); 216 PyObject *m;
217 m = Py_InitModule3("bdiff", methods, mdiff_doc);
218 PyModule_AddIntConstant(m, "version", version);
212 } 219 }
213 #endif 220 #endif