pike.git / src / array.c

version» Context lines:

pike.git/src/array.c:903:       get_order_fsort(current_order,    current_order+v->size-1,    fun,    ITEM(v));       UNSET_ONERROR(tmp);    return current_order;   }    - /* Returns 2 if no relation is established through lfun calls, or 3 if -  * no order defining lfuns (i.e. `< or `>) were found. */ + /* Returns CMPFUN_UNORDERED if no relation is established through lfun +  * calls, or -CMPFUN_UNORDERED if no order defining lfuns (i.e. `< or +  * `>) were found. */   static int lfun_cmp (const struct svalue *a, const struct svalue *b)   {    struct program *p; -  int default_res = 3, fun; +  int default_res = -CMPFUN_UNORDERED, fun;       if (a->type == T_OBJECT && (p = a->u.object->prog)) {    if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_LT)) != -1) {    push_svalue(b);    apply_low(a->u.object,    fun + p->inherits[a->subtype].identifier_level, 1);    if(!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();    return -1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_GT)) != -1) {    push_svalue(b);    apply_low(a->u.object,    fun + p->inherits[a->subtype].identifier_level, 1);    if(!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();    return 1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_EQ)) != -1) {    push_svalue(b);    apply_low(a->u.object,    fun + p->inherits[a->subtype].identifier_level, 1);    if (!UNSAFE_IS_ZERO(Pike_sp-1)) {    pop_stack();    return 0;    }
pike.git/src/array.c:960:    if ((fun = FIND_LFUN(p->inherits[b->subtype].prog, LFUN_LT)) != -1) {    push_svalue(a);    apply_low(b->u.object,    fun + p->inherits[b->subtype].identifier_level, 1);    if(!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();    return 1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[b->subtype].prog, LFUN_GT)) != -1) {    push_svalue(a);    apply_low(b->u.object,    fun + p->inherits[b->subtype].identifier_level, 1);    if(!UNSAFE_IS_ZERO(Pike_sp-1))    {    pop_stack();    return -1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[b->subtype].prog, LFUN_EQ)) != -1) {    push_svalue(a);    apply_low(b->u.object,    fun + p->inherits[b->subtype].identifier_level, 1);    if (!UNSAFE_IS_ZERO(Pike_sp-1)) {    pop_stack();    return 0;    }
pike.git/src/array.c:1039:    b = &tmp_b;    }       else {    a_subtype = a->subtype;    b_subtype = b->subtype;    }       res = lfun_cmp (a, b);    -  if (res == 3) { +  if (res == -CMPFUN_UNORDERED) {    /* If the objects had no inequality comparison lfuns to call, use    * their pointers to get a well defined internal sort order. Let's    * also group objects cloned from the same program. */    if (a->u.object->prog == b->u.object->prog)    return a->u.object < b->u.object ? -1 : 1;    else    return a->u.object->prog < b->u.object->prog ? -1 : 1;    }    -  return res == 2 ? -1 : res; +  return res;   }      int set_svalue_cmpfun(const struct svalue *a, const struct svalue *b)   {    int typediff = a->type - b->type;    if (typediff) {    if (a->type == T_OBJECT || b->type == T_OBJECT) {    int res = lfun_cmp (a, b); -  if (res < 2) return res; +  if (res != -CMPFUN_UNORDERED) return res;    }    return typediff;    }       switch(a->type)    {    case T_FLOAT:    if(a->u.float_number < b->u.float_number) return -1;    if(a->u.float_number > b->u.float_number) return 1;    return 0;
pike.git/src/array.c:1126:    }    /* NOT REACHED */   }      int alpha_svalue_cmpfun(const struct svalue *a, const struct svalue *b)   {    int typediff = a->type - b->type;    if (typediff) {    if (a->type == T_OBJECT || b->type == T_OBJECT) {    int res = lfun_cmp (a, b); -  if (res < 2) return res; +  if (res != -CMPFUN_UNORDERED) return res;    }    return typediff;    }       switch(a->type)    {    case T_INT:    if(a->u.integer < b->u.integer) return -1;    if(a->u.integer > b->u.integer) return 1;    return 0;
pike.git/src/array.c:1235:    if(!v->size) return;    if (v->type_field == BIT_INT) {    low_sort_int_svalues(ITEM(v), ITEM(v)+v->size-1);    } else {    low_sort_svalues(ITEM(v), ITEM(v)+v->size-1);    }   }      #define SORT_BY_INDEX   #define EXTRA_LOCALS int cmpfun_res; - #define CMP(X,Y) ((cmpfun_res = alpha_svalue_cmpfun(svals + X, svals + Y)) ? \ + #define CMP(X,Y) ((cmpfun_res = \ +  (alpha_svalue_cmpfun(svals + X, svals + Y) & \ +  ~CMPFUN_UNORDERED)) ? \    cmpfun_res : pos[X] - pos[Y])   #define SWAP(X,Y) { \    {struct svalue tmp = svals[X]; svals[X] = svals[Y]; svals[Y] = tmp;} \    {int tmp = pos[X]; pos[X] = pos[Y]; pos[Y] = tmp;} \   }   #define TYPE struct svalue   #define ID low_stable_sort_svalues   #define EXTRA_ARGS , struct svalue *svals, INT32 *pos, int size   #define XARGS , svals, pos, size   #include "fsort_template.h"