construct icon indicating copy to clipboard operation
construct copied to clipboard

CString.sizeof(context) throws "can't calculate size" SizeofError

Open HazimGazov opened this issue 12 years ago • 1 comments

This seems to be an issue with CString being an adapted RepeatUntil, which always throws an error for sizeof calls.

>>> from construct import *
>>> str = CString("a_string")
>>> str_parsed = str.parse("foo\x00")
>>> print str_parsed
foo
>>> str.sizeof()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/construct-2.06-py2.7.egg/construct/core.py", line 242, in sizeof
    raise SizeofError(e)
construct.core.SizeofError: can't calculate size
>>> str.sizeof(str_parsed)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/construct-2.06-py2.7.egg/construct/core.py", line 242, in sizeof
    raise SizeofError(e)
construct.core.SizeofError: can't calculate size

HazimGazov avatar Nov 14 '11 15:11 HazimGazov

Hm, this could almost certainly be improved for cases where we have a context. RepeatUntil's a bit of a whiner like that. I'd have to carefully look at how its builder works. RepeatUntil's not super-tested, although we do test its basic functionality.

MostAwesomeDude avatar Nov 16 '11 03:11 MostAwesomeDude