pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:16:   #include "pike_types.h"   #include "fsort.h"   #include "builtin_functions.h"   #include "pike_memory.h"   #include "gc.h"   #include "main.h"   #include "security.h"   #include "stuff.h"   #include "bignum.h"    - RCSID("$Id: array.c,v 1.93 2000/11/08 20:03:45 hubbe Exp $"); + RCSID("$Id: array.c,v 1.94 2000/11/17 10:14:03 per Exp $");      PMOD_EXPORT struct array empty_array=   {    1, /* Never free */   #ifdef PIKE_SECURITY    0,   #endif    &empty_array, /* Next */    &empty_array, /* previous (circular) */    0, /* Size = 0 */
pike.git/src/array.c:1205:    if(p->pointer_a == (void *)a && p->pointer_b == (void *)b)    return 1;       for(e=0; e<a->size; e++)    if(!low_is_equal(ITEM(a)+e, ITEM(b)+e, &curr))    return 0;       return 1;   }    - static INT32 *ordera=0, *orderb=0; + typedef int(*mycmpfun)(INT32*,INT32*,INT32*,INT32*); + #define ID fsort_with_order + #define CMP(X,Y) ((*cmpfun)((X),(Y),oa,ob)) + #define EXTRA_ARGS ,mycmpfun cmpfun,INT32 *oa,INT32 *ob + #define XARGS ,cmpfun,oa,ob + #define TYPE INT32 + #include "fsort_template.h" + #undef ID + #undef TYPE + #undef XARGS + #undef EXTRA_ARGS + #undef CMP +  +  +    /*    * this is used to rearrange the zipper so that the order is retained    * as it was before (check merge_array_with_order below)    */ - static int array_merge_fun(INT32 *a, INT32 *b) + static int array_merge_fun(INT32 *a, INT32 *b, +  INT32 *ordera, INT32 *orderb)   {    if(*a<0)    {    if(*b<0)    {    return orderb[~*a] - orderb[~*b];    }else{    return 1;    }    }else{    if(*b<0)    {    return -1;    }else{    return ordera[*a] - ordera[*b];    }    }   }    -  -  +    /*    * merge two arrays and retain their order, this is done by arranging them    * into ordered sets, merging them as sets and then rearranging the zipper    * before zipping the sets together.    */   PMOD_EXPORT struct array *merge_array_with_order(struct array *a, struct array *b,INT32 op)   { -  ONERROR r1,r2,r3; +  ONERROR r1,r2,r3,r4,r5;    INT32 *zipper;    struct array *tmpa,*tmpb,*ret; -  +  INT32 *ordera, *orderb;    -  if(ordera) { free((char *)ordera); ordera=0; } -  if(orderb) { free((char *)orderb); orderb=0; } -  +     ordera=get_set_order(a);    orderb=get_set_order(b);    -  +  SET_ONERROR(r5,free,orderb); +  SET_ONERROR(r4,free,ordera);    tmpa=reorder_and_copy_array(a,ordera);    SET_ONERROR(r1,do_free_array,tmpa);       tmpb=reorder_and_copy_array(b,orderb);    SET_ONERROR(r2,do_free_array,tmpb);       zipper=merge(tmpa,tmpb,op);    SET_ONERROR(r3,free,zipper);    -  fsort((char *)(zipper+1),*zipper,sizeof(INT32),(fsortfun)array_merge_fun); +     -  free((char *)orderb); -  free((char *)ordera); -  orderb=ordera=0; +  fsort_with_order( (zipper+1), zipper+*zipper, array_merge_fun, +  ordera, orderb );       ret=array_zip(tmpa,tmpb,zipper);    UNSET_ONERROR(r3); free((char *)zipper);    UNSET_ONERROR(r2); free_array(tmpb);    UNSET_ONERROR(r1); free_array(tmpa); -  +  UNSET_ONERROR(r4); free((char *)ordera); +  UNSET_ONERROR(r5); free((char *)orderb);    return ret;   }         #define CMP(X,Y) set_svalue_cmpfun(X,Y)   #define TYPE struct svalue   #define ID set_sort_svalues   #include "fsort_template.h"   #undef CMP   #undef TYPE