]> arthur.barton.de Git - bup.git/commitdiff
Rename _faster.so to _helpers.so. bup-0.17
authorAvery Pennarun <apenwarr@gmail.com>
Mon, 23 Aug 2010 03:27:03 +0000 (20:27 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 23 Aug 2010 03:27:31 +0000 (20:27 -0700)
Okay, _faster.so wasn't a good choice of names.  Partly because not
everything in there is just to make stuff faster, and partly because some
*proposed* changes to it don't just make stuff faster.  So let's rename it
one more time.  Hopefully the last time for a while!

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
Makefile
cmd/margin-cmd.py
cmd/random-cmd.py
lib/bup/_faster.c [deleted file]
lib/bup/_helpers.c [new file with mode: 0644]
lib/bup/csetup.py
lib/bup/hashsplit.py
lib/bup/t/thashsplit.py

index 47b03ead01072171baff6aa8e73307bcda5cbf90..7f38c7fabf228dd686ac00003c9a65295b181175 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ default: all
 
 all: bup Documentation/all
 
-bup: lib/bup/_version.py lib/bup/_faster$(SOEXT) cmds
+bup: lib/bup/_version.py lib/bup/_helpers$(SOEXT) cmds
 
 Documentation/all: bup
 
@@ -62,11 +62,11 @@ install: all
 %/clean:
        $(MAKE) -C $* clean
 
-lib/bup/_faster$(SOEXT): \
-               lib/bup/bupsplit.c lib/bup/_faster.c lib/bup/csetup.py
+lib/bup/_helpers$(SOEXT): \
+               lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
        @rm -f $@
        cd lib/bup && $(PYTHON) csetup.py build
-       cp lib/bup/build/*/_faster$(SOEXT) lib/bup/
+       cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
 
 .PHONY: lib/bup/_version.py
 lib/bup/_version.py:
index 21f711f7e4acf37ab51622c336f161f1b33c804e..cb059a3809687593222a3e91def7f1d7b987ba6b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 import sys
-from bup import options, git, _faster
+from bup import options, git, _helpers
 from bup.helpers import *
 
 
@@ -23,7 +23,7 @@ for i in mi:
     if i == last:
         continue
     #assert(str(i) >= last)
-    pm = _faster.bitmatch(last, i)
+    pm = _helpers.bitmatch(last, i)
     longmatch = max(longmatch, pm)
     last = i
 print longmatch
index 9a24face2598f27ab81bfee007fa2bef7365315d..19732b9e18e519abd5848f6ca8a6f1954230638e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 import sys
-from bup import options, _faster
+from bup import options, _helpers
 from bup.helpers import *
 
 optspec = """
@@ -21,7 +21,7 @@ handle_ctrl_c()
 
 if opt.force or (not os.isatty(1) and
                  not atoi(os.environ.get('BUP_FORCE_TTY')) & 1):
-    _faster.write_random(sys.stdout.fileno(), total, opt.seed)
+    _helpers.write_random(sys.stdout.fileno(), total, opt.seed)
 else:
     log('error: not writing binary data to a terminal. Use -f to force.\n')
     sys.exit(1)
diff --git a/lib/bup/_faster.c b/lib/bup/_faster.c
deleted file mode 100644 (file)
index cfab4fb..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-#include "bupsplit.h"
-#include <Python.h>
-#include <assert.h>
-#include <stdint.h>
-#include <fcntl.h>
-
-static PyObject *selftest(PyObject *self, PyObject *args)
-{
-    if (!PyArg_ParseTuple(args, ""))
-       return NULL;
-    
-    return Py_BuildValue("i", !bupsplit_selftest());
-}
-
-
-static PyObject *blobbits(PyObject *self, PyObject *args)
-{
-    if (!PyArg_ParseTuple(args, ""))
-       return NULL;
-    return Py_BuildValue("i", BUP_BLOBBITS);
-}
-
-
-static PyObject *splitbuf(PyObject *self, PyObject *args)
-{
-    unsigned char *buf = NULL;
-    int len = 0, out = 0, bits = -1;
-
-    if (!PyArg_ParseTuple(args, "t#", &buf, &len))
-       return NULL;
-    out = bupsplit_find_ofs(buf, len, &bits);
-    return Py_BuildValue("ii", out, bits);
-}
-
-
-static PyObject *bitmatch(PyObject *self, PyObject *args)
-{
-    unsigned char *buf1 = NULL, *buf2 = NULL;
-    int len1 = 0, len2 = 0;
-    int byte, bit;
-
-    if (!PyArg_ParseTuple(args, "t#t#", &buf1, &len1, &buf2, &len2))
-       return NULL;
-    
-    bit = 0;
-    for (byte = 0; byte < len1 && byte < len2; byte++)
-    {
-       int b1 = buf1[byte], b2 = buf2[byte];
-       if (b1 != b2)
-       {
-           for (bit = 0; bit < 8; bit++)
-               if ( (b1 & (0x80 >> bit)) != (b2 & (0x80 >> bit)) )
-                   break;
-           break;
-       }
-    }
-    
-    return Py_BuildValue("i", byte*8 + bit);
-}
-
-
-// I would have made this a lower-level function that just fills in a buffer
-// with random values, and then written those values from python.  But that's
-// about 20% slower in my tests, and since we typically generate random
-// numbers for benchmarking other parts of bup, any slowness in generating
-// random bytes will make our benchmarks inaccurate.  Plus nobody wants
-// pseudorandom bytes much except for this anyway.
-static PyObject *write_random(PyObject *self, PyObject *args)
-{
-    uint32_t buf[1024/4];
-    int fd = -1, seed = 0;
-    ssize_t ret;
-    long long len = 0, kbytes = 0, written = 0;
-
-    if (!PyArg_ParseTuple(args, "iLi", &fd, &len, &seed))
-       return NULL;
-    
-    srandom(seed);
-    
-    for (kbytes = 0; kbytes < len/1024; kbytes++)
-    {
-       unsigned i;
-       for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
-           buf[i] = random();
-       ret = write(fd, buf, sizeof(buf));
-       if (ret < 0)
-           ret = 0;
-       written += ret;
-       if (ret < (int)sizeof(buf))
-           break;
-       if (kbytes/1024 > 0 && !(kbytes%1024))
-           fprintf(stderr, "Random: %lld Mbytes\r", kbytes/1024);
-    }
-    
-    // handle non-multiples of 1024
-    if (len % 1024)
-    {
-       unsigned i;
-       for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
-           buf[i] = random();
-       ret = write(fd, buf, len % 1024);
-       if (ret < 0)
-           ret = 0;
-       written += ret;
-    }
-    
-    if (kbytes/1024 > 0)
-       fprintf(stderr, "Random: %lld Mbytes, done.\n", kbytes/1024);
-    return Py_BuildValue("L", written);
-}
-
-
-static PyObject *open_noatime(PyObject *self, PyObject *args)
-{
-    char *filename = NULL;
-    int attrs, attrs_noatime, fd;
-    if (!PyArg_ParseTuple(args, "s", &filename))
-       return NULL;
-    attrs = O_RDONLY;
-#ifdef O_NOFOLLOW
-    attrs |= O_NOFOLLOW;
-#endif
-#ifdef O_LARGEFILE
-    attrs |= O_LARGEFILE;
-#endif
-    attrs_noatime = attrs;
-#ifdef O_NOATIME
-    attrs_noatime |= O_NOATIME;
-#endif
-    fd = open(filename, attrs_noatime);
-    if (fd < 0 && errno == EPERM)
-    {
-       // older Linux kernels would return EPERM if you used O_NOATIME
-       // and weren't the file's owner.  This pointless restriction was
-       // relaxed eventually, but we have to handle it anyway.
-       // (VERY old kernels didn't recognized O_NOATIME, but they would
-       // just harmlessly ignore it, so this branch won't trigger)
-       fd = open(filename, attrs);
-    }
-    if (fd < 0)
-       return PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
-    return Py_BuildValue("i", fd);
-}
-
-
-static PyObject *fadvise_done(PyObject *self, PyObject *args)
-{
-    int fd = -1;
-    long long ofs = 0;
-    if (!PyArg_ParseTuple(args, "iL", &fd, &ofs))
-       return NULL;
-#ifdef POSIX_FADV_DONTNEED
-    posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED);
-#endif    
-    return Py_BuildValue("");
-}
-
-
-static PyMethodDef faster_methods[] = {
-    { "selftest", selftest, METH_VARARGS,
-       "Check that the rolling checksum rolls correctly (for unit tests)." },
-    { "blobbits", blobbits, METH_VARARGS,
-       "Return the number of bits in the rolling checksum." },
-    { "splitbuf", splitbuf, METH_VARARGS,
-       "Split a list of strings based on a rolling checksum." },
-    { "bitmatch", bitmatch, METH_VARARGS,
-       "Count the number of matching prefix bits between two strings." },
-    { "write_random", write_random, METH_VARARGS,
-       "Write random bytes to the given file descriptor" },
-    { "open_noatime", open_noatime, METH_VARARGS,
-       "open() the given filename for read with O_NOATIME if possible" },
-    { "fadvise_done", fadvise_done, METH_VARARGS,
-       "Inform the kernel that we're finished with earlier parts of a file" },
-    { NULL, NULL, 0, NULL },  // sentinel
-};
-
-PyMODINIT_FUNC init_faster(void)
-{
-    Py_InitModule("_faster", faster_methods);
-}
diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c
new file mode 100644 (file)
index 0000000..3ce5ecb
--- /dev/null
@@ -0,0 +1,180 @@
+#include "bupsplit.h"
+#include <Python.h>
+#include <assert.h>
+#include <stdint.h>
+#include <fcntl.h>
+
+static PyObject *selftest(PyObject *self, PyObject *args)
+{
+    if (!PyArg_ParseTuple(args, ""))
+       return NULL;
+    
+    return Py_BuildValue("i", !bupsplit_selftest());
+}
+
+
+static PyObject *blobbits(PyObject *self, PyObject *args)
+{
+    if (!PyArg_ParseTuple(args, ""))
+       return NULL;
+    return Py_BuildValue("i", BUP_BLOBBITS);
+}
+
+
+static PyObject *splitbuf(PyObject *self, PyObject *args)
+{
+    unsigned char *buf = NULL;
+    int len = 0, out = 0, bits = -1;
+
+    if (!PyArg_ParseTuple(args, "t#", &buf, &len))
+       return NULL;
+    out = bupsplit_find_ofs(buf, len, &bits);
+    return Py_BuildValue("ii", out, bits);
+}
+
+
+static PyObject *bitmatch(PyObject *self, PyObject *args)
+{
+    unsigned char *buf1 = NULL, *buf2 = NULL;
+    int len1 = 0, len2 = 0;
+    int byte, bit;
+
+    if (!PyArg_ParseTuple(args, "t#t#", &buf1, &len1, &buf2, &len2))
+       return NULL;
+    
+    bit = 0;
+    for (byte = 0; byte < len1 && byte < len2; byte++)
+    {
+       int b1 = buf1[byte], b2 = buf2[byte];
+       if (b1 != b2)
+       {
+           for (bit = 0; bit < 8; bit++)
+               if ( (b1 & (0x80 >> bit)) != (b2 & (0x80 >> bit)) )
+                   break;
+           break;
+       }
+    }
+    
+    return Py_BuildValue("i", byte*8 + bit);
+}
+
+
+// I would have made this a lower-level function that just fills in a buffer
+// with random values, and then written those values from python.  But that's
+// about 20% slower in my tests, and since we typically generate random
+// numbers for benchmarking other parts of bup, any slowness in generating
+// random bytes will make our benchmarks inaccurate.  Plus nobody wants
+// pseudorandom bytes much except for this anyway.
+static PyObject *write_random(PyObject *self, PyObject *args)
+{
+    uint32_t buf[1024/4];
+    int fd = -1, seed = 0;
+    ssize_t ret;
+    long long len = 0, kbytes = 0, written = 0;
+
+    if (!PyArg_ParseTuple(args, "iLi", &fd, &len, &seed))
+       return NULL;
+    
+    srandom(seed);
+    
+    for (kbytes = 0; kbytes < len/1024; kbytes++)
+    {
+       unsigned i;
+       for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
+           buf[i] = random();
+       ret = write(fd, buf, sizeof(buf));
+       if (ret < 0)
+           ret = 0;
+       written += ret;
+       if (ret < (int)sizeof(buf))
+           break;
+       if (kbytes/1024 > 0 && !(kbytes%1024))
+           fprintf(stderr, "Random: %lld Mbytes\r", kbytes/1024);
+    }
+    
+    // handle non-multiples of 1024
+    if (len % 1024)
+    {
+       unsigned i;
+       for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i++)
+           buf[i] = random();
+       ret = write(fd, buf, len % 1024);
+       if (ret < 0)
+           ret = 0;
+       written += ret;
+    }
+    
+    if (kbytes/1024 > 0)
+       fprintf(stderr, "Random: %lld Mbytes, done.\n", kbytes/1024);
+    return Py_BuildValue("L", written);
+}
+
+
+static PyObject *open_noatime(PyObject *self, PyObject *args)
+{
+    char *filename = NULL;
+    int attrs, attrs_noatime, fd;
+    if (!PyArg_ParseTuple(args, "s", &filename))
+       return NULL;
+    attrs = O_RDONLY;
+#ifdef O_NOFOLLOW
+    attrs |= O_NOFOLLOW;
+#endif
+#ifdef O_LARGEFILE
+    attrs |= O_LARGEFILE;
+#endif
+    attrs_noatime = attrs;
+#ifdef O_NOATIME
+    attrs_noatime |= O_NOATIME;
+#endif
+    fd = open(filename, attrs_noatime);
+    if (fd < 0 && errno == EPERM)
+    {
+       // older Linux kernels would return EPERM if you used O_NOATIME
+       // and weren't the file's owner.  This pointless restriction was
+       // relaxed eventually, but we have to handle it anyway.
+       // (VERY old kernels didn't recognized O_NOATIME, but they would
+       // just harmlessly ignore it, so this branch won't trigger)
+       fd = open(filename, attrs);
+    }
+    if (fd < 0)
+       return PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
+    return Py_BuildValue("i", fd);
+}
+
+
+static PyObject *fadvise_done(PyObject *self, PyObject *args)
+{
+    int fd = -1;
+    long long ofs = 0;
+    if (!PyArg_ParseTuple(args, "iL", &fd, &ofs))
+       return NULL;
+#ifdef POSIX_FADV_DONTNEED
+    posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED);
+#endif    
+    return Py_BuildValue("");
+}
+
+
+static PyMethodDef faster_methods[] = {
+    { "selftest", selftest, METH_VARARGS,
+       "Check that the rolling checksum rolls correctly (for unit tests)." },
+    { "blobbits", blobbits, METH_VARARGS,
+       "Return the number of bits in the rolling checksum." },
+    { "splitbuf", splitbuf, METH_VARARGS,
+       "Split a list of strings based on a rolling checksum." },
+    { "bitmatch", bitmatch, METH_VARARGS,
+       "Count the number of matching prefix bits between two strings." },
+    { "write_random", write_random, METH_VARARGS,
+       "Write random bytes to the given file descriptor" },
+    { "open_noatime", open_noatime, METH_VARARGS,
+       "open() the given filename for read with O_NOATIME if possible" },
+    { "fadvise_done", fadvise_done, METH_VARARGS,
+       "Inform the kernel that we're finished with earlier parts of a file" },
+    { NULL, NULL, 0, NULL },  // sentinel
+};
+
+PyMODINIT_FUNC init_helpers(void)
+{
+    Py_InitModule("_helpers", faster_methods);
+}
index 6036e4281ea5e4f956d0c2abe4913be245ee97f4..2a0eeaf30d2be63e08db49291e07da377e863057 100644 (file)
@@ -1,8 +1,8 @@
 from distutils.core import setup, Extension
 
-_faster_mod = Extension('_faster', sources=['_faster.c', 'bupsplit.c'])
+_helpers_mod = Extension('_helpers', sources=['_helpers.c', 'bupsplit.c'])
 
-setup(name='_faster',
+setup(name='_helpers',
       version='0.1',
       description='accelerator library for bup',
-      ext_modules=[_faster_mod])
+      ext_modules=[_helpers_mod])
index 71e0327da6ed07a6b43b4c5582b281e593e8bb7a..61840ada73de6256fd14e709bd1764e2cb43af06 100644 (file)
@@ -1,5 +1,5 @@
 import math
-from bup import _faster
+from bup import _helpers
 from bup.helpers import *
 
 BLOB_LWM = 8192*2
@@ -38,7 +38,7 @@ class Buf:
 
 def splitbuf(buf):
     b = buf.peek(buf.used())
-    (ofs, bits) = _faster.splitbuf(b)
+    (ofs, bits) = _helpers.splitbuf(b)
     if ofs:
         buf.eat(ofs)
         return (buffer(b, 0, ofs), bits)
@@ -135,7 +135,7 @@ def split_to_shalist(w, files):
             shal.append(('100644', sha, size))
         return _make_shalist(shal)[0]
     else:
-        base_bits = _faster.blobbits()
+        base_bits = _helpers.blobbits()
         fanout_bits = int(math.log(fanout, 2))
         def bits_to_idx(n):
             assert(n >= base_bits)
@@ -163,7 +163,7 @@ def split_to_blob_or_tree(w, files):
 
 
 def open_noatime(name):
-    fd = _faster.open_noatime(name)
+    fd = _helpers.open_noatime(name)
     try:
         return os.fdopen(fd, 'rb', 1024*1024)
     except:
@@ -177,4 +177,4 @@ def open_noatime(name):
 def fadvise_done(f, ofs):
     assert(ofs >= 0)
     if ofs > 0:
-        _faster.fadvise_done(f.fileno(), ofs)
+        _helpers.fadvise_done(f.fileno(), ofs)
index bd8a015ede8e1910e7cec3e9803440da962fe638..43d589b4124e6eebdcd95673e0217c7d253ac726 100644 (file)
@@ -1,6 +1,6 @@
-from bup import hashsplit, _faster
+from bup import hashsplit, _helpers
 from wvtest import *
 
 @wvtest
 def test_rolling_sums():
-    WVPASS(_faster.selftest())
+    WVPASS(_helpers.selftest())