diff --git a/bindings/ctypes/Makefile b/bindings/ctypes/Makefile new file mode 100644 index 00000000..ec753198 --- /dev/null +++ b/bindings/ctypes/Makefile @@ -0,0 +1,5 @@ +all: + valabind --ctypes --module sdb -l sdb ../vala/sdb.vapi + +pub publish: + LC_CTYPE=C python setup.py sdist upload diff --git a/bindings/python/sdb.py b/bindings/ctypes/sdb.py similarity index 100% rename from bindings/python/sdb.py rename to bindings/ctypes/sdb.py diff --git a/bindings/python/sdb3.py b/bindings/ctypes/sdb3.py similarity index 100% rename from bindings/python/sdb3.py rename to bindings/ctypes/sdb3.py diff --git a/bindings/ctypes/test.py b/bindings/ctypes/test.py new file mode 100644 index 00000000..814c1038 --- /dev/null +++ b/bindings/ctypes/test.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from sdb import * + +db = Sdb(None, "test.sdb", False) +db.set("foo", "World",0) +print("Hello " + db.get("foo", None)) +db.query(b"foo=Patata") +#print("--> "+db.querys(None, 0, ("foo").decode("utf-8"), 0, None)) +#print("--> "+db.querys(None, 0, "foo")) +db.sync() diff --git a/bindings/python/Makefile b/bindings/python/Makefile index ec753198..db540371 100644 --- a/bindings/python/Makefile +++ b/bindings/python/Makefile @@ -1,5 +1,5 @@ all: - valabind --ctypes --module sdb -l sdb ../vala/sdb.vapi + python setup.py build_ext -j 8 -i -I../../src -pub publish: - LC_CTYPE=C python setup.py sdist upload +clean: + rm -rf *.out *.bin *.exe *.o *.a *.so test build diff --git a/bindings/python/pysdb.c b/bindings/python/pysdb.c new file mode 100644 index 00000000..0241f714 --- /dev/null +++ b/bindings/python/pysdb.c @@ -0,0 +1,54 @@ +#include +#include + +PyObject * hello(PyObject * self) { + Sdb *db = sdb_new0(); + sdb_set (db, "foo", "bar", 0); + sdb_free (db); + return PyUnicode_FromFormat("Hello C extension!"); +} + +PyObject * open(PyObject * self, PyObject *args) { + const char * command = NULL; + if (!PyArg_ParseTuple(args, "s", &command)) { + return NULL; + } +eprintf ("OPEN (%s)\n", command); + ////PyObject *item = PyObject_SetItem(self, file_name); + PyObject *res = PyUnicode_FromString (command); + Sdb *db = sdb_new0(); + sdb_set (db, "foo", "bar", 0); + return res; // PyUnicode_FromFormat("Hello C extension!"); +} + +char hellofunc_docs[] = "Hello world description."; + +PyMethodDef sdb_funcs[] = { + { "hello", + (PyCFunction)hello, + METH_NOARGS, + hellofunc_docs}, + { "open", + (PyCFunction)open, + METH_VARARGS, + hellofunc_docs}, + { NULL} +}; + +static const char sdbmod_docs[] = "This is the native sdb module for Python"; + +PyModuleDef sdb_mod = { + PyModuleDef_HEAD_INIT, + "sdb", + sdbmod_docs, + -1, + sdb_funcs, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC PyInit_sdb(void) { + return PyModule_Create(&sdb_mod); +} diff --git a/bindings/python/setup.py b/bindings/python/setup.py new file mode 100644 index 00000000..0784cafc --- /dev/null +++ b/bindings/python/setup.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +from distutils.core import setup, Extension + +setup( + name = "sdb", + version = "1.8.8", + ext_modules = [Extension("sdb", + ["pysdb.c", +"../../src/cdb_make.c", +"../../src/dict.c", +"../../src/match.c", +"../../src/json.c", +"../../src/diff.c", +"../../src/buffer.c", +"../../src/ls.c", +"../../src/util.c", +"../../src/array.c", +"../../src/cdb.c", +"../../src/journal.c", +"../../src/ht_uu.c", +"../../src/set.c", +"../../src/sdb.c", +"../../src/ht_pu.c", +"../../src/sdbht.c", +#"../../src/json/api.c", +#"../../src/json/rangstr.c", +#"../../src/json/main.c", +#"../../src/json/js0n.c", +#"../../src/json/path.c", +#"../../src/json/test.c", +#"../../src/json/indent.c", +"../../src/ht_up.c", +"../../src/main.c", +"../../src/query.c", +"../../src/base64.c", +"../../src/text.c", +"../../src/ht_pp.c", +"../../src/num.c", +"../../src/lock.c", +"../../src/disk.c", +"../../src/fmt.c", +"../../src/ns.c", + +], + include_dirs = ["../../src"] +)] + #extra_compile_args = ["-L../../src", "../../src/libsdb.a"])] + ); diff --git a/bindings/python/test.py b/bindings/python/test.py old mode 100644 new mode 100755 index b3c34f52..539f878c --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -1,11 +1,14 @@ -#!/usr/bin/python +#!/usr/bin/env python3 -from sdb import * +import sdb -db = Sdb(None, "test.sdb", False) -db.set("foo", "World",0) -print("Hello "+db.get("foo", None)) -db.query(b"foo=Patata") -#print("--> "+db.querys(None, 0, ("foo").decode("utf-8"), 0, None)) -#print("--> "+db.querys(None, 0, "foo")) -db.sync() +db = sdb.open("test.sdb") +print(db) + +#db.set("hello", "world") +#s = db.get("hello") +#print(s) +#db.close() + +print(sdb.hello()); +# help(sdb); diff --git a/test/bench/Makefile b/test/bench/Makefile index 7c38b3c6..94900f6d 100644 --- a/test/bench/Makefile +++ b/test/bench/Makefile @@ -1,6 +1,8 @@ include ../sdb-test.mk TESTS=array new sync set reset stack +CFLAGS+=-I../../src +LDFLAGS+=../../src/libsdb.a BINS=$(addprefix bench-,${TESTS}) OBJS=$(addsuffix .o,${BINS}) diff --git a/test/bench/bench-array.c b/test/bench/bench-array.c index 9d891c0d..6587c9c7 100644 --- a/test/bench/bench-array.c +++ b/test/bench/bench-array.c @@ -7,7 +7,7 @@ void arradd (int count) { int i; Sdb *db = sdb_new (NULL, NULL, 0); r_prof_start (&p); - for (i=0; i