Beispiel #1
0
static gboolean
update_brush_setting_from_json_object(MyPaintBrush *self,
                                      char *setting_name,
                                      json_object *setting_obj)
{
    MyPaintBrushSetting setting_id = mypaint_brush_setting_from_cname(setting_name);

    if (!(setting_id >= 0 && setting_id < MYPAINT_BRUSH_SETTINGS_COUNT)) {
        fprintf(stderr, "Warning: Unknown setting_id: %d for setting: %s\n",
                setting_id, setting_name);
        return FALSE;
    }

    if (!json_object_is_type(setting_obj, json_type_object)) {
        fprintf(stderr, "Warning: Wrong type for setting: %s\n", setting_name);
        return FALSE;
    }

    // Base value
    json_object *base_value_obj = NULL;
    if (! obj_get(setting_obj, "base_value", &base_value_obj)) {
        fprintf(stderr, "Warning: No 'base_value' field for setting: %s\n", setting_name);
        return FALSE;
    }
    const double base_value = json_object_get_double(base_value_obj);
    mypaint_brush_set_base_value(self, setting_id, base_value);

    // Inputs
    json_object *inputs = NULL;
    if (! obj_get(setting_obj, "inputs", &inputs)) {
        fprintf(stderr, "Warning: No 'inputs' field for setting: %s\n", setting_name);
        return FALSE;
    }
    json_object_object_foreach(inputs, input_name, input_obj) {
        MyPaintBrushInput input_id = mypaint_brush_input_from_cname(input_name);

        if (!json_object_is_type(input_obj, json_type_array)) {
            fprintf(stderr, "Warning: Wrong inputs type for setting: %s\n", setting_name);
            return FALSE;
        }

        const int number_of_mapping_points = json_object_array_length(input_obj);

        mypaint_brush_set_mapping_n(self, setting_id, input_id, number_of_mapping_points);

        for (int i=0; i<number_of_mapping_points; i++) {
            json_object *mapping_point = json_object_array_get_idx(input_obj, i);

            json_object *x_obj = json_object_array_get_idx(mapping_point, 0);
            const float x = json_object_get_double(x_obj);
            json_object *y_obj = json_object_array_get_idx(mapping_point, 1);
            const float y = json_object_get_double(y_obj);

            mypaint_brush_set_mapping_point(self, setting_id, input_id, i, x, y);
        }
    }
Beispiel #2
0
// call->master_lock held in W
struct media_player *media_player_new(struct call_monologue *ml) {
#ifdef WITH_TRANSCODING
	ilog(LOG_DEBUG, "creating media_player");

	uint32_t ssrc = 0;
	while (ssrc == 0)
		ssrc = random();
	struct ssrc_ctx *ssrc_ctx = get_ssrc_ctx(ssrc, ml->call->ssrc_hash, SSRC_DIR_OUTPUT);

	struct media_player *mp = obj_alloc0("media_player", sizeof(*mp), __media_player_free);

	mp->tt_obj.tt = &media_player_thread;
	mutex_init(&mp->lock);
	mp->call = obj_get(ml->call);
	mp->ml = ml;
	mp->seq = random();
	mp->ssrc_out = ssrc_ctx;

	av_init_packet(&mp->pkt);
	mp->pkt.data = NULL;
	mp->pkt.size = 0;

	return mp;
#else
	return NULL;
#endif
}
Beispiel #3
0
INLINE void call_bencode_hold_ref(struct call *c, bencode_item_t *bi) {
	/* We cannot guarantee that the "call" structures are still around at the time
	 * when the bencode reply is finally read and sent out. Since we use scatter/gather
	 * to avoid duplication of strings and stuff, we reserve a reference to the call
	 * structs and have it released when the bencode buffer is destroyed. This is
	 * necessary every time the bencode response may reference strings contained
	 * within the call structs. */
	bencode_buffer_destroy_add(bi->buffer, call_release_ref, obj_get(c));
}
Beispiel #4
0
struct dtls_cert *dtls_cert() {
	struct dtls_cert *ret;

	rwlock_lock_r(&__dtls_cert_lock);
	ret = obj_get(__dtls_cert);
	rwlock_unlock_r(&__dtls_cert_lock);

	return ret;
}
Beispiel #5
0
/* unlocks on return */
static int __poller_add_item(struct poller *p, struct poller_item *i, int has_lock) {
	struct poller_item_int *ip;
	unsigned int u;
	struct epoll_event e;

	if (!p || !i)
		goto fail_lock;
	if (i->fd < 0)
		goto fail_lock;
	if (!i->readable && !i->writeable)
		goto fail_lock;
	if (!i->closed)
		goto fail_lock;

	if (!has_lock)
		mutex_lock(&p->lock);

	if (i->fd < p->items_size && p->items[i->fd])
		goto fail;

	ZERO(e);
	e.events = epoll_events(i, NULL);
	e.data.fd = i->fd;
	if (epoll_ctl(p->fd, EPOLL_CTL_ADD, i->fd, &e))
		abort();

	if (i->fd >= p->items_size) {
		u = p->items_size;
		p->items_size = i->fd + 1;
		p->items = realloc(p->items, sizeof(*p->items) * p->items_size);
		memset(p->items + u, 0, sizeof(*p->items) * (p->items_size - u - 1));
	}

	ip = obj_alloc0("poller_item_int", sizeof(*ip), poller_item_free);
	memcpy(&ip->item, i, sizeof(*i));
	obj_hold_o(ip->item.obj); /* new ref in *ip */
	p->items[i->fd] = obj_get(ip);

	mutex_unlock(&p->lock);

	if (i->timer)
		poller_add_timer(p, poller_fd_timer, &ip->obj);

	obj_put(ip);

	return 0;

fail:
	mutex_unlock(&p->lock);
	return -1;
fail_lock:
	if (has_lock)
		mutex_unlock(&p->lock);
	return -1;
}
Beispiel #6
0
// call->master_lock held in W
struct send_timer *send_timer_new(struct packet_stream *ps) {
	ilog(LOG_DEBUG, "creating send_timer");

	struct send_timer *st = obj_alloc0("send_timer", sizeof(*st), __send_timer_free);
	st->tt_obj.tt = &send_timer_thread;
	mutex_init(&st->lock);
	st->call = obj_get(ps->call);
	st->sink = ps;
	g_queue_init(&st->packets);

	return st;
}
Beispiel #7
0
static struct ice_agent *__ice_agent_new(struct call_media *media) {
	struct ice_agent *ag;
	struct call *call = media->call;

	ag = obj_alloc0("ice_agent", sizeof(*ag), __ice_agent_free);
	ag->call = obj_get(call);
	ag->media = media;
	mutex_init(&ag->lock);

	__ice_agent_initialize(ag);

	return ag;
}
Beispiel #8
0
static VALUE
obj_current(VALUE klass, const char *name)
{
  VALUE new_inst;
  struct objlist *nobj;
  int id;

  nobj = ngraph_get_object(name);
  id = ngraph_get_object_current_id(nobj);
  if (id < 0) {
    return Qnil;
  }

  new_inst = obj_get(klass, INT2FIX(id), name);

  return new_inst;
}
Beispiel #9
0
static VALUE
inst_get_obj(VALUE self, const char *field)
{
  struct ngraph_instance *inst;
  ngraph_returned_value str;
  ngraph_arg carg;
  const char *name;
  int id, n, *ids;
  struct objlist *obj;
  VALUE klass;

  inst = check_id(self);
  if (inst == NULL) {
    return Qnil;
  }

  carg.num = 0;
  inst->rcode = ngraph_object_get(inst->obj, field, inst->id, &carg, &str);
  if (inst->rcode < 0) {
    return Qnil;
  }

  if (str.str == NULL) {
    return Qnil;
  }

  obj = ngraph_get_object_instances_by_str(str.str, &n, &ids);
  if (obj == NULL) {
    return Qnil;
  }

  id = ids[n - 1];
  ngraph_free(ids);

  name = ngraph_get_object_name(obj);
  if (name == NULL) {
    return Qnil;
  }

  klass = get_ngraph_obj(name);

  return obj_get(klass, INT2FIX(id), name);
}
Beispiel #10
0
static VALUE
str2inst_get_ary(VALUE data1)
{
  const char *name;
  int i, n;
  VALUE ary, obj, klass;
  struct obj_ids *obj_ids;

  obj_ids = (struct obj_ids *) data1;

  name = ngraph_get_object_name(obj_ids->obj);
  klass = get_ngraph_obj(name);
  ary = rb_ary_new2(obj_ids->num);
  n = obj_ids->num;
  for (i = 0; i < n; i++) {
    obj = obj_get(klass, INT2FIX(obj_ids->ids[i]), name);
    rb_ary_push(ary, obj);
  }

  return ary;
}
Beispiel #11
0
static VALUE
obj_new(VALUE klass, const char *name)
{
  VALUE new_inst;
  struct objlist *nobj;
  int r;

  nobj = ngraph_get_object(name);
  r = ngraph_object_new(nobj);
  if (r < 0) {
    return Qnil;
  }

  new_inst = obj_get(klass, INT2FIX(r), name);

  if (RTEST(rb_block_given_p())) {
    new_inst = rb_ensure(obj_new_with_block_body, new_inst, obj_new_with_block_ensure, new_inst);
  }

  return new_inst;
}
Beispiel #12
0
static VALUE
obj_each(VALUE klass, const char *name)
{
  struct objlist *nobj;
  int i, n;
  VALUE inst, id, ary;

  nobj = ngraph_get_object(name);
  n = ngraph_get_object_last_id(nobj) + 1;
  if (n < 1) {
    return klass;
  }

  name = ngraph_get_object_name(nobj);
  ary = rb_ary_new2(n);
  for (i = 0; i < n; i++) {
    id = INT2FIX(i);
    inst = obj_get(klass, id, name);
    rb_ary_store(ary, i, inst);
  }
  rb_ary_each(ary);

  return klass;
}
Beispiel #13
0
size_t getNumLevels () {
  ASSERT(levelSerie != NULL);
  json_t* levels = obj_get(levelSerie, "levels");
  return json_array_size(levels);
}
Beispiel #14
0
n_object * obj_number(n_object * obj, n_string name, n_int number)
{
    return ar_number(obj_get(obj, name), number);
}
Beispiel #15
0
void rpc_service_handle(rpc_service_t *service, zmq_msg_t *request) {
  /* Parse the msgpack */
  zmq_msg_t response;
  int rc;
  msgpack_unpacked request_msg;
  msgpack_unpacked_init(&request_msg);
  rc = msgpack_unpack_next(&request_msg, zmq_msg_data(request),
                           zmq_msg_size(request), NULL);
  insist_return(rc, (void)(0), "Failed to unpack message '%.*s'",
                (int)zmq_msg_size(request), (char *)zmq_msg_data(request));

  msgpack_object request_obj = request_msg.data;

  /* Find the method name */
  char *method = NULL;
  size_t method_len = -1;
  rc = obj_get(&request_obj, "method", MSGPACK_OBJECT_RAW, &method, &method_len);

  msgpack_sbuffer *response_buffer = msgpack_sbuffer_new();
  msgpack_sbuffer *result_buffer = msgpack_sbuffer_new();
  msgpack_sbuffer *error_buffer = msgpack_sbuffer_new();

  msgpack_packer *response_msg = msgpack_packer_new(response_buffer, msgpack_sbuffer_write);
  msgpack_packer *result = msgpack_packer_new(result_buffer, msgpack_sbuffer_write);
  msgpack_packer *error = msgpack_packer_new(error_buffer, msgpack_sbuffer_write);

  //printf("Method: %.*s\n", method_len, method);

  void *clock = zmq_stopwatch_start();
  double duration;

  if (rc != 0) { /* method not found */
    msgpack_pack_nil(result); /* result is nil on error */
    msgpack_pack_map(error, 2);
    msgpack_pack_string(error, "error", -1);
    msgpack_pack_string(error, "Message had no 'method' field", -1);
    msgpack_pack_string(error, "request", -1);
    msgpack_pack_object(error, request_obj);
  } else { /* valid method, keep going */
    //printf("The method is: '%.*s'\n", (int)method_len, method);
    rpc_name name;
    name.name = method;
    name.len = method_len;

    rpc_method *rpcmethod = g_tree_lookup(service->methods, &name);

    /* if we found a valid rpc method and the args check passed ... */
    if (rpcmethod != NULL) {
      /* the callback is responsible for filling in the 'result' and 'error' 
       * objects. */
      rpcmethod->callback(NULL, &request_obj, result, error, rpcmethod->data);
    } else {
      msgpack_pack_nil(result); /* result is nil on error */

      /* TODO(sissel): allow methods to register themselves */
      //fprintf(stderr, "Invalid request '%.*s' (unknown method): ",
              //method_len, method);
      //msgpack_object_print(stderr, request_obj);
      //fprintf(stderr, "\n");

      msgpack_pack_map(error, 2);
      msgpack_pack_string(error, "error", -1);
      msgpack_pack_string(error, "No such method requested", -1);
      msgpack_pack_string(error, "request", -1);
      msgpack_pack_object(error, request_obj);
    }
  } /* valid/invalid method handling */

  duration = zmq_stopwatch_stop(clock) / 1000000.;
  //printf("method '%.*s' took %lf seconds\n", (int)method_len, method);

  msgpack_unpacked result_unpacked;
  msgpack_unpacked error_unpacked;
  msgpack_unpacked response_unpacked;
  msgpack_unpacked_init(&result_unpacked);
  msgpack_unpacked_init(&error_unpacked);
  msgpack_unpacked_init(&response_unpacked);

  /* TODO(sissel): If this unpack test fails, we should return an error to the calling
   * client indicating that some internal error has occurred */
  //fprintf(stderr, "Result payload: '%.*s'\n", result_buffer->size,
  //result_buffer->data);
  rc = msgpack_unpack_next(&result_unpacked, result_buffer->data,
                           result_buffer->size, NULL);
  insist(rc == true, "msgpack_unpack_next failed on 'result' buffer"
         " of request '%.*s'", (int)method_len, method);
  rc = msgpack_unpack_next(&error_unpacked, error_buffer->data,
                           error_buffer->size, NULL);
  insist(rc == true, "msgpack_unpack_next failed on 'error' buffer"
         " of request '%.*s'", (int)method_len, method);

  msgpack_pack_map(response_msg, 3); /* result, error, duration */
  msgpack_pack_string(response_msg, "result", 6);
  msgpack_pack_object(response_msg, result_unpacked.data);
  msgpack_pack_string(response_msg, "error", 5);
  msgpack_pack_object(response_msg, error_unpacked.data);
  msgpack_pack_string(response_msg, "duration", 8);
  msgpack_pack_double(response_msg, duration);

  rc = msgpack_unpack_next(&response_unpacked, response_buffer->data,
                           response_buffer->size, NULL);
  insist(rc == true, "msgpack_unpack_next failed on full response buffer"
         " of request '%.*s'", (int)method_len, method);

  //printf("request: ");
  //msgpack_object_print(stdout, request_obj);
  //printf("\n");
  //printf("response: ");
  //msgpack_object_print(stdout, response_unpacked.data);
  //printf("\n");

  zmq_msg_init_data(&response, response_buffer->data, response_buffer->size,
                    free_msgpack_buffer, response_buffer);
  zmq_send(service->socket, &response, 0);
  zmq_msg_close(&response);

  msgpack_packer_free(error);
  msgpack_packer_free(result);
  msgpack_sbuffer_free(error_buffer);
  msgpack_sbuffer_free(result_buffer);
  msgpack_packer_free(response_msg);
  msgpack_unpacked_destroy(&request_msg);
} /* rpc_service_handle */
Beispiel #16
0
n_object * obj_string(n_object * obj, n_string name, n_string string)
{
    return ar_string(obj_get(obj, name), string);
}
Beispiel #17
0
void rpc_handle(rpc_io *rpcio, zmq_msg_t *request) {
  /* Parse the msgpack */
  zmq_msg_t response;
  int rc;
  msgpack_unpacked request_msg;
  msgpack_unpacked_init(&request_msg);
  rc = msgpack_unpack_next(&request_msg, zmq_msg_data(request),
                           zmq_msg_size(request), NULL);
  insist_return(rc, (void)(0), "Failed to unpack message '%.*s'",
                zmq_msg_size(request), zmq_msg_data(request));

  msgpack_object request_obj = request_msg.data;
  printf("Object: ");
  msgpack_object_print(stdout, request_obj);  /*=> ["Hello", "MessagePack"] */
  printf("\n");

  /* Find the method name */
  char *method = NULL;
  size_t method_len = -1;
  rc = obj_get(&request_obj, "request", MSGPACK_OBJECT_RAW, &method, &method_len);
  msgpack_sbuffer *buffer = msgpack_sbuffer_new();
  msgpack_packer *response_msg = msgpack_packer_new(buffer, msgpack_sbuffer_write);

  printf("Method: %.*s\n", method_len, method);

  if (rc != 0) {
    fprintf(stderr, "Message had no 'request' field. Ignoring: ");
    msgpack_object_print(stderr, request_obj);
    msgpack_pack_map(response_msg, 2);
    msgpack_pack_string(response_msg, "error", -1);
    msgpack_pack_string(response_msg, "Message had no 'request' field", -1);
    msgpack_pack_string(response_msg, "request", -1);
    msgpack_pack_object(response_msg, request_obj);
  } else {
    /* Found request */
    printf("The method is: '%.*s'\n", (int)method_len, method);

    //msgpack_pack_map(response_msg, 2);
    //msgpack_pack_string(response_msg, "results", 7);

    void *clock = zmq_stopwatch_start();
    /* TODO(sissel): Use gperf here or allow methods to register themselves */
    if (!strncmp("dance", method, method_len)) {
      api_request_dance(rpcio, &request_obj, response_msg);
    } else if (!strncmp("restart", method, method_len)) {
      api_request_restart(rpcio, &request_obj, response_msg);
    } else if (!strncmp("status", method, method_len)) {
      api_request_status(rpcio, &request_obj, response_msg);
    } else if (!strncmp("create", method, method_len)) {
      api_request_create(rpcio, &request_obj, response_msg);
    } else {
      fprintf(stderr, "Invalid request '%.*s' (unknown method): ", method_len, method);
      msgpack_object_print(stderr, request_obj);
      msgpack_pack_map(response_msg, 2);
      msgpack_pack_string(response_msg, "error", -1);
      msgpack_pack_string(response_msg, "No such method requested", -1);
      msgpack_pack_string(response_msg, "request", -1);
      msgpack_pack_object(response_msg, request_obj);
    }
    double duration = zmq_stopwatch_stop(clock) / 1000000.;

    printf("method '%.*s' took %lf seconds\n", (int)method_len, method);

    //msgpack_pack_string(response_msg, "stats", 5);
    //msgpack_pack_map(response_msg, 1),
    //msgpack_pack_string(response_msg, "duration", 8);
    //msgpack_pack_double(response_msg, duration);
  }

  zmq_msg_init_data(&response, buffer->data, buffer->size, free_msgpack_buffer, buffer); 
  zmq_send(rpcio->socket, &response, 0);
  zmq_msg_close(&response);

  //msgpack_sbuffer_free(buffer);
  msgpack_packer_free(response_msg);
  msgpack_unpacked_destroy(&request_msg);
} /* rpc_handle */
Beispiel #18
0
n_object * obj_object(n_object * obj, n_string name, n_object * object)
{
    return ar_object(obj_get(obj, name), object);
}
Beispiel #19
0
n_object * obj_array(n_object * obj, n_string name, n_array * array)
{
    return ar_array(obj_get(obj, name), array);
}
Beispiel #20
0
//Loads a level from the APK (an original level)
//Return NULL if an error occurs during loading
Level* loadAPKLevel (int levelNum) {
  ASSERT(levelSerie != NULL && levelNum < (int)getNumLevels());
  json_t* levels = obj_get(levelSerie, "levels");
  return levelFromJSON(json_array_get(levels, levelNum));
}
Beispiel #21
0
void api_request_status(rpc_io *rpcio, msgpack_object *request_obj,
                        msgpack_packer *response_msg) {
  int rc;
  char *program_name = NULL;
  size_t program_len = 0;
  rc = obj_get(request_obj, "program", MSGPACK_OBJECT_RAW, &program_name, &program_len);
  /* A missing 'program' field is OK. It means we want all programs */

  msgpack_pack_map(response_msg, 1);
  msgpack_pack_string(response_msg, "programs", -1);

  /* programs is a map of:
   *   programname => {
   *     command: "string",
   *     args: "string",
   *     uid: uid,
   *     gid: gid,
   *     nice: nice,
   *     ionice: ionice,
   *     is_running: boolean
   *     instances: {
   *       pid: ...
   *       state: ...
   *       admin_state: ...
   *       start: ...
   *       duration: ...
   *     }
   *   }
   */
  msgpack_pack_map(response_msg, rpcio->procnanny->programs_len);

  pn_prog_each(rpcio->procnanny, i, program, {
    if (program_name != NULL && strncmp(program->name, program_name, program_len)) {
      continue;
    }

    msgpack_pack_string(response_msg, program->name, program->name_len);
    msgpack_pack_map(response_msg, 8);  /* 8 fields */

    msgpack_pack_string(response_msg, "command", -1);
    msgpack_pack_string(response_msg, program->command, program->command_len);

    msgpack_pack_string(response_msg, "args", -1);
    msgpack_pack_array(response_msg, program->args_len);
    int argind = 0;
    for (argind = 0; argind < program->args_len; argind++) {
      msgpack_pack_string(response_msg, program->args[argind], -1);
    }

    msgpack_pack_string(response_msg, "uid", -1);
    msgpack_pack_uint32(response_msg, program->uid);

    msgpack_pack_string(response_msg, "gid", -1);
    msgpack_pack_uint32(response_msg, program->gid);

    msgpack_pack_string(response_msg, "nice", -1);
    msgpack_pack_int32(response_msg, program->nice);

    msgpack_pack_string(response_msg, "ionice", -1);
    msgpack_pack_int32(response_msg, program->ionice);

    msgpack_pack_string(response_msg, "active", -1);
    msgpack_pack_true(response_msg);

    msgpack_pack_string(response_msg, "instances", -1);
    msgpack_pack_map(response_msg, program->nprocs);

    pn_prog_proc_each(program, instance, process, {
      msgpack_pack_uint32(response_msg, instance);
      msgpack_pack_map(response_msg, 5);

      msgpack_pack_string(response_msg, "pid", -1);
      msgpack_pack_uint32(response_msg, process->pid);

      msgpack_pack_string(response_msg, "state", -1);
      switch (process->state) {
        case PROCESS_STATE_STARTING:
          msgpack_pack_string(response_msg, "starting", -1); break;
        case PROCESS_STATE_RUNNING:
          msgpack_pack_string(response_msg, "running", -1); break;
        case PROCESS_STATE_STOPPING:
          msgpack_pack_string(response_msg, "stopping", -1); break;
        case PROCESS_STATE_EXITED:
          msgpack_pack_string(response_msg, "exited", -1); break;
        case PROCESS_STATE_BACKOFF:
          msgpack_pack_string(response_msg, "backoff", -1); break;
        case PROCESS_STATE_NEW:
          msgpack_pack_string(response_msg, "new", -1); break;
        default:
          msgpack_pack_string(response_msg, "unknown", -1); break;
      }

      msgpack_pack_string(response_msg, "exitcode", -1);
      msgpack_pack_uint8(response_msg, process->exit_status);

      msgpack_pack_string(response_msg, "exitsignal", -1);
      msgpack_pack_uint8(response_msg, process->exit_signal);

      msgpack_pack_string(response_msg, "admin_state", -1);
      switch (process->admin_state) {
        case ADMIN_STATE_DOWN:
          msgpack_pack_string(response_msg, "down", -1); break;
        case ADMIN_STATE_UP:
          msgpack_pack_string(response_msg, "up", -1); break;
        default:
          msgpack_pack_string(response_msg, "unknown", -1); break;
      }
    })
  });
Beispiel #22
0
int
db_object_fetch (DB_OBJECT * obj_mop, int num_attrs, const char **attrs, DB_QUERY_RESULT ** result)
{
  MOP class_mop;
  DB_QUERY_RESULT *r;
  DB_QUERY_TYPE *t;
  int k, bytes;
  const char **name;
  int err = NO_ERROR;
  DB_VALUE **v;
  bool r_inited = false;

  CHECK_CONNECT_ERROR ();

  if (!result)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OBJ_INVALID_ARGUMENTS, 0);
      return -1;
    }

  *result = NULL;
  if ((class_mop = sm_get_class (obj_mop)) == NULL)
    goto err_end;

  r = *result = db_alloc_query_result (T_OBJFETCH, num_attrs);
  if (r == NULL)
    goto err_end;
  r_inited = true;

  db_init_query_result (r, T_OBJFETCH);
  r->type = T_OBJFETCH;
  r->col_cnt = num_attrs;
  r->oid_included = false;

  /* allocate and initialize type list */
  r->type_cnt = num_attrs;
  r->query_type = db_alloc_query_format (num_attrs);
  if (!r->query_type)
    {
      goto err_end;
    }

  r->res.o.crs_pos = C_BEFORE;
  for (k = 0, t = r->query_type, name = attrs, v = r->res.o.valptr_list;
       k < num_attrs && t && name && v && err == NO_ERROR; k++, t = t->next, name++, v++)
    {
      t->db_type = sm_att_type_id (class_mop, *name);
      t->size = pt_find_size_from_dbtype (t->db_type);
      t->name = (char *) malloc (bytes = 1 + strlen (*name));
      if (t->name)
	strcpy ((char *) t->name, *name);
      else
	goto err_end;

      *v = pr_make_ext_value ();
      if (*v == NULL)
	goto err_end;

      err = obj_get (obj_mop, *name, *v);
    }

  if (err != NO_ERROR)
    goto err_end;

  err = 0;
  goto end;

err_end:
  if (r_inited)
    {
      db_free_query_result (r);
    }
  *result = NULL;
  err = -1;

end:
  return err;
}