unusual syntax?
Hi,
i noticed that this doesn't work for me (Perl 5.10):
sub _close_hash_and_insert_object {
my ($self) = @_;
return unless defined($self->{hash_object_pid});
my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
command_close_bidi_pipe($self->{@vars});
delete $self->{@vars};
}$self->{@vars} evaluates to undef. i can't find any mention of using arrays to dereference objects in the manual and elsewhere; is this a mistake?
Signature · 2 lines
Cheers, Ray Chuan
PATCH 1/1 Fix hash slice syntax error
---
Quoted 4 lines · At 2008-08-04 12:49:27 +0800, [email protected] wrote:
$self->{@vars} evaluates to undef. i can't find any mention of using arrays to dereference objects in the manual and elsewhere; is this a mistake?
Yes, @vars would be interpreted in scalar context, which certainly isn't the intended effect.
-- ams
perl/Git.pm | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
perl/Git.pm +4 -4
@@ -839,8 +839,8 @@ sub _close_hash_and_insert_object { my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx); - command_close_bidi_pipe($self->{@vars}); - delete $self->{@vars}; + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; } =item cat_blob ( SHA1, FILEHANDLE )
@@ -928,8 +928,8 @@ sub _close_cat_blob { my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx); - command_close_bidi_pipe($self->{@vars}); - delete $self->{@vars}; + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; } =back
Signature · 1 line
1.6.0.rc0.43.g2aa74
PATCH 1/1 Git.pm: Fix internal git_command_bidi_pipe() users
In reply to Ray ChuanThe hash_and_insert_object() and cat_blob() helpers were using an incorrect slice-from-ref Perl syntax. This patch fixes that up in the _close_*() helpers and make the _open_*() helpers use the same syntax for consistnecy.
---
Wow, the command_bidi_pipe API really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches introducing it.
perl/Git.pm | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
perl/Git.pm +6 -10
@@ -827,8 +827,7 @@ sub _open_hash_and_insert_object_if_needed { return if defined($self->{hash_object_pid}); - ($self->{hash_object_pid}, $self->{hash_object_in}, - $self->{hash_object_out}, $self->{hash_object_ctx}) = + @$self{map { "hash_object_$_" } qw(pid in out ctx)} = command_bidi_pipe(qw(hash-object -w --stdin-paths)); }
@@ -837,9 +836,8 @@ sub _close_hash_and_insert_object { return unless defined($self->{hash_object_pid}); - my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx); - - command_close_bidi_pipe($self->{@vars}); + my @vars = map { "hash_object_$_" } qw(pid in out ctx); + command_close_bidi_pipe(@$self{@vars}); delete $self->{@vars}; }
@@ -916,8 +914,7 @@ sub _open_cat_blob_if_needed { return if defined($self->{cat_blob_pid}); - ($self->{cat_blob_pid}, $self->{cat_blob_in}, - $self->{cat_blob_out}, $self->{cat_blob_ctx}) = + @$self{map { "cat_blob_$_" } qw(pid in out ctx)} = command_bidi_pipe(qw(cat-file --batch)); }
@@ -926,9 +923,8 @@ sub _close_cat_blob { return unless defined($self->{cat_blob_pid}); - my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx); - - command_close_bidi_pipe($self->{@vars}); + my @vars = map { "cat_blob_$_" } qw(pid in out ctx); + command_close_bidi_pipe(@$self{@vars}); delete $self->{@vars}; }
Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users
Quoted 11 lines · Petr Baudis
The
hash_and_insert_object()andcat_blob()helpers were using an incorrect slice-from-ref Perl syntax. This patch fixes that up in the _close_*() helpers and make the _open_*() helpers use the same syntax for consistnecy.Signed-off-by Petr Baudis <[email protected]>---
Wow, the
command_bidi_pipeAPI really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches introducing it.
Sorry, delete is still broken with your patch, isn't it?
The earlier patch from Abhijit Menon-Sen does this properly for close_hash_and_insert and close_cat_blob, which I've queued already.
Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Petr Baudis
The
hash_and_insert_object()andcat_blob()helpers were using an incorrect slice-from-ref Perl syntax. This patch fixes that up in the _close_*() helpers and make the _open_*() helpers use the same syntax for consistnecy.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Petr Baudis <[email protected]>---
Wow, the
command_bidi_pipeAPI really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches introducing it.Sorry, delete is still broken with your patch, isn't it?
Oh, right - I forgot that one and it didn't occur to me to test this part.
Quoted 2 lines
The earlier patch from Abhijit Menon-Sen does this properly for
close_hash_and_insertandclose_cat_blob, which I've queued already.
Abhijit, can you please tag your Git.pm patches so that I actually have a chance to see and review it?
Thanks,
Petr "Pasky" Baudis
Re: [PATCH] Git.pm: Fix internal git_command_bidi_pipe() users
Quoted 17 lines · Petr Baudis
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Petr Baudis
The
hash_and_insert_object()andcat_blob()helpers were using an incorrect slice-from-ref Perl syntax. This patch fixes that up in the _close_*() helpers and make the _open_*() helpers use the same syntax for consistnecy.Quoted 8 lines
Quoted 6 lines
Signed-off-by Petr Baudis <[email protected]>---
Wow, the
command_bidi_pipeAPI really is dirty. Of course, it is
my fault as anyone's since I didn't get around to review the patches introducing it.Sorry, delete is still broken with your patch, isn't it?
Quoted 8 lines
Oh, right - I forgot that one and it didn't occur to me to test this part.
Quoted 2 lines
The earlier patch from Abhijit Menon-Sen does this properly for
close_hash_and_insertandclose_cat_blob, which I've queued already.Abhijit, can you please tag your Git.pm patches so that I actually have a chance to see and review it?
It is $gmane/91316, Message-ID: <[email protected]>
After queueing it, I actually had to revert it, because it seems to break git-svn (t9106-git-svn-commit-diff-clobber.sh, test #8), and I am about to go to bed. If you did not see the same breakage with your patch that does not "fix" delete, it could be that the git-svn uses some of the resources that are released by the delete actually doing what it is asked to do.
---
Quoted 4 lines · At 2008-08-04 12:49:27 +0800, [email protected] wrote:
$self->{@vars} evaluates to undef. i can't find any mention of using arrays to dereference objects in the manual and elsewhere; is this a mistake?
Yes, @vars would be interpreted in scalar context, which certainly isn't the intended effect.
-- ams
perl/Git.pm | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
perl/Git.pm +4 -4
@@ -839,8 +839,8 @@ sub _close_hash_and_insert_object { my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx); - command_close_bidi_pipe($self->{@vars}); - delete $self->{@vars}; + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; } =item cat_blob ( SHA1, FILEHANDLE )
@@ -928,8 +928,8 @@ sub _close_cat_blob { my @vars = map { 'cat_blob_' . $_ } qw(pid in out ctx); - command_close_bidi_pipe($self->{@vars}); - delete $self->{@vars}; + command_close_bidi_pipe(@$self{@vars}); + delete @$self{@vars}; } =back
Signature · 1 line
1.6.0.rc0.43.g2aa74
PATCH 1/1 Git.pm: localise $? in command_close_bidi_pipe()
Git::DESTROY calls _close_cat_blob and _close_hash_and_insert_object, which in turn call command_close_bidi_pipe, which calls waitpid, which alters $?. If this happens during global destruction, it may alter the program's exit status unexpectedly. Making $? local to the function solves the problem.
(The problem was discovered due to a failure of test #8 in t9106-git-svn-commit-diff-clobber.sh.)
---
Quoted 4 lines · At 2008-08-04 01:37:06 -0700, [email protected] wrote:
After queueing it, I actually had to revert it, because it seems to break git-svn (
t9106-git-svn-commit-diff-clobber.sh, test #8), and I am about to go to bed.
This patch in addition to my earlier one should solve the problem.
For test #8 to fail, the "git svn dcommit" must succeed, but in both cases (i.e. without my patch applied, or with), the rebase fails:
rebase refs/remotes/git-svn: command returned error: 1
This results in a call to "fatal $@" on git-svn.perl:254, which calls "exit 1", and test_must_fail is happy.
With my patch, however, Git::DESTROY calls the two _close functions during global destruction, which in turn call command_close_bidi_pipe, which calls waitpid with sensible arguments this time, which alters $?, thus altering the exit status of the dcommit itself to 0. Oops.
All of "make test" passes for me after this change.
-- ams
perl/Git.pm | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
perl/Git.pm +1 -0
@@ -417,6 +417,7 @@ have more complicated structure. =cut sub command_close_bidi_pipe { + local $?; my ($pid, $in, $out, $ctx) = @_; foreach my $fh ($in, $out) { unless (close $fh) {
Signature · 1 line
1.6.0.rc0.43.g2aa74
Re: [PATCH] Git.pm: localise $? in command_close_bidi_pipe()
Quoted 4 lines · Abhijit Menon-Sen
With my patch, however,
Git::DESTROYcalls the two_closefunctions during global destruction, which in turn callcommand_close_bidi_pipe, which calls waitpid with sensible arguments this time, which alters $?, thus altering the exit status of the dcommit itself to 0. Oops.
Thanks.
Quoted 10 lines
sub _close_hash_and_insert_object {
my ($self) = @_;
return unless defined($self->{hash_object_pid});
my @vars = map { 'hash_object_' . $_ } qw(pid in out ctx);
command_close_bidi_pipe($self->{@vars});
delete $self->{@vars};
}Quoted 3 lines
$self->{@vars} evaluates to undef. i can't find any mention of using arrays to dereference objects in the manual and elsewhere; is this a mistake?
This is a hash slice notation, returning an array of hash values matching the corresponding keys. 5.10 removed some syntax warts in the case of hash slices; this is more portably expressed as @{$self}{@vars}; this should work in 5.10 and earlier versions, and so is the preferred syntax.
Regards,
David
--
David Christensen
End Point Corporation
[email protected]