# New Ticket Created by  chromatic 
# Please include the string:  [perl #29380]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29380 >


I have an array hanging off of a struct:

        typedef struct SDL_Surface {
                Uint32 flags;               /* Read-only */
                SDL_PixelFormat *format;        /* Read-only */
                int w, h;               /* Read-only */
                Uint16 pitch;               /* Read-only */
                void *pixels;               /* Read-write */
                ...
        }

I'd like to be able to access pixels (an array of Uint32s) directly in
some cases.  It's fairly difficult to write a good general way to do
that, since the number of elements of the array depends on the size of
the surface; I can't know that in all cases before hand.

Here's a test case that demonstrates what I'm trying to do.  As usual,
it may not be the best way to do things.

This seems related to the problem of accessing nested structs.

-- c


Index: t/pmc/nci.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/nci.t,v
retrieving revision 1.39
diff -u -u -r1.39 nci.t
--- t/pmc/nci.t	4 May 2004 12:55:33 -0000	1.39
+++ t/pmc/nci.t	6 May 2004 03:46:26 -0000
@@ -17,7 +17,7 @@
 
 =cut
 
-use Parrot::Test tests => 32;
+use Parrot::Test tests => 33;
 use Parrot::Config;
 
 SKIP: {
@@ -1191,6 +1191,37 @@
 Old Y: 200
 X: 1
 Y: 2
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', 'accessing an aggregate within a struct');
+
+.include "datatypes.pasm"
+  loadlib P1, "libnci"
+  dlfunc P0, P1, "nci_pi", "pi"
+  # this test function returns a struct { *int i }
+  set I5, 8
+  invoke
+  new P2, .OrderedHash
+.include "datatypes.pasm"
+  set  P2[ 'i' ], .DATATYPE_PTR
+  push P2, 0
+  push P2, 0
+  assign P5, P2
+  set I0, P5[ 'i'; 0 ]
+  print I0
+  print "\n"
+  set I0, P5[ 'i'; 1 ]
+  print I0
+  print "\n"
+  set P5[ 'i'; 2 ], 77
+  set I0, P5[ 'i'; 2 ]
+  print I0
+  print "\n"
+  end
+CODE
+42
+100
+77
 OUTPUT
 
 } # SKIP
Index: src/nci_test.c
===================================================================
RCS file: /cvs/public/parrot/src/nci_test.c,v
retrieving revision 1.26
diff -u -u -r1.26 nci_test.c
--- src/nci_test.c	4 May 2004 07:48:52 -0000	1.26
+++ src/nci_test.c	6 May 2004 03:46:37 -0000
@@ -239,6 +239,23 @@
                 };
                 return &_x;
             }
+		case 8:
+			{
+				static int i[3];
+				i[0] =  42;
+				i[1] = 100;
+				i[2] =  66;
+
+				static struct
+				{
+					int *i;
+				} x =
+				{
+					i
+				};
+
+				return &x;
+			}
         default:
             fprintf(stderr, "unknown test number\n");
     }

Reply via email to