Skip to content

Commit

Permalink
Test commit for clang
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimes committed Aug 25, 2024
1 parent 6977447 commit cf459bc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# A clang-format style that approximates Python's PEP 7
# Useful for IDE integration
BasedOnStyle: LLVM
ColumnLimit: 79
DerivePointerAlignment: false
IndentWidth: 4
Language: Cpp
PointerAlignment: Right
Expand Down
44 changes: 22 additions & 22 deletions src/mmh3/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,28 @@
* of PyObject_GetBuffer. Sets an exception and issues the erraction
* on any errors, e.g. 'return NULL' or 'goto error'.
*/
#define GET_BUFFER_VIEW_OR_ERROR(obj, viewp, erraction) \
do { \
if (PyUnicode_Check((obj))) { \
PyErr_SetString(PyExc_TypeError, \
"Strings must be encoded before hashing"); \
erraction; \
} \
if (!PyObject_CheckBuffer((obj))) { \
PyErr_SetString(PyExc_TypeError, \
"object supporting the buffer API required"); \
erraction; \
} \
if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
erraction; \
} \
if ((viewp)->ndim > 1) { \
PyErr_SetString(PyExc_BufferError, \
"Buffer must be single dimension"); \
PyBuffer_Release((viewp)); \
erraction; \
} \
#define GET_BUFFER_VIEW_OR_ERROR(obj, viewp, erraction) \
do { \
if (PyUnicode_Check((obj))) { \
PyErr_SetString(PyExc_TypeError, \
"Strings must be encoded before hashing"); \
erraction; \
} \
if (!PyObject_CheckBuffer((obj))) { \
PyErr_SetString(PyExc_TypeError, \
"object supporting the buffer API required"); \
erraction; \
} \
if (PyObject_GetBuffer((obj), (viewp), PyBUF_SIMPLE) == -1) { \
erraction; \
} \
if ((viewp)->ndim > 1) { \
PyErr_SetString(PyExc_BufferError, \
"Buffer must be single dimension"); \
PyBuffer_Release((viewp)); \
erraction; \
} \
} while (0)

#define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) \
#define GET_BUFFER_VIEW_OR_ERROUT(obj, viewp) \
GET_BUFFER_VIEW_OR_ERROR(obj, viewp, return NULL)
39 changes: 17 additions & 22 deletions src/mmh3/mmh3module.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ typedef unsigned __int64 uint64_t;
//-----------------------------------------------------------------------------
// One shot functions

PyDoc_STRVAR(mmh3_hash_doc,
"hash(key[, seed=0, signed=True]) -> 32-bit int\n\n"
"Return a hash value as a 32-bit integer. "
"Calculated by the MurmurHash3_x86_32 algorithm.");
PyDoc_STRVAR(mmh3_hash_doc, "hash(key[, seed=0, signed=True]) -> 32-bit int\n\n"
"Return a hash value as a 32-bit integer. "
"Calculated by the MurmurHash3_x86_32 algorithm.");

static PyObject *mmh3_hash(PyObject *self, PyObject *args, PyObject *keywds) {
const char *target_str;
Expand All @@ -57,9 +56,8 @@ static PyObject *mmh3_hash(PyObject *self, PyObject *args, PyObject *keywds) {
#endif
#endif

if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|IB", kwlist,
&target_str, &target_str_len, &seed,
&is_signed)) {
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|IB", kwlist, &target_str,
&target_str_len, &seed, &is_signed)) {
return NULL;
}

Expand Down Expand Up @@ -112,8 +110,8 @@ static PyObject *mmh3_hash_from_buffer(PyObject *self, PyObject *args,
#endif
#endif

if (!PyArg_ParseTupleAndKeywords(args, keywds, "s*|IB", kwlist,
&target_buf, &seed, &is_signed)) {
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s*|IB", kwlist, &target_buf,
&seed, &is_signed)) {
return NULL;
}

Expand Down Expand Up @@ -151,8 +149,7 @@ PyDoc_STRVAR(
"Calculated by the MurmurHash3_x{64, 86}_128 algorithm. Optimized "
"for the x64 bit architecture when x64arch=True, otherwise for x86.");

static PyObject *mmh3_hash64(PyObject *self, PyObject *args,
PyObject *keywds) {
static PyObject *mmh3_hash64(PyObject *self, PyObject *args, PyObject *keywds) {
const char *target_str;
Py_ssize_t target_str_len;
uint32_t seed = 0;
Expand Down Expand Up @@ -224,18 +221,17 @@ static PyObject *mmh3_hash128(PyObject *self, PyObject *args,
* cf.
* https://mail.python.org/pipermail/python-list/2006-August/372365.html
*/
PyObject *retval = _PyLong_FromByteArray(
(unsigned char *)result, MMH3_128_DIGESTSIZE, 1, is_signed);
PyObject *retval = _PyLong_FromByteArray((unsigned char *)result,
MMH3_128_DIGESTSIZE, 1, is_signed);

return retval;
}

PyDoc_STRVAR(
mmh3_hash_bytes_doc,
"hash_bytes(key[, seed=0, x64arch=True]) -> bytes\n\n"
"Return a 128 bit hash value as bytes for a string. Optimized for "
"the x64 bit architecture when "
"x64arch=True, otherwise for the x86.");
PyDoc_STRVAR(mmh3_hash_bytes_doc,
"hash_bytes(key[, seed=0, x64arch=True]) -> bytes\n\n"
"Return a 128 bit hash value as bytes for a string. Optimized for "
"the x64 bit architecture when "
"x64arch=True, otherwise for the x86.");

static PyObject *mmh3_hash_bytes(PyObject *self, PyObject *args,
PyObject *keywds) {
Expand All @@ -248,9 +244,8 @@ static PyObject *mmh3_hash_bytes(PyObject *self, PyObject *args,
static char *kwlist[] = {(char *)"key", (char *)"seed", (char *)"x64arch",
NULL};

if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|IB", kwlist,
&target_str, &target_str_len, &seed,
&x64arch)) {
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|IB", kwlist, &target_str,
&target_str_len, &seed, &x64arch)) {
return NULL;
}

Expand Down

0 comments on commit cf459bc

Please sign in to comment.