]> arthur.barton.de Git - bup.git/commitdiff
Rename chashsplit.so to _hashsplit.so.
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 25 Jan 2010 04:00:32 +0000 (23:00 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 25 Jan 2010 04:00:32 +0000 (23:00 -0500)
Looks like the python standard is _modulename.so when making a C helper for
a module named modulename.py, so let's do it that way.

Also get rid of the annoying "module" suffix in the .c's filename.  Not sure
why I ever thought that was needed.

Makefile
_hashsplit.c [new file with mode: 0644]
chashsplitmodule.c [deleted file]
csetup.py
hashsplit.py

index 9393fb0bc2716d7e913ab498835d10de82cd4439..1068de55bc27c1253ad2a2fc13c44cf7ff433e35 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,15 +20,15 @@ endif
 default: all
 
 all: bup-split bup-join bup-save bup-init bup-server bup-index bup-tick \
-       bup memtest randomgen$(EXT) chashsplit$(SOEXT)
+       bup memtest randomgen$(EXT) _hashsplit$(SOEXT)
 
 randomgen$(EXT): randomgen.o
        $(CC) $(CFLAGS) -o $@ $<
 
-chashsplit$(SOEXT): chashsplitmodule.c csetup.py
+_hashsplit$(SOEXT): _hashsplit.c csetup.py
        @rm -f $@
        python csetup.py build
-       cp build/*/chashsplit.so .
+       cp build/*/_hashsplit.so .
        
 runtests: all runtests-python runtests-cmdline
 
diff --git a/_hashsplit.c b/_hashsplit.c
new file mode 100644 (file)
index 0000000..a213d00
--- /dev/null
@@ -0,0 +1,60 @@
+#include <Python.h>
+#include <assert.h>
+#include <stdint.h>
+
+#define BLOBBITS (14)
+#define BLOBSIZE (1<<(BLOBBITS-1))
+#define WINDOWBITS (7)
+#define WINDOWSIZE (1<<(WINDOWBITS-1))
+
+
+// FIXME: replace this with a not-stupid rolling checksum algorithm,
+// such as the one used in rsync (Adler32?)
+static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
+{
+    return ((old<<1) | (old>>31)) ^ drop ^ add;
+}
+
+
+static int find_ofs(const unsigned char *buf, int len)
+{
+    unsigned char window[WINDOWSIZE];
+    uint32_t sum = 0;
+    int i = 0, count;
+    memset(window, 0, sizeof(window));
+    
+    for (count = 0; count < len; count++)
+    {
+       sum = stupidsum_add(sum, window[i], buf[count]);
+       window[i] = buf[count];
+       i = (i + 1) % WINDOWSIZE;
+       if ((sum & (BLOBSIZE-1)) == ((~0) & (BLOBSIZE-1)))
+           return count+1;
+    }
+    return 0;
+}
+
+
+static PyObject *splitbuf(PyObject *self, PyObject *args)
+{
+    unsigned char *buf = NULL;
+    int len = 0, out = 0;
+
+    if (!PyArg_ParseTuple(args, "t#", &buf, &len))
+       return NULL;
+    out = find_ofs(buf, len);
+    //return Py_BuildValue("i", len);//len>BLOBSIZE ? BLOBSIZE : len);
+    return Py_BuildValue("i", out);
+}
+
+
+static PyMethodDef hashsplit_methods[] = {
+    { "splitbuf", splitbuf, METH_VARARGS,
+       "Split a list of strings based on a rolling checksum." },
+    { NULL, NULL, 0, NULL },  // sentinel
+};
+
+PyMODINIT_FUNC init_hashsplit(void)
+{
+    Py_InitModule("_hashsplit", hashsplit_methods);
+}
diff --git a/chashsplitmodule.c b/chashsplitmodule.c
deleted file mode 100644 (file)
index d2beb29..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-#include <Python.h>
-#include <assert.h>
-#include <stdint.h>
-
-#define BLOBBITS (14)
-#define BLOBSIZE (1<<(BLOBBITS-1))
-#define WINDOWBITS (7)
-#define WINDOWSIZE (1<<(WINDOWBITS-1))
-
-
-// FIXME: replace this with a not-stupid rolling checksum algorithm,
-// such as the one used in rsync (Adler32?)
-static uint32_t stupidsum_add(uint32_t old, uint8_t drop, uint8_t add)
-{
-    return ((old<<1) | (old>>31)) ^ drop ^ add;
-}
-
-
-static int find_ofs(const unsigned char *buf, int len)
-{
-    unsigned char window[WINDOWSIZE];
-    uint32_t sum = 0;
-    int i = 0, count;
-    memset(window, 0, sizeof(window));
-    
-    for (count = 0; count < len; count++)
-    {
-       sum = stupidsum_add(sum, window[i], buf[count]);
-       window[i] = buf[count];
-       i = (i + 1) % WINDOWSIZE;
-       if ((sum & (BLOBSIZE-1)) == ((~0) & (BLOBSIZE-1)))
-           return count+1;
-    }
-    return 0;
-}
-
-
-static PyObject *splitbuf(PyObject *self, PyObject *args)
-{
-    unsigned char *buf = NULL;
-    int len = 0, out = 0;
-
-    if (!PyArg_ParseTuple(args, "t#", &buf, &len))
-       return NULL;
-    out = find_ofs(buf, len);
-    //return Py_BuildValue("i", len);//len>BLOBSIZE ? BLOBSIZE : len);
-    return Py_BuildValue("i", out);
-}
-
-
-static PyMethodDef hashsplit_methods[] = {
-    { "splitbuf", splitbuf, METH_VARARGS,
-       "Split a list of strings based on a rolling checksum." },
-    { NULL, NULL, 0, NULL },  // sentinel
-};
-
-PyMODINIT_FUNC initchashsplit(void)
-{
-    Py_InitModule("chashsplit", hashsplit_methods);
-}
index 2590557d6f6a6abad37eaaa259c0c8b66ddf3c94..b58932c0ae2cf5dcddaf4576b9194b4da0787397 100644 (file)
--- a/csetup.py
+++ b/csetup.py
@@ -1,8 +1,8 @@
 from distutils.core import setup, Extension
 
-chashsplit_mod = Extension('chashsplit', sources=['chashsplitmodule.c'])
+_hashsplit_mod = Extension('_hashsplit', sources=['_hashsplit.c'])
 
-setup(name='chashsplit',
+setup(name='_hashsplit',
       version='0.1',
       description='hashsplit helper library for bup',
-      ext_modules=[chashsplit_mod])
+      ext_modules=[_hashsplit_mod])
index 7dee3d6ae91586cf3912e49a35b3a737034a1565..15efd08c6a533a669270e0011870149ca98df3a2 100644 (file)
@@ -1,5 +1,5 @@
 import sys
-import git, chashsplit
+import git, _hashsplit
 from helpers import *
 
 BLOB_LWM = 8192*2
@@ -39,7 +39,7 @@ class Buf:
 def splitbuf(buf):
     global split_verbosely
     b = buf.peek(buf.used())
-    ofs = chashsplit.splitbuf(b)
+    ofs = _hashsplit.splitbuf(b)
     if ofs:
         if split_verbosely >= 2:
             log('.')