lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [3/4] git commit: refs/heads/master - Check that parcel nickname is unique
Date Mon, 01 Jul 2013 18:48:08 GMT
Check that parcel nickname is unique


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

Branch: refs/heads/master
Commit: 146a6860d31b52bfcef6ce9f9747e7596a7e7085
Parents: 25b290f
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Jul 1 03:01:03 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Jul 1 20:41:33 2013 +0200

----------------------------------------------------------------------
 clownfish/compiler/perl/t/403-parcel.t | 15 ++++++++++++++-
 clownfish/compiler/src/CFCParcel.c     | 17 ++++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/146a6860/clownfish/compiler/perl/t/403-parcel.t
----------------------------------------------------------------------
diff --git a/clownfish/compiler/perl/t/403-parcel.t b/clownfish/compiler/perl/t/403-parcel.t
index de887fd..c311987 100644
--- a/clownfish/compiler/perl/t/403-parcel.t
+++ b/clownfish/compiler/perl/t/403-parcel.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 16;
+use Test::More tests => 18;
 use File::Spec::Functions qw( catfile );
 
 BEGIN { use_ok('Clownfish::CFC::Model::Parcel') }
@@ -26,6 +26,19 @@ isa_ok( $foo, "Clownfish::CFC::Model::Parcel", "new" );
 ok( !$foo->included, "not included" );
 $foo->register;
 
+my $same_name = Clownfish::CFC::Model::Parcel->new( name => "Foo" );
+eval { $same_name->register; };
+like( $@, qr/parcel .* already registered/i,
+      "can't register two parcels with the same name" );
+
+my $same_nick = Clownfish::CFC::Model::Parcel->new(
+    name  => "OtherFoo",
+    cnick => "Foo",
+);
+eval { $same_nick->register; };
+like( $@, qr/parcel with nickname .* already registered/i,
+      "can't register two parcels with the same nickname" );
+
 my $included_foo = Clownfish::CFC::Model::Parcel->new(
     name        => "IncludedFoo",
     is_included => 1,

http://git-wip-us.apache.org/repos/asf/lucy/blob/146a6860/clownfish/compiler/src/CFCParcel.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCParcel.c b/clownfish/compiler/src/CFCParcel.c
index 6e72f2e..bb6eb56 100644
--- a/clownfish/compiler/src/CFCParcel.c
+++ b/clownfish/compiler/src/CFCParcel.c
@@ -94,10 +94,20 @@ CFCParcel_fetch(const char *name) {
 
 void
 CFCParcel_register(CFCParcel *self) {
-    CFCParcel *existing = CFCParcel_fetch(self->name);
-    if (existing) {
-        CFCUtil_die("Parcel '%s' already registered", self->name);
+    const char *name  = self->name;
+    const char *cnick = self->cnick;
+
+    for (size_t i = 0; i < num_registered ; i++) {
+        CFCParcel *other = registry[i];
+
+        if (strcmp(other->name, name) == 0) {
+            CFCUtil_die("Parcel '%s' already registered", name);
+        }
+        if (strcmp(other->cnick, cnick) == 0) {
+            CFCUtil_die("Parcel with nickname '%s' already registered", cnick);
+        }
     }
+
     if (!num_registered) {
         // Init default parcel as first.
         registry = (CFCParcel**)CALLOCATE(3, sizeof(CFCParcel*));
@@ -105,6 +115,7 @@ CFCParcel_register(CFCParcel *self) {
         registry[0] = (CFCParcel*)CFCBase_incref((CFCBase*)def);
         num_registered++;
     }
+
     size_t size = (num_registered + 2) * sizeof(CFCParcel*);
     registry = (CFCParcel**)REALLOCATE(registry, size);
     registry[num_registered++] = (CFCParcel*)CFCBase_incref((CFCBase*)self);


Mime
View raw message