On Wed, 2004-05-05 at 22:54, Leopold Toetsch wrote: > > I'd like to be able to access pixels (an array of Uint32s) directly in > > some cases. > > + set P2[ 'i' ], .DATATYPE_PTR
> Why not just define an array of uintvals? The pointer type does nothing > useful AFAIK. It's true that the pointer value does nothing useful, but I'm having severe difficulty getting the correct values out of an array of this type. The attached test patch shows what I would expect to work. It fails on my box: Count: 4 0: 263958416 1: 0 2: 263958412 3: 264243256 I expect to see: Count: 4 0: 100 1: 200 2: 400 3: 800 (On the plus size, this'd add a small Pac-Man tribute to the test suite.) -- c
Index: t/pmc/nci.t =================================================================== RCS file: /cvs/public/parrot/t/pmc/nci.t,v retrieving revision 1.42 diff -u -u -r1.42 nci.t --- t/pmc/nci.t 7 May 2004 10:33:41 -0000 1.42 +++ t/pmc/nci.t 9 May 2004 06:36:09 -0000 @@ -17,7 +17,7 @@ =cut -use Parrot::Test tests => 33; +use Parrot::Test tests => 34; use Parrot::Config; SKIP: { @@ -1256,6 +1256,68 @@ X: 1 Y: 2 2 +OUTPUT + +output_is(<<'CODE', <<'OUTPUT', 'nested array in a struct'); + +.include "datatypes.pasm" + set I0, 1 + set I1, 4 + set I2, 0 + set I3, 0 + set I4, 0 + set I5, 100 + set I6, 200 + set I7, 400 + set I8, 800 + + loadlib P1, "libnci" + dlfunc P0, P1, "nci_p_iiii", "piiii" + invoke + + new P6, .OrderedHash + set P6[ 'count' ], .DATATYPE_INT + push P6, 0 + push P6, 0 + + # yes, the array within the struct has _4_ elements + # but with an UnManagedStruct, you can't always know the amount beforehand + set P6[ 'array' ], .DATATYPE_INT + push P6, 2 + push P6, 0 + + assign P5, P6 + set I0, P5[ 'count' ] + + print "Count: " + print I0 + print "\n" + + # now that we do know, update the UnManagedStruct appropriately + set P6[ 4 ], I0 + assign P5, P6 + + set I0, P5[ 'array'; 0 ] + set I1, P5[ 'array'; 1 ] + set I2, P5[ 'array'; 2 ] + set I3, P5[ 'array'; 3 ] + print "0: " + print I0 + print "\n1: " + print I1 + print "\n2: " + print I2 + print "\n3: " + print I3 + print "\n" + + end +CODE +Count: 4 +0: 100 +1: 200 +2: 400 +3: 800 OUTPUT } # SKIP Index: src/nci_test.c =================================================================== RCS file: /cvs/public/parrot/src/nci_test.c,v retrieving revision 1.27 diff -u -u -r1.27 nci_test.c --- src/nci_test.c 6 May 2004 15:07:11 -0000 1.27 +++ src/nci_test.c 9 May 2004 06:36:19 -0000 @@ -48,6 +48,7 @@ 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); +void * nci_p_iiii (int alpha, int beta, int gamma, int delta); double nci_dd(double d) { return d * 2.0; @@ -318,8 +319,25 @@ void nci_v_pii (Outer *my_data, int my_x, int my_y) { - my_data->x = my_x; - my_data->nested->y = my_y; + my_data->x = my_x; + my_data->nested->y = my_y; +} + +static int my_array[4]; +void * nci_p_iiii (int alpha, int beta, int gamma, int delta) +{ + my_array[0] = alpha; + my_array[1] = beta; + my_array[2] = gamma; + my_array[3] = delta; + + static struct array_container + { + int x; + void *array; + } container = { 4, &my_array }; + + return &container; } #ifdef TEST Index: libnci.def =================================================================== RCS file: /cvs/public/parrot/libnci.def,v retrieving revision 1.5 diff -u -u -r1.5 libnci.def --- libnci.def 4 May 2004 07:48:49 -0000 1.5 +++ libnci.def 9 May 2004 06:36:57 -0000 @@ -23,3 +23,4 @@ nci_pip nci_i_33 nci_v_pii + nci_p_iiii