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 f30ff60 commit 9a9bc78
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# A clang-format style that approximates Python's PEP 7
# Useful for IDE integration
BasedOnStyle: LLVM
ColumnLimit: 79
DerivePointerAlignment: false
Language: Cpp
PointerAlignment: Right
ReflowComments: true
Expand Down
42 changes: 21 additions & 21 deletions src/mmh3/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@
* 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)
41 changes: 22 additions & 19 deletions src/mmh3/mmh3module.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ 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 Down Expand Up @@ -149,7 +150,8 @@ 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 @@ -227,11 +229,12 @@ static PyObject *mmh3_hash128(PyObject *self, PyObject *args,
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 Down Expand Up @@ -875,17 +878,17 @@ static PyObject *MMH3Hasher128x86_digest(MMH3Hasher128x86 *self,
PyObject *Py_UNUSED(ignored)) {
char out[MMH3_128_DIGESTSIZE];
digest_x86_128_impl(self->h1, self->h2, self->h3, self->h4, self->buffer1,
self->buffer2, self->buffer3, self->buffer4, self->length,
out);
self->buffer2, self->buffer3, self->buffer4,
self->length, out);
return PyBytes_FromStringAndSize(out, MMH3_128_DIGESTSIZE);
}

static PyObject *MMH3Hasher128x86_sintdigest(MMH3Hasher128x86 *self,
PyObject *Py_UNUSED(ignored)) {
const char out[MMH3_128_DIGESTSIZE];
digest_x86_128_impl(self->h1, self->h2, self->h3, self->h4, self->buffer1,
self->buffer2, self->buffer3, self->buffer4, self->length,
out);
self->buffer2, self->buffer3, self->buffer4,
self->length, out);
const int little_endian = 1;
const int is_signed = 1;

Expand All @@ -905,8 +908,8 @@ static PyObject *MMH3Hasher128x86_uintdigest(MMH3Hasher128x86 *self,
PyObject *Py_UNUSED(ignored)) {
const char out[MMH3_128_DIGESTSIZE];
digest_x86_128_impl(self->h1, self->h2, self->h3, self->h4, self->buffer1,
self->buffer2, self->buffer3, self->buffer4, self->length,
out);
self->buffer2, self->buffer3, self->buffer4,
self->length, out);
const int little_endian = 1;
const int is_signed = 0;

Expand All @@ -926,8 +929,8 @@ static PyObject *MMH3Hasher128x86_stupledigest(MMH3Hasher128x86 *self,
PyObject *Py_UNUSED(ignored)) {
const char out[MMH3_128_DIGESTSIZE];
digest_x86_128_impl(self->h1, self->h2, self->h3, self->h4, self->buffer1,
self->buffer2, self->buffer3, self->buffer4, self->length,
out);
self->buffer2, self->buffer3, self->buffer4,
self->length, out);

const char *valflag = "LL";
uint64_t result1 = ((uint64_t *)out)[0];
Expand All @@ -945,8 +948,8 @@ static PyObject *MMH3Hasher128x86_utupledigest(MMH3Hasher128x86 *self,
PyObject *Py_UNUSED(ignored)) {
const char out[MMH3_128_DIGESTSIZE];
digest_x86_128_impl(self->h1, self->h2, self->h3, self->h4, self->buffer1,
self->buffer2, self->buffer3, self->buffer4, self->length,
out);
self->buffer2, self->buffer3, self->buffer4,
self->length, out);

const char *valflag = "KK";
uint64_t result1 = ((uint64_t *)out)[0];
Expand Down

0 comments on commit 9a9bc78

Please sign in to comment.