diff --git a/kitty/data-types.c b/kitty/data-types.c index c8d68b89c..6f8dac951 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -13,10 +13,14 @@ extern int init_ColorProfile(PyObject *); extern int init_SpriteMap(PyObject *); extern int init_ChangeTracker(PyObject *); extern PyObject* create_256_color_table(); +extern PyObject* parse_bytes_dump(PyObject UNUSED *self, PyObject *val); +extern PyObject* parse_bytes(PyObject UNUSED *self, PyObject *val); #include "gl.h" static PyMethodDef module_methods[] = { GL_METHODS + {"parse_bytes", (PyCFunction)parse_bytes, METH_VARARGS, ""}, + {"parse_bytes_dump", (PyCFunction)parse_bytes_dump, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/kitty/parser.c b/kitty/parser.c new file mode 100644 index 000000000..bd3021f05 --- /dev/null +++ b/kitty/parser.c @@ -0,0 +1,20 @@ +/* + * parser.c + * Copyright (C) 2016 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#include "data-types.h" + + +PyObject* +#ifdef DUMP_COMMANDS +parse_bytes_dump(PyObject UNUSED *self, PyObject *args) { +#else +parse_bytes(PyObject UNUSED *self, PyObject *args) { +#endif + Py_buffer pybuf; + if (!PyArg_ParseTuple(args, "y*", &pybuf)) return NULL; + Py_RETURN_NONE; +} diff --git a/setup.py b/setup.py index 7afa82225..ebde36759 100644 --- a/setup.py +++ b/setup.py @@ -71,6 +71,10 @@ def init_env(debug=False): pass +def define(x): + return '-D' + x + + def run_tool(cmd): if isinstance(cmd, str): cmd = shlex.split(cmd[0]) @@ -80,13 +84,22 @@ def run_tool(cmd): if ret != 0: raise SystemExit(ret) +SPECIAL_SOURCES = { + 'kitty/parser_dump.c': ('kitty/parser.c', ['DUMP_COMMANDS']), +} + def compile_c_extension(module, *sources): prefix = os.path.basename(module) objects = [os.path.join(build_dir, prefix + '-' + os.path.basename(src) + '.o') for src in sources] for src, dest in zip(sources, objects): + cflgs = cflags[:] + if src in SPECIAL_SOURCES: + src, defines = SPECIAL_SOURCES[src] + cflgs.extend(map(define, defines)) + src = os.path.join(base, src) - run_tool([cc] + cflags + ['-c', src] + ['-o', dest]) + run_tool([cc] + cflgs + ['-c', src] + ['-o', dest]) run_tool([cc] + ldflags + objects + ldpaths + ['-o', os.path.join(base, module + '.so')]) @@ -103,6 +116,7 @@ def find_c_files(): for x in os.listdir(d): if x.endswith('.c'): yield os.path.join('kitty', x) + yield 'kitty/parser_dump.c' def main():