Changes between Version 7 and Version 8 of Ticket #218

Show
Ignore:
Timestamp:
04/20/09 11:02:07 (6 years ago)
Author:
bacek
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #218 – description

    v7 v8  
     1I would expect the following code to print out 'a' twice, once for each type. 
    12This patch solves the ticket. But I'm not sure how "kosher" is it. 
     3  
     4 {{{ 
     5.sub main 
     6  sortme('ResizablePMCArray') 
     7 
     8  $P1 = get_class 'ResizablePMCArray' 
     9  $P0 = subclass $P1, 'RPA' 
     10 
     11  sortme('RPA') 
     12 
     13.end 
     14 
     15.sub sortme 
     16  .param string type 
     17  $P0 = new type 
     18  $P0[0]='z' 
     19  $P0[1]='a' 
     20  .local pmc comparator 
     21  comparator = get_global 'ascii' 
     22  $P0.'sort'(comparator) 
     23  $S0 = $P0[0] 
     24  say $S0 
     25.end 
     26 
     27.sub ascii 
     28  .param string a 
     29  .param string b 
     30  $I0 = cmp_str a,b 
     31  .return($I0) 
     32.end 
     33 }}} 
     34 
     35Instead, it generates: 
    236 
    337{{{ 
    4 diff --git a/src/pmc/fixedpmcarray.pmc b/src/pmc/fixedpmcarray.pmc 
    5 index 6eb6e9f..4146ca4 100644 
    6 --- a/src/pmc/fixedpmcarray.pmc 
    7 +++ b/src/pmc/fixedpmcarray.pmc 
    8 @@ -47,7 +47,7 @@ Sort this array, optionally using the provided cmp_func 
    9          const INTVAL n = SELF.elements(); 
    10   
    11          if (n > 1) 
    12 -           Parrot_quicksort(interp, (void **)PMC_array(SELF), n, cmp_func); 
    13 +           Parrot_quicksort(interp, (void **)SELF.get_pointer(), n, cmp_func); 
    14      } 
    15   
    16  /* 
    17 @@ -144,6 +144,19 @@ fixed sized array). 
    18   
    19  /* 
    20   
    21 +=item C<void *get_pointer()> 
    22 + 
    23 +Get pointer to stored data. Used in sort method. 
    24 + 
    25 +=cut 
    26 + 
    27 +*/ 
    28 + 
    29 +    VTABLE void * get_pointer() { 
    30 +        return PMC_array(SELF); 
    31 +    } 
    32 +/* 
    33 + 
    34  =item C<INTVAL get_integer()> 
    35   
    36  Returns the number of elements in the array. 
     38a 
     39Method 'sort' not found for invocant of class 'RPA' 
     40current instr.: 'sortme' pc 53 (foo.pir:21) 
     41called from Sub 'main' pc 25 (foo.pir:10) 
    3742}}} 
     43 
     44sort is a method on FixedPMCArray; it's inherited by esizablePMCArray. It is apparently then NOT inherited by my PIR level subclass.