Author: marvin
Date: Sun May 13 22:00:52 2012
New Revision: 1337990
URL: http://svn.apache.org/viewvc?rev=1337990&view=rev
Log:
Remove CFCParcel_singleton().
Replace usage of CFCParcel_singleton() with combinations of fetch(),
new() and register().
Modified:
lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
lucy/trunk/clownfish/perl/t/051-symbol.t
lucy/trunk/clownfish/perl/t/100-type.t
lucy/trunk/clownfish/perl/t/403-parcel.t
lucy/trunk/clownfish/src/CFCClass.c
lucy/trunk/clownfish/src/CFCParcel.c
lucy/trunk/clownfish/src/CFCParcel.h
lucy/trunk/clownfish/src/CFCParseHeader.y
lucy/trunk/clownfish/src/CFCType.c
lucy/trunk/clownfish/src/CFCVariable.c
Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.pm Sun May 13 22:00:52 2012
@@ -136,10 +136,7 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
# Maybe prepend parcel prefix.
my $parcel = $args{parcel};
if ( defined $parcel ) {
- if ( !a_isa_b( $parcel, "Clownfish::CFC::Model::Parcel" ) ) {
- $parcel = Clownfish::CFC::Model::Parcel->singleton(
- name => $parcel );
- }
+ $parcel = Clownfish::CFC::Model::Parcel->acquire($parcel);
}
return _fetch_singleton( $parcel, $args{class_name} );
}
@@ -322,18 +319,6 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
use Scalar::Util qw( blessed );
use Carp;
- our %singleton_PARAMS = (
- name => undef,
- cnick => undef,
- );
-
- sub singleton {
- my ( $either, %args ) = @_;
- verify_args( \%singleton_PARAMS, %args ) or confess $@;
- confess "no subclassing allowed" unless $either eq __PACKAGE__;
- return _singleton( @args{qw( name cnick )} );
- }
-
our %new_PARAMS = (
name => undef,
cnick => undef,
@@ -368,11 +353,11 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
return _new_from_file( $args{path} );
}
-# $parcel =
Clownfish::CFC::Model::Parcel->aquire($parcel_name_or_parcel_object);
+# $parcel =
Clownfish::CFC::Model::Parcel->acquire($parcel_name_or_parcel_object);
#
# Aquire a parcel one way or another. If the supplied argument is a
# Parcel, return it. If it's not defined, return the default Parcel. If
-# it's a name, invoke singleton().
+# it's a name, fetch an existing Parcel or register a new one.
sub acquire {
my ( undef, $thing ) = @_;
if ( !defined $thing ) {
@@ -384,7 +369,13 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
return $thing;
}
else {
- return Clownfish::CFC::Model::Parcel->singleton( name => $thing );
+ my $parcel = Clownfish::CFC::Model::Parcel->fetch($thing);
+ if ( !$parcel ) {
+ $parcel
+ = Clownfish::CFC::Model::Parcel->new( name => $thing, );
+ $parcel->register;
+ }
+ return $parcel;
}
}
}
@@ -717,10 +708,8 @@ BEGIN { XSLoader::load( 'Clownfish::CFC'
sub new {
my ( $either, %args ) = @_;
verify_args( \%new_PARAMS, %args ) or confess $@;
- if ( !a_isa_b( $args{parcel}, 'Clownfish::CFC::Model::Parcel' ) ) {
- $args{parcel} = Clownfish::CFC::Model::Parcel->singleton(
- name => $args{parcel} );
- }
+ $args{parcel}
+ = Clownfish::CFC::Model::Parcel->acquire( $args{parcel} );
return _new(
@args{qw( parcel hierarchy lib_dir boot_class header footer )} );
}
Modified: lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs (original)
+++ lucy/trunk/clownfish/perl/lib/Clownfish/CFC.xs Sun May 13 22:00:52 2012
@@ -1091,16 +1091,23 @@ CODE:
OUTPUT: RETVAL
SV*
-_singleton(name_sv, cnick_sv)
+fetch(unused, name_sv)
+ SV *unused;
SV *name_sv;
- SV *cnick_sv;
CODE:
+ (void)unused;
const char *name = SvOK(name_sv) ? SvPV_nolen(name_sv) : NULL;
- const char *cnick = SvOK(cnick_sv) ? SvPV_nolen(cnick_sv) : NULL;
- CFCParcel *self = CFCParcel_singleton(name, cnick);
+ CFCParcel *self = CFCParcel_fetch(name);
RETVAL = S_cfcbase_to_perlref(self);
OUTPUT: RETVAL
+
+void
+register(self)
+ CFCParcel *self;
+PPCODE:
+ CFCParcel_register(self);
+
int
equals(self, other)
CFCParcel *self;
Modified: lucy/trunk/clownfish/perl/t/051-symbol.t
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/051-symbol.t?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/051-symbol.t (original)
+++ lucy/trunk/clownfish/perl/t/051-symbol.t Sun May 13 22:00:52 2012
@@ -47,8 +47,8 @@ ok( !$public_exposure->equals($parcel_ex
"different exposure spoils equals"
);
-my $lucifer_parcel
- = Clownfish::CFC::Model::Parcel->singleton( name => 'Lucifer' );
+my $lucifer_parcel = Clownfish::CFC::Model::Parcel->new( name => 'Lucifer' );
+$lucifer_parcel->register;
my $lucifer = new_symbol( parcel => 'Lucifer' );
ok( $$lucifer_parcel == ${ $lucifer->get_parcel }, "derive parcel" );
is( $lucifer->get_prefix, "lucifer_", "get_prefix" );
Modified: lucy/trunk/clownfish/perl/t/100-type.t
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/100-type.t?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/100-type.t (original)
+++ lucy/trunk/clownfish/perl/t/100-type.t Sun May 13 22:00:52 2012
@@ -19,8 +19,8 @@ use warnings;
use Test::More tests => 11;
use Clownfish::CFC::Model::Parcel;
-my $neato_parcel
- = Clownfish::CFC::Model::Parcel->singleton( name => 'Neato' );
+my $neato_parcel = Clownfish::CFC::Model::Parcel->new( name => 'Neato' );
+$neato_parcel->register;
my $type = Clownfish::CFC::Model::Type->new(
parcel => 'Neato',
Modified: lucy/trunk/clownfish/perl/t/403-parcel.t
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/perl/t/403-parcel.t?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/perl/t/403-parcel.t (original)
+++ lucy/trunk/clownfish/perl/t/403-parcel.t Sun May 13 22:00:52 2012
@@ -44,10 +44,10 @@ isa_ok(
);
# Register singleton.
-Clownfish::CFC::Model::Parcel->singleton(
+Clownfish::CFC::Model::Parcel->new(
name => 'Crustacean',
cnick => 'Crust',
-);
+)->register;
my $thing = Clownfish::CFC::Model::Symbol->new(
micro_sym => 'sym',
Modified: lucy/trunk/clownfish/src/CFCClass.c
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCClass.c?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCClass.c (original)
+++ lucy/trunk/clownfish/src/CFCClass.c Sun May 13 22:00:52 2012
@@ -131,7 +131,7 @@ CFCClass_do_create(CFCClass *self, struc
CFCUTIL_NULL_CHECK(class_name);
exposure = exposure ? exposure : "parcel";
micro_sym = micro_sym ? micro_sym : "class";
- parcel = parcel ? parcel : CFCParcel_singleton(NULL, NULL);
+ parcel = parcel ? parcel : CFCParcel_default_parcel();
CFCSymbol_init((CFCSymbol*)self, parcel, exposure, class_name, cnick,
micro_sym);
self->parent = NULL;
Modified: lucy/trunk/clownfish/src/CFCParcel.c
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParcel.c?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParcel.c (original)
+++ lucy/trunk/clownfish/src/CFCParcel.c Sun May 13 22:00:52 2012
@@ -68,25 +68,6 @@ static CFCParcel **registry = NULL;
static size_t num_registered = 0;
CFCParcel*
-CFCParcel_singleton(const char *name, const char *cnick) {
- // Return an existing singleton if the parcel has already been registered.
- CFCParcel *existing = CFCParcel_fetch(name);
- if (existing) {
- if (cnick && strcmp(existing->cnick, cnick) != 0) {
- CFCUtil_die("cnick '%s' for parcel '%s' conflicts with '%s'",
- cnick, name, existing->cnick);
- }
- return existing;
- }
-
- // Register new parcel.
- CFCParcel *singleton = CFCParcel_new(name, cnick);
- CFCParcel_register(singleton);
-
- return singleton;
-}
-
-CFCParcel*
CFCParcel_fetch(const char *name) {
// Return the default parcel for either a blank name or a NULL name.
if (!name || !strlen(name)) {
@@ -286,7 +267,13 @@ CFCParcel_default_parcel(void) {
CFCParcel*
CFCParcel_clownfish_parcel(void) {
- return CFCParcel_singleton("Lucy", "Lucy");
+ CFCParcel *parcel = CFCParcel_fetch("Lucy");
+ if (!parcel) {
+ parcel = CFCParcel_new("Lucy", "Lucy");
+ CFCParcel_register(parcel);
+ CFCBase_decref((CFCBase*)parcel);
+ }
+ return parcel;
}
int
Modified: lucy/trunk/clownfish/src/CFCParcel.h
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParcel.h?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParcel.h (original)
+++ lucy/trunk/clownfish/src/CFCParcel.h Sun May 13 22:00:52 2012
@@ -38,17 +38,6 @@ extern "C" {
typedef struct CFCParcel CFCParcel;
-/** Add a Parcel singleton to a global registry. May be called multiple times,
- * but only with compatible arguments.
- *
- * @param name The name of the parcel.
- * @param cnick The C nickname for the parcel, which will be used as a prefix
- * for generated global symbols. Must be mixed case and start with a capital
- * letter. Defaults to <code>name</code>
- */
-CFCParcel*
-CFCParcel_singleton(const char *name, const char *cnick);
-
/** Return the parcel which has been registered for <code>name</code>.
*/
CFCParcel*
Modified: lucy/trunk/clownfish/src/CFCParseHeader.y
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCParseHeader.y?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCParseHeader.y (original)
+++ lucy/trunk/clownfish/src/CFCParseHeader.y Sun May 13 22:00:52 2012
@@ -319,7 +319,12 @@ parcel_definition(A) ::= exposure_specif
* declaration and exposure specifier). */
CFCUtil_die("A syntax error was detected when parsing '%s'", B);
}
- A = CFCParcel_singleton(C, NULL);
+ A = CFCParcel_fetch(C);
+ if (!A) {
+ A = CFCParcel_new(C, NULL);
+ CFCParcel_register(A);
+ CFCBase_decref((CFCBase*)A);
+ }
CFCBase_incref((CFCBase*)A);
CFCParser_set_parcel(state, A);
}
@@ -329,7 +334,12 @@ parcel_definition(A) ::= exposure_specif
if (strcmp(B, "parcel") != 0) {
CFCUtil_die("A syntax error was detected when parsing '%s'", B);
}
- A = CFCParcel_singleton(C, D);
+ A = CFCParcel_fetch(C);
+ if (!A) {
+ A = CFCParcel_new(C, D);
+ CFCParcel_register(A);
+ CFCBase_decref((CFCBase*)A);
+ }
CFCBase_incref((CFCBase*)A);
CFCParser_set_parcel(state, A);
}
Modified: lucy/trunk/clownfish/src/CFCType.c
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCType.c?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCType.c (original)
+++ lucy/trunk/clownfish/src/CFCType.c Sun May 13 22:00:52 2012
@@ -213,7 +213,7 @@ CFCType_new_object(int flags, CFCParcel
// Use default parcel if none supplied.
if (!parcel) {
- parcel = CFCParcel_singleton(NULL, NULL);
+ parcel = CFCParcel_default_parcel();
}
// Add flags.
Modified: lucy/trunk/clownfish/src/CFCVariable.c
URL:
http://svn.apache.org/viewvc/lucy/trunk/clownfish/src/CFCVariable.c?rev=1337990&r1=1337989&r2=1337990&view=diff
==============================================================================
--- lucy/trunk/clownfish/src/CFCVariable.c (original)
+++ lucy/trunk/clownfish/src/CFCVariable.c Sun May 13 22:00:52 2012
@@ -61,7 +61,7 @@ CFCVariable_init(CFCVariable *self, stru
// Validate params.
CFCUTIL_NULL_CHECK(type);
if (!parcel) {
- parcel = CFCParcel_singleton(NULL, NULL);
+ parcel = CFCParcel_default_parcel();
}
// Default exposure to "local".