pike.git / src / post_modules / Nettle / hash.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hash.cmod:41:    va_list args;       va_start(args, format);    vfprintf(stderr, format, args);    va_end(args);   }   #else   #define werror(x)   #endif    - static struct program *Fd_ref_program = NULL; - static struct program *Fd_program = NULL; -  +    /*! @module Nettle */      /*! @class HashInfo    *!    *! Represents information about a hash algorithm, such as    *! name, digest size, and internal block size.    */   PIKECLASS HashInfo   {    CVAR const struct nettle_hash *meta;
pike.git/src/post_modules/Nettle/hash.cmod:139:    }       digest_length = meta->digest_size;    out = begin_shared_string(digest_length);    meta->digest(ctx, digest_length, (uint8_t *)out->str);       pop_n_elems(args);    push_string(end_shared_string(out));    }    +  int is_stdio_file(struct object *o) +  { +  struct program *p = o->prog; +  INT32 i = p->num_inherits; +  while( i-- ) +  { +  if( p->inherits[i].prog->id == PROG_STDIO_FD_ID || +  p->inherits[i].prog->id == PROG_STDIO_FD_REF_ID ) +  return 1; +  } +  return 0; +  } +     /*! @decl string(0..255) hash(Stdio.File file, void|int bytes)    *!    *! Works as a (faster) shortcut for    *! @expr{HashState()->update(Stdio.read_file(file))->digest()@},    *! where HashState is the hash state class corresponding to this    *! HashInfo.    *!    *! @param bytes    *! The number of bytes of the file object @[file] that should be    *! hashed. Negative numbers are ignored and the whole file is
pike.git/src/post_modules/Nettle/hash.cmod:168:    void *ctx;    int len, fd;    char *read_buffer;    PIKE_STAT_T st;    struct pike_string *out;    const struct nettle_hash *meta = THIS->meta;       if (!meta)    Pike_error("HashInfo not properly initialized.\n");    -  /* Verify that the input is a Stdio.Fd or Stdio.Fd_ref */ -  if (!Fd_program) -  { -  push_text("files.Fd"); -  SAFE_APPLY_MASTER("resolv",1); -  Fd_program = program_from_svalue(Pike_sp-1); -  if (!Fd_program) { -  pop_stack(); -  Pike_error("Unable to resolv files.Fd.\n"); -  } -  add_ref(Fd_program); -  pop_stack( ); -  } +  if (!is_stdio_file(in)) +  Pike_error("Object not Fd or Fd_ref, or subclass.\n");    -  if (!Fd_ref_program) -  { -  push_text("files.Fd_ref"); -  SAFE_APPLY_MASTER("resolv",1); -  Fd_ref_program = program_from_svalue(Pike_sp-1); -  if (!Fd_ref_program) { -  pop_stack(); -  Pike_error("Unable to resolv files.Fd_ref.\n"); -  } -  add_ref(Fd_ref_program); -  pop_stack( ); -  } -  -  if (!get_storage(in, Fd_program) && !get_storage(in, Fd_ref_program) ) -  Pike_error("Object not Fd or Fd_ref or subclass.\n"); -  -  safe_apply(in, "query_fd", 0); +  apply(in, "query_fd", 0);    fd = Pike_sp[-1].u.integer;    pop_stack();       if (fd_fstat(fd, &st)<0)    Pike_error("File not found!\n");       if (!S_ISREG(st.st_mode))    Pike_error("Non-regular file.\n");       ctx = (void *)alloca(meta->context_size);
pike.git/src/post_modules/Nettle/hash.cmod:635:   hash_init(void)   {    werror("Nettle, hash init\n");    INIT;   }      void   hash_exit(void)   {    werror("Nettle, hash exit\n"); -  if (Fd_program) { -  free_program( Fd_program ); -  } -  if (Fd_ref_program) { -  free_program( Fd_ref_program ); -  } +     EXIT;   }      #endif /* HAVE_LIBNETTLE */