Ejemplo n.º 1
0
//we'll use this to play with closures
void *
add(list *l) {
  int *a = unbox(l);
  int *b = unbox(l->next);
  int *o = malloc(sizeof(int));
  *o = *a + *b;
  return o; 
}
Ejemplo n.º 2
0
void emitUnbox(HTS& env) {
  auto const exit = makeExit(env);
  auto const srcBox = popV(env);
  auto const unboxed = unbox(env, srcBox, exit);
  pushIncRef(env, unboxed);
  gen(env, DecRef, srcBox);
}
Ejemplo n.º 3
0
Archivo: eval.c Proyecto: Melab/gvmt
/** Compiles an integer literal to bytecode */
void compile_int(GVMT_Object o, R_environment env, R_bytes b) {
    intptr_t i = unbox(o);
    if (((int8_t)i) == i) {
        bytes_append(b, op(byte));
        bytes_append(b, i);
    } else if (((int16_t)i) == i) {
        bytes_append(b, op(short));
        bytes_append(b, (i >> 8));
        bytes_append(b, i);
    } else {
Ejemplo n.º 4
0
 void initialize() override {
   CAF_LOG_TRACE("");
   this->init_broker();
   auto bhvr = make_behavior();
   CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
                            << CAF_ARG(this->has_behavior()));
   if (bhvr) {
     // make_behavior() did return a behavior instead of using become()
     CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
     this->do_become(std::move(bhvr.unbox()), true);
   }
 }
 void initialize() override {
   CAF_LOG_TRACE("");
   super::initialize();
   this->setf(abstract_actor::is_initialized_flag);
   auto bhvr = make_behavior();
   CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
                           << CAF_ARG2("alive", this->alive()));
   if (bhvr) {
     // make_behavior() did return a behavior instead of using become()
     CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
     this->do_become(std::move(bhvr.unbox()), true);
   }
 }
Ejemplo n.º 6
0
namespace contr {

enum class Column : int { //
  CheckState, //
  Mnem, //
  Display, //
  Asset, //
  Ccy, //
  LotNumer, //
  LotDenom, //
  TickNumer, //
  TickDenom, //
  PipDp, //
  MinLots, //
  MaxLots
};
constexpr int ColumnCount{unbox(Column::MaxLots) + 1};

} // contr
Ejemplo n.º 7
0
/* INFO: toplevel udt_clr_instance_copy */
int
copy_ref (int gc_in, void* udt)
{
  MonoDomain *domain = virtuoso_domain;
  MonoArray *v_args, *mono_list;
  caddr_t aret;
  int ret;
  get_mono_thread ();

  v_args = MAKE_PARAM_ARRAY (domain, 1);

  SET_INT_ARG (domain, v_args, 0, gc_in);

  mono_list = (MonoArray *) call_mono (VIRTCLR_NAME, "VInvoke:get_copy", v_args, domain);

  aret = sa_to_dk (mono_list, 0, 1, udt);
  ret = unbox(aret);
  dk_free_box (aret);
  return ret;
}
Ejemplo n.º 8
0
/* INFO: toplevel udt_clr_instantiate_class */
int
create_instance (caddr_t *type_vec, int n_args, long _mode, caddr_t asm_name, caddr_t type,
    void * udt)
{
  MonoArray *v_args, *i_array = NULL, *o_array = NULL;
  MonoObject *mono_list;
  int len, ret = 0;
  MonoDomain *domain = virtuoso_domain;

  get_mono_thread ();

  v_args = MAKE_PARAM_ARRAY (domain, 5);

  if (param_to_mono_array (type_vec, n_args, &i_array, &o_array))
    sqlr_new_error ("22023", "MN010", "Can't convert parameters");

  SET_INT_ARG (domain, v_args, 0, _mode);
  SET_STRING_ARG (domain, v_args, 1, asm_name);
  SET_STRING_ARG (domain, v_args, 2, type);

  mono_array_set (v_args, gpointer, 3, i_array);
  mono_array_set (v_args, gpointer, 4, o_array);

  mono_list = call_mono (VIRTCLR_NAME, "VInvoke:create_ins_asm", v_args, domain);
  len = mono_array_length ((MonoArray*)mono_list);
  if (len == 2)
    {
      caddr_t aret = sa_to_dk ((MonoArray *) mono_list, 0, 1, udt);
      ret = unbox (aret);
      dk_free_box (aret);
    }
  else
    GPF_T1 ("create_instance");

  return ret;
}
Ejemplo n.º 9
0
 static fun make(std::true_type, std::false_type, Fun fun) {
   return [fun](local_actor*) -> behavior {
     auto res = fun();
     return std::move(res.unbox());
   };
 }
Ejemplo n.º 10
0
 static fun make(std::true_type, std::true_type, Fun fun) {
   return [fun](local_actor* ptr) -> behavior {
     auto res = fun(static_cast<Base*>(ptr));
     return std::move(res.unbox());
   };
 }
Ejemplo n.º 11
0
int Integer::compareTo(Integer *object)
{
  if(unbox() < object->unbox()) return -1;
  else if(unbox() == object->unbox()) return 0;
  else return 1;
}
Ejemplo n.º 12
0
int Char::compareTo(Char *object)
{
  if(unbox() < object->unbox()) return -1;
  else if(unbox() == object->unbox()) return 0;
  else return 1;
}
Ejemplo n.º 13
0
static int
param_to_mono_array (caddr_t *list_args, int n_args, MonoArray ** p_i_array, MonoArray **p_o_array)
{
  caddr_t * line;
  MonoObject *arg = NULL;
  MonoDomain *domain = virtuoso_domain;
  MonoArray *i_array, *o_array;
  guint32 is_object;
  int inx;

  i_array = (MonoArray*)mono_array_new (domain, mono_get_object_class (), n_args);
  o_array = (MonoArray*)mono_array_new (domain, mono_get_intptr_class (), n_args);
  for (inx = 0; inx < n_args; ++inx)
    {
      line = (caddr_t *) list_args[inx];

      is_object = 0;
      if (DV_TYPE_OF (line[1]) == DV_DB_NULL)
	{
	  arg = NULL;
	  goto put_it;
	}

      if (!strncmp (line[0], "System.String", sizeof ("System.String")) ||
	  !strncmp (line[0], "String", sizeof ("String")))
	{
	  if (!DV_STRINGP (line[1]))
	    goto convert_error;

	  arg = (MonoObject *) mono_string_new (domain, line[1]);
	}
      else if (!strncmp (line[0], "Int32", sizeof ("Int32"))
	  || !strncmp (line[0], "System.Int32", sizeof ("System.Int32"))
	  || !strncmp (line[0], "int", sizeof ("int")))
	{
	  gint32 ivalue;
	  if (DV_TYPE_OF (line[1]) != DV_LONG_INT)
	    goto convert_error;

	  ivalue = unbox (line[1]);
	  arg = mono_value_box (domain, mono_get_int32_class (), &ivalue);
	}
      else if (!strncmp (line[0], "System.Single", sizeof ("System.Single"))
	  || !strncmp (line[0], "Single", sizeof ("Single")))
	{
	  float flt_value;
	  if (DV_TYPE_OF (line[1]) != DV_SINGLE_FLOAT)
	    goto convert_error;

	  flt_value = unbox_float (line[1]);
	  arg = mono_value_box (domain, mono_get_single_class (), &flt_value);
	}
      else if (!strncmp (line[0], "System.Data.SqlTypes.SqlDouble", sizeof ("System.Data.SqlTypes.SqlDouble"))
            || !strncmp (line[0], "System.Double", sizeof ("System.Double"))
            || !strncmp (line[0], "Double", sizeof ("Double")))
	{
	  double dbl_value;
	  if (DV_TYPE_OF (line[1]) != DV_DOUBLE_FLOAT)
	    goto convert_error;
	  dbl_value = unbox_double (line[1]);
	  arg = mono_value_box (domain, mono_get_double_class (), &dbl_value);
	}
      else /*if (!strncmp (line[0], "CLRObject", sizeof ("CLRObject")))	  */
	{
	  gint32 ivalue;
	  if (DV_TYPE_OF (line[1]) != DV_LONG_INT)
	    goto convert_error;
	  is_object = unbox (line[1]);
	  arg = mono_value_box (domain, mono_get_int32_class (), &ivalue);
	}
put_it:
      mono_array_set (i_array, gpointer, inx, arg);
      mono_array_set (o_array, gpointer, inx, (gpointer) is_object);
    }

  *p_i_array = i_array;
  *p_o_array = o_array;
  return 0;
convert_error:
  sqlr_new_error ("22023", "XXXXX", "wrong or unknown type");
  return 0;
}
Ejemplo n.º 14
0
SQLRETURN SQL_API
virtodbc__SQLSetPos (
    SQLHSTMT		hstmt,
    SQLSETPOSIROW	_irow,
    SQLUSMALLINT	fOption,
    SQLUSMALLINT	fLock)
{
    sql_error_rec_t *err_queue = NULL;
    int irow = (int) _irow;
    STMT (stmt, hstmt);
    int n_rows = (int) (irow != 0 ? 1 : (fOption == SQL_ADD ? stmt->stmt_rowset_size : stmt->stmt_rowset_fill));
    /* insert irow==0 is by rowset sz, others are by rowset fill */
    int inx = 0, rc = 0, firstinx = 0, lastinx = 0;
    int co = irow == 0 ? 0 : irow - 1;
    cli_stmt_t *sps = NULL;
    long op = fOption;
    long row_no = irow;
    caddr_t *params = NULL;
    int all_errors = 1;

    stmt->stmt_pending.p_api = SQL_API_SQLSETPOS;
    stmt->stmt_pending.psp_op = fOption;
    stmt->stmt_pending.psp_irow = irow;
    set_error (&stmt->stmt_error, NULL, NULL, NULL);

    if (stmt->stmt_fetch_mode != FETCH_EXT)
    {
        if (!irow && fOption == SQL_POSITION && fLock == SQL_LOCK_NO_CHANGE)
            return SQL_SUCCESS;	/* this is NOP in fact */

        set_error (&stmt->stmt_error, "S1010", "CL007", "SQLSetPos only allowed after SQLExtendedFetch");

        return SQL_ERROR;
    }

    if (co >= stmt->stmt_rowset_fill && op != SQL_ADD)
    {
        set_error (&stmt->stmt_error, "HY092", "CL008", "SQLSetPos irow out of range");

        return SQL_ERROR;
    }

    if (fOption != SQL_REFRESH)
    {
        stmt->stmt_current_of = co;
        stmt_reset_getdata_status (stmt, stmt->stmt_rowset[co]);
        stmt->stmt_current_row = stmt->stmt_rowset[co];
    }

    if (fOption == SQL_POSITION)
        return SQL_SUCCESS;

    if (stmt->stmt_opts->so_cursor_type == SQL_CURSOR_FORWARD_ONLY)
    {
        set_error (&stmt->stmt_error, "HY109", "CL009", "Only SQL_POSITION SQLSetPos option supported for forward cursors");

        return SQL_ERROR;
    }

    if (!stmt->stmt_set_pos_stmt)
    {
        virtodbc__SQLAllocStmt ((SQLHDBC) stmt->stmt_connection, (SQLHSTMT *) & stmt->stmt_set_pos_stmt);
        virtodbc__SQLPrepare ((SQLHSTMT) stmt->stmt_set_pos_stmt, (SQLCHAR *) "__set_pos (?, ?, ?, ?)", SQL_NTS);
    }

    sps = stmt->stmt_set_pos_stmt;

    if (fOption == SQL_POSITION)
    {
        stmt->stmt_current_of = irow;

        return SQL_SUCCESS;
    }

    if (SQL_UPDATE == fOption || SQL_ADD == fOption)
    {
        params = stmt->stmt_param_array;

        if (!params)
        {
            if (0 == irow)
            {
                params = (caddr_t *) dk_alloc_box_zero (n_rows * sizeof (caddr_t), DV_ARRAY_OF_POINTER);
                for (inx = 0; inx < n_rows; inx++)
                {
                    if (NULL == (params[inx] = (caddr_t) set_pos_param_row (stmt, inx)))
                    {
                        dk_free_tree ((box_t) params);
                        return SQL_ERROR;
                    }
                }
            }
            else if (NULL == (params = set_pos_param_row (stmt, irow - 1)))
                return SQL_ERROR;

            if (stmt->stmt_dae)
            {
                stmt->stmt_status = STS_LOCAL_DAE;
                stmt->stmt_param_array = params;

                return SQL_NEED_DATA;
            }
        }

        stmt->stmt_param_array = NULL;
    }

    memset (&stmt->stmt_pending, 0, sizeof (pending_call_t));

    virtodbc__SQLSetParam ((SQLHSTMT) sps, 1, SQL_C_CHAR, SQL_VARCHAR, 0, 0, stmt->stmt_id, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 2, SQL_C_LONG, SQL_INTEGER, 0, 0, &op, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 3, SQL_C_LONG, SQL_INTEGER, 0, 0, &row_no, NULL);
    virtodbc__SQLSetParam ((SQLHSTMT) sps, 4, SQL_C_BOX, SQL_VARCHAR, 0, 0, &params, NULL);

    stmt->stmt_status = STS_SERVER_DAE;
    rc = virtodbc__SQLExecDirect ((SQLHSTMT) sps, NULL, 0);
    dk_free_tree ((caddr_t) params);

    if (SQL_ERROR == rc)
    {
        err_queue_append (&stmt->stmt_error.err_queue, &sps->stmt_error.err_queue);
        return SQL_ERROR;
    }
    if (0 == irow)
    {
        firstinx = 0;
        lastinx = n_rows;
    }
    else
    {
        firstinx = irow - 1;
        lastinx = irow;
    }

    for (inx = firstinx; inx < lastinx; inx++)
    {
        rc = stmt_process_result ((cli_stmt_t *) sps, 1);

        if (SQL_ERROR == rc)
        {
            sql_error_rec_t *err1 = cli_make_error ("01S01", "CL082", "Error in row in SQLSetPos", 0);

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = SQL_ROW_ERROR;

            err_queue_append (&err_queue, &err1);
            err_queue_append (&err_queue, &sps->stmt_error.err_queue);
        }
        else if (rc == SQL_SUCCESS && sps->stmt_prefetch_row)
        {
            long stat = (long) unbox (((caddr_t *) sps->stmt_prefetch_row)[0]);

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = qa_to_row_stat (stat);

            stmt_set_columns (stmt, (caddr_t *) sps->stmt_prefetch_row, inx);
            dk_free_tree ((caddr_t) stmt->stmt_rowset[inx]);
            stmt->stmt_rowset[inx] = (caddr_t *) sps->stmt_prefetch_row;
            sps->stmt_prefetch_row = NULL;
            all_errors = 0;
        }
        else
        {
            int stat = SQL_ROW_SUCCESS;

            all_errors = 0;
            switch (op)
            {
            case SQL_UPDATE:
                stat = SQL_ROW_UPDATED;
                break;

            case SQL_DELETE:
                stat = SQL_ROW_DELETED;
                break;

            case SQL_ADD:
                stat = SQL_ROW_ADDED;
                break;
            }

            if (stmt->stmt_row_status)
                stmt->stmt_row_status[inx] = stat;
        }
    }

    if (SQL_REFRESH == fOption)
        stmt->stmt_current_row = stmt->stmt_rowset[co];

    stmt->stmt_rows_affected = sps->stmt_rows_affected;
    rc = stmt_process_result (sps, 1);	/* the ret from the proc call, w/ possible autocommit txn error code */

    if (rc == SQL_ERROR)
        err_queue_append (&err_queue, &sps->stmt_error.err_queue);

    if (rc == SQL_NO_DATA_FOUND)
        rc = SQL_SUCCESS;

    if (SQL_SUCCESS == rc && err_queue)
    {
        if (all_errors)
            rc = SQL_ERROR;
        else
            rc = SQL_SUCCESS_WITH_INFO;
    }

    set_error (&stmt->stmt_error, NULL, NULL, NULL);
    stmt->stmt_error.err_queue = err_queue;
    stmt->stmt_error.err_queue_head = err_queue;

    return (rc);
}
Ejemplo n.º 15
0
caddr_t
arithm_dt_add_num (ccaddr_t box1, ccaddr_t box2, int subtraction, caddr_t *err_ret)
{
  int dt_type = DT_DT_TYPE (box1);
  dtp_t dtp2 = DV_TYPE_OF (box2);
  boxint whole_seconds = 0;
  boxint nanoseconds = 0;
  TIMESTAMP_STRUCT ts;
  caddr_t res;
  switch (dtp2)
    {
    case DV_LONG_INT:
      whole_seconds = unbox (box2);
      break;
    case DV_DOUBLE_FLOAT:
      {
        double n = unbox_double (box2);
        double rest;
        whole_seconds = (n >= 0.0) ? floor(n + 0.5) : ceil(n - 0.5);
        rest = n - whole_seconds;
        if (abs(rest/n) > (3 * DBL_EPSILON))
          nanoseconds = (n - whole_seconds) * 1000000000L;
        break;
      }
    case DV_NUMERIC:
      {
        numeric_t n = (numeric_t)box2;
        if (NUMERIC_STS_SUCCESS != numeric_to_int64 (n, &whole_seconds))
          {
            err_ret[0] = srv_make_new_error ("22003", "SR087", "Wrong arguments for datetime arithmetic: decimal is out of range.");
            return NULL;
          }
        if (n->n_scale > 0)
          {
            char *nptr = n->n_value + n->n_len;
            int ctr;
            int mult = 1;
            for (ctr = 9; ctr > n->n_scale; ctr--) mult *= 10;
            while (ctr--)
              {
                nanoseconds += mult * nptr[ctr];
                mult *= 10;
              }
          }
        break;
      }
    default:
      return NULL;
    }
  DT_AUDIT_FIELDS (dt);
  dt_to_GMTimestamp_struct (box1, &ts);
  ts_add (&ts, (subtraction ? -whole_seconds : whole_seconds), "second");
  if (nanoseconds)
    ts_add (&ts, (subtraction ? -nanoseconds : nanoseconds), "nanosecond");
  res = dk_alloc_box (DT_LENGTH, DV_DATETIME);
  GMTimestamp_struct_to_dt (&ts, res);
  DT_SET_TZ (res, DT_TZ (box1));
  if ((DT_TYPE_DATE == dt_type) && (0 == (((whole_seconds * 1000000000L) + nanoseconds) % (SPERDAY * 1000000000L))))
    DT_SET_DT_TYPE (res, dt_type);
  DT_AUDIT_FIELDS (dt);
  return res;
}