pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:230:    }      MK_HASHMEM(simple_hashmem, unsigned char)   MK_HASHMEM(simple_hashmem1, p_wchar1)   MK_HASHMEM(simple_hashmem2, p_wchar2)      /*! @decl int hash(string s)    *! @decl int hash(string s, int max)    *!    *! Return an integer derived from the string @[s]. The same string -  *! will always hash to the same value, also between processes. -  *! -  *! If @[max] is given, the result will be >= 0 and < @[max], -  *! otherwise the result will be >= 0 and <= 0x7fffffff. -  *! -  *! @note -  *! This function is provided for backward compatibility reasons. -  *! -  *! This function is byte-order dependant for wide strings. -  *! -  *! @seealso -  *! @[predef::hash()], @[7.0::hash()] -  */ - static void f_hash_7_4(INT32 args) - { -  size_t i = 0; -  struct pike_string *s = Pike_sp[-args].u.string; -  -  if(!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("7.4::hash",1); -  -  if(TYPEOF(Pike_sp[-args]) != T_STRING) -  SIMPLE_BAD_ARG_ERROR("7.4::hash", 1, "string"); -  -  i = simple_hashmem((unsigned char *)s->str, s->len<<s->size_shift, -  100<<s->size_shift); -  -  if(args > 1) -  { -  if(TYPEOF(Pike_sp[1-args]) != T_INT) -  SIMPLE_BAD_ARG_ERROR("7.4::hash",2,"int"); -  -  if(!Pike_sp[1-args].u.integer) -  PIKE_ERROR("7.4::hash", "Modulo by zero.\n", Pike_sp, args); -  -  i%=(unsigned INT32)Pike_sp[1-args].u.integer; -  } -  pop_n_elems(args); -  push_int64(i); - } -  - /*! @endnamespace -  */ -  - ATTRIBUTE((const)) static INLINE size_t hashstr(const unsigned char *str, ptrdiff_t maxn) - { -  size_t ret,c; -  -  if(!(ret=str++[0])) -  return ret; -  for(; maxn>=0; maxn--) -  { -  c=str++[0]; -  if(!c) break; -  ret ^= ( ret << 4 ) + c ; -  ret &= 0x7fffffff; -  } -  -  return ret; - } -  - /*! @decl int hash_7_0(string s) -  *! @decl int hash_7_0(string s, int max) -  *! -  *! Return an integer derived from the string @[s]. The same string -  *! always hashes to the same value, also between processes. -  *! -  *! If @[max] is given, the result will be >= 0 and < @[max], -  *! otherwise the result will be >= 0 and <= 0x7fffffff. -  *! -  *! @note -  *! This function is provided for backward compatibility with -  *! code written for Pike up and including version 7.0. -  *! -  *! This function is not NUL-safe, and is byte-order dependant. -  *! -  *! @seealso -  *! @[hash()], @[7.4::hash()] -  */ - static void f_hash_7_0( INT32 args ) - { -  struct pike_string *s = Pike_sp[-args].u.string; -  unsigned int i; -  if(!args) -  SIMPLE_TOO_FEW_ARGS_ERROR("7.0::hash",1); -  if(TYPEOF(Pike_sp[-args]) != T_STRING) -  SIMPLE_BAD_ARG_ERROR("7.0::hash", 1, "string"); -  -  if( s->size_shift ) -  { -  f_hash_7_4( args ); -  return; -  } -  -  i = DO_NOT_WARN((unsigned int)hashstr( (unsigned char *)s->str, -  MINIMUM(100,s->len))); -  if(args > 1) -  { -  if(TYPEOF(Pike_sp[1-args]) != T_INT) -  SIMPLE_BAD_ARG_ERROR("7.0::hash",2,"int"); -  -  if(!Pike_sp[1-args].u.integer) -  PIKE_ERROR("7.0::hash", "Modulo by zero.\n", Pike_sp, args); -  -  i%=(unsigned INT32)Pike_sp[1-args].u.integer; -  } -  pop_n_elems(args); -  push_int( i ); - } -  - /*! @decl int hash(string s) -  *! @decl int hash(string s, int max) -  *! -  *! Return an integer derived from the string @[s]. The same string +     *! always hashes to the same value, also between processes,    *! architectures, and Pike versions (see compatibility notes below,    *! though).    *!    *! If @[max] is given, the result will be >= 0 and < @[max],    *! otherwise the result will be >= 0 and <= 0x7fffffff.    *!    *! @note -  *! The hash algorithm was changed in Pike 7.5. If you want a hash -  *! that is compatible with Pike 7.4 and earlier, use @[7.4::hash()]. -  *! The difference only affects wide strings. -  *! -  *! The hash algorithm was also changed in Pike 7.1. If you want a hash -  *! that is compatible with Pike 7.0 and earlier, use @[7.0::hash()]. -  *! -  *! @note +     *! This hash function differs from the one provided by @[hash_value()],    *! in that @[hash_value()] returns a process specific value.    *!    *! @seealso -  *! @[hash_7_0()], @[7.4::hash()], @[hash_value] +  *! @[hash_value]    */   PMOD_EXPORT void f_hash(INT32 args)   {    size_t i = 0;    struct pike_string *s;       if(!args)    SIMPLE_TOO_FEW_ARGS_ERROR("hash",1);       if(TYPEOF(Pike_sp[-args]) != T_STRING)
pike.git/src/builtin_functions.c:1810:   #endif    }    pop_n_elems(args);    push_string(out);   }      /*! @decl string unicode_to_string(string(0..255) s)    *!    *! Converts an UTF16 byte-stream into a string.    *! -  *! @note -  *! This function did not decode surrogates in Pike 7.2 and earlier. -  *! +     *! @seealso    *! @[Charset.decoder()], @[string_to_unicode()], @[string_to_utf8()],    *! @[utf8_to_string()]    */   PMOD_EXPORT void f_unicode_to_string(INT32 args)   {    struct pike_string *in;    struct pike_string *out = NULL;    ptrdiff_t len, i, num_surrogates = 0;    int swab=0;
pike.git/src/builtin_functions.c:5464: Inside #if defined(PIKE_DEBUG)
  /*! @decl void dump_program_tables(program p, int(0..)|void indent)    *! @belongs Debug    *!    *! Dumps the internal tables for the program @[p] on stderr.    *!    *! @param p    *! Program to dump.    *!    *! @param indent    *! Number of spaces to indent the output. -  *! -  *! @note -  *! In Pike 7.8.308 and earlier @[indent] wasn't supported. +     */   void f__dump_program_tables(INT32 args)   {    struct program *p;    INT_TYPE indent = 0;       ASSERT_SECURITY_ROOT("_dump_program_tables"); /* FIXME: Might want lower. */    get_all_args("_dump_program_tables", args, "%p.%+", &p, &indent);       dump_program_tables(p, indent);
pike.git/src/builtin_functions.c:9722:    ADD_EFUN("callablep", f_callablep,tFunc(tMix,tInt01),OPT_TRY_OPTIMIZE);      /* function(string,string:int(0..1))|function(string,string*:array(string)) */    ADD_EFUN("glob",f_glob,    tOr(tFunc(tOr(tStr,tArr(tStr)) tStr,tInt01),tFunc(tOr(tStr,tArr(tStr)) tSetvar(1,tArr(tStr)),tVar(1))),    OPT_TRY_OPTIMIZE);      /* function(string,int|void:int) */    ADD_EFUN("hash",f_hash,tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE);    -  ADD_EFUN("hash_7_0",f_hash_7_0, -  tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE); -  -  ADD_EFUN("hash_7_4",f_hash_7_4, -  tFunc(tStr tOr(tInt,tVoid),tInt),OPT_TRY_OPTIMIZE); -  +     ADD_EFUN("hash_value",f_hash_value,tFunc(tMix,tInt),OPT_TRY_OPTIMIZE);       ADD_EFUN2("indices",f_indices,    tOr3(tFunc(tArray,tArr(tIntPos)),    tFunc(tOr3(tMap(tSetvar(1,tMix),tMix),    tSet(tSetvar(1,tMix)),    tNStr(tSetvar(1,tInt))),    tArr(tVar(1))),    tFunc(tOr(tObj,tPrg(tObj)),tArr(tStr))),    OPT_TRY_OPTIMIZE,fix_indices_type,0);