cvsuser     04/05/04 00:48:56

  Modified:    classes  unmanagedstruct.pmc
               .        libnci.def
               src      call_list.txt nci_test.c
               t/pmc    nci.t
  Log:
  [perl #29333] NCI Nested Struct Access Broken?
  
  The attached test patch demonstrates what I think is a problem.  Running
  gdb and looking through unmanagedstruct.pmc makes me wonder if the
  PMC_val of the nested struct is ever actually assigned to the enclosing
  struct.
  
  Courtesy of Chromatic <[EMAIL PROTECTED]>
  
  The code didn't handle the case where we are creating a nested struct,
  which is refered to by a pointer, like the given example:
  
    int bpp = surface->format->BytesPerPixel;
  
  Fixed now.
  
  Revision  Changes    Path
  1.40      +6 -1      parrot/classes/unmanagedstruct.pmc
  
  Index: unmanagedstruct.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/unmanagedstruct.pmc,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -w -r1.39 -r1.40
  --- unmanagedstruct.pmc       28 Apr 2004 10:06:02 -0000      1.39
  +++ unmanagedstruct.pmc       4 May 2004 07:48:46 -0000       1.40
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: unmanagedstruct.pmc,v 1.39 2004/04/28 10:06:02 leo Exp $
  +$Id: unmanagedstruct.pmc,v 1.40 2004/05/04 07:48:46 leo Exp $
   
   =head1 NAME
   
  @@ -175,6 +175,11 @@
                   /* or just an offset for nested structs */
                   PMC_data(init) = p;
               }
  +        }
  +        else if (init->vtable->base_type == enum_class_ManagedStruct &&
  +            *type == enum_type_struct_ptr) {
  +            /* a nested struct pointer belonging to us */
  +            printf("here\n");
           }
           return char_offset_key(interpreter, init, next, type);
       }
  
  
  
  1.5       +1 -0      parrot/libnci.def
  
  Index: libnci.def
  ===================================================================
  RCS file: /cvs/public/parrot/libnci.def,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- libnci.def        3 May 2004 07:29:45 -0000       1.4
  +++ libnci.def        4 May 2004 07:48:49 -0000       1.5
  @@ -22,3 +22,4 @@
       nci_cb_D1
       nci_pip
       nci_i_33
  +    nci_v_pii
  
  
  
  1.32      +2 -0      parrot/src/call_list.txt
  
  Index: call_list.txt
  ===================================================================
  RCS file: /cvs/public/parrot/src/call_list.txt,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -w -r1.31 -r1.32
  --- call_list.txt     30 Apr 2004 16:05:43 -0000      1.31
  +++ call_list.txt     4 May 2004 07:48:52 -0000       1.32
  @@ -209,8 +209,10 @@
   # Used by SDL
   p    iiil
   i    ppl
  +v    pip
   
   # used by t/pmc/nci.t
   v    pP
   p    ip
   i    33
  +v    pii
  
  
  
  1.26      +18 -0     parrot/src/nci_test.c
  
  Index: nci_test.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/nci_test.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -w -r1.25 -r1.26
  --- nci_test.c        3 May 2004 07:29:48 -0000       1.25
  +++ nci_test.c        4 May 2004 07:48:52 -0000       1.26
  @@ -30,12 +30,24 @@
   
   typedef struct
   {
  +     int y;
  +} Nested;
  +
  +typedef struct
  +{
  +     int x;
  +     Nested *nested;
  +} Outer;
  +
  +typedef struct
  +{
        int x, y;
        int w, h;
   } Rect_Like;
   
   void nci_pip (int count, Rect_Like *rects);
   int nci_i_33 (int *double_me, int *triple_me);
  +void nci_v_pii (Outer *my_data, int my_x, int my_y);
   
   double nci_dd(double d) {
       return d * 2.0;
  @@ -283,6 +295,12 @@
        *triple_me *= 3;
   
        return( *double_me + *triple_me );
  +}
  +
  +void nci_v_pii (Outer *my_data, int my_x, int my_y)
  +{
  +     my_data->x         = my_x;
  +     my_data->nested->y = my_y;
   }
   
   #ifdef TEST
  
  
  
  1.38      +64 -2     parrot/t/pmc/nci.t
  
  Index: nci.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/nci.t,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -w -r1.37 -r1.38
  --- nci.t     30 Apr 2004 16:05:47 -0000      1.37
  +++ nci.t     4 May 2004 07:48:56 -0000       1.38
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: nci.t,v 1.37 2004/04/30 16:05:47 leo Exp $
  +# $Id: nci.t,v 1.38 2004/05/04 07:48:56 leo Exp $
   
   =head1 NAME
   
  @@ -17,7 +17,7 @@
   
   =cut
   
  -use Parrot::Test tests => 31;
  +use Parrot::Test tests => 32;
   use Parrot::Config;
   
   print STDERR $PConfig{jitcpuarch}, " JIT CPU\n";
  @@ -1137,6 +1137,68 @@
   Double: 6
   Triple: 6
   Sum: 12
  +OUTPUT
  +
  +output_is(<<'CODE', <<'OUTPUT', 'nested structs');
  +
  +.include "datatypes.pasm"
  +  new  P8, .OrderedHash
  +  set  P8[ 'y' ],      .DATATYPE_INT
  +  push P8, 0
  +  push P8, 0
  +  new  P9, .ManagedStruct, P8
  +
  +  new  P6, .OrderedHash
  +  set  P6[ 'x' ],      .DATATYPE_INT
  +  push P6, 0
  +  push P6, 0
  +  set  P6[ 'nested' ], .DATATYPE_STRUCT_PTR
  +
  +  set  P7, P6[ -1 ]
  +  setprop P7, '_struct', P9
  +
  +  push P6, 0
  +  push P6, 0
  +
  +  new  P5, .ManagedStruct, P6
  +  set  P9[ 'y' ], 200
  +  set  P5[ 'x' ], 100
  +
  +  set I0, P5[ 'x' ]
  +  set I1, P5[ 'nested'; 'y' ]
  +  print "Old X: "
  +  print I0
  +  print "\nOld Y: "
  +  print I1
  +  print "\n"
  +
  +  set I5, 1
  +  set I6, 2
  +
  +  set I0, 1
  +  set I1, 2
  +  set I2, 0
  +  set I3, 1
  +  set I4, 0
  +
  +  loadlib P1, "libnci"
  +  dlfunc P0, P1, "nci_v_pii", "vpii"
  +  invoke
  +
  +  set I0, P5[ 'x' ]
  +  set I1, P5[ 'nested'; 'y' ]
  +  print "X: "
  +  print I0
  +  print "\nY: "
  +  print I1
  +  print "\n"
  +
  +  end
  +CODE
  +Old X: 100
  +Old Y: 200
  +X: 1
  +Y: 2
   OUTPUT
   
   } # SKIP
  
  
  

Reply via email to