Patchwork [2,of,9] mercurial: add an extension module for fast dict operations

login
register
mail settings
Submitter Siddharth Agarwal
Date March 25, 2013, 12:27 a.m.
Message ID <7a4e0dbc4e1c576f4469.1364171266@sid0x220>
Download mbox | patch
Permalink /patch/1179/
State Rejected
Headers show

Comments

Siddharth Agarwal - March 25, 2013, 12:27 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1364116242 25200
#      Sun Mar 24 02:10:42 2013 -0700
# Node ID 7a4e0dbc4e1c576f4469c9d31e2dca16cc35b790
# Parent  72770effd8ccb4b33430410f5b0bd33964795af5
mercurial: add an extension module for fast dict operations

This is a stub which will be filled in by an upcoming patch.
Bryan O'Sullivan - March 25, 2013, 5:22 p.m.
On Sun, Mar 24, 2013 at 5:27 PM, Siddharth Agarwal <sid0@fb.com> wrote:

> +    Extension('mercurial.dicthelpers', ['mercurial/dicthelpers.c']),
>

I have a hazy recollection of a conversation with Matt a few years ago,
from which external packagers have some difficulty with new extension
modules. I have no details, but that's why parsers.c contains a bunch of
random very-much-not-parsers code.

Matt, am I recalling correctly? (And even if I am, is that a valid reason
to continue to contort the code?)
Matt Mackall - March 28, 2013, 4:54 p.m.
On Mon, 2013-03-25 at 10:22 -0700, Bryan O'Sullivan wrote:
> On Sun, Mar 24, 2013 at 5:27 PM, Siddharth Agarwal <sid0@fb.com>
> wrote:
>         +    Extension('mercurial.dicthelpers',
>         ['mercurial/dicthelpers.c']),
>         
> 
> I have a hazy recollection of a conversation with Matt a few years
> ago, from which external packagers have some difficulty with new
> extension modules. I have no details, but that's why parsers.c
> contains a bunch of random very-much-not-parsers code.

New C APIs tend to break our usual running-is-compiling development
model.

That's pain for us (when updating, when bisecting, etc.) and pain for
users who are upgrading by checkout. Some of the latter don't even have
compilers (the sort of people using HackableMercurial).

There may be occasional packaging glitches too. THG has failed to
package newly-added files on several releases, not really sure why this
happens.

Patch

diff --git a/mercurial/dicthelpers.c b/mercurial/dicthelpers.c
new file mode 100644
--- /dev/null
+++ b/mercurial/dicthelpers.c
@@ -0,0 +1,47 @@ 
+/*
+ * dicthelpers.c - helper routines for Python dicts
+ *
+ * Copyright 2013 Facebook
+ *
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License v2, incorporated herein by reference.
+ */
+
+#include <Python.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+static char dicthelpers_doc[] = "Fast dict operations.";
+
+static PyMethodDef methods[] = {
+	{NULL, NULL}
+};
+
+#ifdef IS_PY3K
+static struct PyModuleDef dicthelpers_module = {
+	PyModuleDef_HEAD_INIT,
+	"dicthelpers",
+	dicthelpers_doc,
+	-1,
+	methods
+};
+
+PyMODINIT_FUNC PyInit_dicthelpers(void)
+{
+	PyObject *m;
+
+	m = PyModule_Create(&dicthelpers_module);
+	if (m == NULL)
+		return NULL;
+
+	return m;
+}
+#else
+PyMODINIT_FUNC
+initdicthelpers(void)
+{
+	Py_InitModule3("dicthelpers", methods, dicthelpers_doc);
+}
+#endif
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -429,6 +429,7 @@  extmodules = [
     Extension('mercurial.mpatch', ['mercurial/mpatch.c']),
     Extension('mercurial.parsers', ['mercurial/parsers.c',
                                     'mercurial/pathencode.c']),
+    Extension('mercurial.dicthelpers', ['mercurial/dicthelpers.c']),
     ]
 
 osutil_ldflags = []