# New Ticket Created by chromatic
# Please include the string: [perl #29333]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29333 >
>From Parrot, I'm trying to access a struct within a struct. Given an
SDL_Surface named surface, the relevant C code is:
int bpp = surface->format->BytesPerPixel;
Given surface, a working UnManagedStruct representing an SDL_Surface (to
which I can draw -- that part works), I'd expect the following PIR to be
equivalent:
.local int bpp
bpp = surface[ 'format'; 'BytesPerPixel' ]
However this complains about the unknown key 'BytesPerPixel'.
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.
Then again, I'm not a great C programmer and it is late here. I could
be doing things *completely* wrongly, in which case I'll write a
documentation patch to make things more clear after someone explains it
to me.
-- c
Index: t/pmc/nci.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/nci.t,v
retrieving revision 1.37
diff -u -u -r1.37 nci.t
--- t/pmc/nci.t 30 Apr 2004 16:05:47 -0000 1.37
+++ t/pmc/nci.t 4 May 2004 05:54:32 -0000
@@ -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
Index: src/call_list.txt
===================================================================
RCS file: /cvs/public/parrot/src/call_list.txt,v
retrieving revision 1.31
diff -u -u -r1.31 call_list.txt
--- src/call_list.txt 30 Apr 2004 16:05:43 -0000 1.31
+++ src/call_list.txt 4 May 2004 05:55:27 -0000
@@ -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
Index: src/nci_test.c
===================================================================
RCS file: /cvs/public/parrot/src/nci_test.c,v
retrieving revision 1.25
diff -u -u -r1.25 nci_test.c
--- src/nci_test.c 3 May 2004 07:29:48 -0000 1.25
+++ src/nci_test.c 4 May 2004 05:59:51 -0000
@@ -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