diff mercurial/cext/revlog.c @ 41052:4c25038c112c

rust-cpython: implement Graph using C parents function We introduce the `Index` struct that wraps the C index. It is not intrinsically protected by the GIL (see the lengthy discussion in its docstring). Improving on this seems prematurate at this point. A pointer to the parents function is stored on the parsers C extension module as a capsule object. This is the recommended way to export a C API for consumption from other extensions. See also: https://docs.python.org/2.7/c-api/capsule.html In our case, we use it in cindex.rs, retrieving function pointer from the capsule and storing it within the CIndex struct, alongside with a pointer to the index. From there, the implementation is very close to the one from hg-direct-ffi. The naming convention for the capsule is inspired from the one in datetime: >>> import datetime >>> datetime.datetime_CAPI <capsule object "datetime.datetime_CAPI" at 0x7fb51201ecf0> although in datetime's case, the capsule points to a struct holding several type objects and methods. Differential Revision: https://phab.mercurial-scm.org/D5438
author Georges Racinet <gracinet@anybox.fr>
date Mon, 03 Dec 2018 07:44:08 +0100
parents 2e305e54eae3
children 46e0563c67db
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Thu Dec 20 22:28:39 2018 -0500
+++ b/mercurial/cext/revlog.c	Mon Dec 03 07:44:08 2018 +0100
@@ -2866,6 +2866,7 @@
 
 void revlog_module_init(PyObject *mod)
 {
+	PyObject *caps = NULL;
 	HgRevlogIndex_Type.tp_new = PyType_GenericNew;
 	if (PyType_Ready(&HgRevlogIndex_Type) < 0)
 		return;
@@ -2885,6 +2886,12 @@
 	if (nullentry)
 		PyObject_GC_UnTrack(nullentry);
 
+	caps = PyCapsule_New(HgRevlogIndex_GetParents,
+	                     "mercurial.cext.parsers.index_get_parents_CAPI",
+	                     NULL);
+	if (caps != NULL)
+		PyModule_AddObject(mod, "index_get_parents_CAPI", caps);
+
 #ifdef WITH_RUST
 	rustlazyancestorsType.tp_new = PyType_GenericNew;
 	if (PyType_Ready(&rustlazyancestorsType) < 0)