From 61cbaf864281eb1189a02ec842abb9008e0da5fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Mon, 1 Mar 2010 23:39:14 +0100 Subject: [PATCH] Implemented checksum() in _speedups.c --- dedupestore/{_speedup.c => _speedups.c} | 38 +++++++++++++++++++------ setup.py | 2 +- 2 files changed, 31 insertions(+), 9 deletions(-) rename dedupestore/{_speedup.c => _speedups.c} (79%) diff --git a/dedupestore/_speedup.c b/dedupestore/_speedups.c similarity index 79% rename from dedupestore/_speedup.c rename to dedupestore/_speedups.c index b330dfa92..6640c255f 100644 --- a/dedupestore/_speedup.c +++ b/dedupestore/_speedups.c @@ -87,28 +87,50 @@ chunkify(PyObject *self, PyObject *args) return NULL; } - p->m = 10; - p->i = 0; - p->fd = fd; - p->chunk_size = chunk_size; - p->chunks = chunks; - return (PyObject *)p; + p->m = 10; + p->i = 0; + p->fd = fd; + p->chunk_size = chunk_size; + p->chunks = chunks; + return (PyObject *)p; + } + + static PyObject * + checksum(PyObject *self, PyObject *args) + { + unsigned long int sum = 0, s1, s2; + PyObject *data; + Py_ssize_t i, len; + const char *ptr; + if (!PyArg_ParseTuple(args, "O|l", &data, &sum)) return NULL; + len = PyString_Size(data); + ptr = PyString_AsString(data); + s1 = sum & 0xffff; + s2 = sum >> 16; + printf("Woot %lu\n", sizeof(s1)); + for(i=0; i < len; i++) + { + s1 += ptr[i] + 1; + s2 += s1; + } + return PyInt_FromLong(((s2 & 0xffff) << 16) | (s1 & 0xffff)); } static PyMethodDef ChunkifierMethods[] = { {"chunkify", chunkify, METH_VARARGS, ""}, + {"checksum", checksum, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC -init_chunkifier(void) +init_speedups(void) { PyObject* m; ChunkifyIterType.tp_new = PyType_GenericNew; if (PyType_Ready(&ChunkifyIterType) < 0) return; - m = Py_InitModule("_chunkifier", ChunkifierMethods); + m = Py_InitModule("_speedups", ChunkifierMethods); Py_INCREF(&ChunkifyIterType); PyModule_AddObject(m, "_ChunkifyIter", (PyObject *)&ChunkifyIterType); diff --git a/setup.py b/setup.py index 7397af1b0..d91c247fb 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,6 @@ setup(name='Dedupestore', author='Jonas Borgström', author_email='jonas@borgstrom.se', packages=['dedupestore'], - ext_modules=[Extension('_speedup', ['deduepstore/_speedup.c'])], + ext_modules=[Extension('_speedups', ['dedupestore/_speedups.c'])], ) \ No newline at end of file