You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2014/08/11 16:38:01 UTC
[1/4] git commit: Consolidate invalid callback check
Repository: lucy-clownfish
Updated Branches:
refs/heads/overridden_exclusions [created] fc8f8c8ce
Consolidate invalid callback check
Create a callback that throws an error whenever a method can't be bound
including private and excluded methods.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/fc8f8c8c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/fc8f8c8c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/fc8f8c8c
Branch: refs/heads/overridden_exclusions
Commit: fc8f8c8cef8472622a005f00bdfddd14447c3e96
Parents: 7ece5f5
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Jul 31 14:15:34 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Aug 11 16:37:07 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCPerlMethod.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fc8f8c8c/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 9b412dc..24ee475 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -444,18 +444,18 @@ S_xsub_def_positional_args(CFCPerlMethod *self) {
char*
CFCPerlMethod_callback_def(CFCMethod *method) {
+ // Return a callback wrapper that throws an error if there are no
+ // bindings for a method.
+ if (!CFCPerlMethod_can_be_bound(method)) {
+ return S_invalid_callback_def(method);
+ }
+
CFCType *return_type = CFCMethod_get_return_type(method);
char *start = S_callback_start(method);
char *callback_def = NULL;
char *refcount_mods = S_callback_refcount_mods(method);
- if (!start) {
- // Can't map vars, because there's at least one type in the argument
- // list we don't yet support. Return a callback wrapper that throws
- // an error error.
- callback_def = S_invalid_callback_def(method);
- }
- else if (CFCType_is_void(return_type)) {
+ if (CFCType_is_void(return_type)) {
callback_def = S_void_callback_def(method, start, refcount_mods);
}
else if (CFCType_is_object(return_type)) {
@@ -573,9 +573,9 @@ S_callback_start(CFCMethod *method) {
name, ");\n", NULL);
}
else {
- // Can't map variable type. Signal to caller.
- FREEMEM(params);
- return NULL;
+ // Can't map variable type.
+ const char *type_str = CFCType_to_c(type);
+ CFCUtil_die("Can't map type '%s' to Perl", type_str);
}
}
[2/4] git commit: Function parameter and return type check
Posted by nw...@apache.org.
Function parameter and return type check
Move parameter and return type check from a static function in
CFCPerlClass to CFCPerlSub. Allow types which are either objects or
primitives.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/dcf237ed
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/dcf237ed
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/dcf237ed
Branch: refs/heads/overridden_exclusions
Commit: dcf237ed4a8744cd2da7667b83097603dc7ad2e7
Parents: 39c05d1
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Jul 31 13:50:52 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Aug 11 16:37:07 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCPerlClass.c | 39 ++++++++-------------------------------
compiler/src/CFCPerlSub.c | 25 +++++++++++++++++++++++++
compiler/src/CFCPerlSub.h | 6 ++++++
3 files changed, 39 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dcf237ed/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index 7c018de..1fb2b7c 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -32,6 +32,7 @@
#include "CFCVariable.h"
#include "CFCType.h"
#include "CFCPerlPod.h"
+#include "CFCPerlSub.h"
#include "CFCPerlMethod.h"
#include "CFCPerlConstructor.h"
#include "CFCPerlTypeMap.h"
@@ -226,26 +227,6 @@ CFCPerlClass_exclude_constructor(CFCPerlClass *self) {
self->exclude_cons = 1;
}
-static int
-S_can_be_bound(CFCParamList *param_list, CFCType *return_type) {
- int success = 1;
- CFCVariable **arg_vars = CFCParamList_get_variables(param_list);
-
- for (size_t i = 0; arg_vars[i] != NULL; i++) {
- CFCType *type = CFCVariable_get_type(arg_vars[i]);
- char *conversion = CFCPerlTypeMap_from_perl(type, "foo");
- if (conversion) { FREEMEM(conversion); }
- else { success = 0; }
- }
- if (!CFCType_is_void(return_type)) {
- char *conversion = CFCPerlTypeMap_to_perl(return_type, "foo");
- if (conversion) { FREEMEM(conversion); }
- else { success = 0; }
- }
-
- return success;
-}
-
CFCPerlMethod**
CFCPerlClass_method_bindings(CFCClass *klass) {
CFCClass *parent = CFCClass_get_parent(klass);
@@ -267,9 +248,7 @@ CFCPerlClass_method_bindings(CFCClass *klass) {
}
// Skip methods with types which cannot be mapped automatically.
- CFCParamList *param_list = CFCMethod_get_param_list(method);
- CFCType *return_type = CFCMethod_get_return_type(method);
- if (!S_can_be_bound(param_list, return_type)) {
+ if (!CFCPerlSub_can_be_bound((CFCFunction*)method)) {
continue;
}
@@ -307,17 +286,15 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) {
// Iterate over the list of possible initialization functions.
for (size_t i = 0; functions[i] != NULL; i++) {
- CFCFunction *function = functions[i];
- const char *micro_sym = CFCFunction_micro_sym(function);
- CFCParamList *param_list = CFCFunction_get_param_list(function);
- CFCType *return_type = CFCFunction_get_return_type(function);
- const char *alias = NULL;
+ CFCFunction *function = functions[i];
+ const char *micro_sym = CFCFunction_micro_sym(function);
+ const char *alias = NULL;
// Find user-specified alias.
if (perl_class == NULL) {
// Bind init() to new() when possible.
if (strcmp(micro_sym, "init") == 0
- && S_can_be_bound(param_list, return_type)
+ && CFCPerlSub_can_be_bound(function)
) {
alias = NEW;
}
@@ -326,7 +303,7 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) {
for (size_t j = 0; j < perl_class->num_cons; j++) {
if (strcmp(micro_sym, perl_class->cons_inits[j]) == 0) {
alias = perl_class->cons_aliases[j];
- if (!S_can_be_bound(param_list, return_type)) {
+ if (!CFCPerlSub_can_be_bound(function)) {
CFCUtil_die("Can't bind %s as %s"
" -- types can't be mapped",
micro_sym, alias);
@@ -339,7 +316,7 @@ CFCPerlClass_constructor_bindings(CFCClass *klass) {
if (!alias
&& !perl_class->exclude_cons
&& strcmp(micro_sym, "init") == 0
- && S_can_be_bound(param_list, return_type)
+ && CFCPerlSub_can_be_bound(function)
) {
int saw_new = 0;
for (size_t j = 0; j < perl_class->num_cons; j++) {
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dcf237ed/compiler/src/CFCPerlSub.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c
index 063d59a..fd508cc 100644
--- a/compiler/src/CFCPerlSub.c
+++ b/compiler/src/CFCPerlSub.c
@@ -20,6 +20,7 @@
#define CFC_NEED_PERLSUB_STRUCT_DEF
#include "CFCPerlSub.h"
#include "CFCBase.h"
+#include "CFCFunction.h"
#include "CFCUtil.h"
#include "CFCParamList.h"
#include "CFCVariable.h"
@@ -72,6 +73,30 @@ CFCPerlSub_destroy(CFCPerlSub *self) {
CFCBase_destroy((CFCBase*)self);
}
+int
+CFCPerlSub_can_be_bound(CFCFunction *function) {
+ // Test whether parameters can be mapped automatically.
+ CFCParamList *param_list = CFCFunction_get_param_list(function);
+ CFCVariable **arg_vars = CFCParamList_get_variables(param_list);
+ for (size_t i = 0; arg_vars[i] != NULL; i++) {
+ CFCType *type = CFCVariable_get_type(arg_vars[i]);
+ if (!CFCType_is_object(type) && !CFCType_is_primitive(type)) {
+ return false;
+ }
+ }
+
+ // Test whether return type can be mapped automatically.
+ CFCType *return_type = CFCFunction_get_return_type(function);
+ if (!CFCType_is_void(return_type)
+ && !CFCType_is_object(return_type)
+ && !CFCType_is_primitive(return_type)
+ ) {
+ return false;
+ }
+
+ return true;
+}
+
char*
CFCPerlSub_params_hash_def(CFCPerlSub *self) {
if (!self->use_labeled_params) {
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dcf237ed/compiler/src/CFCPerlSub.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlSub.h b/compiler/src/CFCPerlSub.h
index 54d1917..1ac3299 100644
--- a/compiler/src/CFCPerlSub.h
+++ b/compiler/src/CFCPerlSub.h
@@ -22,6 +22,7 @@ extern "C" {
#endif
typedef struct CFCPerlSub CFCPerlSub;
+struct CFCFunction;
struct CFCParamList;
struct CFCType;
@@ -64,6 +65,11 @@ CFCPerlSub_init(CFCPerlSub *self, struct CFCParamList *param_list,
void
CFCPerlSub_destroy(CFCPerlSub *self);
+/** Test whether bindings should be generated for a function.
+ */
+int
+CFCPerlSub_can_be_bound(struct CFCFunction *function);
+
/** Return Perl code initializing a package-global hash where all the keys are
* the names of labeled params. The hash's name consists of the the binding's
* perl_name() plus "_PARAMS".
[4/4] git commit: Remove support for void* return types
Posted by nw...@apache.org.
Remove support for void* return types
Assuming that a void pointer is a reference SV is fragile. Lucy builds
and tests fine without this feature so I guess it's not really needed.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/39c05d1a
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/39c05d1a
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/39c05d1a
Branch: refs/heads/overridden_exclusions
Commit: 39c05d1a1ce0ecab970e9cd4a66eba875ee74e1b
Parents: d73098d
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Jul 31 13:28:05 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Aug 11 16:37:07 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCPerlTypeMap.c | 7 -------
1 file changed, 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/39c05d1a/compiler/src/CFCPerlTypeMap.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c
index 7997ea9..2a87f43 100644
--- a/compiler/src/CFCPerlTypeMap.c
+++ b/compiler/src/CFCPerlTypeMap.c
@@ -187,13 +187,6 @@ CFCPerlTypeMap_to_perl(CFCType *type, const char *cf_var) {
result = NULL;
}
}
- else if (CFCType_is_composite(type)) {
- if (strcmp(type_str, "void*") == 0) {
- // Assume that void* is a reference SV -- either a hashref or an
- // arrayref.
- result = CFCUtil_sprintf("newRV_inc((SV*)%s)", cf_var);
- }
- }
return result;
}
[3/4] git commit: Separate test whether to create method bindings
Posted by nw...@apache.org.
Separate test whether to create method bindings
Move the code that checks whether bindings for a method should be
generated to a separate function.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/7ece5f56
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/7ece5f56
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/7ece5f56
Branch: refs/heads/overridden_exclusions
Commit: 7ece5f56607e667c42b795b4b4d60e8985948d9d
Parents: dcf237e
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Jul 31 14:04:20 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon Aug 11 16:37:07 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCPerlClass.c | 14 ++------------
compiler/src/CFCPerlMethod.c | 14 ++++++++++++++
compiler/src/CFCPerlMethod.h | 5 +++++
3 files changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7ece5f56/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index 1fb2b7c..52eb851 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -239,18 +239,8 @@ CFCPerlClass_method_bindings(CFCClass *klass) {
for (size_t i = 0; fresh_methods[i] != NULL; i++) {
CFCMethod *method = fresh_methods[i];
- // Skip private methods.
- if (CFCSymbol_private((CFCSymbol*)method)) { continue; }
-
- // Skip methods which have been explicitly excluded.
- if (CFCMethod_excluded_from_host(method)) {
- continue;
- }
-
- // Skip methods with types which cannot be mapped automatically.
- if (!CFCPerlSub_can_be_bound((CFCFunction*)method)) {
- continue;
- }
+ // Skip methods that shouldn't be bound.
+ if (!CFCPerlMethod_can_be_bound(method)) { continue; }
/* Create the binding, add it to the array.
*
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7ece5f56/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 2aad102..9b412dc 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -23,6 +23,7 @@
#include "CFCPerlMethod.h"
#include "CFCUtil.h"
#include "CFCClass.h"
+#include "CFCFunction.h"
#include "CFCMethod.h"
#include "CFCSymbol.h"
#include "CFCType.h"
@@ -134,6 +135,19 @@ CFCPerlMethod_destroy(CFCPerlMethod *self) {
CFCPerlSub_destroy((CFCPerlSub*)self);
}
+int
+CFCPerlMethod_can_be_bound(CFCMethod *method) {
+ /*
+ * Check for
+ * - private methods
+ * - methods which have been explicitly excluded
+ * - methods with types which cannot be mapped automatically
+ */
+ return !CFCSymbol_private((CFCSymbol*)method)
+ && !CFCMethod_excluded_from_host(method)
+ && CFCPerlSub_can_be_bound((CFCFunction*)method);
+}
+
char*
CFCPerlMethod_perl_name(CFCMethod *method) {
// See if the user wants the method to have a specific alias.
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/7ece5f56/compiler/src/CFCPerlMethod.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.h b/compiler/src/CFCPerlMethod.h
index be441c4..ee85efe 100644
--- a/compiler/src/CFCPerlMethod.h
+++ b/compiler/src/CFCPerlMethod.h
@@ -46,6 +46,11 @@ CFCPerlMethod_init(CFCPerlMethod *self, struct CFCMethod *method);
void
CFCPerlMethod_destroy(CFCPerlMethod *self);
+/** Test whether bindings should be generated for a method.
+ */
+int
+CFCPerlMethod_can_be_bound(struct CFCMethod *method);
+
/**
* Create the Perl name of the method.
*/