2009-09-11 | Paul Boddie | raw annotate files changeset graph | Added a Pyrex implementation of the vint function. |
1 #!/usr/bin/env python 2 3 cdef extern from "Python.h": 4 object PyString_FromStringAndSize(char *, int) 5 6 def vint(int number): 7 8 cdef char bytes[40] # NOTE: Arbitrary limit. 9 cdef int lsd, i 10 11 i = 0 12 while number != 0: 13 lsd = number & 127 14 number = number >> 7 15 if number != 0: 16 lsd = lsd | 128 17 bytes[i] = lsd 18 i = i + 1 19 20 s = PyString_FromStringAndSize(bytes, i) 21 return s 22 23 # vim: tabstop=4 expandtab shiftwidth=4