"ValueError: right operand length must match slice length"
Created originally on Bitbucket by zooko (Zooko O'Whielacronx)
As far as I can see, the right operand length definitely matches the slice length! Arigo tried to reproduce this when I reported it on IRC and couldn't so it could be the fault of my code.
#!python
File "/home/zooko/playground/BackOffTrigramModel/src/Python/BackOffTrigramModel/BackOffTrigramModelCFFI.py", line 86, in vocabulary_with_prefix
bufo[:len(prefix)] = prefix
ValueError: right operand length must match slice length
Here is the code:
#!python
def vocabulary_with_prefix(self, prefix):
assert isinstance(prefix, unicode), (repr(prefix), type(prefix))
assert len(prefix) < 274, len(prefix)
palimpsest = ffi.new("char[274]")
assert len(prefix) < len(palimpsest), (len(prefix), len(palimpsest))
bufo = ffi.buffer(palimpsest)
assert len(bufo) > len(prefix), (len(bufo), len(prefix))
bufo[:len(prefix)] = prefix
ptr = C.JudySLFirst(self.UP[0], palimpsest, ffi.NULL)
while (ptr is not ffi.NULL):
pstr = ffi.string(palimpsest).decode('utf-8')
if pstr[:len(prefix)] == prefix:
yield pstr
ptr = C.JudySLNext(self.UP[0], palimpsest, ffi.NULL)
else:
break