D5235: revlog: replace PyInt_AS_LONG with a more portable helper function
yuja (Yuya Nishihara)
phabricator at mercurial-scm.org
Wed Nov 7 07:36:01 EST 2018
yuja added a comment.
> +/* Convert a PyInt or PyLong to a long. Returns false if there is an
> + error, in which case an exception will already have been set. */
> +static inline bool pylong_to_long(PyObject *pylong, long *out)
Nit: I prefer 0/-1 return value instead of bool since that's the convention
of CPython API.
> + *out = PyLong_AsLong(pylong);
> + return PyErr_Occurred() == NULL;
Perhaps, checking `*out != -1` can be a fast path, though I don't know how
much we care about the performance here.
> static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev)
> {
>
> - if (!(PyInt_Check(rev))) { + long lrev; + if (!pylong_to_long(rev, &lrev)) { return 0;
Needs `PyErr_Clear() since `non_int in self` isn't an error.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5235
To: durin42, #hg-reviewers
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list