D3554: xdiff: fix Py_BuildValue types (issue5885)

quark (Jun Wu) phabricator at mercurial-scm.org
Sun May 13 18:48:34 UTC 2018


quark created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Julien Cristau reported and provided the fix [1]. I added an assertion.
  
  Note Python documentation (2.7 to 3.5) says "L" in `Py_BuildValue` might be
  unsupported on some platforms:
  
    L (int) [PY_LONG_LONG]
    Convert a Python integer to a C long long. This format is only available
    on platforms that support long long (or _int64 on Windows).
  
  But it is required to build Python 2.7 itself [2]. So using it won't affect
  supported platforms.
  
  [1]: https://bz.mercurial-scm.org/show_bug.cgi?id=5885#c3
  [2]: https://bugs.python.org/issue27961

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3554

AFFECTED FILES
  mercurial/cext/bdiff.c

CHANGE DETAILS

diff --git a/mercurial/cext/bdiff.c b/mercurial/cext/bdiff.c
--- a/mercurial/cext/bdiff.c
+++ b/mercurial/cext/bdiff.c
@@ -261,7 +261,8 @@
                          void *priv)
 {
 	PyObject *rl = (PyObject *)priv;
-	PyObject *m = Py_BuildValue("llll", a1, a2, b1, b2);
+	Py_BUILD_ASSERT(sizeof(a1) == sizeof(PY_LONG_LONG));
+	PyObject *m = Py_BuildValue("LLLL", a1, a2, b1, b2);
 	if (!m)
 		return -1;
 	if (PyList_Append(rl, m) != 0) {



To: quark, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list