Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from todofixthis/develop
Browse files Browse the repository at this point in the history
1.0.0a3
  • Loading branch information
todofixthis authored Mar 26, 2017
2 parents 9c54526 + d402833 commit fb61d35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
name = 'PyOTA-CCurl',
description = 'C Curl extension for PyOTA',
url = 'https://github.com/todofixthis/pyota-ccurl',
version = '1.0.0a2',
version = '1.0.0a3',

long_description = long_description,

Expand Down
28 changes: 15 additions & 13 deletions src/ccurlmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Curl_absorb(Curl *self, PyObject *args, PyObject *kwds)
}

// Check for invalid values in ``incoming``.
incoming_count = PyObject_Length(incoming);
incoming_count = PyList_Size(incoming);
trits = (trit_t*)malloc(incoming_count * sizeof(trit_t));

for (i=0; i < incoming_count; i++) {
Expand Down Expand Up @@ -111,7 +111,7 @@ static PyObject*
Curl_squeeze(Curl *self, PyObject *args, PyObject *kwds)
{
PyObject *incoming;
int incoming_count, offset=0;
int incoming_count;

static char *kwlist[] = {"trits", NULL};

Expand All @@ -124,20 +124,22 @@ Curl_squeeze(Curl *self, PyObject *args, PyObject *kwds)
return NULL;
}

incoming_count = PyObject_Length(incoming);
// Ensure that ``incoming`` can hold at least 1 hash worth of trits.
for(incoming_count = PyList_Size(incoming); incoming_count < HASH_LENGTH; incoming_count++) {
PyList_Append(incoming, PyLong_FromLong(0));
}

// Adapted from https://github.com/iotaledger/ccurl/blob/master/src/lib/Curl.c
do {
// Can't use ``memcpy`` here because we have to convert ints into ``PyLongObject``.
// This isn't the slow part of Curl (that honor is reserved for ``_Curl_transform``),
// so it shouldn't be that big of a problem.
for (int i=offset; i < (incoming_count < HASH_LENGTH ? incoming_count : HASH_LENGTH ); i++) {
PyList_SetItem(incoming, i, PyLong_FromLong(self->_state[i]));
}
// Note that squeeze only copies one hash.

_Curl_transform(self);
offset += HASH_LENGTH;
} while ((incoming_count -= HASH_LENGTH) > 0);
// Can't use ``memcpy`` here because we have to convert ints into ``PyLongObject``.
// This isn't the slow part of Curl (that honor is reserved for ``_Curl_transform``),
// so it shouldn't be that big of a problem.
for (int i=0; i < HASH_LENGTH; i++) {
PyList_SetItem(incoming, i, PyLong_FromLong(self->_state[i]));
}

_Curl_transform(self);

Py_INCREF(Py_None);
return Py_None;
Expand Down

0 comments on commit fb61d35

Please sign in to comment.