[3/5] lucy-clownfish git commit: Rework labeled argument assignment
Rework labeled argument assignment Change the code to assign labeled arguments from bool args_ok = XSBind_allot_params(aTHX_ (0), 1, items, ALLOT_SIZE_T(_first, "first", ...), ALLOT_OBJ(_second, "second", ...), NULL); if (!args_ok) { CFISH_RETHROW(...); } to static const XSBind_Param param_specs[2] = { XSBIND_PARAM("first", ...), XSBIND_PARAM("second", ...), }; int32_t locations[2]; XSBind_locate_args(aTHX_ (0), 1, items, param_specs, locations, 2); arg_first = (size_t)SvIV(ST(locations[0])); arg_second = (Type*)XSBind_arg_to_cfish(..., ST(locations[1]), ...); This simplifies the code, replaces the vararg lists with static arrays and replaces the switch statement in S_extract_from_sv with direct calls to conversion functions. Accept undef for nullable parameters. Optimize constructors with no parameters. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ffeefa58 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ffeefa58 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ffeefa58 Branch: refs/heads/master Commit: ffeefa582cf9fb07d07edcf3f7badc4e160bc32c Parents: fab17a8 Author: Nick WellnhoferAuthored: Fri Nov 20 20:42:27 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:18:22 2015 +0100 -- compiler/perl/lib/Clownfish/CFC.xs | 11 +- compiler/src/CFCParamList.c | 6 + compiler/src/CFCPerlConstructor.c | 72 -- compiler/src/CFCPerlMethod.c| 85 +++ compiler/src/CFCPerlSub.c | 197 compiler/src/CFCPerlSub.h | 13 +- compiler/src/CFCPerlTypeMap.c | 14 +- compiler/src/CFCPerlTypeMap.h | 3 +- .../perl/buildlib/Clownfish/Build/Binding.pm| 21 +- runtime/perl/t/binding/019-obj.t| 2 +- runtime/perl/xs/XSBind.c| 226 --- runtime/perl/xs/XSBind.h| 203 - 12 files changed, 306 insertions(+), 547 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ffeefa58/compiler/perl/lib/Clownfish/CFC.xs -- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index 27fa942..d7a5385 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -2068,11 +2068,11 @@ CODE: OUTPUT: RETVAL SV* -build_allot_params(self, first) +build_param_specs(self, first) CFCPerlSub *self; size_t first; CODE: -RETVAL = S_sv_eat_c_string(CFCPerlSub_build_allot_params(self, first)); +RETVAL = S_sv_eat_c_string(CFCPerlSub_build_param_specs(self, first)); OUTPUT: RETVAL @@ -2418,11 +2418,12 @@ OUTPUT: RETVAL MODULE = Clownfish PACKAGE = Clownfish::CFC::Binding::Perl::TypeMap SV* -from_perl(type, xs_var) -CFCType *type; +from_perl(type, xs_var, label) +CFCType*type; const char *xs_var; +const char *label; CODE: -RETVAL = S_sv_eat_c_string(CFCPerlTypeMap_from_perl(type, xs_var)); +RETVAL = S_sv_eat_c_string(CFCPerlTypeMap_from_perl(type, xs_var, label)); OUTPUT: RETVAL SV* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ffeefa58/compiler/src/CFCParamList.c -- diff --git a/compiler/src/CFCParamList.c b/compiler/src/CFCParamList.c index 190dd97..6c23f7f 100644 --- a/compiler/src/CFCParamList.c +++ b/compiler/src/CFCParamList.c @@ -72,6 +72,12 @@ void CFCParamList_add_param(CFCParamList *self, CFCVariable *variable, const char *value) { CFCUTIL_NULL_CHECK(variable); +// It might be better to enforce that object parameters with a NULL +// default are also nullable. +if (value && strcmp(value, "NULL") == 0) { +CFCType *type = CFCVariable_get_type(variable); +CFCType_set_nullable(type, 1); +} self->num_vars++; size_t amount = (self->num_vars + 1) * sizeof(void*); self->variables = (CFCVariable**)REALLOCATE(self->variables, amount); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ffeefa58/compiler/src/CFCPerlConstructor.c -- diff --git a/compiler/src/CFCPerlConstructor.c b/compiler/src/CFCPerlConstructor.c index 9dfce1f..1d235ca 100644 --- a/compiler/src/CFCPerlConstructor.c +++ b/compiler/src/CFCPerlConstructor.c @@ -89,17 +89,43 @@ CFCPerlConstructor_destroy(CFCPerlConstructor *self) { char*
[1/5] lucy-clownfish git commit: Rework detection of invalid parameters
Repository: lucy-clownfish Updated Branches: refs/heads/master 1150ddb72 -> 93d02b036 Rework detection of invalid parameters Don't use a bit vector but scan the stack again for every parameter. This optimizes the common case (no invalid parameters). Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/fab17a81 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/fab17a81 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/fab17a81 Branch: refs/heads/master Commit: fab17a81147f45ea605319020f2f273490df Parents: 1150ddb Author: Nick WellnhoferAuthored: Fri Nov 20 20:42:26 2015 +0100 Committer: Nick Wellnhofer Committed: Sun Nov 22 16:23:26 2015 +0100 -- runtime/perl/t/binding/018-host.t | 7 +++- runtime/perl/xs/XSBind.c | 61 +++--- 2 files changed, 40 insertions(+), 28 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fab17a81/runtime/perl/t/binding/018-host.t -- diff --git a/runtime/perl/t/binding/018-host.t b/runtime/perl/t/binding/018-host.t index dc546fd..3d6e4c7 100644 --- a/runtime/perl/t/binding/018-host.t +++ b/runtime/perl/t/binding/018-host.t @@ -16,7 +16,7 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 4; use Clownfish qw( to_clownfish ); my %complex_data_structure = ( @@ -40,3 +40,8 @@ $complex_data_structure{c} = { bread => 'butter' }; $complex_data_structure{d} = { salt => 'pepper' }; is_deeply( $transformed, \%complex_data_structure, "handle mixed data structure correctly" ); + +my $string = Clownfish::String->new("string"); +eval { $string->substring(offset => 0, len => 1, foo => 1) }; +like( $@, qr/Invalid parameter/, "Die on invalid parameter" ); + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/fab17a81/runtime/perl/xs/XSBind.c -- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 83007ab..e72d1e0 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -416,29 +416,10 @@ S_extract_from_sv(pTHX_ SV *value, void *target, const char *label, return true; } -static CFISH_INLINE bool -S_u1get(const void *array, uint32_t tick) { -const uint8_t *const u8bits = (const uint8_t*)array; -const uint32_t byte_offset = tick >> 3; -const uint8_tmask= 1 << (tick & 0x7); -return (u8bits[byte_offset] & mask) != 0; -} - -static CFISH_INLINE void -S_u1set(void *array, uint32_t tick) { -uint8_t *const u8bits = (uint8_t*)array; -const uint32_t byte_offset = tick >> 3; -const uint8_t mask= 1 << (tick & 0x7); -u8bits[byte_offset] |= mask; -} - bool XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems, ...) { va_list args; -size_t size = sizeof(int64_t) + num_stack_elems / 64; -void *verified_labels = alloca(size); -memset(verified_labels, 0, size); // Verify that our args come in pairs. Return success if there are no // args. @@ -450,6 +431,7 @@ XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems, return false; } +int32_t num_consumed = 0; void *target; va_start(args, num_stack_elems); while (NULL != (target = va_arg(args, void*))) { @@ -470,7 +452,7 @@ XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems, if (SvCUR(key_sv) == (STRLEN)label_len) { if (memcmp(SvPVX(key_sv), label, label_len) == 0) { found_arg = tick; -S_u1set(verified_labels, tick); +++num_consumed; } } } @@ -500,14 +482,39 @@ XSBind_allot_params(pTHX_ SV** stack, int32_t start, int32_t num_stack_elems, va_end(args); // Ensure that all parameter labels were valid. -for (int32_t tick = start; tick < num_stack_elems; tick += 2) { -if (!S_u1get(verified_labels, tick)) { +if (num_consumed != (num_stack_elems - start) / 2) { +// Find invalid parameter. +for (int32_t tick = start; tick < num_stack_elems; tick += 2) { SV *const key_sv = stack[tick]; -char *key = SvPV_nolen(key_sv); -cfish_String *mess -= CFISH_MAKE_MESS("Invalid parameter: '%s'", key); -cfish_Err_set_error(cfish_Err_new(mess)); -return false; +const char *key = SvPVX(key_sv); +STRLEN key_len = SvCUR(key_sv); +bool found = false; + +va_start(args,
[5/5] lucy-clownfish git commit: Merge branch 'labeled_params_v2'
Merge branch 'labeled_params_v2' Resolves #47. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/93d02b03 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/93d02b03 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/93d02b03 Branch: refs/heads/master Commit: 93d02b036cd4d5821be4e6513e00b92ce8c6215e Parents: 1150ddb 4aab73c Author: Nick WellnhoferAuthored: Thu Nov 26 19:19:39 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:19:39 2015 +0100 -- compiler/perl/lib/Clownfish/CFC.xs | 18 +- compiler/src/CFCParamList.c | 6 + compiler/src/CFCPerlConstructor.c | 72 -- compiler/src/CFCPerlMethod.c| 85 ++ compiler/src/CFCPerlSub.c | 235 +++-- compiler/src/CFCPerlSub.h | 20 +- compiler/src/CFCPerlTypeMap.c | 18 +- compiler/src/CFCPerlTypeMap.h | 3 +- .../perl/buildlib/Clownfish/Build/Binding.pm| 21 +- runtime/perl/t/binding/018-host.t | 7 +- runtime/perl/t/binding/019-obj.t| 2 +- runtime/perl/xs/XSBind.c| 256 +-- runtime/perl/xs/XSBind.h| 210 --- 13 files changed, 342 insertions(+), 611 deletions(-) --
[2/5] lucy-clownfish git commit: Remove unused method
Remove unused method Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/69dd42d3 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/69dd42d3 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/69dd42d3 Branch: refs/heads/master Commit: 69dd42d3d3c68cbf651296fb5608bfde044e8e75 Parents: ffeefa5 Author: Nick WellnhoferAuthored: Sun Nov 22 18:15:27 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:18:22 2015 +0100 -- compiler/perl/lib/Clownfish/CFC.xs | 7 -- compiler/src/CFCPerlSub.c | 38 - compiler/src/CFCPerlSub.h | 7 -- 3 files changed, 52 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/69dd42d3/compiler/perl/lib/Clownfish/CFC.xs -- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index d7a5385..c942338 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -2061,13 +2061,6 @@ PPCODE: } SV* -params_hash_def(self) -CFCPerlSub *self; -CODE: -RETVAL = S_sv_eat_c_string(CFCPerlSub_params_hash_def(self)); -OUTPUT: RETVAL - -SV* build_param_specs(self, first) CFCPerlSub *self; size_t first; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/69dd42d3/compiler/src/CFCPerlSub.c -- diff --git a/compiler/src/CFCPerlSub.c b/compiler/src/CFCPerlSub.c index f1dee85..6942abc 100644 --- a/compiler/src/CFCPerlSub.c +++ b/compiler/src/CFCPerlSub.c @@ -79,44 +79,6 @@ CFCPerlSub_destroy(CFCPerlSub *self) { } char* -CFCPerlSub_params_hash_def(CFCPerlSub *self) { -if (!self->use_labeled_params) { -return NULL; -} - -char *def = CFCUtil_strdup(""); -def = CFCUtil_cat(def, "%", self->perl_name, "_PARAMS = (", NULL); - -CFCVariable **arg_vars = CFCParamList_get_variables(self->param_list); -const char **vals = CFCParamList_get_initial_values(self->param_list); - -// No labeled params means an empty params hash def. -if (!arg_vars[1]) { -def = CFCUtil_cat(def, ");\n", NULL); -return def; -} - -for (int i = 1; arg_vars[i] != NULL; i++) { -CFCVariable *var = arg_vars[i]; -const char *var_name = CFCVariable_get_name(var); -const char *val = vals[i]; -val = val == NULL - ? "undef" - : strcmp(val, "NULL") == 0 - ? "undef" - : strcmp(val, "true") == 0 - ? "1" - : strcmp(val, "false") == 0 - ? "0" - : val; -def = CFCUtil_cat(def, "\n", var_name, " => ", val, ",", NULL); -} -def = CFCUtil_cat(def, "\n);\n", NULL); - -return def; -} - -char* CFCPerlSub_arg_declarations(CFCPerlSub *self, size_t first) { CFCParamList *param_list = self->param_list; CFCVariable **arg_vars = CFCParamList_get_variables(param_list); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/69dd42d3/compiler/src/CFCPerlSub.h -- diff --git a/compiler/src/CFCPerlSub.h b/compiler/src/CFCPerlSub.h index d45852a..f113d7a 100644 --- a/compiler/src/CFCPerlSub.h +++ b/compiler/src/CFCPerlSub.h @@ -66,13 +66,6 @@ CFCPerlSub_init(CFCPerlSub *self, struct CFCParamList *param_list, void CFCPerlSub_destroy(CFCPerlSub *self); -/** 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". - */ -char* -CFCPerlSub_params_hash_def(CFCPerlSub *self); - /** Generate C declarations for the variables holding the arguments, from * `first` onwards. */
[4/5] lucy-clownfish git commit: Wrap expensive SvTRUE macro in a function
Wrap expensive SvTRUE macro in a function The SvTRUE macro expands to a huge expression. Replacing it with a function call in the XS wrappers reduces the code size of the Lucy binary by about 30 KB on 32-bit. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4aab73c2 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4aab73c2 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4aab73c2 Branch: refs/heads/master Commit: 4aab73c25752f5cd6e68539418e85c914618a2de Parents: 69dd42d Author: Nick WellnhoferAuthored: Thu Nov 26 16:20:40 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:18:22 2015 +0100 -- compiler/src/CFCPerlTypeMap.c | 4 ++-- runtime/perl/xs/XSBind.c | 5 + runtime/perl/xs/XSBind.h | 7 +++ 3 files changed, 14 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/compiler/src/CFCPerlTypeMap.c -- diff --git a/compiler/src/CFCPerlTypeMap.c b/compiler/src/CFCPerlTypeMap.c index f320a82..2ac4985 100644 --- a/compiler/src/CFCPerlTypeMap.c +++ b/compiler/src/CFCPerlTypeMap.c @@ -108,7 +108,7 @@ CFCPerlTypeMap_from_perl(CFCType *type, const char *xs_var, result = CFCUtil_sprintf("(int8_t)SvIV(%s)", xs_var); } else if (strcmp(specifier, "bool") == 0) { -result = CFCUtil_sprintf("SvTRUE(%s) ? 1 : 0", xs_var); +result = CFCUtil_sprintf("XSBind_sv_true(aTHX_ %s)", xs_var); } else { FREEMEM(result); @@ -212,7 +212,7 @@ static const char typemap_input[] = "INPUT\n" "\n" "CFISH_BOOL\n" -"$var = ($type)SvTRUE($arg);\n" +"$var = ($type)XSBind_sv_true(aTHX_ $arg);\n" "\n" "CFISH_SIGNED_INT \n" "$var = ($type)SvIV($arg);\n" http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/runtime/perl/xs/XSBind.c -- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 7b9e1e5..a03f5f7 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -88,6 +88,11 @@ XSBind_foster_obj(pTHX_ SV *sv, cfish_Class *klass) { return obj; } +bool +XSBind_sv_true(pTHX_ SV *sv) { +return !!SvTRUE(sv); +} + cfish_Obj* XSBind_perl_to_cfish(pTHX_ SV *sv, cfish_Class *klass) { cfish_Obj *retval = NULL; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4aab73c2/runtime/perl/xs/XSBind.h -- diff --git a/runtime/perl/xs/XSBind.h b/runtime/perl/xs/XSBind.h index a104797..40c98c7 100644 --- a/runtime/perl/xs/XSBind.h +++ b/runtime/perl/xs/XSBind.h @@ -71,6 +71,12 @@ cfish_XSBind_sv_defined(pTHX_ SV *sv) { return !!SvOK(sv); } +/** Test whether an SV is true. Wraps the expensive SvTRUE macro in a + * function. + */ +CFISH_VISIBLE bool +cfish_XSBind_sv_true(pTHX_ SV *sv); + /** Derive an SV from a Clownfish object. If the Clownfish object is NULL, the SV * will be undef. Doesn't invoke To_Host and always returns a reference to a * Clownfish::Obj. @@ -208,6 +214,7 @@ cfish_XSBind_arg_to_cfish(pTHX_ SV *value, const char *label, bool nullable, #define XSBind_new_blank_obj cfish_XSBind_new_blank_obj #define XSBind_foster_obj cfish_XSBind_foster_obj #define XSBind_sv_defined cfish_XSBind_sv_defined +#define XSBind_sv_true cfish_XSBind_sv_true #define XSBind_cfish_obj_to_sv cfish_XSBind_cfish_obj_to_sv #define XSBind_cfish_obj_to_sv_noinc cfish_XSBind_cfish_obj_to_sv_noinc #define XSBind_cfish_to_perl cfish_XSBind_cfish_to_perl
lucy git commit: Adjust for changes to labeled param handling
Repository: lucy Updated Branches: refs/heads/master dc3a17e88 -> 0d4f3465b Adjust for changes to labeled param handling Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0d4f3465 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0d4f3465 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0d4f3465 Branch: refs/heads/master Commit: 0d4f3465b424212ee1b029e29c86a1ed771b59d0 Parents: dc3a17e Author: Nick WellnhoferAuthored: Thu Nov 26 14:51:15 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:21:12 2015 +0100 -- perl/buildlib/Lucy/Build/Binding/Analysis.pm | 59 +++ perl/buildlib/Lucy/Build/Binding/Document.pm | 43 + perl/buildlib/Lucy/Build/Binding/Index.pm| 39 +++ perl/buildlib/Lucy/Build/Binding/Object.pm | 16 +++--- perl/buildlib/Lucy/Build/Binding/Search.pm | 18 +++ 5 files changed, 87 insertions(+), 88 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy/blob/0d4f3465/perl/buildlib/Lucy/Build/Binding/Analysis.pm -- diff --git a/perl/buildlib/Lucy/Build/Binding/Analysis.pm b/perl/buildlib/Lucy/Build/Binding/Analysis.pm index 22f101f..c73ff77 100644 --- a/perl/buildlib/Lucy/Build/Binding/Analysis.pm +++ b/perl/buildlib/Lucy/Build/Binding/Analysis.pm @@ -127,22 +127,20 @@ SV* new(...) CODE: { +static const XSBind_ParamSpec param_specs[1] = { +XSBIND_PARAM("text", false) +}; +int32_t locations[1]; +SV *text_sv = NULL; lucy_Token *starter_token = NULL; -// parse params, only if there's more than one arg -if (items > 1) { -SV *text_sv = NULL; -bool args_ok -= XSBind_allot_params(aTHX_ &(ST(0)), 1, items, - ALLOT_SV(_sv, "text", 4, false), - NULL); -if (!args_ok) { -CFISH_RETHROW(CFISH_INCREF(cfish_Err_get_error())); -} -if (XSBind_sv_defined(aTHX_ text_sv)) { -STRLEN len; -char *text = SvPVutf8(text_sv, len); -starter_token = lucy_Token_new(text, len, 0, len, 1.0, 1); -} + +XSBind_locate_args(aTHX_ (0), 1, items, param_specs, locations, 1); + +text_sv = locations[0] < items ? ST(locations[0]) : NULL; +if (XSBind_sv_defined(aTHX_ text_sv)) { +STRLEN len; +char *text = SvPVutf8(text_sv, len); +starter_token = lucy_Token_new(text, len, 0, len, 1.0, 1); } RETVAL = CFISH_OBJ_TO_SV_NOINC(lucy_Inversion_new(starter_token)); @@ -419,7 +417,14 @@ new(either_sv, ...) SV *either_sv; CODE: { -SV *text_sv = NULL; +static const XSBind_ParamSpec param_specs[5] = { +XSBIND_PARAM("text", true), +XSBIND_PARAM("start_offset", true), +XSBIND_PARAM("end_offset", true), +XSBIND_PARAM("pos_inc", false), +XSBIND_PARAM("boost", false) +}; +int32_t locations[5]; uint32_tstart_off = 0; uint32_tend_off = 0; int32_t pos_inc = 1; @@ -427,21 +432,15 @@ CODE: STRLEN len = 0; char *text = NULL; lucy_Token *self = NULL; -boolargs_ok; - -args_ok -= XSBind_allot_params(aTHX_ &(ST(0)), 1, items, - ALLOT_SV(_sv, "text", 4, true), - ALLOT_U32(_off, "start_offset", 12, true), - ALLOT_U32(_off, "end_offset", 10, true), - ALLOT_I32(_inc, "pos_inc", 7, false), - ALLOT_F32(, "boost", 5, false), - NULL); -if (!args_ok) { -CFISH_RETHROW(CFISH_INCREF(cfish_Err_get_error())); -} -text = SvPVutf8(text_sv, len); +XSBind_locate_args(aTHX_ (0), 1, items, param_specs, locations, 5); + +text = SvPVutf8(ST(locations[0]), len); +start_off = (uint32_t)SvUV(ST(locations[1])); +end_off = (uint32_t)SvUV(ST(locations[2])); +pos_inc = locations[3] < items ? (int32_t)SvIV(ST(locations[3])) : 1; +boost = locations[4] < items ? (float)SvNV(ST(locations[4])) : 1.0f; + self = (lucy_Token*)XSBind_new_blank_obj(aTHX_ either_sv); lucy_Token_init(self, text, len, start_off, end_off, boost, pos_inc); http://git-wip-us.apache.org/repos/asf/lucy/blob/0d4f3465/perl/buildlib/Lucy/Build/Binding/Document.pm -- diff --git a/perl/buildlib/Lucy/Build/Binding/Document.pm b/perl/buildlib/Lucy/Build/Binding/Document.pm index c4d559c..605a1e9 100644 --- a/perl/buildlib/Lucy/Build/Binding/Document.pm +++
lucy-clownfish git commit: Optimize XSBind_cfish_obj_to_sv_noinc
Repository: lucy-clownfish Updated Branches: refs/heads/master 93d02b036 -> b51cc4684 Optimize XSBind_cfish_obj_to_sv_noinc Also rename XSBind_cfish_obj_to_sv to XSBind_cfish_obj_to_sv_inc. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/b51cc468 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/b51cc468 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/b51cc468 Branch: refs/heads/master Commit: b51cc468439756c14f9e130ddfc3492591ae0f69 Parents: 93d02b0 Author: Nick WellnhoferAuthored: Thu Nov 26 19:23:44 2015 +0100 Committer: Nick Wellnhofer Committed: Thu Nov 26 19:23:44 2015 +0100 -- compiler/src/CFCPerlConstructor.c | 9 + .../perl/buildlib/Clownfish/Build/Binding.pm| 6 ++-- runtime/perl/xs/XSBind.c| 38 +++- runtime/perl/xs/XSBind.h| 36 +++ 4 files changed, 47 insertions(+), 42 deletions(-) -- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b51cc468/compiler/src/CFCPerlConstructor.c -- diff --git a/compiler/src/CFCPerlConstructor.c b/compiler/src/CFCPerlConstructor.c index 1d235ca..bde723b 100644 --- a/compiler/src/CFCPerlConstructor.c +++ b/compiler/src/CFCPerlConstructor.c @@ -160,14 +160,7 @@ CFCPerlConstructor_xsub_def(CFCPerlConstructor *self, CFCClass *klass) { "arg_%s = (%s)XSBind_new_blank_obj(aTHX_ ST(0));%s\n" "\n" "retval = %s(%s);\n" -"if (retval) {\n" -"ST(0) = CFISH_OBJ_TO_SV(retval);\n" -"CFISH_DECREF_NN(retval);\n" -"}\n" -"else {\n" -"ST(0) = newSV(0);\n" -"}\n" -"sv_2mortal(ST(0));\n" +"ST(0) = sv_2mortal(CFISH_OBJ_TO_SV_NOINC(retval));\n" "XSRETURN(1);\n" "}\n\n"; char *xsub_def http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b51cc468/runtime/perl/buildlib/Clownfish/Build/Binding.pm -- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index 068a29e..a50af01 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -200,7 +200,7 @@ singleton(either_sv, value) bool value; CODE: { -RETVAL = CFISH_OBJ_TO_SV(cfish_Bool_singleton(value)); +RETVAL = CFISH_OBJ_TO_SV_INC(cfish_Bool_singleton(value)); } OUTPUT: RETVAL END_XS_CODE @@ -506,7 +506,7 @@ fetch_obj(self, key) cfish_Hash *self; cfish_String *key; CODE: -RETVAL = CFISH_OBJ_TO_SV(CFISH_Hash_Fetch_IMP(self, key)); +RETVAL = CFISH_OBJ_TO_SV_INC(CFISH_Hash_Fetch_IMP(self, key)); OUTPUT: RETVAL void @@ -895,7 +895,7 @@ fetch_obj(self, tick) cfish_Vector *self; uint32_t tick; CODE: -RETVAL = CFISH_OBJ_TO_SV(CFISH_Vec_Fetch(self, tick)); +RETVAL = CFISH_OBJ_TO_SV_INC(CFISH_Vec_Fetch(self, tick)); OUTPUT: RETVAL END_XS_CODE http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/b51cc468/runtime/perl/xs/XSBind.c -- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index a03f5f7..c89f669 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -176,9 +176,7 @@ S_maybe_perl_to_cfish(pTHX_ SV *sv, cfish_Class *klass, bool increment, // Mortalize the converted object -- which is somewhat // dangerous, but is the only way to avoid requiring that the // caller take responsibility for a refcount. -SV *mortal = XSBind_cfish_obj_to_sv(aTHX_ obj); -CFISH_DECREF(obj); -sv_2mortal(mortal); +sv_2mortal(XSBind_cfish_obj_to_sv_noinc(aTHX_ obj)); } *obj_ptr = obj; @@ -426,9 +424,9 @@ SI_is_string_type(cfish_Class *klass) { return false; } -// Returns an incref'd, blessed RV. +// Returns a blessed RV. static SV* -S_lazy_init_host_obj(pTHX_ cfish_Obj *self) { +S_lazy_init_host_obj(pTHX_ cfish_Obj *self, bool increment) { cfish_Class *klass = self->klass; cfish_String *class_name = CFISH_Class_Get_Name(klass); @@ -441,6 +439,7 @@ S_lazy_init_host_obj(pTHX_ cfish_Obj *self) { * will assume responsibility for maintaining the refcount. */ cfish_ref_t old_ref = self->ref; size_t excess = old_ref.count >> XSBIND_REFCOUNT_SHIFT; +if (!increment) { excess -= 1; } SvREFCNT(inner_obj) += excess; // Overwrite refcount with host