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/18 23:15:59 UTC
[lucy-commits] svn commit: r1072170 - in /incubator/lucy/trunk/clownfish: lib/Clownfish.xs
lib/Clownfish/Parcel.pm src/CFCParcel.c src/CFCParcel.h src/CFCSymbol.c
src/CFCType.c
Author: marvin
Date: Fri Feb 18 22:15:58 2011
New Revision: 1072170
URL: http://svn.apache.org/viewvc?rev=1072170&view=rev
Log:
Fix refcounting situation for CFCParcel objects, so that instead of leaking
them intentionally they are refcounted and destroyed appropriately.
Modified:
incubator/lucy/trunk/clownfish/lib/Clownfish.xs
incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
incubator/lucy/trunk/clownfish/src/CFCParcel.c
incubator/lucy/trunk/clownfish/src/CFCParcel.h
incubator/lucy/trunk/clownfish/src/CFCSymbol.c
incubator/lucy/trunk/clownfish/src/CFCType.c
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish.xs
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish.xs?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish.xs (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish.xs Fri Feb 18 22:15:58 2011
@@ -480,6 +480,11 @@ CODE:
OUTPUT: RETVAL
void
+reap_singletons(...)
+PPCODE:
+ CFCParcel_reap_singletons();
+
+void
_set_or_get(self, ...)
CFCParcel *self;
ALIAS:
@@ -651,19 +656,14 @@ PPCODE:
MODULE = Clownfish PACKAGE = Clownfish::Type
SV*
-_new(klass, flags, parcel_sv, specifier, indirection, c_string)
+_new(klass, flags, parcel, specifier, indirection, c_string)
const char *klass;
int flags;
- SV *parcel_sv;
+ CFCParcel *parcel;
const char *specifier;
int indirection;
const char *c_string;
CODE:
- CFCParcel *parcel = NULL;
- if (SvOK(parcel_sv) && sv_derived_from(parcel_sv, "Clownfish::Parcel")) {
- IV objint = SvIV((SV*)SvRV(parcel_sv));
- parcel = INT2PTR(CFCParcel*, objint);
- }
CFCType *self = CFCType_new(flags, parcel, specifier, indirection,
c_string);
RETVAL = newRV((SV*)CFCBase_get_perl_obj((CFCBase*)self));
@@ -693,18 +693,13 @@ CODE:
OUTPUT: RETVAL
SV*
-_new_object(klass, flags, parcel_sv, specifier, indirection)
+_new_object(klass, flags, parcel, specifier, indirection)
const char *klass;
int flags;
- SV *parcel_sv;
+ CFCParcel *parcel;
const char *specifier;
int indirection;
CODE:
- CFCParcel *parcel = NULL;
- if (SvOK(parcel_sv) && sv_derived_from(parcel_sv, "Clownfish::Parcel")) {
- IV objint = SvIV((SV*)SvRV(parcel_sv));
- parcel = INT2PTR(CFCParcel*, objint);
- }
CFCType *self = CFCType_new_object(flags, parcel, specifier, indirection);
RETVAL = newRV((SV*)CFCBase_get_perl_obj((CFCBase*)self));
CFCBase_decref((CFCBase*)self);
@@ -751,16 +746,11 @@ CODE:
OUTPUT: RETVAL
SV*
-_new_arbitrary(klass, parcel_sv, specifier)
+_new_arbitrary(klass, parcel, specifier)
const char *klass;
- SV *parcel_sv;
+ CFCParcel *parcel;
const char *specifier;
CODE:
- CFCParcel *parcel = NULL;
- if (SvOK(parcel_sv) && sv_derived_from(parcel_sv, "Clownfish::Parcel")) {
- IV objint = SvIV((SV*)SvRV(parcel_sv));
- parcel = INT2PTR(CFCParcel*, objint);
- }
CFCType *self = CFCType_new_arbitrary(parcel, specifier);
RETVAL = newRV((SV*)CFCBase_get_perl_obj((CFCBase*)self));
CFCBase_decref((CFCBase*)self);
@@ -993,9 +983,9 @@ OUTPUT: RETVAL
MODULE = Clownfish PACKAGE = Clownfish::Variable
SV*
-_new(klass, parcel_sv, exposure, class_name_sv, class_cnick_sv, micro_sym_sv, type_sv)
+_new(klass, parcel, exposure, class_name_sv, class_cnick_sv, micro_sym_sv, type_sv)
const char *klass;
- SV *parcel_sv;
+ CFCParcel *parcel;
const char *exposure;
SV *class_name_sv;
SV *class_cnick_sv;
@@ -1008,11 +998,6 @@ CODE:
? SvPV_nolen(class_cnick_sv) : NULL;
const char *micro_sym = SvOK(micro_sym_sv)
? SvPV_nolen(micro_sym_sv) : NULL;
- CFCParcel *parcel = NULL;
- if (SvOK(parcel_sv) && sv_derived_from(parcel_sv, "Clownfish::Parcel")) {
- IV objint = SvIV((SV*)SvRV(parcel_sv));
- parcel = INT2PTR(CFCParcel*, objint);
- }
CFCType *type = NULL;
if (SvOK(type_sv) && sv_derived_from(type_sv, "Clownfish::Type")) {
IV objint = SvIV((SV*)SvRV(type_sv));
Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Parcel.pm Fri Feb 18 22:15:58 2011
@@ -23,6 +23,10 @@ use Clownfish::Util qw( verify_args );
use Scalar::Util qw( blessed );
use Carp;
+END {
+ __PACKAGE__->reap_singletons();
+}
+
our %singleton_PARAMS = (
name => undef,
cnick => undef,
Modified: incubator/lucy/trunk/clownfish/src/CFCParcel.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParcel.c?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParcel.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParcel.c Fri Feb 18 22:15:58 2011
@@ -81,6 +81,20 @@ CFCParcel_singleton(const char *name, co
return singleton;
}
+void
+CFCParcel_reap_singletons(void)
+{
+ if (registry[0]) {
+ // default parcel.
+ CFCBase_decref((CFCBase*)registry[0]);
+ }
+ int i;
+ for (i = 1; registry[i] != NULL; i++) {
+ CFCParcel *parcel = registry[i];
+ CFCBase_decref((CFCBase*)parcel);
+ }
+}
+
static int
S_validate_name_or_cnick(const char *orig)
{
Modified: incubator/lucy/trunk/clownfish/src/CFCParcel.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCParcel.h?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCParcel.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCParcel.h Fri Feb 18 22:15:58 2011
@@ -22,6 +22,11 @@ typedef struct CFCParcel CFCParcel;
CFCParcel*
CFCParcel_singleton(const char *name, const char *cnick);
+/** Decref all singletons at shutdown.
+ */
+void
+CFCParcel_reap_singletons(void);
+
CFCParcel*
CFCParcel_new(const char *name, const char *cnick);
Modified: incubator/lucy/trunk/clownfish/src/CFCSymbol.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCSymbol.c?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCSymbol.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCSymbol.c Fri Feb 18 22:15:58 2011
@@ -131,8 +131,8 @@ CFCSymbol_init(CFCSymbol *self, struct C
const char *exposure, const char *class_name,
const char *class_cnick, const char *micro_sym)
{
+ // Validate parcel.
CFCUTIL_NULL_CHECK(parcel);
- self->parcel = parcel;
// Validate exposure.
if (!S_validate_exposure(exposure)) {
@@ -173,6 +173,9 @@ CFCSymbol_init(CFCSymbol *self, struct C
}
self->micro_sym = CFCUtil_strdup(micro_sym);
+ // Assign parcel.
+ self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
+
// Derive short_sym.
size_t class_cnick_len = self->class_cnick
? strlen(self->class_cnick)
@@ -204,7 +207,7 @@ CFCSymbol_init(CFCSymbol *self, struct C
void
CFCSymbol_destroy(CFCSymbol *self)
{
- // SvREFCNT_dec((SV*)self->parcel);
+ CFCBase_decref((CFCBase*)self->parcel);
free(self->exposure);
free(self->class_name);
free(self->class_cnick);
Modified: incubator/lucy/trunk/clownfish/src/CFCType.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCType.c?rev=1072170&r1=1072169&r2=1072170&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCType.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCType.c Fri Feb 18 22:15:58 2011
@@ -58,7 +58,7 @@ CFCType_init(CFCType *self, int flags, s
const char *specifier, int indirection, const char *c_string)
{
self->flags = flags;
- self->parcel = parcel;
+ self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel);
self->specifier = CFCUtil_strdup(specifier);
self->indirection = indirection;
self->c_string = c_string ? CFCUtil_strdup(c_string) : CFCUtil_strdup("");
@@ -311,6 +311,7 @@ CFCType_destroy(CFCType *self)
if (self->child) {
CFCBase_decref((CFCBase*)self->child);
}
+ CFCBase_decref((CFCBase*)self->parcel);
free(self->specifier);
free(self->c_string);
CFCBase_destroy((CFCBase*)self);