You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/16 21:40:10 UTC

[lucy-commits] svn commit: r1071391 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs src/CFCVariable.c src/CFCVariable.h

Author: marvin
Date: Wed Feb 16 20:40:10 2011
New Revision: 1071391

URL: http://svn.apache.org/viewvc?rev=1071391&view=rev
Log:
Cache Perl objects within CFCVariable.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish.xs
    incubator/lucy/trunk/clownfish/src/CFCVariable.c
    incubator/lucy/trunk/clownfish/src/CFCVariable.h

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1071391&r1=1071390&r2=1071391&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Wed Feb 16 20:40:10 2011
@@ -939,8 +939,7 @@ CODE:
     }
     CFCVariable *self = CFCVariable_new(parcel, exposure, class_name,
         class_cnick, micro_sym, type);
-    RETVAL = newSV(0);
-	sv_setref_pv(RETVAL, klass, (void*)self);
+    RETVAL = newRV(CFCVariable_get_perl_obj(self));
 OUTPUT: RETVAL
 
 void

Modified: incubator/lucy/trunk/clownfish/src/CFCVariable.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCVariable.c?rev=1071391&r1=1071390&r2=1071391&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCVariable.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCVariable.c Wed Feb 16 20:40:10 2011
@@ -31,6 +31,7 @@
 #include "CFCVariable.h"
 #include "CFCParcel.h"
 #include "CFCType.h"
+#include "CFCUtil.h"
 
 struct CFCVariable {
     struct CFCSymbol symbol;
@@ -38,6 +39,7 @@ struct CFCVariable {
     char *local_c;
     char *global_c;
     char *local_dec;
+    void *perl_obj;
 };
 
 CFCVariable*
@@ -63,6 +65,9 @@ CFCVariable_init(CFCVariable *self, stru
     CFCSymbol_init((CFCSymbol*)self, parcel, real_exposure, class_name,
         class_cnick, micro_sym);
 
+    // Cache perl object SV.
+    self->perl_obj = CFCUtil_make_perl_obj(self, "Clownfish::Variable");
+
     // Assign type.
     self->type = type;
     SV *type_sv = CFCType_get_perl_obj(type);
@@ -101,6 +106,22 @@ CFCVariable_init(CFCVariable *self, stru
 void
 CFCVariable_destroy(CFCVariable *self)
 {
+    if (self->perl_obj) {
+        int refcount = SvREFCNT((SV*)self->perl_obj);
+        if (refcount > 0) {
+            if (refcount == 1) {
+                // Trigger Perl destructor, which causes recursion.
+                SV *perl_obj = (SV*)self->perl_obj;
+                self->perl_obj = NULL;
+                SvREFCNT_dec((SV*)self->perl_obj);
+                return;
+            }
+            else {
+                SvREFCNT_dec((SV*)self->perl_obj);
+                return;
+            }
+        }
+    }
     SV *type_sv = CFCType_get_perl_obj(self->type);
     SvREFCNT_dec(type_sv);
     free(self->local_c);
@@ -140,3 +161,9 @@ CFCVariable_local_declaration(CFCVariabl
     return self->local_dec;
 }
 
+void*
+CFCVariable_get_perl_obj(CFCVariable *self)
+{
+    return self->perl_obj;
+}
+

Modified: incubator/lucy/trunk/clownfish/src/CFCVariable.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCVariable.h?rev=1071391&r1=1071390&r2=1071391&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCVariable.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCVariable.h Wed Feb 16 20:40:10 2011
@@ -47,3 +47,6 @@ CFCVariable_global_c(CFCVariable *self);
 const char*
 CFCVariable_local_declaration(CFCVariable *self);
 
+void*
+CFCVariable_get_perl_obj(CFCVariable *self);
+