Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work on a native python module #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bindings/ctypes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
valabind --ctypes --module sdb -l sdb ../vala/sdb.vapi

pub publish:
LC_CTYPE=C python setup.py sdist upload
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions bindings/ctypes/test.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions bindings/python/Makefile
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions bindings/python/pysdb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <Python.h>
#include <sdb.h>

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);
}
49 changes: 49 additions & 0 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
@@ -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"])]
);
21 changes: 12 additions & 9 deletions bindings/python/test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions test/bench/Makefile
Original file line number Diff line number Diff line change
@@ -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})

Expand Down
2 changes: 1 addition & 1 deletion test/bench/bench-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<count; i++) {
for (i=0; i < count; i++) {
sprintf (rkey, "%d", i);
sdb_array_set (db, "foo", -1, rkey, 0);
}
Expand Down