pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.555 2004/05/14 13:54:02 nilsson Exp $ + || $Id: builtin_functions.c,v 1.556 2004/05/14 18:18:42 nilsson Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.555 2004/05/14 13:54:02 nilsson Exp $"); + RCSID("$Id: builtin_functions.c,v 1.556 2004/05/14 18:18:42 nilsson Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:5545:   static struct array *diff_dyn_longest_sequence(struct array *cmptbl, int blen)   {    struct array *res = NULL;    struct diff_magic_link_head *table;    struct diff_magic_link_pool *dml_pool = NULL;    struct diff_magic_link *dml;    unsigned int sz = (unsigned int)cmptbl->size;    unsigned int i;    unsigned int off1 = 0;    unsigned int off2 = blen + 1; +  ONERROR err;       table = calloc(sizeof(struct diff_magic_link_head)*2, off2);    if (!table) {    int args = 0;    SIMPLE_OUT_OF_MEMORY_ERROR("diff_dyn_longest_sequence",    sizeof(struct diff_magic_link_head) * 2 * off2);    }       /* FIXME: Assumes NULL is represented with all zeroes */    /* NOTE: Scan strings backwards to get the same result as the G-M
pike.git/src/builtin_functions.c:5661:    }       /* Convert table into res */    sz = table[off1].depth;    dml = table[off1].link;    free(table);   #ifdef DIFF_DEBUG    fprintf(stderr, "Result array size:%d\n", sz);   #endif /* DIFF_DEBUG */    +  if(dml_pool) SET_ONERROR(err, dml_free_pools, dml_pool);    res = allocate_array(sz); -  if (!res) { -  /* FIXME: This is never called, so there should probably be -  * SET_ONERROR stuff somewhere. I can't find where dml_pool is -  * initialized, though. /mast */ -  int args = 0; -  if (dml_pool) { -  dml_free_pools(dml_pool); -  } -  SIMPLE_OUT_OF_MEMORY_ERROR("diff_dyn_longest_sequence", -  sizeof(struct array) + -  sz*sizeof(struct svalue)); -  } +  if(dml_pool) UNSET_ONERROR(err);       i = 0;    while(dml) {   #ifdef PIKE_DEBUG    if (i >= sz) {    Pike_fatal("Consistency error in diff_dyn_longest_sequence()\n");    }   #endif /* PIKE_DEBUG */   #ifdef DIFF_DEBUG    fprintf(stderr, " %02d: %d\n", i, dml->x);
pike.git/src/builtin_functions.c:5832:    *!    *! @seealso    *! @[diff_compare_table()], @[diff_longest_sequence()],    *! @[String.fuzzymatch()]    */   PMOD_EXPORT void f_diff(INT32 args)   {    struct array *seq;    struct array *cmptbl;    struct array *diff; +  struct array *a, *b;    int uniq;    -  /* FIXME: Ought to use get_all_args() */ +  get_all_args("diff", args, "%a%a", &a, &b);    -  if (args<2) -  SIMPLE_TOO_FEW_ARGS_ERROR("diff", 2); +  cmptbl = diff_compare_table(a, b, &uniq);    -  if (Pike_sp[-args].type != T_ARRAY) -  SIMPLE_BAD_ARG_ERROR("diff", 1, "array"); -  if (Pike_sp[1-args].type != T_ARRAY) -  SIMPLE_BAD_ARG_ERROR("diff", 2, "array"); -  -  cmptbl = diff_compare_table(Pike_sp[-args].u.array, Pike_sp[1-args].u.array, &uniq); -  +     push_array(cmptbl);   #ifdef ENABLE_DYN_DIFF -  if (uniq * 100 > Pike_sp[1-args].u.array->size) { +  if (uniq * 100 > cmptbl->size) {   #endif /* ENABLE_DYN_DIFF */   #ifdef DIFF_DEBUG    fprintf(stderr, "diff: Using G-M algorithm, u:%d, s:%d\n", -  uniq, Pike_sp[1-args].u.array->size); +  uniq, cmptbl->size);   #endif /* DIFF_DEBUG */ -  seq = diff_longest_sequence(cmptbl, Pike_sp[1-1-args].u.array->size); +  seq = diff_longest_sequence(cmptbl, b->size);   #ifdef ENABLE_DYN_DIFF    } else {   #ifdef DIFF_DEBUG    fprintf(stderr, "diff: Using dyn algorithm, u:%d, s:%d\n", -  uniq, Pike_sp[1-args].u.array->size); +  uniq, cmptbl->size);   #endif /* DIFF_DEBUG */ -  seq = diff_dyn_longest_sequence(cmptbl, Pike_sp[1-1-args].u.array->size); +  seq = diff_dyn_longest_sequence(cmptbl, b->size);    }   #endif /* ENABLE_DYN_DIFF */    push_array(seq);    -  diff=diff_build(Pike_sp[-2-args].u.array,Pike_sp[1-2-args].u.array,seq); +  diff=diff_build(a,b,seq);       pop_n_elems(2+args);    push_array(diff);   }      /*! @decl array(array(int)) diff_compare_table(array a, array b)    *!    *! Returns an array which maps from index in @[a] to corresponding    *! indices in @[b].    *!