"ValueError: right operand length must match slice length"

Issue #86 on hold
Zooko O'Whielacronx
created an issue

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.

  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:

    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)

Comments (3)

  1. Armin Rigo

    It's unlikely we can do anything without being able to reproduce the problem. Please provide a complete working example (it can be big, but we need to run it ourselves).

  2. Log in to comment