diff options
author | Jack Lloyd <[email protected]> | 2019-04-19 06:56:26 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-04-19 06:56:26 -0400 |
commit | 164b1dcf148ac7caa45074819b5f934143b92682 (patch) | |
tree | be1957e98111d2aae6a2abd0c86a08a939d834b3 /src/scripts/ffi_decls.py | |
parent | 0e931e8beee767297ed4f660970dfffc561ff312 (diff) |
Use script to generate Python FFI decls
Remove unimplemented declaration botan_x509_cert_gen_selfsigned
Diffstat (limited to 'src/scripts/ffi_decls.py')
-rwxr-xr-x | src/scripts/ffi_decls.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/scripts/ffi_decls.py b/src/scripts/ffi_decls.py index 9610c82cc..e76fca1fc 100755 --- a/src/scripts/ffi_decls.py +++ b/src/scripts/ffi_decls.py @@ -35,12 +35,12 @@ def to_ctype(typ, is_ptr): else: if typ == 'void': return 'c_void_p' - elif typ in ['char']: + elif typ in ['char', 'uint8_t']: # hack return 'c_char_p' elif typ == 'size_t': return 'POINTER(c_size_t)' - elif typ == 'uint8_t': - return 'POINTER(c_uint8)' + #elif typ == 'uint8_t': + # return 'POINTER(c_uint8)' elif typ == 'uint32_t': return 'POINTER(c_uint32)' elif typ == 'uint64_t': @@ -50,6 +50,8 @@ def to_ctype(typ, is_ptr): raise Exception("Unknown type %s/%d" % (typ, is_ptr)) +GROUP = None + class FuncDefVisitor(c_ast.NodeVisitor): def visit_FuncDecl(self, node): @@ -64,6 +66,20 @@ class FuncDefVisitor(c_ast.NodeVisitor): # all functions returning ints: fn_name = node.type.declname + fn_group = fn_name.split('_')[1] + if fn_group == 'privkey': + fn_group = 'pubkey' # hack + + global GROUP + + if fn_group != GROUP: + if fn_group in ['rng', 'hash', 'mac', 'cipher', 'block', 'mp', 'pubkey', 'pk', 'x509', 'hotp', 'totp', 'fpe']: + print("\n # ", fn_group.upper()) + else: + print("") + GROUP = fn_group + + fn_args = [] for param in node.args.params: @@ -82,10 +98,15 @@ class FuncDefVisitor(c_ast.NodeVisitor): ctype = to_ctype(typ, is_ptr) fn_args.append(ctype) + decl = " ffi_api(dll.%s," % (fn_name) if len(fn_args) > 4: - print(" ffi_api(_dll.%s,\n %s)" % (fn_name, fn_args)) + decl += "\n " else: - print(" ffi_api(_dll.%s, %s)" % (fn_name, fn_args)) + decl += ' ' + + decl += '[' + ', '.join(fn_args) + '])' + + print(decl) ast = parse_file(ffi_header, use_cpp=True, cpp_args=['-Ibuild/include', '-std=c89', '-DBOTAN_DLL=']) v = FuncDefVisitor() |