1.1 --- a/iixr.py Fri Sep 11 01:21:09 2009 +0200
1.2 +++ b/iixr.py Fri Sep 11 01:27:18 2009 +0200
1.3 @@ -48,7 +48,17 @@
1.4 # Utility functions.
1.5
1.6 try:
1.7 - from vint import vint
1.8 + from vint import vint as _vint
1.9 +
1.10 + def vint(number):
1.11 +
1.12 + "Write 'number' as a variable-length integer."
1.13 +
1.14 + if number >= 0:
1.15 + return _vint(number)
1.16 + else:
1.17 + raise ValueError, "Number %r is negative." % number
1.18 +
1.19 except ImportError:
1.20
1.21 def vint(number):
2.1 --- a/vint.c Fri Sep 11 01:21:09 2009 +0200
2.2 +++ b/vint.c Fri Sep 11 01:27:18 2009 +0200
2.3 @@ -1,4 +1,4 @@
2.4 -/* Generated by Pyrex 0.9.6.4 on Fri Sep 11 01:17:16 2009 */
2.5 +/* Generated by Pyrex 0.9.6.4 on Fri Sep 11 01:26:01 2009 */
2.6
2.7 #define PY_SSIZE_T_CLEAN
2.8 #include "Python.h"
2.9 @@ -61,41 +61,62 @@
2.10 __pyx_v_s = Py_None; Py_INCREF(Py_None);
2.11
2.12 /* "/home/paulb/Software/Python/iixr/vint.pyx":11 */
2.13 + __pyx_1 = (__pyx_v_number < 128);
2.14 + if (__pyx_1) {
2.15 +
2.16 + /* "/home/paulb/Software/Python/iixr/vint.pyx":12 */
2.17 + (__pyx_v_bytes[0]) = __pyx_v_number;
2.18 +
2.19 + /* "/home/paulb/Software/Python/iixr/vint.pyx":13 */
2.20 + __pyx_2 = PyString_FromStringAndSize(__pyx_v_bytes,1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;}
2.21 + Py_DECREF(__pyx_v_s);
2.22 + __pyx_v_s = __pyx_2;
2.23 + __pyx_2 = 0;
2.24 +
2.25 + /* "/home/paulb/Software/Python/iixr/vint.pyx":14 */
2.26 + Py_INCREF(__pyx_v_s);
2.27 + __pyx_r = __pyx_v_s;
2.28 + goto __pyx_L0;
2.29 + goto __pyx_L2;
2.30 + }
2.31 + __pyx_L2:;
2.32 +
2.33 + /* "/home/paulb/Software/Python/iixr/vint.pyx":16 */
2.34 __pyx_v_i = 0;
2.35
2.36 - /* "/home/paulb/Software/Python/iixr/vint.pyx":12 */
2.37 + /* "/home/paulb/Software/Python/iixr/vint.pyx":17 */
2.38 while (1) {
2.39 __pyx_1 = (__pyx_v_number != 0);
2.40 if (!__pyx_1) break;
2.41
2.42 - /* "/home/paulb/Software/Python/iixr/vint.pyx":13 */
2.43 + /* "/home/paulb/Software/Python/iixr/vint.pyx":18 */
2.44 __pyx_v_lsd = (__pyx_v_number & 127);
2.45
2.46 - /* "/home/paulb/Software/Python/iixr/vint.pyx":14 */
2.47 + /* "/home/paulb/Software/Python/iixr/vint.pyx":19 */
2.48 __pyx_v_number = (__pyx_v_number >> 7);
2.49
2.50 - /* "/home/paulb/Software/Python/iixr/vint.pyx":15 */
2.51 + /* "/home/paulb/Software/Python/iixr/vint.pyx":20 */
2.52 __pyx_1 = (__pyx_v_number != 0);
2.53 if (__pyx_1) {
2.54 __pyx_v_lsd = (__pyx_v_lsd | 128);
2.55 - goto __pyx_L4;
2.56 + goto __pyx_L5;
2.57 }
2.58 - __pyx_L4:;
2.59 + __pyx_L5:;
2.60
2.61 - /* "/home/paulb/Software/Python/iixr/vint.pyx":17 */
2.62 + /* "/home/paulb/Software/Python/iixr/vint.pyx":22 */
2.63 (__pyx_v_bytes[__pyx_v_i]) = __pyx_v_lsd;
2.64
2.65 - /* "/home/paulb/Software/Python/iixr/vint.pyx":18 */
2.66 + /* "/home/paulb/Software/Python/iixr/vint.pyx":23 */
2.67 __pyx_v_i = (__pyx_v_i + 1);
2.68 }
2.69
2.70 - /* "/home/paulb/Software/Python/iixr/vint.pyx":20 */
2.71 - __pyx_2 = PyString_FromStringAndSize(__pyx_v_bytes,__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;}
2.72 + /* "/home/paulb/Software/Python/iixr/vint.pyx":25 */
2.73 + __pyx_2 = PyString_FromStringAndSize(__pyx_v_bytes,__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;}
2.74 Py_DECREF(__pyx_v_s);
2.75 __pyx_v_s = __pyx_2;
2.76 __pyx_2 = 0;
2.77
2.78 - /* "/home/paulb/Software/Python/iixr/vint.pyx":21 */
2.79 + /* "/home/paulb/Software/Python/iixr/vint.pyx":26 */
2.80 Py_INCREF(__pyx_v_s);
2.81 __pyx_r = __pyx_v_s;
2.82 goto __pyx_L0;
3.1 --- a/vint.pyx Fri Sep 11 01:21:09 2009 +0200
3.2 +++ b/vint.pyx Fri Sep 11 01:27:18 2009 +0200
3.3 @@ -8,6 +8,11 @@
3.4 cdef char bytes[40] # NOTE: Arbitrary limit.
3.5 cdef int lsd, i
3.6
3.7 + if number < 128:
3.8 + bytes[0] = number
3.9 + s = PyString_FromStringAndSize(bytes, 1)
3.10 + return s
3.11 +
3.12 i = 0
3.13 while number != 0:
3.14 lsd = number & 127