Implemented checksum() in _speedups.c

This commit is contained in:
Jonas Borgström 2010-03-01 23:39:14 +01:00
parent 60126b6330
commit 61cbaf8642
2 changed files with 31 additions and 9 deletions

View File

@ -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);

View File

@ -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'])],
)