Skip to content

Commit

Permalink
Fixed Python bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tirath Ramdas committed Nov 21, 2011
1 parent 37915d4 commit bdc54e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions swig/castle.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def __setitem__(self, key, val):
elif isinstance(val, str):
vstr = str(val)
libcastle.memmove(self.val_buf, vstr)
val_len = len(_val)
val_len = len(vstr)
else:
raise Exception("Currently only str values supported")

Expand Down Expand Up @@ -392,7 +392,7 @@ def __init__(self, val=None):
elif isinstance(val, int):
self.value=val
elif isinstance(val, str):
self.value=struct.unpack('q', val)
self.value=int(struct.unpack('q', val)[0])
else:
raise Exception("Dunno what to do with val of type "+str(type(val)))

Expand Down
10 changes: 9 additions & 1 deletion swig/counters_test
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ def main(argv):

foo = castle.Castle()
foo.new_collection_attach("bar")

#init the counter
comp = 0;
foo["bar"]=castle.CastleCounterAdd(0)
for i in range(1, 6):
c = pow(2, i)
print "inserting ADD "+str(c)
comp+=c
foo["bar"]=castle.CastleCounterAdd(c)

print "got "+str(castle.CastleCounter(foo["bar"]).value)
retval = castle.CastleCounter(foo["bar"]).value
print "got "+str(retval)+", expecting "+str(comp)
assert retval == comp, "wtf??"

if __name__ == '__main__':
main(sys.argv[1:])

0 comments on commit bdc54e0

Please sign in to comment.