Permalink
Browse files

Remove wrappers from C++ to C and Python

The wrappers from C++ to C and Python were added to LibNeubot following
this rationale:

1) LibNeubot was to be written in C++ for SWIG to generate more
   easily usable NDK/JNI code;

2) The C interface was helpful to cherry-pick functions from Python
   using ctypes and to create a nice Python interface around the rought
   edges of the ctypes interface. In turn, this was because LibNeubot
   was to be used both for mobile and Neubot for PC.

After the discussion with @hellais that led to Libight, the scope was
narrowed to include only 1), because Libight is meant to support Neubot
and OONI on mobile platforms only.

Therefore (and, also, because the wrappers are on my way now that I am
working on a fully C++ poller that uses std::function and other C++11
goodies), I suggest that we remove the `optional complexity` represented
by 2) to develop more quickly.

In fact, if 2) is not a Libight objective, my time is better spent working
on the C++ core rather than working to keep 2) up to date.

I tested this change by rebuilding everything as in `make distclean;
autoreconf -i; ./configure; make V=0 check', without breakages or new
warnings.

I am aware that this diff removes some Python based tests, but C++ tests
are to be written in any case (I'd rather do testing of the C++ core than
do testing of the Python wrapper of the C wrapper of the core itself).
  • Loading branch information...
bassosimone committed Jun 6, 2014
1 parent 0ab0db4 commit 98def29b2520c09b5789ec64bd7dd90a7e4bf889
Showing with 0 additions and 2,745 deletions.
  1. +0 −1,017 _libight.py
  2. +0 −30 config.local
  3. +0 −3 configure.ac
  4. +0 −91 libight.json
  5. +0 −182 scripts/gen_header
  6. +0 −471 scripts/gen_python
  7. +0 −342 src/ight_wrappers.cpp
  8. +0 −74 src/ight_wrappers.h
  9. +0 −24 test/callback1.py
  10. +0 −86 test/connection.py
  11. +0 −24 test/dns1.py
  12. +0 −20 test/echo1.py
  13. +0 −188 test/echo_client2.c
  14. +0 −4 test/include.am
  15. +0 −42 test/pollable1.py
  16. +0 −34 test/poller1.py
  17. +0 −62 test/self_connection.py
  18. +0 −30 test/stringvector.py
  19. +0 −21 test/typesafety.py
View
1,017 _libight.py

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,30 +0,0 @@
#!/bin/sh -e
#
# Copyright (c) 2013-2014
# Nexa Center for Internet & Society, Politecnico di Torino (DAUIN)
# and Simone Basso <bassosimone@gmail.com>.
#
# This file is part of Neubot <http://www.neubot.org/>.
#
# Neubot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Neubot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Neubot. If not, see <http://www.gnu.org/licenses/>.
#
echo "Generate: src/ight_wrappers.h"
./scripts/gen_header libight.json > src/ight_wrappers.h
echo "Generate: _libight.py"
./scripts/gen_python libight.json > _libight.py
View
@@ -47,7 +47,6 @@ AC_CANONICAL_HOST
# checks for programs
AC_PROG_INSTALL
AC_PROG_CXX([clang++ g++ c++])
AM_PATH_PYTHON([2.6])
# checks for libraries
@@ -92,5 +91,3 @@ AC_LANG_POP([C++])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
./config.local
View
@@ -1,91 +0,0 @@
{
"__license__": "Public domain, 2013-2014 Simone Basso.",
"classes": [
["IghtPoller", [
["__construct__", "construct"],
["status_t", "sched", ["double", "delta"],
["hook_vo", ["callback"]]],
["status_t", "defer_read", ["long long", "fileno"],
["hook_vo", ["handle_ok", "handle_timeout"]],
["double", "timeout"]],
["status_t", "defer_write", ["long long", "fileno"],
["hook_vo", ["handle_ok", "handle_timeout"]],
["double", "timeout"]],
["status_t", "resolve", ["cstring", "family"], ["cstring", "name"],
["hook_vos", ["callback"]]],
["void", "loop"],
["void", "break_loop"]
]],
["IghtStringVector", [
["__construct__", "construct", ["__gettable__", "IghtPoller_p",
"poller"], ["size_t", "count"]],
["status_t", "append", ["cstring", "str"]],
["__object_getter__", "poller"],
["cstring", "get_next"],
["__destruct__", "destruct"]
]],
["IghtEchoServer", [
["__construct__", "construct", ["IghtPoller_p", "poller"],
["int", "use_ipv6"], ["cstring", "address"],
["cstring", "port"]]
]],
["IghtProtocol", [
["__construct__", "construct", ["__gettable__", "IghtPoller_p",
"poller"], ["slot_vo", ["handle_connect", "handle_ssl",
"handle_data", "handle_flush", "handle_eof", "handle_error"]]],
["__object_getter__", "poller"],
["__destruct__", "destruct"]
]],
["IghtConnection", [
["__static_construct__", "attach", ["__gettable__",
"IghtProtocol_p", "protocol"], ["long long", "filenum"]],
["__static_construct__", "connect", ["__gettable__",
"IghtProtocol_p", "protocol"], ["cstring", "family"],
["cstring", "address"], ["cstring", "port"]],
["__static_construct__", "connect_hostname", ["__gettable__",
"IghtProtocol_p", "protocol"], ["cstring", "family"],
["cstring", "address"], ["cstring", "port"]],
["__object_getter__", "protocol"],
["status_t", "set_timeout", ["double", "timeo"]],
["status_t", "clear_timeout"],
["status_t", "start_tls", ["unsigned", "server_side"]],
["ioresult_t", "read", ["string", "base"], ["size_t", "count"]],
["ioresult_t", "readline", ["string", "base"], ["size_t", "count"]],
["ioresult_t", "readn", ["string", "base"], ["size_t", "count"]],
["ioresult_t", "discardn", ["size_t", "count"]],
["status_t", "write", ["cstring", "base"], ["size_t", "count"]],
["status_t", "puts", ["cstring", "base"]],
["status_t", "write_rand", ["size_t", "count"]],
["status_t", "write_readbuf", ["cstring", "base"],
["size_t", "count"]],
["status_t", "puts_readbuf", ["cstring", "base"]],
["status_t", "write_rand_readbuf", ["size_t", "count"]],
["status_t", "read_into_", ["evbuffer_p", "evdest"]],
["status_t", "write_from_", ["evbuffer_p", "evsource"]],
["status_t", "enable_read"],
["status_t", "disable_read"],
["__destruct__", "close"]
]],
["IghtPollable", [
["__construct__", "construct", ["IghtPoller_p", "poller"],
["slot_vo", ["handle_read", "handle_write", "handle_error"]]],
["status_t", "attach", ["long long", "filenum"]],
["void", "detach"],
["long long", "get_fileno"],
["status_t", "set_readable"],
["status_t", "unset_readable"],
["status_t", "set_writable"],
["status_t", "unset_writable"],
["void", "set_timeout", ["double", "delta"]],
["void", "clear_timeout"],
["__destruct__", "close"]
]]
]
}
View
@@ -1,182 +0,0 @@
#!/usr/bin/env python
#
# Copyright (c) 2013
# Nexa Center for Internet & Society, Politecnico di Torino (DAUIN)
# and Simone Basso <bassosimone@gmail.com>.
#
# This file is part of Neubot <http://www.neubot.org/>.
#
# Neubot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Neubot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Neubot. If not, see <http://www.gnu.org/licenses/>.
#
# pylint: disable = C0111
import json
import sys
CLANG_TYPE = {
"Object": "void *",
"cstring": "const char *",
"evbuffer_p": "struct evbuffer *",
"hook_vo": "ight_hook_vo",
"hook_vos": "ight_hook_vos",
"ioresult_t": "int",
"slot_vo": "ight_slot_vo",
"status_t": "int",
"string": "char *",
"void_p": "void *",
}
def clang_comment(string):
sys.stdout.write("/* %s */\n" % string)
def clang_empty_line():
sys.stdout.write("\n")
def clang_write_copyright():
sys.stdout.write("/*\n")
sys.stdout.write(" * Libight interface - Public domain.\n")
sys.stdout.write(" * WARNING: Autogenerated file - do not edit!\n")
sys.stdout.write(" */\n")
def clang_type(name):
return CLANG_TYPE.get(name, name)
def clang_declare_class(name):
sys.stdout.write("struct %s;\n" % name)
CLANG_TYPE[name] = "struct " + name
CLANG_TYPE[name + "_p"] = "struct " + name + " *"
def clang_declare_method(name, method):
if method[0] in ("__construct__", "__static_construct__"):
retval = name + "_p"
funcname = name + "_" + method[1]
args = method[2:]
elif method[0] == "__destruct__":
retval = "void"
funcname = name + "_" + method[1]
args = method[2:]
args.insert(0, (name + "_p", "self"))
else:
retval = method[0]
funcname = name + "_" + method[1]
args = method[2:]
args.insert(0, (name + "_p", "self"))
retval = clang_type(retval)
if retval.endswith("*"):
space = ""
else:
space = " "
sys.stdout.write("%s%s%s(" % (retval, space, funcname))
if args:
total = len(retval) + len(funcname) + 2
new_args = []
for argtype, argname in args:
if argtype.startswith("slot_") or argtype.startswith("hook_"):
for sh_name in argname:
new_args.append((argtype, sh_name))
new_args.append(("Object", "opaque"))
else:
new_args.append((argtype, argname))
for index, elem in enumerate(new_args):
name, _ = elem
name = clang_type(name)
if index > 0:
sys.stdout.write(",")
total += 1
if total + len(name) >= 78:
sys.stdout.write("\n ")
total = 4
elif index > 0:
sys.stdout.write(" ")
total += 1
total += len(name)
sys.stdout.write("%s" % name)
else:
sys.stdout.write("void")
sys.stdout.write(");\n")
def main():
path = sys.argv[1]
filep = open(path, "r")
interface = json.load(filep)
clang_write_copyright()
clang_empty_line()
sys.stdout.write("#ifndef IGHT_WRAPPERS_H\n")
sys.stdout.write("# define IGHT_WRAPPERS_H\n")
sys.stdout.write("\n")
sys.stdout.write("#ifdef __cplusplus\n")
sys.stdout.write("extern \"C\" {\n")
sys.stdout.write("#endif\n")
sys.stdout.write("\n")
sys.stdout.write("/* Hooks and slots: */\n")
sys.stdout.write("\n")
sys.stdout.write("typedef void (*ight_hook_vo)(void *);\n")
sys.stdout.write("typedef void (*ight_hook_vos)(void *, const char *);\n")
sys.stdout.write("\n")
sys.stdout.write("typedef void (*ight_slot_vo)(void *);\n")
sys.stdout.write("\n")
sys.stdout.write("struct evbuffer;\n")
sys.stdout.write("\n")
clang_comment("Classes:")
clang_empty_line()
for name, _ in sorted(interface["classes"]):
clang_declare_class(name)
clang_empty_line()
for name, methods in interface["classes"]:
clang_comment("%s API:" % name)
clang_empty_line()
gettables = {}
for method in methods:
if method[0] in ("__construct__", "__static_construct__"):
new_method = [method[0], method[1]]
for elem in method[2:]:
if len(elem) == 2:
new_method.append(elem)
continue
if len(elem) != 3 or elem[0] != "__gettable__":
raise RuntimeError("invalid argument")
new_method.append([elem[1], elem[2]])
if elem[2] not in gettables:
gettables[elem[2]] = elem[1]
elif gettables[elem[2]] != elem[1]:
raise RuntimeError("inconsistent gettables")
method = new_method
elif method[0] == "__object_getter__":
method = [gettables[method[1]], "get_" + method[1]]
clang_declare_method(name, method)
clang_empty_line()
sys.stdout.write("#ifdef __cplusplus\n")
sys.stdout.write("}\n")
sys.stdout.write("#endif\n")
sys.stdout.write("\n")
sys.stdout.write("#endif /* IGHT_WRAPPERS_H */\n")
if __name__ == "__main__":
main()
Oops, something went wrong.

0 comments on commit 98def29

Please sign in to comment.