cvsuser     04/07/12 07:22:40

  Modified:    classes  fixedpmcarray.pmc
               src      string.c
  Log:
  Pie-thon 52 - FixedPMCArray sort() hook as a demo for sort implementers
  
  Revision  Changes    Path
  1.5       +35 -1     parrot/classes/fixedpmcarray.pmc
  
  Index: fixedpmcarray.pmc
  ===================================================================
  RCS file: /cvs/public/parrot/classes/fixedpmcarray.pmc,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- fixedpmcarray.pmc 12 Jul 2004 13:09:58 -0000      1.4
  +++ fixedpmcarray.pmc 12 Jul 2004 14:22:35 -0000      1.5
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: fixedpmcarray.pmc,v 1.4 2004/07/12 13:09:58 leo Exp $
  +$Id: fixedpmcarray.pmc,v 1.5 2004/07/12 14:22:35 leo Exp $
   
   =head1 NAME
   
  @@ -22,8 +22,42 @@
   
   #include "parrot/parrot.h"
   
  +static Interp* the_interp;
  +
  +static int
  +sort_compare(void *a, void *b)
  +{
  +    PMC *pa = *(PMC**)a;
  +    PMC *pb = *(PMC**)b;
  +    return mmd_dispatch_i_pp(the_interp, pa, pb, MMD_CMP);
  +}
  +
  +static void array_sort(Interp *interpreter, PMC *self, PMC *cmp_func)
  +{
  +    if (REG_INT(3) == 0) {
  +        int (*func)(const void*, const void*) = sort_compare;
  +        the_interp = interpreter;
  +        qsort(PMC_data(self), PMC_int_val(self), sizeof(PMC *), func);
  +    }
  +    else {
  +        /*
  +         * cmp_func is an invokable PMC
  +         *
  +         * VTABLE_invoke(interpreter, cmp_func, NULL);
  +         * sort_result = REG_INT(5)
  +         */
  +    }
  +}
  +
   pmclass FixedPMCArray need_ext does array {
   
  +    void class_init () {
  +        if (pass) {
  +            enter_nci_method(INTERP, enum_class_FixedPMCArray,
  +                    F2DPTR(array_sort),
  +                    "sort", "vIOP");
  +        }
  +    }
   /*
   
   =back
  
  
  
  1.209     +7 -5      parrot/src/string.c
  
  Index: string.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/string.c,v
  retrieving revision 1.208
  retrieving revision 1.209
  diff -u -w -r1.208 -r1.209
  --- string.c  12 Jul 2004 13:10:24 -0000      1.208
  +++ string.c  12 Jul 2004 14:22:39 -0000      1.209
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: string.c,v 1.208 2004/07/12 13:10:24 leo Exp $
  +$Id: string.c,v 1.209 2004/07/12 14:22:39 leo Exp $
   
   =head1 NAME
   
  @@ -2526,10 +2526,12 @@
   {
       FLOATVAL f = 0.0;
   
  +    if (s) {
       char *cstr = string_to_cstring(interpreter, s);
       f = atof(cstr);
       string_cstring_free(cstr);
       return f;
  +    }
       /*
        * results from that code below aren't really exact:
        * float("1e100") != 10**100
  
  
  

Reply via email to