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

Perl object state survives destruction...

Expand Messages
  • Darryl L. Pierce
    I ve written a class for use by my project, named qpid::proton::Array. It seeks to be a replacement in our code for a standard array, adding additional
    Message 1 of 6 , Apr 18, 2013
    • 0 Attachment
      I've written a class for use by my project, named qpid::proton::Array.
      It seeks to be a replacement in our code for a standard array, adding
      additional functions needed inside of our codebase.

      The issue that I've come across is this: in testing the class, I'm
      seeing the values in one array instance creeping in the the values of
      another instance. Even though my array reference is to a new instance:

      $array = qpid::proton::Array->new;

      I see, when I examine it, that it contains the values from the previous
      instance to which $array had pointed. To make it worse, the value
      assigned to array is actually being retrieved from a method which has no
      knowledge of the previous instance of Array.

      Any ideas on why one object's state would bleed into another's? The code
      for the qpid::proton::Array class is here:

      http://github.com/mcpierce/Proton/blob/PROTON-228-Perl-Data-class/proton-c/bindings/perl/lib/qpid/proton/Array.pm

      The tests can be seen here:

      http://github.com/mcpierce/Proton/blob/PROTON-228-Perl-Data-class/proton-c/bindings/perl/tests/array.t

      --
      Darryl L. Pierce <mcpierce@...>
      http://mcpierce.multiply.com/
      "What do you care what people think, Mr. Feynman?"


      [Non-text portions of this message have been removed]
    • Oral Akkan
      I don t know really but is that ok with two semi colons? lives_ok(sub {$array = qpid::proton::Array- new(0, qpid::proton::INT);},           Can create
      Message 2 of 6 , Apr 18, 2013
      • 0 Attachment
        I don't know really but is that ok with two semi colons?


        lives_ok(sub {$array = qpid::proton::Array->new(0, qpid::proton::INT);},
                 "Can create an array");

        # cannot push onto a nil array reference
        dies_ok(sub {push(undef, "foo");}, "Cannot push onto a null array");




        ________________________________
        Von: Darryl L. Pierce <mcpierce@...>
        An: perl-beginner@yahoogroups.com
        Gesendet: 19:15 Donnerstag, 18.April 2013
        Betreff: [PBML] Perl object state survives destruction...



         
        I've written a class for use by my project, named qpid::proton::Array.
        It seeks to be a replacement in our code for a standard array, adding
        additional functions needed inside of our codebase.

        The issue that I've come across is this: in testing the class, I'm
        seeing the values in one array instance creeping in the the values of
        another instance. Even though my array reference is to a new instance:

        $array = qpid::proton::Array->new;

        I see, when I examine it, that it contains the values from the previous
        instance to which $array had pointed. To make it worse, the value
        assigned to array is actually being retrieved from a method which has no
        knowledge of the previous instance of Array.

        Any ideas on why one object's state would bleed into another's? The code
        for the qpid::proton::Array class is here:

        http://github.com/mcpierce/Proton/blob/PROTON-228-Perl-Data-class/proton-c/bindings/perl/lib/qpid/proton/Array.pm

        The tests can be seen here:

        http://github.com/mcpierce/Proton/blob/PROTON-228-Perl-Data-class/proton-c/bindings/perl/tests/array.t

        --
        Darryl L. Pierce <mcpierce@...>
        http://mcpierce.multiply.com/
        "What do you care what people think, Mr. Feynman?"

        [Non-text portions of this message have been removed]




        [Non-text portions of this message have been removed]
      • Jenda Krynicky
        From: Darryl L. Pierce ... use strict; # !!! The problem is this line: $self- {_elements} = @elements; It s missing a backslash. This
        Message 3 of 6 , Apr 18, 2013
        • 0 Attachment
          From: "Darryl L. Pierce" <mcpierce@...>
          > I've written a class for use by my project, named qpid::proton::Array.
          > It seeks to be a replacement in our code for a standard array, adding
          > additional functions needed inside of our codebase.
          >
          > The issue that I've come across is this: in testing the class, I'm
          > seeing the values in one array instance creeping in the the values of
          > another instance. Even though my array reference is to a new instance:
          >
          > $array = qpid::proton::Array->new;
          >
          > I see, when I examine it, that it contains the values from the previous
          > instance to which $array had pointed. To make it worse, the value
          > assigned to array is actually being retrieved from a method which has no
          > knowledge of the previous instance of Array.
          >
          > Any ideas on why one object's state would bleed into another's? The code
          > for the qpid::proton::Array class is here:
          >
          > http://github.com/mcpierce/Proton/blob/PROTON-228-Perl-Data-class/proton-c/bindings/perl/lib/qpid/proton/Array.pm

          use strict; # !!!

          The problem is this line:


          $self->{_elements} = @elements;

          It's missing a backslash. This way the $self->{_elements} is assigned
          the number of elemens in @elements. Which means 0.
          Later on instead of working with an array specific to the instance of
          your class, you are working with array named @0 !!!

          If you used strict you would be warned!

          Jenda
          P.S.: What do you think
          return \@{$elements};
          does? And what do you think it would do if you did not make the
          mistake I descried above?

          ===== Jenda@... === http://Jenda.Krynicky.cz =====
          When it comes to wine, women and song, wizards are allowed
          to get drunk and croon as much as they like.
          -- Terry Pratchett in Sourcery
        • Darryl L. Pierce
          ... Which part do you mean? -- Darryl L. Pierce http://mcpierce.multiply.com/ What do you care what people think, Mr. Feynman? [Non-text
          Message 4 of 6 , Apr 18, 2013
          • 0 Attachment
            On Thu, Apr 18, 2013 at 11:42:32PM +0100, Oral Akkan wrote:
            >
            >
            > I don't know really but is that ok with two semi colons?
            >
            >
            > lives_ok(sub {$array = qpid::proton::Array->new(0, qpid::proton::INT);},
            >          "Can create an array");
            >
            > # cannot push onto a nil array reference
            > dies_ok(sub {push(undef, "foo");}, "Cannot push onto a null array");

            Which part do you mean?

            --
            Darryl L. Pierce <mcpierce@...>
            http://mcpierce.multiply.com/
            "What do you care what people think, Mr. Feynman?"


            [Non-text portions of this message have been removed]
          • Jenda Krynicky
            From: Oral Akkan ... Ye.s Both are fine. Let me reformat it for you: lives_ok( sub { $array = qpid::proton::Array- new(0,
            Message 5 of 6 , Apr 19, 2013
            • 0 Attachment
              From: Oral Akkan <oral_akkan@...>
              > I don't know really but is that ok with two semi colons?
              >
              >
              > lives_ok(sub {$array = qpid::proton::Array->new(0, qpid::proton::INT);},
              >          "Can create an array");
              >
              > # cannot push onto a nil array reference
              > dies_ok(sub {push(undef, "foo");}, "Cannot push onto a null array");

              Ye.s Both are fine. Let me reformat it for you:

              lives_ok(
              sub {
              $array = qpid::proton::Array->new(0, qpid::proton::INT);
              },
              "Can create an array"
              );

              The first semicolon is insite the curly braces of the anonymous
              subroutine passed to lives_ok() as the first parameter. It's
              equivalent to:

              {
              my $subroutine = sub {
              $array = qpid::proton::Array->new(0, qpid::proton::INT);
              };
              lives_ok(
              $subroutine,
              "Can create an array"
              );
              }

              Jenda

              ===== Jenda@... === http://Jenda.Krynicky.cz =====
              When it comes to wine, women and song, wizards are allowed
              to get drunk and croon as much as they like.
              -- Terry Pratchett in Sourcery
            • Darryl L. Pierce
              ... Should this go in each module, or only in the top-level module that users include in their code; i.e., qpid_proton.pm? ... Ah, thank you! And sorry for not
              Message 6 of 6 , May 3, 2013
              • 0 Attachment
                On Fri, Apr 19, 2013 at 02:02:53AM +0200, Jenda Krynicky wrote:
                > use strict; # !!!

                Should this go in each module, or only in the top-level module that
                users include in their code; i.e., qpid_proton.pm?

                >
                > The problem is this line:
                >
                >
                > $self->{_elements} = @elements;
                >
                > It's missing a backslash. This way the $self->{_elements} is assigned
                > the number of elemens in @elements. Which means 0.
                > Later on instead of working with an array specific to the instance of
                > your class, you are working with array named @0 !!!
                >
                > If you used strict you would be warned!

                Ah, thank you! And sorry for not responding sooner: I was pulled off of
                this for a while to work on some packaging tasks. Things are back to
                working properly now. :D

                --
                Darryl L. Pierce <mcpierce@...>
                http://mcpierce.multiply.com/
                "What do you care what people think, Mr. Feynman?"


                [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.