Patchwork [5,of,8] osutil: add _version to help detect breaking binary changes

login
register
mail settings
Submitter Jun Wu
Date May 3, 2017, 12:20 a.m.
Message ID <54f38c921b4aa125c4cc.1493770802@x1c>
Download mbox | patch
Permalink /patch/20379/
State Deferred
Headers show

Comments

Jun Wu - May 3, 2017, 12:20 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1493167019 25200
#      Tue Apr 25 17:36:59 2017 -0700
# Node ID 54f38c921b4aa125c4cc64f425ca7931617d3bc8
# Parent  3ee58fc62a7de71b2bb3767d1a20c7e51d51cb04
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 54f38c921b4a
osutil: add _version to help detect breaking binary changes

See the previous patch for why.

Patch

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -1302,4 +1302,8 @@  static PyMethodDef methods[] = {
 };
 
+/* Binary version. When breaking changes are made, bump this number and change
+ * __init__.py, so the module loader can notice and fallback to pure. */
+static const int _version = 1;
+
 #ifdef IS_PY3K
 static struct PyModuleDef osutil_module = {
@@ -1313,16 +1317,21 @@  static struct PyModuleDef osutil_module 
 PyMODINIT_FUNC PyInit_osutil(void)
 {
+	PyObject *m;
 	if (PyType_Ready(&listdir_stat_type) < 0)
 		return NULL;
 
-	return PyModule_Create(&osutil_module);
+	m = PyModule_Create(&osutil_module);
+	PyModule_AddIntConstant(m, "_version", _version);
+	return m;
 }
 #else
 PyMODINIT_FUNC initosutil(void)
 {
+	PyObject *m;
 	if (PyType_Ready(&listdir_stat_type) == -1)
 		return;
 
-	Py_InitModule3("osutil", methods, osutil_doc);
+	m = Py_InitModule3("osutil", methods, osutil_doc);
+	PyModule_AddIntConstant(m, "_version", _version);
 }
 #endif