Replace CFCFile_cfh_path with CFCFile_get_path The new method returns a const char*.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/6ab4fc69 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/6ab4fc69 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/6ab4fc69 Branch: refs/heads/master Commit: 6ab4fc6991d9bc0623a9faff1765ea7725eff32d Parents: ac45960 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Sat Jul 16 15:14:47 2016 +0200 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Sat Jul 16 16:11:08 2016 +0200 ---------------------------------------------------------------------- compiler/perl/lib/Clownfish/CFC.xs | 10 ++++++---- compiler/perl/t/404-file.t | 9 +++++---- compiler/perl/t/500-hierarchy.t | 2 +- compiler/src/CFCFile.c | 10 +++++----- compiler/src/CFCFile.h | 8 +++----- compiler/src/CFCHierarchy.c | 7 ++----- compiler/src/CFCTestFile.c | 5 ++--- compiler/src/CFCTestHierarchy.c | 3 +-- 8 files changed, 25 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/perl/lib/Clownfish/CFC.xs ---------------------------------------------------------------------- diff --git a/compiler/perl/lib/Clownfish/CFC.xs b/compiler/perl/lib/Clownfish/CFC.xs index 4827fab..08930e1 100644 --- a/compiler/perl/lib/Clownfish/CFC.xs +++ b/compiler/perl/lib/Clownfish/CFC.xs @@ -522,6 +522,7 @@ ALIAS: get_source_dir = 16 included = 18 get_parcel = 20 + get_path = 22 PPCODE: { START_SET_OR_GET_SWITCH @@ -571,6 +572,11 @@ PPCODE: retval = S_cfcbase_to_perlref(parcel); } break; + case 22: { + const char *value = CFCFile_get_path(self); + retval = newSVpv(value, strlen(value)); + } + break; END_SET_OR_GET_SWITCH } @@ -581,7 +587,6 @@ _gen_path(self, base_dir = NULL) ALIAS: c_path = 1 h_path = 2 - cfh_path = 3 CODE: { char *buf; @@ -592,9 +597,6 @@ CODE: case 2: buf = CFCFile_h_path(self, base_dir); break; - case 3: - buf = CFCFile_cfh_path(self, base_dir); - break; default: croak("unexpected ix value: %d", (int)ix); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/perl/t/404-file.t ---------------------------------------------------------------------- diff --git a/compiler/perl/t/404-file.t b/compiler/perl/t/404-file.t index d641101..b907d69 100644 --- a/compiler/perl/t/404-file.t +++ b/compiler/perl/t/404-file.t @@ -17,7 +17,7 @@ use strict; use warnings; use Test::More tests => 21; -use File::Spec::Functions qw( catdir ); +use File::Spec::Functions qw( catfile ); use Clownfish::CFC::Model::File; use Clownfish::CFC::Parser; @@ -35,7 +35,7 @@ my $class_content = qq| |; my $c_block = "__C__\nint foo;\n__END_C__\n"; -my $path_part = catdir(qw( Stuff Thing )); +my $path_part = catfile(qw( Stuff Thing )); my $file_spec = Clownfish::CFC::Model::FileSpec->new( source_dir => '.', path_part => $path_part, @@ -43,10 +43,13 @@ my $file_spec = Clownfish::CFC::Model::FileSpec->new( ); { + my $path_sep = $^O =~ /^mswin/i ? '\\' : '/'; my $file = $parser->_parse_file( "$parcel_declaration\n$class_content\n$c_block", $file_spec ); + is( $file->get_path, join( $path_sep, qw( . Stuff Thing.cfh ) ), + "get_path" ); is( $file->get_source_dir, ".", "get_source_dir" ); is( $file->get_path_part, $path_part, "get_path_part" ); ok( !$file->included, "included" ); @@ -61,9 +64,7 @@ my $file_spec = Clownfish::CFC::Model::FileSpec->new( $file->set_modified(1); ok( $file->get_modified, "set_modified, get_modified" ); - my $path_sep = $^O =~ /^mswin/i ? '\\' : '/'; my $path_to_stuff_thing = join( $path_sep, qw( path to Stuff Thing ) ); - is( $file->cfh_path('path/to'), "$path_to_stuff_thing.cfh", "cfh_path" ); is( $file->c_path('path/to'), "$path_to_stuff_thing.c", "c_path" ); is( $file->h_path('path/to'), "$path_to_stuff_thing.h", "h_path" ); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/perl/t/500-hierarchy.t ---------------------------------------------------------------------- diff --git a/compiler/perl/t/500-hierarchy.t b/compiler/perl/t/500-hierarchy.t index 44b0b6a..a066496 100644 --- a/compiler/perl/t/500-hierarchy.t +++ b/compiler/perl/t/500-hierarchy.t @@ -89,7 +89,7 @@ for my $file (@files) { or die "utime failed for '$h_path': $!"; } -my $path_to_animal_cf = $animal->cfh_path( $base_dir ); +my $path_to_animal_cf = $animal->get_path; # Strawberry Perl may unpack the distribution's files as read-only. if ( ! -w $path_to_animal_cf ) { chmod( 0644, $path_to_animal_cf ) http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/src/CFCFile.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCFile.c b/compiler/src/CFCFile.c index d8620f2..632aea9 100644 --- a/compiler/src/CFCFile.c +++ b/compiler/src/CFCFile.c @@ -179,11 +179,6 @@ CFCFile_h_path(CFCFile *self, const char *base_dir) { return S_some_path(self, base_dir, ".h"); } -char* -CFCFile_cfh_path(CFCFile *self, const char *base_dir) { - return S_some_path(self, base_dir, ".cfh"); -} - CFCParcel* CFCFile_get_parcel(CFCFile *self) { return self->parcel; @@ -210,6 +205,11 @@ CFCFile_get_modified(CFCFile *self) { } const char* +CFCFile_get_path(CFCFile *self) { + return CFCFileSpec_get_path(self->spec); +} + +const char* CFCFile_get_source_dir(CFCFile *self) { return CFCFileSpec_get_source_dir(self->spec); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/src/CFCFile.h ---------------------------------------------------------------------- diff --git a/compiler/src/CFCFile.h b/compiler/src/CFCFile.h index bb3ecd4..72f055a 100644 --- a/compiler/src/CFCFile.h +++ b/compiler/src/CFCFile.h @@ -64,11 +64,6 @@ CFCFile_c_path(CFCFile *self, const char *base_dir); char* CFCFile_h_path(CFCFile *self, const char *base_dir); -/** As c_path, but with a ".cfh" extension. - */ -char* -CFCFile_cfh_path(CFCFile *self, const char *base_dir); - struct CFCParcel* CFCFile_get_parcel(CFCFile *self); @@ -91,6 +86,9 @@ int CFCFile_get_modified(CFCFile *self); const char* +CFCFile_get_path(CFCFile *self); + +const char* CFCFile_get_source_dir(CFCFile *self); const char* http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/src/CFCHierarchy.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c index 87e596c..6e0d787 100644 --- a/compiler/src/CFCHierarchy.c +++ b/compiler/src/CFCHierarchy.c @@ -480,16 +480,13 @@ S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified) { CFCUTIL_NULL_CHECK(path_part); CFCFile *file = S_fetch_file(self, path_part); CFCUTIL_NULL_CHECK(file); - const char *source_dir = CFCFile_get_source_dir(file); - CFCUTIL_NULL_CHECK(source_dir); - char *source_path = CFCFile_cfh_path(file, source_dir); - char *h_path = CFCFile_h_path(file, self->inc_dest); + const char *source_path = CFCFile_get_path(file); + char *h_path = CFCFile_h_path(file, self->inc_dest); if (!CFCUtil_current(source_path, h_path)) { modified = true; } FREEMEM(h_path); - FREEMEM(source_path); if (modified) { CFCFile_set_modified(file, modified); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/src/CFCTestFile.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestFile.c b/compiler/src/CFCTestFile.c index c1290fb..5d55912 100644 --- a/compiler/src/CFCTestFile.c +++ b/compiler/src/CFCTestFile.c @@ -58,6 +58,8 @@ S_run_tests(CFCTest *test) { "__END_C__\n"; CFCFile *file = CFCParser_parse_file(parser, string, file_spec); + STR_EQ(test, CFCFile_get_path(file), + "." CHY_DIR_SEP STUFF_THING ".cfh", "get_path"); STR_EQ(test, CFCFile_get_source_dir(file), ".", "get_source_dir"); STR_EQ(test, CFCFile_get_path_part(file), STUFF_THING, "get_path_part"); @@ -80,9 +82,6 @@ S_run_tests(CFCTest *test) { "Stuff" CHY_DIR_SEP \ "Thing" - char *cfh_path = CFCFile_cfh_path(file, "path/to"); - STR_EQ(test, cfh_path, PATH_TO_STUFF_THING ".cfh", "cfh_path"); - FREEMEM(cfh_path); char *c_path = CFCFile_c_path(file, "path/to"); STR_EQ(test, c_path, PATH_TO_STUFF_THING ".c", "c_path"); FREEMEM(c_path); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6ab4fc69/compiler/src/CFCTestHierarchy.c ---------------------------------------------------------------------- diff --git a/compiler/src/CFCTestHierarchy.c b/compiler/src/CFCTestHierarchy.c index 4df8c5f..03d0df8 100644 --- a/compiler/src/CFCTestHierarchy.c +++ b/compiler/src/CFCTestHierarchy.c @@ -139,9 +139,8 @@ S_run_basic_tests(CFCTest *test) { CFCTest_set_file_times(h_path, past_time); } - char *cfh_path = CFCFile_cfh_path(animal, cfbase_path); + const char *cfh_path = CFCFile_get_path(animal); CFCTest_set_file_times(cfh_path, now); - FREEMEM(cfh_path); CFCHierarchy_propagate_modified(hierarchy, 0);