/* Created By: Virgil Dupras * Created On: 2010-01-30 * Copyright 2010 Hardcoded Software (http://www.hardcoded.net) * * This software is licensed under the "HS" License as described in the "LICENSE" file, * which should be included with this package. The terms are also available at * http://www.hardcoded.net/licenses/hs_license */ #define PY_SSIZE_T_CLEAN #include "Python.h" /* avgdiff/maxdiff has been called with empty lists */ static PyObject *NoBlocksError; /* avgdiff/maxdiff has been called with 2 block lists of different size. */ static PyObject *DifferentBlockCountError; static int max(int a, int b) { return b > a ? b : a; } static int min(int a, int b) { return b < a ? b : a; } /* Create a tuple out of an array of integers. */ static PyObject* inttuple(int numbers[], int count) { int i; PyObject *pnumber; PyObject *result; result = PyTuple_New(count); for (i=0; i limit*iteration_count) && (iteration_count >= min_iterations)) { return PyInt_FromSsize_t(limit + 1); } } result = sum / count; if (!result && sum) { result = 1; } return PyInt_FromSsize_t(result); } static PyMethodDef BlockMethods[] = { {"getblocks2", block_getblocks2, METH_VARARGS, block_getblocks2_doc}, {"avgdiff", block_avgdiff, METH_VARARGS, block_avgdiff_doc}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC init_block(void) { PyObject *m = Py_InitModule("_block", BlockMethods); if (m == NULL) { return; } NoBlocksError = PyErr_NewException("_block.NoBlocksError", NULL, NULL); PyModule_AddObject(m, "NoBlocksError", NoBlocksError); DifferentBlockCountError = PyErr_NewException("_block.DifferentBlockCountError", NULL, NULL); PyModule_AddObject(m, "DifferentBlockCountError", DifferentBlockCountError); }