2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/setup.py Fri Sep 11 01:21:09 2009 +0200
2.3 @@ -0,0 +1,16 @@
2.4 +#! /usr/bin/env python
2.5 +
2.6 +from distutils.core import setup, Extension
2.7 +
2.8 +vint = Extension("vint", ["vint.c"])
2.9 +
2.10 +setup(
2.11 + name = "iixr",
2.12 + description = "A simple (and sane) text indexing library",
2.13 + author = "Paul Boddie",
2.14 + author_email = "paul@boddie.org.uk",
2.15 + url = "http://www.boddie.org.uk/python/iixr.html",
2.16 + version = "0.1",
2.17 + py_modules = ["iixr", "itermerge"],
2.18 + ext_modules = [vint],
2.19 + )
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/vint.c Fri Sep 11 01:21:09 2009 +0200
3.3 @@ -0,0 +1,203 @@
3.4 +/* Generated by Pyrex 0.9.6.4 on Fri Sep 11 01:17:16 2009 */
3.5 +
3.6 +#define PY_SSIZE_T_CLEAN
3.7 +#include "Python.h"
3.8 +#include "structmember.h"
3.9 +#ifndef PY_LONG_LONG
3.10 + #define PY_LONG_LONG LONG_LONG
3.11 +#endif
3.12 +#if PY_VERSION_HEX < 0x02050000
3.13 + typedef int Py_ssize_t;
3.14 + #define PY_SSIZE_T_MAX INT_MAX
3.15 + #define PY_SSIZE_T_MIN INT_MIN
3.16 + #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
3.17 + #define PyInt_AsSsize_t(o) PyInt_AsLong(o)
3.18 +#endif
3.19 +#ifndef WIN32
3.20 + #ifndef __stdcall
3.21 + #define __stdcall
3.22 + #endif
3.23 + #ifndef __cdecl
3.24 + #define __cdecl
3.25 + #endif
3.26 +#endif
3.27 +#ifdef __cplusplus
3.28 +#define __PYX_EXTERN_C extern "C"
3.29 +#else
3.30 +#define __PYX_EXTERN_C extern
3.31 +#endif
3.32 +#include <math.h>
3.33 +
3.34 +
3.35 +typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
3.36 +typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
3.37 +
3.38 +static PyObject *__pyx_m;
3.39 +static PyObject *__pyx_b;
3.40 +static int __pyx_lineno;
3.41 +static char *__pyx_filename;
3.42 +static char **__pyx_f;
3.43 +
3.44 +static void __Pyx_AddTraceback(char *funcname); /*proto*/
3.45 +
3.46 +/* Declarations from vint */
3.47 +
3.48 +
3.49 +
3.50 +/* Implementation of vint */
3.51 +
3.52 +static PyObject *__pyx_f_4vint_vint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
3.53 +static PyObject *__pyx_f_4vint_vint(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
3.54 + int __pyx_v_number;
3.55 + char __pyx_v_bytes[40];
3.56 + int __pyx_v_lsd;
3.57 + int __pyx_v_i;
3.58 + PyObject *__pyx_v_s;
3.59 + PyObject *__pyx_r;
3.60 + int __pyx_1;
3.61 + PyObject *__pyx_2 = 0;
3.62 + static char *__pyx_argnames[] = {"number",0};
3.63 + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "i", __pyx_argnames, &__pyx_v_number)) return 0;
3.64 + __pyx_v_s = Py_None; Py_INCREF(Py_None);
3.65 +
3.66 + /* "/home/paulb/Software/Python/iixr/vint.pyx":11 */
3.67 + __pyx_v_i = 0;
3.68 +
3.69 + /* "/home/paulb/Software/Python/iixr/vint.pyx":12 */
3.70 + while (1) {
3.71 + __pyx_1 = (__pyx_v_number != 0);
3.72 + if (!__pyx_1) break;
3.73 +
3.74 + /* "/home/paulb/Software/Python/iixr/vint.pyx":13 */
3.75 + __pyx_v_lsd = (__pyx_v_number & 127);
3.76 +
3.77 + /* "/home/paulb/Software/Python/iixr/vint.pyx":14 */
3.78 + __pyx_v_number = (__pyx_v_number >> 7);
3.79 +
3.80 + /* "/home/paulb/Software/Python/iixr/vint.pyx":15 */
3.81 + __pyx_1 = (__pyx_v_number != 0);
3.82 + if (__pyx_1) {
3.83 + __pyx_v_lsd = (__pyx_v_lsd | 128);
3.84 + goto __pyx_L4;
3.85 + }
3.86 + __pyx_L4:;
3.87 +
3.88 + /* "/home/paulb/Software/Python/iixr/vint.pyx":17 */
3.89 + (__pyx_v_bytes[__pyx_v_i]) = __pyx_v_lsd;
3.90 +
3.91 + /* "/home/paulb/Software/Python/iixr/vint.pyx":18 */
3.92 + __pyx_v_i = (__pyx_v_i + 1);
3.93 + }
3.94 +
3.95 + /* "/home/paulb/Software/Python/iixr/vint.pyx":20 */
3.96 + __pyx_2 = PyString_FromStringAndSize(__pyx_v_bytes,__pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;}
3.97 + Py_DECREF(__pyx_v_s);
3.98 + __pyx_v_s = __pyx_2;
3.99 + __pyx_2 = 0;
3.100 +
3.101 + /* "/home/paulb/Software/Python/iixr/vint.pyx":21 */
3.102 + Py_INCREF(__pyx_v_s);
3.103 + __pyx_r = __pyx_v_s;
3.104 + goto __pyx_L0;
3.105 +
3.106 + __pyx_r = Py_None; Py_INCREF(Py_None);
3.107 + goto __pyx_L0;
3.108 + __pyx_L1:;
3.109 + Py_XDECREF(__pyx_2);
3.110 + __Pyx_AddTraceback("vint.vint");
3.111 + __pyx_r = 0;
3.112 + __pyx_L0:;
3.113 + Py_DECREF(__pyx_v_s);
3.114 + return __pyx_r;
3.115 +}
3.116 +
3.117 +static struct PyMethodDef __pyx_methods[] = {
3.118 + {"vint", (PyCFunction)__pyx_f_4vint_vint, METH_VARARGS|METH_KEYWORDS, 0},
3.119 + {0, 0, 0, 0}
3.120 +};
3.121 +
3.122 +static void __pyx_init_filenames(void); /*proto*/
3.123 +
3.124 +PyMODINIT_FUNC initvint(void); /*proto*/
3.125 +PyMODINIT_FUNC initvint(void) {
3.126 + __pyx_init_filenames();
3.127 + __pyx_m = Py_InitModule4("vint", __pyx_methods, 0, 0, PYTHON_API_VERSION);
3.128 + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
3.129 + Py_INCREF(__pyx_m);
3.130 + __pyx_b = PyImport_AddModule("__builtin__");
3.131 + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
3.132 + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; goto __pyx_L1;};
3.133 +
3.134 + /* "/home/paulb/Software/Python/iixr/vint.pyx":6 */
3.135 + return;
3.136 + __pyx_L1:;
3.137 + __Pyx_AddTraceback("vint");
3.138 +}
3.139 +
3.140 +static char *__pyx_filenames[] = {
3.141 + "vint.pyx",
3.142 +};
3.143 +
3.144 +/* Runtime support code */
3.145 +
3.146 +static void __pyx_init_filenames(void) {
3.147 + __pyx_f = __pyx_filenames;
3.148 +}
3.149 +
3.150 +#include "compile.h"
3.151 +#include "frameobject.h"
3.152 +#include "traceback.h"
3.153 +
3.154 +static void __Pyx_AddTraceback(char *funcname) {
3.155 + PyObject *py_srcfile = 0;
3.156 + PyObject *py_funcname = 0;
3.157 + PyObject *py_globals = 0;
3.158 + PyObject *empty_tuple = 0;
3.159 + PyObject *empty_string = 0;
3.160 + PyCodeObject *py_code = 0;
3.161 + PyFrameObject *py_frame = 0;
3.162 +
3.163 + py_srcfile = PyString_FromString(__pyx_filename);
3.164 + if (!py_srcfile) goto bad;
3.165 + py_funcname = PyString_FromString(funcname);
3.166 + if (!py_funcname) goto bad;
3.167 + py_globals = PyModule_GetDict(__pyx_m);
3.168 + if (!py_globals) goto bad;
3.169 + empty_tuple = PyTuple_New(0);
3.170 + if (!empty_tuple) goto bad;
3.171 + empty_string = PyString_FromString("");
3.172 + if (!empty_string) goto bad;
3.173 + py_code = PyCode_New(
3.174 + 0, /*int argcount,*/
3.175 + 0, /*int nlocals,*/
3.176 + 0, /*int stacksize,*/
3.177 + 0, /*int flags,*/
3.178 + empty_string, /*PyObject *code,*/
3.179 + empty_tuple, /*PyObject *consts,*/
3.180 + empty_tuple, /*PyObject *names,*/
3.181 + empty_tuple, /*PyObject *varnames,*/
3.182 + empty_tuple, /*PyObject *freevars,*/
3.183 + empty_tuple, /*PyObject *cellvars,*/
3.184 + py_srcfile, /*PyObject *filename,*/
3.185 + py_funcname, /*PyObject *name,*/
3.186 + __pyx_lineno, /*int firstlineno,*/
3.187 + empty_string /*PyObject *lnotab*/
3.188 + );
3.189 + if (!py_code) goto bad;
3.190 + py_frame = PyFrame_New(
3.191 + PyThreadState_Get(), /*PyThreadState *tstate,*/
3.192 + py_code, /*PyCodeObject *code,*/
3.193 + py_globals, /*PyObject *globals,*/
3.194 + 0 /*PyObject *locals*/
3.195 + );
3.196 + if (!py_frame) goto bad;
3.197 + py_frame->f_lineno = __pyx_lineno;
3.198 + PyTraceBack_Here(py_frame);
3.199 +bad:
3.200 + Py_XDECREF(py_srcfile);
3.201 + Py_XDECREF(py_funcname);
3.202 + Py_XDECREF(empty_tuple);
3.203 + Py_XDECREF(empty_string);
3.204 + Py_XDECREF(py_code);
3.205 + Py_XDECREF(py_frame);
3.206 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/vint.pyx Fri Sep 11 01:21:09 2009 +0200
4.3 @@ -0,0 +1,23 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +cdef extern from "Python.h":
4.7 + object PyString_FromStringAndSize(char *, int)
4.8 +
4.9 +def vint(int number):
4.10 +
4.11 + cdef char bytes[40] # NOTE: Arbitrary limit.
4.12 + cdef int lsd, i
4.13 +
4.14 + i = 0
4.15 + while number != 0:
4.16 + lsd = number & 127
4.17 + number = number >> 7
4.18 + if number != 0:
4.19 + lsd = lsd | 128
4.20 + bytes[i] = lsd
4.21 + i = i + 1
4.22 +
4.23 + s = PyString_FromStringAndSize(bytes, i)
4.24 + return s
4.25 +
4.26 +# vim: tabstop=4 expandtab shiftwidth=4