revlog: export symbol of indexType
authorYuya Nishihara <yuya@tcha.org>
Sun, 02 Dec 2018 21:37:42 +0900
changeset 53624 aa76be85029bddab0db79f959527bde8255198c5
parent 53623 67d20f62fd199d34f5c124398c1dd5797672e22a
child 53625 18a8def6e1b58a642e83f7a47ecaabd6f14d4a33
push id1079
push usergszorc@mozilla.com
push dateMon, 10 Dec 2018 19:44:59 +0000
revlog: export symbol of indexType The idea is to wrap the index object with rust-cpython. I haven't tried it, but it should be doable. We'll probably need a better interface than raw function pointers to do more in Rust.
mercurial/cext/revlog.c
mercurial/cext/revlog.h
setup.py
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -12,16 +12,17 @@
 #include <ctype.h>
 #include <limits.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "bitmanipulation.h"
 #include "charencode.h"
+#include "revlog.h"
 #include "util.h"
 
 #ifdef IS_PY3K
 /* The mapping of Python types is meant to be temporary to get Python
  * 3 to compile. We should remove this once Python 3 support is fully
  * supported and proper types are used in the extensions themselves. */
 #define PyInt_Check PyLong_Check
 #define PyInt_FromLong PyLong_FromLong
@@ -1506,18 +1507,16 @@ static int nt_init(nodetree *self, index
 	if (self->nodes == NULL) {
 		PyErr_NoMemory();
 		return -1;
 	}
 	self->length = 1;
 	return 0;
 }
 
-static PyTypeObject indexType;
-
 static int ntobj_init(nodetreeObject *self, PyObject *args)
 {
 	PyObject *index;
 	unsigned capacity;
 	if (!PyArg_ParseTuple(args, "O!I", &indexType, &index, &capacity))
 		return -1;
 	Py_INCREF(index);
 	return nt_init(&self->nt, (indexObject *)index, capacity);
@@ -2577,17 +2576,17 @@ static PyMethodDef index_methods[] = {
     {NULL} /* Sentinel */
 };
 
 static PyGetSetDef index_getset[] = {
     {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL},
     {NULL} /* Sentinel */
 };
 
-static PyTypeObject indexType = {
+PyTypeObject indexType = {
     PyVarObject_HEAD_INIT(NULL, 0) /* header */
     "parsers.index",               /* tp_name */
     sizeof(indexObject),           /* tp_basicsize */
     0,                             /* tp_itemsize */
     (destructor)index_dealloc,     /* tp_dealloc */
     0,                             /* tp_print */
     0,                             /* tp_getattr */
     0,                             /* tp_setattr */
new file mode 100644
--- /dev/null
+++ b/mercurial/cext/revlog.h
@@ -0,0 +1,15 @@
+/*
+ revlog.h - efficient revlog parsing
+
+ This software may be used and distributed according to the terms of
+ the GNU General Public License, incorporated herein by reference.
+*/
+
+#ifndef _HG_REVLOG_H_
+#define _HG_REVLOG_H_
+
+#include <Python.h>
+
+extern PyTypeObject indexType;
+
+#endif /* _HG_REVLOG_H_ */
--- a/setup.py
+++ b/setup.py
@@ -963,16 +963,17 @@ extmodules = [
                                              'mercurial/cext/manifest.c',
                                              'mercurial/cext/parsers.c',
                                              'mercurial/cext/pathencode.c',
                                              'mercurial/cext/revlog.c'],
                   'hgdirectffi',
                   'hg-direct-ffi',
                   include_dirs=common_include_dirs,
                   depends=common_depends + ['mercurial/cext/charencode.h',
+                                            'mercurial/cext/revlog.h',
                                             'rust/hg-core/src/ancestors.rs',
                                             'rust/hg-core/src/lib.rs']),
     Extension('mercurial.cext.osutil', ['mercurial/cext/osutil.c'],
               include_dirs=common_include_dirs,
               extra_compile_args=osutil_cflags,
               extra_link_args=osutil_ldflags,
               depends=common_depends),
     Extension(