Skip to content

Commit

Permalink
big updates with auto-generated wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Mühleisen committed Jan 2, 2024
1 parent 6199b51 commit 1d3f115
Show file tree
Hide file tree
Showing 5 changed files with 1,046 additions and 673 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ test:

check: test

.PHONY: test clean build
.PHONY: test clean build format

format:
clang-format --sort-includes=0 -style=file -i src/*.cpp
11 changes: 9 additions & 2 deletions generate-wrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import sys
import pycparser

# those functions return promises asynchronously since they may block and/or do IO
async_functions = ['duckdb_open', 'duckdb_open_ext', 'duckdb_close', 'duckdb_connect', 'duckdb_interrupt', 'duckdb_disconnect', 'duckdb_query', 'duckdb_prepare', 'duckdb_execute_prepared', 'duckdb_stream_fetch_chunk', 'duckdb_execute_tasks', 'duckdb_appender_create', 'duckdb_appender_flush', 'duckdb_appender_close', 'duckdb_appender_destroy', 'duckdb_execute_prepared', 'duckdb_extract_statements', 'duckdb_prepare_extracted_statement', 'duckdb_execute_pending']

def typename(decl):
const = ''
if hasattr(decl, 'quals') and 'const' in decl.quals:
Expand Down Expand Up @@ -50,18 +53,22 @@ def visit_FuncDecl(self, node):
return # TODO

register_name = name.replace('duckdb_', '')
print(f"{ret} {name} ({', '.join(args)})")
#print(f"{ret} {name} ({', '.join(args)})")
print(f"{name}")

n_args = len(args)
args.append(name)
asyncstr = ''
if name in async_functions:
asyncstr = 'Async'
voidstr = ''
if ret == 'void':
voidstr = 'Void'
else:
args.insert(0, ret)
arg_str = ', '.join(args)

self.result += f'exports.Set(String::New(env, "{register_name}"), Function::New<AsyncFunctionWrapper{n_args}{voidstr}<{arg_str}>>(env));\n'
self.result += f'exports.Set(String::New(env, "{register_name}"), Function::New<{asyncstr}FunctionWrapper{n_args}{voidstr}<{arg_str}>>(env));\n'

def create_func_defs(filename):
# produce input like so: gcc -E -D__builtin_va_list=int src/duckdb/src/include/duckdb.h > dd.h
Expand Down
Loading

0 comments on commit 1d3f115

Please sign in to comment.