Patchwork [1,of,6,V2] bdiff: add version to help detect breaking binary changes

login
register
mail settings
Submitter Jun Wu
Date May 19, 2017, 3:46 p.m.
Message ID <90ad5352d3c20b5f463d.1495208768@x1c>
Download mbox | patch
Permalink /patch/20728/
State Accepted
Headers show

Comments

Jun Wu - May 19, 2017, 3:46 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1493166881 25200
#      Tue Apr 25 17:34:41 2017 -0700
# Node ID 90ad5352d3c20b5f463d814b46cef15512edbacb
# Parent  763d7292569138886c3fdf179f7e688351bfb212
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 90ad5352d3c2
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.

Patch

diff --git a/mercurial/bdiff_module.c b/mercurial/bdiff_module.c
--- a/mercurial/bdiff_module.c
+++ b/mercurial/bdiff_module.c
@@ -193,4 +193,6 @@  static PyMethodDef methods[] = {
 };
 
+static const int version = 1;
+
 #ifdef IS_PY3K
 static struct PyModuleDef bdiff_module = {
@@ -204,10 +206,15 @@  static struct PyModuleDef bdiff_module =
 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