Skip to content

Commit

Permalink
fix #3: error while deserializing symbol list with null as a first el…
Browse files Browse the repository at this point in the history
…ement
  • Loading branch information
maciejlach committed May 14, 2014
1 parent cdfe3cf commit 603b8da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions qpython/qreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _read_dictionary(self, qtype = QDICTIONARY):
keys = self._read_object()
values = self._read_object()

if isinstance(keys, QTable):
if isinstance(keys, QTable):
return QKeyedTable(keys, values)
else:
return QDictionary(keys, values)
Expand Down Expand Up @@ -381,15 +381,16 @@ def get_symbols(self, size):
return []

while count < size:
new_position = self._data.find('\x00', new_position + 1)
new_position = self._data.find('\x00', new_position)

if new_position < 0:
raise QReaderException('Failed to read symbol from stream')

count += 1
new_position += 1

raw = self._data[self._position : new_position]
self._position = new_position + 1
raw = self._data[self._position : new_position - 1]
self._position = new_position

return raw.split('\x00')

6 changes: 5 additions & 1 deletion tests/QExpressions3.out
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ ED00000080
0B000400000074686500717569636B0062726F776E00666F7800
`jumps`over`a`lazy`dog
0B00050000006A756D7073006F7665720061006C617A7900646F6700
``quick``fox
0B000400000000717569636B0000666F7800
``
0B00020000000000
2000.01.04D05:36:57.600 0Np
0C000200000000C0CAFA20FE00000000000000000080
(2001.01m; 0Nm)
Expand Down Expand Up @@ -151,7 +155,7 @@ flip `abc`def!(1 2 3; 4 5 6)
flip `name`iq!(`Dent`Beeblebrox`Prefect;98 42 126)
6200630B00020000006E616D65006971000000020000000B000300000044656E7400426565626C6562726F7800507265666563740007000300000062000000000000002A000000000000007E00000000000000
flip `name`iq`grade!(`Dent`Beeblebrox`Prefect;98 42 126;"a c")
6200630b00030000006e616d65006971006772616465000000030000000b000300000044656e7400426565626c6562726f7800507265666563740007000300000062000000000000002a000000000000007e000000000000000a0003000000612063
6200630B00030000006E616D65006971006772616465000000030000000B000300000044656E7400426565626C6562726F7800507265666563740007000300000062000000000000002A000000000000007E000000000000000A0003000000612063
([] sc:1 2 3; nsc:(1 2; 3 4; 5 6 7))
6200630B00020000007363006E7363000000020000000700030000000100000000000000020000000000000003000000000000000000030000000700020000000100000000000000020000000000000007000200000003000000000000000400000000000000070003000000050000000000000006000000000000000700000000000000
([] name:`symbol$(); iq:`int$())
Expand Down
2 changes: 2 additions & 0 deletions tests/qreader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
('3.23 6.46', qlist(numpy.array([3.23, 6.46], dtype=numpy.float64), qtype=QDOUBLE_LIST)),
('(1;`bcd;"0bc";5.5e)', [numpy.int64(1), numpy.string_('bcd'), '0bc', numpy.float32(5.5)]),
('`the`quick`brown`fox', qlist(numpy.array([numpy.string_('the'), numpy.string_('quick'), numpy.string_('brown'), numpy.string_('fox')], dtype=numpy.object), qtype=QSYMBOL_LIST)),
('``quick``fox', qlist(numpy.array([qnull(QSYMBOL), numpy.string_('quick'), qnull(QSYMBOL), numpy.string_('fox')], dtype=numpy.object), qtype=QSYMBOL_LIST)),
('``', qlist(numpy.array([qnull(QSYMBOL), qnull(QSYMBOL)], dtype=numpy.object), qtype=QSYMBOL_LIST)),
('{x+y}', QLambda('{x+y}')),
('{x+y}[3]', QLambda('{x+y}', numpy.int64(3))),

Expand Down
2 changes: 2 additions & 0 deletions tests/qwriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
('`jumps`over`a`lazy`dog', (numpy.array(['jumps', 'over', 'a', 'lazy', 'dog'], dtype=numpy.string_),
qlist(numpy.array(['jumps', 'over', 'a', 'lazy', 'dog']), qtype = QSYMBOL_LIST))),
('`the`quick`brown`fox', numpy.array([numpy.string_('the'), numpy.string_('quick'), numpy.string_('brown'), numpy.string_('fox')], dtype=numpy.object)),
('``quick``fox', qlist(numpy.array([qnull(QSYMBOL), numpy.string_('quick'), qnull(QSYMBOL), numpy.string_('fox')], dtype=numpy.object), qtype=QSYMBOL_LIST)),
('``', qlist(numpy.array([qnull(QSYMBOL), qnull(QSYMBOL)], dtype=numpy.object), qtype=QSYMBOL_LIST)),
('{x+y}', QLambda('{x+y}')),
('{x+y}[3]', QLambda('{x+y}', numpy.int64(3))),

Expand Down

0 comments on commit 603b8da

Please sign in to comment.