Gen stub Py method wrappers.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/cb25fd0b Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cb25fd0b Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cb25fd0b Branch: refs/heads/py_exp13 Commit: cb25fd0bd79dfcd8097db6bf8c0319cb44a07531 Parents: a158003 Author: Marvin Humphrey <[email protected]> Authored: Mon Feb 1 19:13:00 2016 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Wed Feb 24 15:20:39 2016 -0800 ---------------------------------------------------------------------- compiler/src/CFCPyClass.c | 17 +++++++++++++++++ compiler/src/CFCPyMethod.c | 18 ++++++++++++++++++ compiler/src/CFCPyMethod.h | 3 +++ 3 files changed, 38 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cb25fd0b/compiler/src/CFCPyClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPyClass.c b/compiler/src/CFCPyClass.c index 9f46b60..11a4905 100644 --- a/compiler/src/CFCPyClass.c +++ b/compiler/src/CFCPyClass.c @@ -145,6 +145,23 @@ CFCPyClass_gen_binding_code(CFCPyClass *self) { char *bindings = CFCUtil_strdup(self->pre_code ? self->pre_code : ""); char *meth_defs = CFCUtil_strdup(self->meth_defs); + // Instance methods. + CFCMethod **methods = CFCClass_fresh_methods(klass); + for (size_t j = 0; methods[j] != NULL; j++) { + CFCMethod *meth = methods[j]; + + if (CFCMethod_excluded_from_host(meth) + || !CFCMethod_can_be_bound(meth) + ) { + continue; + } + + // Add the function wrapper. + char *wrapper = CFCPyMethod_wrapper(meth, klass); + bindings = CFCUtil_cat(bindings, wrapper, "\n", NULL); + FREEMEM(wrapper); + } + // Complete the PyMethodDef array. const char *struct_sym = CFCClass_get_struct_sym(klass); char *meth_defs_pattern = http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cb25fd0b/compiler/src/CFCPyMethod.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPyMethod.c b/compiler/src/CFCPyMethod.c index 983df28..0a5cd27 100644 --- a/compiler/src/CFCPyMethod.c +++ b/compiler/src/CFCPyMethod.c @@ -215,3 +215,21 @@ S_maybe_unreachable(CFCType *return_type) { return return_statement; } +char* +CFCPyMethod_wrapper(CFCMethod *method, CFCClass *invoker) { + char *meth_sym = CFCMethod_full_method_sym(method, invoker); + + char pattern[] = + "static PyObject*\n" + "S_%s(PyObject *unused1, PyObject *unused2) {\n" + " CFISH_UNUSED_VAR(unused1);\n" + " CFISH_UNUSED_VAR(unused2);\n" + " Py_RETURN_NONE;\n" + "}\n" + ; + char *wrapper = CFCUtil_sprintf(pattern, meth_sym); + FREEMEM(meth_sym); + + return wrapper; +} + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cb25fd0b/compiler/src/CFCPyMethod.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPyMethod.h b/compiler/src/CFCPyMethod.h index 15fa1e6..53768e2 100644 --- a/compiler/src/CFCPyMethod.h +++ b/compiler/src/CFCPyMethod.h @@ -31,6 +31,9 @@ struct CFCClass; char* CFCPyMethod_callback_def(struct CFCMethod *method, struct CFCClass *invoker); +char* +CFCPyMethod_wrapper(struct CFCMethod *method, struct CFCClass *invoker); + #ifdef __cplusplus } #endif
