[MERGE] BEncode Pyrex, pt 5
Alexander Belchenko
bialix at ukr.net
Thu May 28 05:39:04 BST 2009
bb:comment
1) You don't keep reference to original python string passed to Decoder, but refer to internal char
buffer. Is it safe? Is it possible situation when such string will be garbage collected while decode
loop still working?
2) self.tail points to internal char buffer of python object
cdef object _decode_int(self):
cdef int i
i = self._read_digits(c'e')
self.tail[i] = 0;
ret = PyInt_FromString(self.tail, NULL, 10)
self.tail[i] = c'e';
According to python documentation you should not modify internal buffer of python string. So you're
change it before calling PyInt_FromString ad revert it back after. What if this function raise
exception? Would it better to use try-finally here?
BTW, you don't need to use trailing semicolons in the pyrex sources ;-)
3) I'd prefer to use enum or macro constant instead of literal 32 here:
cdef int _encode_string(self, x) except 0:
cdef int n
self._ensure_buffer(PyString_GET_SIZE(x) + 32)
n = snprintf(self.tail, 32, '%d:', PyString_GET_SIZE(x))
4) I can't find any documentation on Py_EnterRecursiveCall/Py_LeaveRecursiveCall. Where should I look?
More information about the bazaar
mailing list