提交 b79784ee 编写于 作者: G gongweibao

fix bugs

上级 0fa40924
......@@ -26,17 +26,27 @@ class client(object):
holder[idx] = c_ptr
lib.paddle_set_dataset(self.c, holder, len(paths))
# return format: (record, errno)
# errno = 0: ok
# = -1: EOF
# < -1: error
def next_record(self):
p = ctypes.c_char_p()
ret = ctypes.pointer(p)
size = lib.paddle_next_record(self.c, ret)
if size < 0:
if size == -1:
# EOF
return None
return None, -1
if size < -1:
# Error
return None, size
if size == 0:
# Empty record
return ""
return "", 0
record = ret.contents.value[:size]
# Memory created from C should be freed.
lib.mem_free(ret.contents)
return record
return record, 0
......@@ -97,7 +97,7 @@ def recordio(paths, addr="", buf_size=100):
c.set_dataset(paths)
while True:
r = client.next_record()
r, err = client.next_record()
if r is None:
break
yield r
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册