Loading ...
Sorry, an error occurred while loading the content.

exists("*Foo!garbage") = 1 ?

Expand Messages
  • Srinath Avadhanula
    Hi, If there is a function called Foo(), then it looks like exists( *Foo W.* ) evaluates to 1. For example ... prints 1 This happens not just for functions,
    Message 1 of 9 , Apr 29, 2006
    • 0 Attachment
      Hi,

      If there is a function called Foo(), then it looks like exists('*Foo\W.*')
      evaluates to 1. For example

      :fun Foo
      : return 1
      :endfun
      :echo exists('*Foo!asdf')
      " prints 1

      This happens not just for functions, but variables etc. also. For
      variables, I can work around this by using has_key(g:, varname)
      instead of exists('g:'.varname).

      Thank you,
      Srinath
    • Bram Moolenaar
      ... Right, extra text after the function name was ignored. It s easy to change, see the patch below. Would there be scripts that depended on the text being
      Message 2 of 9 , Apr 29, 2006
      • 0 Attachment
        Srinath Avadhanula wrote:

        > If there is a function called Foo(), then it looks like exists('*Foo\W.*')
        > evaluates to 1. For example
        >
        > :fun Foo
        > : return 1
        > :endfun
        > :echo exists('*Foo!asdf')
        > " prints 1
        >
        > This happens not just for functions, but variables etc. also. For
        > variables, I can work around this by using has_key(g:, varname)
        > instead of exists('g:'.varname).

        Right, extra text after the function name was ignored. It's easy to
        change, see the patch below.

        Would there be scripts that depended on the text being ignored? Hmm, if
        someone has been using exists('function()') then that worked, but won't
        work after the patch.

        I think I better not change this just before a release.


        --- eval.c 27 Apr 2006 21:47:33 -0000 1.171
        +++ eval.c 29 Apr 2006 11:26:22 -0000
        @@ -19098,18 +19098,19 @@
        function_exists(name)
        char_u *name;
        {
        - char_u *p = name;
        + char_u *nm = name;
        + char_u *p;
        int n = FALSE;

        - p = trans_function_name(&p, FALSE, TFN_INT|TFN_QUIET, NULL);
        - if (p != NULL)
        + p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL);
        + if (p != NULL && *skipwhite(nm) == NUL)
        {
        if (builtin_function(p))
        n = (find_internal_func(p) >= 0);
        else
        n = (find_func(p) != NULL);
        - vim_free(p);
        }
        + vim_free(p);
        return n;
        }


        --
        It is illegal to rob a bank and then shoot at the bank teller with a water
        pistol.
        [real standing law in Louisana, United States of America]

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
      • Srinath Avadhanula
        Hi Bram, ... Thanks for the patch. ... I would think that a major release of vim is a good time to fix such things which are possibly not backwards
        Message 3 of 9 , Apr 29, 2006
        • 0 Attachment
          Hi Bram,

          On 4/29/06, Bram Moolenaar <Bram@...> wrote:
          >
          > > This happens not just for functions, but variables etc. also. For
          > > variables, I can work around this by using has_key(g:, varname)
          > > instead of exists('g:'.varname).
          >
          > Right, extra text after the function name was ignored. It's easy to
          > change, see the patch below.
          >
          Thanks for the patch.

          > Would there be scripts that depended on the text being ignored? Hmm, if
          > someone has been using exists('function()') then that worked, but won't
          > work after the patch.
          >
          > I think I better not change this just before a release.

          I would think that a major release of vim is a good time to "fix" such
          things which are possibly not backwards compatible, since most users are
          expecting significant changes anyways. Also I never saw that you could
          use exists('function()') anywhere in the docs (it always returns 0 when
          I try). Its supposed to be exists('*function'), right? Why accomodate
          undocumented behavior, when there is a good documented alternative?

          I am afraid that if this gets into vim7 release, then this behavior will
          be promoted to a "feature"...

          Thanks,
          Srinath
        • Bram Moolenaar
          ... The problem of changing something like this is that all scripts that are included in the release need to be checked for effects. And there are lots of
          Message 4 of 9 , Apr 30, 2006
          • 0 Attachment
            Srinath Avadhanula wrote:

            > On 4/29/06, Bram Moolenaar <Bram@...> wrote:
            > >
            > > > This happens not just for functions, but variables etc. also. For
            > > > variables, I can work around this by using has_key(g:, varname)
            > > > instead of exists('g:'.varname).
            > >
            > > Right, extra text after the function name was ignored. It's easy to
            > > change, see the patch below.
            > >
            > Thanks for the patch.
            >
            > > Would there be scripts that depended on the text being ignored? Hmm, if
            > > someone has been using exists('function()') then that worked, but won't
            > > work after the patch.
            > >
            > > I think I better not change this just before a release.
            >
            > I would think that a major release of vim is a good time to "fix" such
            > things which are possibly not backwards compatible, since most users are
            > expecting significant changes anyways. Also I never saw that you could
            > use exists('function()') anywhere in the docs (it always returns 0 when
            > I try). Its supposed to be exists('*function'), right? Why accomodate
            > undocumented behavior, when there is a good documented alternative?
            >
            > I am afraid that if this gets into vim7 release, then this behavior will
            > be promoted to a "feature"...

            The problem of changing something like this is that all scripts that are
            included in the release need to be checked for effects. And there are
            lots of scripts now. I wouldn't be surprised if, for example, the netrw
            plugin stops working properly.

            --
            ARTHUR: CHARGE!
            [The mighty ARMY charges. Thundering noise of feet. Clatter of coconuts.
            Shouts etc. Suddenly there is a wail of a siren and a couple of police
            cars roar round in front of the charging ARMY and the POLICE leap out and
            stop them. TWO POLICEMAN and the HISTORIAN'S WIFE. Black Marias skid up
            behind them.]
            HISTORIAN'S WIFE: They're the ones, I'm sure.
            "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ download, build and distribute -- http://www.A-A-P.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
          • Charles E Campbell Jr
            ... In perusing netrw, I believe that all the netrw usages of exists( *func ) give exists() a full function name; ie. they don t depend on its just being a
            Message 5 of 9 , May 1 6:33 AM
            • 0 Attachment
              Bram Moolenaar wrote:

              >The problem of changing something like this is that all scripts that are
              >included in the release need to be checked for effects. And there are
              >lots of scripts now. I wouldn't be surprised if, for example, the netrw
              >plugin stops working properly.
              >
              >

              In perusing netrw, I believe that all the netrw usages of
              exists("*func") give exists() a full function
              name; ie. they don't depend on its just being a prefix. So, I expect
              that netrw should work ok with
              such a change.

              Regards,
              Chip Campbell
            • Bram Moolenaar
              ... Bad example... I meant that there are scripts that are too big to check. -- BODY: I m not dead! CART DRIVER: Ere. He says he s not dead. LARGE
              Message 6 of 9 , May 1 3:13 PM
              • 0 Attachment
                Charles Campbell wrote:

                > Bram Moolenaar wrote:
                >
                > >The problem of changing something like this is that all scripts that are
                > >included in the release need to be checked for effects. And there are
                > >lots of scripts now. I wouldn't be surprised if, for example, the netrw
                > >plugin stops working properly.
                >
                > In perusing netrw, I believe that all the netrw usages of
                > exists("*func") give exists() a full function
                > name; ie. they don't depend on its just being a prefix. So, I expect
                > that netrw should work ok with
                > such a change.

                Bad example... I meant that there are scripts that are too big to
                check.

                --
                BODY: I'm not dead!
                CART DRIVER: 'Ere. He says he's not dead.
                LARGE MAN: Yes he is.
                BODY: I'm not!
                "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                \\\ download, build and distribute -- http://www.A-A-P.org ///
                \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
              • Benji Fisher
                ... I tried ... and found that there are 111 matches. If all we are worried about is exists( * ) where contains non- isk characters, then I
                Message 7 of 9 , May 1 7:03 PM
                • 0 Attachment
                  On Tue, May 02, 2006 at 12:13:37AM +0200, Bram Moolenaar wrote:
                  >
                  > Charles Campbell wrote:
                  >
                  > > Bram Moolenaar wrote:
                  > >
                  > > >The problem of changing something like this is that all scripts that are
                  > > >included in the release need to be checked for effects. And there are
                  > > >lots of scripts now. I wouldn't be surprised if, for example, the netrw
                  > > >plugin stops working properly.
                  > >
                  > > In perusing netrw, I believe that all the netrw usages of
                  > > exists("*func") give exists() a full function
                  > > name; ie. they don't depend on its just being a prefix. So, I expect
                  > > that netrw should work ok with
                  > > such a change.
                  >
                  > Bad example... I meant that there are scripts that are too big to
                  > check.

                  I tried

                  :vimgrep /exists[^)]*\*/ $VIMRUNTIME/**/*.vim
                  :cl

                  and found that there are 111 matches. If all we are worried about is
                  exists("*<string>") where <string> contains non-'isk' characters, then I
                  am willing to check them. I bet there are very few.

                  HTH --Benji Fisher
                • Srinath Avadhanula
                  Hi all, ... Thanks Benji for doing this. After Bram mentioned netrw.vim yesterday, I took a look at where all it uses exists( *fun ) and it looks like
                  Message 8 of 9 , May 1 9:46 PM
                  • 0 Attachment
                    Hi all,

                    On 5/1/06, Benji Fisher <benji@...> wrote:
                    > On Tue, May 02, 2006 at 12:13:37AM +0200, Bram Moolenaar wrote:
                    > >
                    > > Bad example... I meant that there are scripts that are too big to
                    > > check.
                    >
                    > I tried
                    >
                    > :vimgrep /exists[^)]*\*/ $VIMRUNTIME/**/*.vim
                    > :cl
                    >
                    > and found that there are 111 matches. If all we are worried about is
                    > exists("*<string>") where <string> contains non-'isk' characters, then I
                    > am willing to check them. I bet there are very few.
                    >

                    Thanks Benji for doing this. After Bram mentioned netrw.vim yesterday,
                    I took a look at where all it uses exists('*fun') and it looks like
                    netrw.vim might also be bitten by the same bug which is troubling me...

                    In netrwfilehandlers.vim, line 32 is

                    if a:exten != "" && exists("*s:NFH_".a:exten)

                    so if the user is for some reason looking at a file which has non-'isk'
                    characters in its extension (for example, CVS ",v" files), then the
                    above will fail. I cannot generate a test case which fails because it
                    looks like netrw.vim automatically invokes rundll32,FileProtocolHandler
                    when has('win32'), however, the following call:

                    call netrwFileHandlers#Invoke('png,v', 'file.png')

                    produces the expected error (instead of just failing gracefully):

                    --------------------------------%<--------------------------------
                    Error detected while processing function netrwFileHandlers#Invoke:
                    line 5:
                    E121: Undefined variable: s:NFH_png
                    E15: Invalid expression: s:NFH_png,v("transmission4bar.png")
                    --------------------------------%<--------------------------------

                    I think this is another argument in favor of fixing bugs and letting
                    unintended behavior produce bugs rather than work for "mysterious"
                    reasons.

                    Thanks,
                    Srinath
                  • Bram Moolenaar
                    ... The point is that the past year we have been testing everything with the way it works now. If this is changed then we have to make sure that there is not
                    Message 9 of 9 , May 2 5:17 AM
                    • 0 Attachment
                      Benji Fisher wrote:

                      > On Tue, May 02, 2006 at 12:13:37AM +0200, Bram Moolenaar wrote:
                      > >
                      > > Charles Campbell wrote:
                      > >
                      > > > Bram Moolenaar wrote:
                      > > >
                      > > > >The problem of changing something like this is that all scripts that are
                      > > > >included in the release need to be checked for effects. And there are
                      > > > >lots of scripts now. I wouldn't be surprised if, for example, the netrw
                      > > > >plugin stops working properly.
                      > > >
                      > > > In perusing netrw, I believe that all the netrw usages of
                      > > > exists("*func") give exists() a full function
                      > > > name; ie. they don't depend on its just being a prefix. So, I expect
                      > > > that netrw should work ok with
                      > > > such a change.
                      > >
                      > > Bad example... I meant that there are scripts that are too big to
                      > > check.
                      >
                      > I tried
                      >
                      > :vimgrep /exists[^)]*\*/ $VIMRUNTIME/**/*.vim
                      > :cl
                      >
                      > and found that there are 111 matches. If all we are worried about is
                      > exists("*<string>") where <string> contains non-'isk' characters, then I
                      > am willing to check them. I bet there are very few.

                      The point is that the past year we have been testing everything with the
                      way it works now. If this is changed then we have to make sure that
                      there is not a new problem anywhere.

                      Also keep in mind that scripts sometimes contain bugs that are not
                      discovered until something seemingly harmless is changed in how Vim
                      behaves.

                      But if you are willing to carefully inspect all places where exists() is
                      used and make sure that this change will not cause any problem then I
                      might reconsider. If you make a mistake and we find a bug anyway than
                      you will be severely punished (we'll send the Spanish inquisition)!

                      --
                      DENNIS: Look, strange women lying on their backs in ponds handing out
                      swords ... that's no basis for a system of government. Supreme
                      executive power derives from a mandate from the masses, not from some
                      farcical aquatic ceremony.
                      "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
                      \\\ download, build and distribute -- http://www.A-A-P.org ///
                      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
                    Your message has been successfully submitted and would be delivered to recipients shortly.