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/17 20:28:13 UTC
[lucy-commits] svn commit: r1071755 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
src/CFCCBlock.c src/CFCCBlock.h src/CFCDocuComment.c src/CFCDocuComment.h
src/CFCFile.c src/CFCFile.h src/CFCParamList.c src/CFCParamList.h
Author: marvin
Date: Thu Feb 17 19:28:13 2011
New Revision: 1071755
URL: http://svn.apache.org/viewvc?rev=1071755&view=rev
Log:
Move towards a full refcounting model, with cached internal Perl objects
attached to each CFC object -- very similar to the refcounting model for
Clownfish itself (and thus all Lucy objects).
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/src/CFCCBlock.c
incubator/lucy/trunk/clownfish/src/CFCCBlock.h
incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
incubator/lucy/trunk/clownfish/src/CFCFile.c
incubator/lucy/trunk/clownfish/src/CFCFile.h
incubator/lucy/trunk/clownfish/src/CFCParamList.c
incubator/lucy/trunk/clownfish/src/CFCParamList.h
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Thu Feb 17 19:28:13 2011
@@ -56,8 +56,8 @@ _new(klass, contents)
const char *contents;
CODE:
CFCCBlock *self = CFCCBlock_new(contents);
- RETVAL = newSV(0);
- sv_setref_pv(RETVAL, klass, (void*)self);
+ RETVAL = newRV(CFCCBlock_get_perl_obj(self));
+ CFCCBlock_decref(self);
OUTPUT: RETVAL
void
@@ -120,8 +120,8 @@ parse(klass, text)
const char *text;
CODE:
CFCDocuComment *self = CFCDocuComment_parse(text);
- RETVAL = newSV(0);
- sv_setref_pv(RETVAL, klass, (void*)self);
+ RETVAL = newRV(CFCDocuComment_get_perl_obj(self));
+ CFCDocuComment_decref(self);
OUTPUT: RETVAL
void
@@ -198,8 +198,8 @@ _new(klass)
const char *klass;
CODE:
CFCFile *self = CFCFile_new();
- RETVAL = newSV(0);
- sv_setref_pv(RETVAL, klass, (void*)self);
+ RETVAL = newRV(CFCFile_get_perl_obj(self));
+ CFCFile_decref(self);
OUTPUT: RETVAL
void
@@ -358,7 +358,7 @@ _new(klass, variadic)
CODE:
CFCParamList *self = CFCParamList_new(variadic);
RETVAL = newRV((SV*)CFCParamList_get_perl_obj(self));
- SvREFCNT_dec(SvRV(RETVAL));
+ CFCParamList_decref(self);
OUTPUT: RETVAL
void
Modified: incubator/lucy/trunk/clownfish/src/CFCCBlock.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCCBlock.c?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCCBlock.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCCBlock.c Thu Feb 17 19:28:13 2011
@@ -24,6 +24,7 @@
struct CFCCBlock {
char *contents;
+ void *perl_obj;
};
CFCCBlock*
@@ -38,6 +39,7 @@ CFCCBlock*
CFCCBlock_init(CFCCBlock *self, const char *contents)
{
self->contents = CFCUtil_strdup(contents);
+ self->perl_obj = CFCUtil_make_perl_obj(self, "Clownfish::CBlock");
return self;
}
@@ -48,6 +50,27 @@ CFCCBlock_destroy(CFCCBlock *self)
free(self);
}
+CFCCBlock*
+CFCCBlock_incref(CFCCBlock *self)
+{
+ SvREFCNT_inc((SV*)self->perl_obj);
+ return self;
+}
+
+unsigned
+CFCCBlock_decref(CFCCBlock *self)
+{
+ unsigned modified_refcount = SvREFCNT((SV*)self->perl_obj) - 1;
+ SvREFCNT_dec((SV*)self->perl_obj);
+ return modified_refcount;
+}
+
+void*
+CFCCBlock_get_perl_obj(CFCCBlock *self)
+{
+ return self->perl_obj;
+}
+
const char*
CFCCBlock_get_contents(CFCCBlock *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCCBlock.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCCBlock.h?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCCBlock.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCCBlock.h Thu Feb 17 19:28:13 2011
@@ -25,7 +25,15 @@ CFCCBlock_init(CFCCBlock *self, const ch
void
CFCCBlock_destroy(CFCCBlock *self);
+CFCCBlock*
+CFCCBlock_incref(CFCCBlock *self);
+
+unsigned
+CFCCBlock_decref(CFCCBlock *self);
+
+void*
+CFCCBlock_get_perl_obj(CFCCBlock *self);
+
const char*
CFCCBlock_get_contents(CFCCBlock *self);
-
Modified: incubator/lucy/trunk/clownfish/src/CFCDocuComment.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.c?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.c Thu Feb 17 19:28:13 2011
@@ -30,6 +30,7 @@ struct CFCDocuComment {
char **param_names;
char **param_docs;
char *retval;
+ void *perl_obj;
};
/** Remove comment open, close, and left border from raw comment text.
@@ -88,6 +89,7 @@ CFCDocuComment_parse(const char *raw_tex
char *text = CFCUtil_strdup(raw_text);
CFCDocuComment *self = (CFCDocuComment*)calloc(1, sizeof(CFCDocuComment));
if (!self) { croak("calloc failed"); }
+ self->perl_obj = CFCUtil_make_perl_obj(self, "Clownfish::DocuComment");
// Strip whitespace, comment open, close, and left border.
CFCUtil_trim_whitespace(text);
@@ -241,6 +243,27 @@ CFCDocuComment_destroy(CFCDocuComment *s
free(self);
}
+CFCDocuComment*
+CFCDocuComment_incref(CFCDocuComment *self)
+{
+ SvREFCNT_inc((SV*)self->perl_obj);
+ return self;
+}
+
+unsigned
+CFCDocuComment_decref(CFCDocuComment *self)
+{
+ unsigned modified_refcount = SvREFCNT((SV*)self->perl_obj) - 1;
+ SvREFCNT_dec((SV*)self->perl_obj);
+ return modified_refcount;
+}
+
+void*
+CFCDocuComment_get_perl_obj(CFCDocuComment *self)
+{
+ return self->perl_obj;
+}
+
const char*
CFCDocuComment_get_description(CFCDocuComment *self)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCDocuComment.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCDocuComment.h?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCDocuComment.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCDocuComment.h Thu Feb 17 19:28:13 2011
@@ -22,6 +22,15 @@ CFCDocuComment_parse(const char *raw_tex
void
CFCDocuComment_destroy(CFCDocuComment *self);
+CFCDocuComment*
+CFCDocuComment_incref(CFCDocuComment *self);
+
+unsigned
+CFCDocuComment_decref(CFCDocuComment *self);
+
+void*
+CFCDocuComment_get_perl_obj(CFCDocuComment *self);
+
const char*
CFCDocuComment_get_description(CFCDocuComment *self);
Modified: incubator/lucy/trunk/clownfish/src/CFCFile.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.c?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.c Thu Feb 17 19:28:13 2011
@@ -20,9 +20,10 @@
#include "XSUB.h"
#include "CFCFile.h"
+#include "CFCUtil.h"
struct CFCFile {
- int dummy;
+ void *perl_obj;
};
CFCFile*
@@ -36,6 +37,7 @@ CFCFile_new(void)
CFCFile*
CFCFile_init(CFCFile *self)
{
+ self->perl_obj = CFCUtil_make_perl_obj(self, "Clownfish::File");
return self;
}
@@ -45,3 +47,24 @@ CFCFile_destroy(CFCFile *self)
free(self);
}
+CFCFile*
+CFCFile_incref(CFCFile *self)
+{
+ SvREFCNT_inc((SV*)self->perl_obj);
+ return self;
+}
+
+unsigned
+CFCFile_decref(CFCFile *self)
+{
+ unsigned modified_refcount = SvREFCNT((SV*)self->perl_obj) - 1;
+ SvREFCNT_dec((SV*)self->perl_obj);
+ return modified_refcount;
+}
+
+void*
+CFCFile_get_perl_obj(CFCFile *self)
+{
+ return self->perl_obj;
+}
+
Modified: incubator/lucy/trunk/clownfish/src/CFCFile.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCFile.h?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCFile.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCFile.h Thu Feb 17 19:28:13 2011
@@ -25,4 +25,12 @@ CFCFile_init(CFCFile *self);
void
CFCFile_destroy(CFCFile *self);
+CFCFile*
+CFCFile_incref(CFCFile *self);
+
+unsigned
+CFCFile_decref(CFCFile *self);
+
+void*
+CFCFile_get_perl_obj(CFCFile *self);
Modified: incubator/lucy/trunk/clownfish/src/CFCParamList.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParamList.c?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParamList.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParamList.c Thu Feb 17 19:28:13 2011
@@ -71,22 +71,6 @@ CFCParamList_add_param(CFCParamList *sel
void
CFCParamList_destroy(CFCParamList *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;
- }
- }
- }
size_t i;
for (i = 0; i < self->num_vars; i++) {
SvREFCNT_dec(CFCVariable_get_perl_obj(self->variables[i]));
@@ -97,6 +81,27 @@ CFCParamList_destroy(CFCParamList *self)
free(self);
}
+CFCParamList*
+CFCParamList_incref(CFCParamList *self)
+{
+ SvREFCNT_inc((SV*)self->perl_obj);
+ return self;
+}
+
+unsigned
+CFCParamList_decref(CFCParamList *self)
+{
+ unsigned modified_refcount = SvREFCNT((SV*)self->perl_obj) - 1;
+ SvREFCNT_dec((SV*)self->perl_obj);
+ return modified_refcount;
+}
+
+void*
+CFCParamList_get_perl_obj(CFCParamList *self)
+{
+ return self->perl_obj;
+}
+
CFCVariable**
CFCParamList_get_variables(CFCParamList *self)
{
@@ -121,9 +126,3 @@ CFCParamList_variadic(CFCParamList *self
return self->variadic;
}
-void*
-CFCParamList_get_perl_obj(CFCParamList *self)
-{
- return self->perl_obj;
-}
-
Modified: incubator/lucy/trunk/clownfish/src/CFCParamList.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParamList.h?rev=1071755&r1=1071754&r2=1071755&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParamList.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParamList.h Thu Feb 17 19:28:13 2011
@@ -26,6 +26,15 @@ CFCParamList_init(CFCParamList *self, in
void
CFCParamList_destroy(CFCParamList *self);
+CFCParamList*
+CFCParamList_incref(CFCParamList *self);
+
+unsigned
+CFCParamList_decref(CFCParamList *self);
+
+void*
+CFCParamList_get_perl_obj(CFCParamList *self);
+
void
CFCParamList_add_param(CFCParamList *self, struct CFCVariable *variable,
const char *value);
@@ -42,6 +51,3 @@ CFCParamList_variadic(CFCParamList *self
size_t
CFCParamList_num_vars(CFCParamList *self);
-void*
-CFCParamList_get_perl_obj(CFCParamList *self);
-