lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject lucy-clownfish git commit: Fix incref'ing of decremented Perl args
Date Wed, 04 Nov 2015 12:32:36 GMT
Repository: lucy-clownfish
Updated Branches:
  refs/heads/master ccb9cabe5 -> ecb990ed7


Fix incref'ing of decremented Perl args

The return value of CFISH_INCREF was discarded, resulting in stack
strings passed as decremented args.

Fixes CLOWNFISH-62.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ecb990ed
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ecb990ed
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ecb990ed

Branch: refs/heads/master
Commit: ecb990ed71272a1108922e1b7a63103b1a2a56bc
Parents: ccb9cab
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Wed Nov 4 13:28:13 2015 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Wed Nov 4 13:31:15 2015 +0100

----------------------------------------------------------------------
 compiler/src/CFCPerlMethod.c        | 10 ++++++++--
 runtime/perl/t/binding/016-varray.t |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ecb990ed/compiler/src/CFCPerlMethod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlMethod.c b/compiler/src/CFCPerlMethod.c
index 9e3704f..4436d8a 100644
--- a/compiler/src/CFCPerlMethod.c
+++ b/compiler/src/CFCPerlMethod.c
@@ -167,12 +167,18 @@ S_xsub_body(CFCPerlMethod *self, CFCClass *klass) {
     FREEMEM(method_ptr);
 
     // Compensate for functions which eat refcounts.
+    // It would be more efficient to convert decremented arguments
+    // by calling XSBind_perl_to_cfish without noinc.
     for (int i = 0; arg_vars[i] != NULL; i++) {
         CFCVariable *var = arg_vars[i];
         CFCType     *type = CFCVariable_get_type(var);
         if (CFCType_is_object(type) && CFCType_decremented(type)) {
-            body = CFCUtil_cat(body, "CFISH_INCREF(arg_",
-                               CFCVariable_get_name(var), ");\n    ", NULL);
+            const char *name   = CFCVariable_get_name(var);
+            const char *type_c = CFCType_to_c(type);
+            const char *pattern =
+                "arg_%s = (%s)CFISH_INCREF(arg_%s);\n    ";
+            char *statement = CFCUtil_sprintf(pattern, name, type_c, name);
+            body = CFCUtil_cat(body, statement, NULL);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ecb990ed/runtime/perl/t/binding/016-varray.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/binding/016-varray.t b/runtime/perl/t/binding/016-varray.t
index 2be6d09..6640310 100644
--- a/runtime/perl/t/binding/016-varray.t
+++ b/runtime/perl/t/binding/016-varray.t
@@ -24,6 +24,11 @@ my ( $varray, $twin );
 $varray = Clownfish::Vector->new;
 $varray->push( Clownfish::String->new($_) ) for 1 .. 5;
 $varray->delete(3);
+$varray->push('abc');
+$varray->insert(
+    tick    => 0,
+    element => 'elem',
+);
 $twin = $varray->_clone;
 is_deeply( $twin->to_perl, $varray->to_perl, "clone" );
 


Mime
View raw message