[PATCH 4 of 6] phases: leverage Py_BuildValue() to build PyInt and steal PyObject
Yuya Nishihara
yuya at tcha.org
Sat Jul 18 10:13:00 UTC 2020
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1595064459 -32400
# Sat Jul 18 18:27:39 2020 +0900
# Node ID ff0940d0168168165b3fd14ebaa7ad476c0aac85
# Parent d2bef0f97e82641bb6719128fbd0380b08ac539c
phases: leverage Py_BuildValue() to build PyInt and steal PyObject
"N" means "O" without incref, so we can just return the created tuple.
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -785,12 +785,10 @@ static PyObject *compute_phases_map_sets
/* 0: public (untracked), 1: draft, 2: secret, 32: archive,
96: internal */
static const char trackedphases[] = {1, 2, 32, 96};
- PyObject *ret = NULL;
PyObject *roots = Py_None;
PyObject *pyphase = NULL;
PyObject *pyrev = NULL;
PyObject *phaseroots = NULL;
- PyObject *phasessize = NULL;
PyObject *phasesets[4] = {NULL, NULL, NULL, NULL};
Py_ssize_t len = index_length(self);
char *phases = NULL;
@@ -891,14 +889,8 @@ static PyObject *compute_phases_map_sets
Py_DECREF(phasesets[i]);
phasesets[i] = NULL;
}
- phasessize = PyInt_FromSsize_t(len);
- if (phasessize == NULL)
- goto release;
- ret = PyTuple_Pack(2, phasessize, phaseroots);
- Py_DECREF(phasessize);
- Py_DECREF(phaseroots);
- return ret;
+ return Py_BuildValue("nN", len, phaseroots);
release:
for (i = 0; i < numphases; ++i)
More information about the Mercurial-devel
mailing list