Make parcel in CFC::Perl::Class optional If there's a Clownfish class matching the Perl class, the parcel can be derived from the Clownfish class.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/516ae686 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/516ae686 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/516ae686 Branch: refs/heads/master Commit: 516ae68607e31a2d068c3ccebf1fcf113356ffb9 Parents: 2dcbb31 Author: Nick Wellnhofer <[email protected]> Authored: Mon May 30 14:22:33 2016 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Mon May 30 15:13:26 2016 +0200 ---------------------------------------------------------------------- compiler/perl/lib/Clownfish/CFC.pm | 6 +++-- compiler/perl/lib/Clownfish/CFC/Perl/Build.pm | 1 - compiler/src/CFCPerlClass.c | 27 +++++++++++++++++--- compiler/src/CFCPerlClass.h | 5 ++++ compiler/src/CFCTestDocuComment.c | 2 +- .../perl/buildlib/Clownfish/Build/Binding.pm | 16 ------------ 6 files changed, 34 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/compiler/perl/lib/Clownfish/CFC.pm ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.pm b/compiler/perl/lib/Clownfish/CFC.pm index f405875..8896925 100644 --- a/compiler/perl/lib/Clownfish/CFC.pm +++ b/compiler/perl/lib/Clownfish/CFC.pm @@ -747,8 +747,10 @@ BEGIN { XSLoader::load( 'Clownfish::CFC', '0.5.0' ) } sub new { my ( $either, %args ) = @_; verify_args( \%new_PARAMS, %args ) or confess $@; - $args{parcel} - = Clownfish::CFC::Model::Parcel->acquire( $args{parcel} ); + if ( exists( $args{parcel} ) ) { + $args{parcel} + = Clownfish::CFC::Model::Parcel->acquire( $args{parcel} ); + } return _new( @args{qw( parcel class_name )} ); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm index 045c0aa..8e7689b 100644 --- a/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm +++ b/compiler/perl/lib/Clownfish/CFC/Perl/Build.pm @@ -616,7 +616,6 @@ For example, the file C<buildlib/My/Module/Binding.pm> could look like: my ($class, $hierarchy) = @_; my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => 'MyModule', class_name => 'My::Module::Class', ); Clownfish::CFC::Binding::Perl::Class->register($binding); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/compiler/src/CFCPerlClass.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c index 6716a3d..30e9043 100644 --- a/compiler/src/CFCPerlClass.c +++ b/compiler/src/CFCPerlClass.c @@ -72,12 +72,29 @@ CFCPerlClass_new(CFCParcel *parcel, const char *class_name) { CFCPerlClass* CFCPerlClass_init(CFCPerlClass *self, CFCParcel *parcel, const char *class_name) { - CFCUTIL_NULL_CHECK(parcel); CFCUTIL_NULL_CHECK(class_name); - self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel); - self->class_name = CFCUtil_strdup(class_name); + // Client may be NULL, since fetch_singleton() does not always succeed. CFCClass *client = CFCClass_fetch_singleton(class_name); + if (client == NULL) { + if (parcel == NULL) { + CFCUtil_die("Missing parcel for class %s", class_name); + } + } + else { + CFCParcel *client_parcel = CFCClass_get_parcel(client); + + if (parcel == NULL) { + parcel = client_parcel; + } + else if (client_parcel != parcel) { + CFCUtil_die("Wrong parcel %s for class %s", + CFCParcel_get_name(parcel), class_name); + } + } + + self->parcel = (CFCParcel*)CFCBase_incref((CFCBase*)parcel); + self->class_name = CFCUtil_strdup(class_name); self->client = (CFCClass*)CFCBase_incref((CFCBase*)client); self->pod_spec = NULL; self->xs_code = NULL; @@ -516,4 +533,8 @@ CFCPerlClass_method_metadata_code(CFCPerlClass *self) { return code; } +CFCParcel* +CFCPerlClass_get_parcel(CFCPerlClass *self) { + return self->parcel; +} http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/compiler/src/CFCPerlClass.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCPerlClass.h b/compiler/src/CFCPerlClass.h index 7051b82..60bd08a 100644 --- a/compiler/src/CFCPerlClass.h +++ b/compiler/src/CFCPerlClass.h @@ -167,6 +167,11 @@ CFCPerlClass_get_class_aliases(CFCPerlClass *self); char* CFCPerlClass_method_metadata_code(CFCPerlClass *self); +/** Accessor for parcel. + */ +struct CFCParcel* +CFCPerlClass_get_parcel(CFCPerlClass *self); + #ifdef __cplusplus } #endif http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/compiler/src/CFCTestDocuComment.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestDocuComment.c b/compiler/src/CFCTestDocuComment.c index 2e697d5..cbad3f4 100644 --- a/compiler/src/CFCTestDocuComment.c +++ b/compiler/src/CFCTestDocuComment.c @@ -251,7 +251,7 @@ S_test_generator(CFCTest *test) { "<p>Paragraph after list</p>\n"; STR_EQ(test, html, expected_html, "create HTML"); - CFCPerlClass *perl_class = CFCPerlClass_new(parcel, "Neato::Object"); + CFCPerlClass *perl_class = CFCPerlClass_new(NULL, "Neato::Object"); CFCPerlPod *perl_pod = CFCPerlPod_new(); CFCPerlClass_set_pod_spec(perl_class, perl_pod); char *pod = CFCPerlClass_create_pod(perl_class); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/516ae686/runtime/perl/buildlib/Clownfish/Build/Binding.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index 57d3a00..8da4d83 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -102,7 +102,6 @@ END_XS_CODE sub bind_test_host { my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "TestClownfish", class_name => "Clownfish::Test::TestHost", ); $binding->bind_method( @@ -148,7 +147,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Blob", ); $binding->set_pod_spec($pod_spec); @@ -202,7 +200,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Boolean", ); $binding->set_pod_spec($pod_spec); @@ -247,7 +244,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::ByteBuf", ); $binding->set_pod_spec($pod_spec); @@ -269,7 +265,6 @@ END_SYNOPSIS $pod_spec->add_constructor(); my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::CharBuf", ); $binding->set_pod_spec($pod_spec); @@ -312,7 +307,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::String", ); $binding->set_pod_spec($pod_spec); @@ -410,7 +404,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::StringIterator", ); $binding->set_pod_spec($pod_spec); @@ -459,7 +452,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Err", ); $binding->bind_constructor( alias => '_new' ); @@ -519,7 +511,6 @@ PPCODE: END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Hash", ); $binding->set_pod_spec($pod_spec); @@ -562,7 +553,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::HashIterator", ); $binding->set_pod_spec($pod_spec); @@ -602,7 +592,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Float", ); $binding->set_pod_spec($pod_spec); @@ -642,7 +631,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Integer", ); $binding->set_pod_spec($pod_spec); @@ -801,7 +789,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Obj", ); $binding->bind_method( @@ -879,7 +866,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Vector", ); $binding->set_pod_spec($pod_spec); @@ -949,7 +935,6 @@ OUTPUT: RETVAL END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Class", ); $binding->set_pod_spec($pod_spec); @@ -1051,7 +1036,6 @@ PPCODE: END_XS_CODE my $binding = Clownfish::CFC::Binding::Perl::Class->new( - parcel => "Clownfish", class_name => "Clownfish::Util::StringHelper", ); $binding->append_xs($xs_code);
