Fatal.pm: context bug / patch

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Re: Fatal.pm: context bug / patch

    [A complimentary Cc of this posting was sent to
    Tom Regner
    <regner@dievision.de>], who wrote in article <444decaf$0$5508$4d3ebbfe@news1.pop-hannover.net>:
    > *** /usr/lib/perl5/5.8.8/Fatal.pm =A0 =A0 =A0 2006-04-25 09:20:38.00000=
    > 0000 +0200
    > --- Fatal.pm =A0 =A02006-04-25 09:31:53.000000000 +0200
    > ***************
    > *** 80,86 ****
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $call(@argv) || croak "Can't $name(\@_)=
    > / .
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0($core ? ': $!' : ', \$! is \"$!\"') . '"'
    > =A0 =A0 } else {
    > ! =A0 =A0 return qq{$call(@argv) || croak "Can't $name(\@_)} .
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0($core ? ': $!' : ', \$! is \"$!\"') . '"';
    > =A0 =A0 }
    > =A0 }
    > --- 80,86 ----
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $call(@argv) || croak "Can't $name(\@_)=
    > / .
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0($core ? ': $!' : ', \$! is \"$!\"') . '"'
    > =A0 =A0 } else {
    > ! =A0 =A0 return qq{wantarray ? ($call(@argv)) : $call(@argv) || croak =
    > "Can't=20
    > $name(\@_)} .
    > =A0 =A0 =A0 =A0 =A0 =A0 =A0($core ? ': $!' : ', \$! is \"$!\"') . '"';
    > =A0 =A0 }
    > =A0 }
    This patch is a no-no-no. Fatal should be used only for functions
    which return scalar value, and indicate failure by returning false.

    Basically, you just disabled Fatal for function calls in list context.
    A function which returns a scalar should behave the same in list and
    scalar context; your patch breaks this.

    Hope this helps,
    Ilya

    P.S. What do you think these parens about $call(@argv) do?
    Ilya Zakharevich Guest

  2. Similar Questions and Discussions

    1. I can't use the context menu
      :confused; Hi, everyone. I have seen that many people has some problems with the right click options. In my case, the context menu appears...
    2. Context Menu
      How can I completely hide context menu if click right button of a mouse?
    3. context root
      I have CF7 enterprise and win2003 server sp1 I wish to get following configuration: https://secure.domain.com/my_cf7_instance1/hello.cfm and...
    4. Response is not available in this context
      As soon as you return to the client the context is gone Can you respond to the client then make the client automatically check back ( Meta Tag or...
    5. No Right Context Menu
      Hi, I'm running Windows XP Pro on a Fujitsu laptop. When I click Srart and move over any previous used program program in the start menu,(I use the...
  3. #2

    Default Re: Fatal.pm: context bug / patch

    Ilya Zakharevich wrote:
    > [A complimentary Cc of this posting was sent to
    > Tom Regner
    [...]
    > This patch is a no-no-no. Fatal should be used only for functions
    > which return scalar value, and indicate failure by returning false.
    >
    > Basically, you just disabled Fatal for function calls in list context..
    > A function which returns a scalar should behave the same in list and
    > scalar context; your patch breaks this.
    >
    > Hope this helps,
    Indeed it does - thanks for the clarification.
    > Ilya
    >
    > P.S. What do you think these parens about $call(@argv) do?
    I thought it would enforce list-context to the call to original function -
    your way of asking me indicates I'm mistaken :) -

    To clarify: I didn't really tried to understand the module, I just set out
    to provide a solution for the original post made on perlmonks[1] (same link
    as mentioned in my original post) - even if a Fatal readdir() didn't make
    much sense to me[2]. OTOH the Fatal POD did not suggest to me that
    readdir()s behaviour would break - ("...replace functions which normally
    return a false value when they fail with equivalents which raise
    exceptions..." - readdir does this both in scalar- and list-context.

    I think I really don't get "it", but despite of that: is it possible to
    reword/supplement Fatal.pm POD with hinds as to the behaviour in cases like
    readdir() (that it behaves like called in scalar-context, even if called in
    list-context)[3] ?

    kind regards,
    Tom


    [1]: [url]http://www.perlmonks.org/?node_id=542441[/url]

    [2]: Why would I want to write:
    opendir(my $dir, $start_dir);
    eval {
    while($_= readdir($dir)) {
    print "$_ ";
    $notempty = 1;
    }
    closedir $dir;
    };
    if ($@ and !$notempty) {
    # handle empty dir
    }

    instead of:

    opendir(my $dir, $start_dir);
    while($_= readdir($dir)) {
    print "$_ ";
    $notempty = 1;
    }
    closedir $dir;
    };
    if (!$notempty) {
    # handle empty dir
    }

    ?

    [3]:
    use Fatal qw(readdir);
    print "With Fatal:\n";
    opendir($dir, $start_dir);
    while(@compare = readdir($dir)) {
    $count = 0;
    for (@compare) {
    print "" . $count++ . ": " . $_ . "\n";
    }
    }
    closedir $dir;
    With Fatal:
    0: .
    0: ..
    0: pm
    0: readfatal.pl
    0: kbs.png
    [...]
    0: grepcount.pl
    0: kbs-we.png
    Can't readdir(GLOB(0x814280)): Ungültiger Dateideskriptor at (eval 1)line 3
    main::__ANON__('GLOB(0x8142180)') called at readfatal.pl line 26

    --
    Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
    Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
    [url]http://www.dievision.de[/url]
    Tom Regner Guest

  4. #3

    Default Re: Fatal.pm: context bug / patch

    [A complimentary Cc of this posting was sent to
    Tom Regner
    <regner@dievision.de>], who wrote in article <444f20d1$0$26380$4d3ebbfe@news1.pop-hannover.net>:
    > much sense to me[2]. OTOH the Fatal POD did not suggest to me that
    > readdir()s behaviour would break - ("...replace functions which normally
    > return a false value when they fail with equivalents which raise
    > exceptions..." - readdir does this both in scalar- and list-context.
    Your description of behaviour of readdir() in list context is wrong.
    > I think I really don't get "it", but despite of that: is it possible
    > to= reword/supplement Fatal.pm POD with hinds as to the behaviour in
    > cases = like readdir() (that it behaves like called in
    > scalar-context, even if calle= d in list-context)[3] ?
    Sure. Any clarification to the docs is welcome - provided it is
    written AS IF the writers understand what they write about. ;-)

    Thanks,
    Ilya
    Ilya Zakharevich Guest

  5. #4

    Default Re: readdir() API broken?

    [A complimentary Cc of this posting was sent to
    Tom Regner
    <regner@dievision.de>], who wrote in article <444f20d1$0$26380$4d3ebbfe@news1.pop-hannover.net>:
    > To clarify: I didn't really tried to understand the module, I just
    > set = out to provide a solution for the original post made on
    > perlmonks[1] (same = link as mentioned in my original post) - even
    > if a Fatal readdir() didn't ma= ke much sense to me[2].
    What you noticed is a fundamental flow of Perl's readdir()
    list-context API: there is no simple way to distinguish failing call
    from an empty (rest of a) directory.

    As an absolute minimum, one needs a snippet in the docs which
    disambiguates between these two cases (probably using $! ?).

    Thanks,
    Ilya
    Ilya Zakharevich Guest

  6. #5

    Default Re: Fatal.pm: context bug / patch

    to provide context:

    Ilya Zakharevich wrote (Message-ID:
    <e2map5$29l$1@agate.berkeley.edu>):
    [concerning my blatantly ignorant patch]
    > This patch is a no-no-no. Fatal should be used only for functions
    > which return scalar value, and indicate failure by returning false.
    Ilya Zakharevich wrote (Message-ID:
    <e2p3hv$10ri$1@agate.berkeley.edu>):
    [A complimentary Cc of this posting was sent to
    Tom Regner
    <regner@dievision.de>], who wrote in article
    <444f20d1$0$26380$4d3ebbfe@news1.pop-hannover.net>:
    [...]
    >> I think I really don't get "it", but despite of that: is it possible
    >> to= reword/supplement Fatal.pm POD with hinds as to the behaviour in
    >> cases = like readdir() (that it behaves like called in
    >> scalar-context, even if calle= d in list-context)[3] ?
    >
    > Sure. Any clarification to the docs is welcome - provided it is
    > written AS IF the writers understand what they write about. ;-)
    1): I did dig deeper now into Fatal.pm and think I have at least a grasp of
    whats going on :-), but couldn't come up with a way to behave like expected
    with "fatalizing" readdir()..., which, as you mentioned (see 2), shouldn't
    be done anyway...

    2): Your first remark to my original post should be in the POD:
    > Fatal should be used only for functions
    > which return scalar value, and indicate failure by returning false.
    I suggest to change

    --
    C<Fatal> provides a way to conveniently replace functions which normally
    return a false value when they fail
    --

    to

    --
    C<Fatal> provides a way to conveniently replace functions which
    return a scalar value and normally indicate failure with returning a false
    value
    --

    I'm not a native english speaker, but I hope this is understandable and not
    to bad; It would have spared the original poster on perlmonks and me a bit
    of confusion on why the code behaves the way it does.

    Kind regards and thanks for your time and effort,
    Tom Regner
    --
    Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
    Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
    [url]http://www.dievision.de[/url]
    Tom Regner Guest

  7. #6

    Default Re: Fatal.pm: context bug / patch

    [A complimentary Cc of this posting was sent to
    Tom Regner
    <regner@dievision.de>], who wrote in article <445093e6$0$27399$4d3ebbfe@news1.pop-hannover.net>:
    > 2): Your first remark to my original post should be in the POD:
    >
    > > Fatal should be used only for functions
    > > which return scalar value, and indicate failure by returning false.
    >
    > I suggest to change
    >
    > --
    > C<Fatal> provides a way to conveniently replace functions which normally
    > return a false value when they fail
    > --
    >
    > to
    >
    > --
    > C<Fatal> provides a way to conveniently replace functions which
    > return a scalar value and normally indicate failure with returning a false
    > value
    > --
    >
    > I'm not a native english speaker, but I hope this is understandable and not
    > to bad; It would have spared the original poster on perlmonks and me a bit
    > of confusion on why the code behaves the way it does.
    Looks reasonable.

    Please send results of `diff -pu' to perl5-porters mailing list.

    Thanks,
    Ilya
    Ilya Zakharevich Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139