Ejemplo n.º 1
0
int is_bignum_object(struct object *o)
{
  /* Note:
   * This function should *NOT* try to resolv Gmp.mpz unless
   * it is already loaded into memory.
   * /Hubbe
   */

  if (auto_bignum_program.type == T_INT)
    return 0; /* not possible */
 
  return o->prog == program_from_svalue(&auto_bignum_program);
}
Ejemplo n.º 2
0
struct source *source_system_memory_make( struct svalue *s,
					  INT64 start, INT64 len )
{
  struct sm_source *res;

  if( TYPEOF(*s) != PIKE_T_OBJECT )
    return 0;

  if (!shm_program) {
    push_static_text("System.Memory");
    SAFE_APPLY_MASTER("resolv", 1);
    shm_program = program_from_svalue(Pike_sp - 1);
    if (!shm_program) {
      pop_stack();
      return 0;
    }
    add_ref(shm_program);
    pop_stack();
  }

  res = calloc( 1, sizeof( struct sm_source ) );
  if( !res ) return NULL;

  if( !(res->mem = get_storage( s->u.object, shm_program ) ) )
  {
    free(res);
    return 0;
  }

  if( !res->mem->data || !res->mem->len )
  {
    free(res);
    return 0;
  }

  res->s.free_source = free_source;
  res->s.get_data = get_data;
  res->obj = s->u.object;
  add_ref(res->obj);
  res->offset = start;

  if( len != -1 )
    if( len > (ptrdiff_t) res->mem->len - start )
    {
      sub_ref(res->obj);
      free(res);
      return 0;
    }
    else
      res->len = len;
  else
    res->len = len;

  if( res->len <= 0 )
  {
    sub_ref(res->obj);
    free(res);
    return 0;
  }
  return (struct source *)res;
}
Ejemplo n.º 3
0
static void f_accept_with_http_parse(INT32 nargs)
{
    /* From socket.c */
    struct port
    {
        struct fd_callback_box box;
        int my_errno;
        struct svalue accept_callback;
        struct svalue id;
    };
    INT_TYPE ms, dolog;
    INT_TYPE to;
    struct object *port;
    struct svalue *fun, *cb, *program;
    struct cache *c;
    struct args *args = LTHIS;
    get_all_args("accept_http_loop", nargs, "%o%*%*%*%i%i%i", &port, &program,
                 &fun, &cb, &ms, &dolog, &to);
    MEMSET(args, 0, sizeof(struct args));
    if(dolog)
    {
        struct log *log = aap_malloc(sizeof(struct log));
        MEMSET(log, 0, sizeof(struct log));
        mt_init(&log->log_lock);
        args->log = log;
        log->next = aap_first_log;
        aap_first_log = log;
    }
    c = aap_malloc(sizeof(struct cache));
    MEMSET(c, 0, sizeof(struct cache));
    mt_init(&c->mutex);
    c->next = first_cache;
    first_cache = c;
    args->cache = c;
    c->max_size = ms;
    {
        extern struct program *port_program;
        args->fd = ((struct port *)get_storage( port, port_program))->box.fd;
    }
    args->filesystem = NULL;
#ifdef HAVE_TIMEOUTS
    args->timeout = to;
#endif
    assign_svalue_no_free(&args->cb, fun);   /* FIXME: cb isn't freed on exit */
    assign_svalue_no_free(&args->args, cb);

    request_program = program_from_svalue( program );
    if(!request_program)
    {
        free_args(args);
        Pike_error("Invalid request program\n");
    }
    if(!my_callback)
        my_callback = add_backend_callback( finished_p, 0, 0 );

    {
        int i;
        for( i = 0; i<8; i++ )
            th_farm((void (*)(void *))low_accept_loop, (void *)args);
    }
}