Patchwork [2,of,6,v3] cext: drop the WITH_RUST block

login
register
mail settings
Submitter Pierre-Yves David
Date March 9, 2020, 5:34 p.m.
Message ID <bbfdc8c2f3a2ac0f3c49.1583775293@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/45639/
State Accepted
Headers show

Comments

Pierre-Yves David - March 9, 2020, 5:34 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1583771190 -3600
#      Mon Mar 09 17:26:30 2020 +0100
# Node ID bbfdc8c2f3a2ac0f3c4921351614f4e134b0d46d
# Parent  27e1e79c1a5ad9dfa699954aa68a4c0361d39f1b
# EXP-Topic rust-test-option
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r bbfdc8c2f3a2
cext: drop the WITH_RUST block

These were used by the `direct-ffi` mode that just got dropped.
Yuya Nishihara - March 10, 2020, 11:58 a.m.
On Mon, 09 Mar 2020 18:34:53 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1583771190 -3600
> #      Mon Mar 09 17:26:30 2020 +0100
> # Node ID bbfdc8c2f3a2ac0f3c4921351614f4e134b0d46d
> # Parent  27e1e79c1a5ad9dfa699954aa68a4c0361d39f1b
> # EXP-Topic rust-test-option
> # Available At https://dev.heptapod.net/octobus/mercurial-devel/
> #              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r bbfdc8c2f3a2
> cext: drop the WITH_RUST block

> -#ifdef WITH_RUST
> -	rustlazyancestorsType.tp_new = PyType_GenericNew;
> -	if (PyType_Ready(&rustlazyancestorsType) < 0)
> -		return;
> -	Py_INCREF(&rustlazyancestorsType);
> -	PyModule_AddObject(mod, "rustlazyancestors",
> -	                   (PyObject *)&rustlazyancestorsType);

And the callers can also be removed?

% rg rustlazyancestors mercurial
mercurial/revlog.py:948:        elif util.safehasattr(parsers, b'rustlazyancestors'):
mercurial/revlog.py:949:            lazyancestors = ancestor.rustlazyancestors
mercurial/ancestor.py:398:class rustlazyancestors(object):
mercurial/ancestor.py:404:        # it's done by rustlazyancestors constructor.
mercurial/ancestor.py:409:        self._containsiter = parsers.rustlazyancestors(
mercurial/ancestor.py:426:        return parsers.rustlazyancestors(

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -2874,169 +2874,6 @@  bail:
 	return NULL;
 }
 
-#ifdef WITH_RUST
-
-/* rustlazyancestors: iteration over ancestors implemented in Rust
- *
- * This class holds a reference to an index and to the Rust iterator.
- */
-typedef struct rustlazyancestorsObjectStruct rustlazyancestorsObject;
-
-struct rustlazyancestorsObjectStruct {
-	PyObject_HEAD
-	    /* Type-specific fields go here. */
-	    indexObject *index; /* Ref kept to avoid GC'ing the index */
-	void *iter;             /* Rust iterator */
-};
-
-/* FFI exposed from Rust code */
-rustlazyancestorsObject *rustlazyancestors_init(indexObject *index,
-                                                /* intrevs vector */
-                                                Py_ssize_t initrevslen,
-                                                long *initrevs, long stoprev,
-                                                int inclusive);
-void rustlazyancestors_drop(rustlazyancestorsObject *self);
-int rustlazyancestors_next(rustlazyancestorsObject *self);
-int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev);
-
-/* CPython instance methods */
-static int rustla_init(rustlazyancestorsObject *self, PyObject *args)
-{
-	PyObject *initrevsarg = NULL;
-	PyObject *inclusivearg = NULL;
-	long stoprev = 0;
-	long *initrevs = NULL;
-	int inclusive = 0;
-	Py_ssize_t i;
-
-	indexObject *index;
-	if (!PyArg_ParseTuple(args, "O!O!lO!", &HgRevlogIndex_Type, &index,
-	                      &PyList_Type, &initrevsarg, &stoprev,
-	                      &PyBool_Type, &inclusivearg))
-		return -1;
-
-	Py_INCREF(index);
-	self->index = index;
-
-	if (inclusivearg == Py_True)
-		inclusive = 1;
-
-	Py_ssize_t linit = PyList_GET_SIZE(initrevsarg);
-
-	initrevs = (long *)calloc(linit, sizeof(long));
-
-	if (initrevs == NULL) {
-		PyErr_NoMemory();
-		goto bail;
-	}
-
-	for (i = 0; i < linit; i++) {
-		initrevs[i] = PyInt_AsLong(PyList_GET_ITEM(initrevsarg, i));
-	}
-	if (PyErr_Occurred())
-		goto bail;
-
-	self->iter =
-	    rustlazyancestors_init(index, linit, initrevs, stoprev, inclusive);
-	if (self->iter == NULL) {
-		/* if this is because of GraphError::ParentOutOfRange
-		 * HgRevlogIndex_GetParents() has already set the proper
-		 * exception */
-		goto bail;
-	}
-
-	free(initrevs);
-	return 0;
-
-bail:
-	free(initrevs);
-	return -1;
-};
-
-static void rustla_dealloc(rustlazyancestorsObject *self)
-{
-	Py_XDECREF(self->index);
-	if (self->iter != NULL) { /* can happen if rustla_init failed */
-		rustlazyancestors_drop(self->iter);
-	}
-	PyObject_Del(self);
-}
-
-static PyObject *rustla_next(rustlazyancestorsObject *self)
-{
-	int res = rustlazyancestors_next(self->iter);
-	if (res == -1) {
-		/* Setting an explicit exception seems unnecessary
-		 * as examples from Python source code (Objects/rangeobjets.c
-		 * and Modules/_io/stringio.c) seem to demonstrate.
-		 */
-		return NULL;
-	}
-	return PyInt_FromLong(res);
-}
-
-static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev)
-{
-	long lrev;
-	if (!pylong_to_long(rev, &lrev)) {
-		PyErr_Clear();
-		return 0;
-	}
-	return rustlazyancestors_contains(self->iter, lrev);
-}
-
-static PySequenceMethods rustla_sequence_methods = {
-    0,                           /* sq_length */
-    0,                           /* sq_concat */
-    0,                           /* sq_repeat */
-    0,                           /* sq_item */
-    0,                           /* sq_slice */
-    0,                           /* sq_ass_item */
-    0,                           /* sq_ass_slice */
-    (objobjproc)rustla_contains, /* sq_contains */
-};
-
-static PyTypeObject rustlazyancestorsType = {
-    PyVarObject_HEAD_INIT(NULL, 0)                  /* header */
-    "parsers.rustlazyancestors",                    /* tp_name */
-    sizeof(rustlazyancestorsObject),                /* tp_basicsize */
-    0,                                              /* tp_itemsize */
-    (destructor)rustla_dealloc,                     /* tp_dealloc */
-    0,                                              /* tp_print */
-    0,                                              /* tp_getattr */
-    0,                                              /* tp_setattr */
-    0,                                              /* tp_compare */
-    0,                                              /* tp_repr */
-    0,                                              /* tp_as_number */
-    &rustla_sequence_methods,                       /* tp_as_sequence */
-    0,                                              /* tp_as_mapping */
-    0,                                              /* tp_hash */
-    0,                                              /* tp_call */
-    0,                                              /* tp_str */
-    0,                                              /* tp_getattro */
-    0,                                              /* tp_setattro */
-    0,                                              /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,                             /* tp_flags */
-    "Iterator over ancestors, implemented in Rust", /* tp_doc */
-    0,                                              /* tp_traverse */
-    0,                                              /* tp_clear */
-    0,                                              /* tp_richcompare */
-    0,                                              /* tp_weaklistoffset */
-    0,                                              /* tp_iter */
-    (iternextfunc)rustla_next,                      /* tp_iternext */
-    0,                                              /* tp_methods */
-    0,                                              /* tp_members */
-    0,                                              /* tp_getset */
-    0,                                              /* tp_base */
-    0,                                              /* tp_dict */
-    0,                                              /* tp_descr_get */
-    0,                                              /* tp_descr_set */
-    0,                                              /* tp_dictoffset */
-    (initproc)rustla_init,                          /* tp_init */
-    0,                                              /* tp_alloc */
-};
-#endif /* WITH_RUST */
-
 static Revlog_CAPI CAPI = {
     /* increment the abi_version field upon each change in the Revlog_CAPI
        struct or in the ABI of the listed functions */
@@ -3070,13 +2907,4 @@  void revlog_module_init(PyObject *mod)
 	caps = PyCapsule_New(&CAPI, "mercurial.cext.parsers.revlog_CAPI", NULL);
 	if (caps != NULL)
 		PyModule_AddObject(mod, "revlog_CAPI", caps);
-
-#ifdef WITH_RUST
-	rustlazyancestorsType.tp_new = PyType_GenericNew;
-	if (PyType_Ready(&rustlazyancestorsType) < 0)
-		return;
-	Py_INCREF(&rustlazyancestorsType);
-	PyModule_AddObject(mod, "rustlazyancestors",
-	                   (PyObject *)&rustlazyancestorsType);
-#endif
 }