Exemple #1
0
PoolRealArray mono_array_to_PoolRealArray(MonoArray *p_array) {
	PoolRealArray ret;
	int length = mono_array_length(p_array);

	for (int i = 0; i < length; i++) {
		real_t elem = mono_array_get(p_array, real_t, i);
		ret.push_back(elem);
	}

	return ret;
}
Exemple #2
0
/* INFO: toplevel udt_clr_serialize */
int clr_serialize (int _gc_in, dk_session_t * ses)
{
  MonoArray *v_args = NULL;
  MonoArray *mono_list;
  int len, inx;
  MonoDomain *domain = virtuoso_domain;
  get_mono_thread ();

  v_args = MAKE_PARAM_ARRAY (domain, 1);

  SET_INT_ARG (domain, v_args, 0, _gc_in);

  QR_RESET_CTX
    {
      mono_list = (MonoArray *) call_mono (VIRTCLR_NAME, "VInvoke:obj_serialize_soap", v_args, domain);
    }
  QR_RESET_CODE
    {
      caddr_t err;
      POP_QR_RESET;
      err = thr_get_error_code (THREAD_CURRENT_THREAD);
      if (ARRAYP (err))
	log_error ("Mono Serialization error : [%s] [%s]", ERR_STATE(err), ERR_MESSAGE (err));
      else
	log_error ("Mono Serialization error : unknown");
      dk_free_tree (err);
      goto no_obj;
    }
  END_QR_RESET;

  len = mono_array_length (mono_list);
  if (len - 1 < 256)
    {
      session_buffered_write_char (DV_BIN, ses);
      session_buffered_write_char (len - 1, ses);
    }
  else
    {
      session_buffered_write_char (DV_LONG_BIN, ses);
      print_long (len - 1, ses);
    }
  for (inx = 1; inx < len; inx++)
    {
      MonoObject *obj = (MonoObject *)mono_array_get (mono_list, gpointer, inx);
      guint8 b = *(guint8 *)((char *)obj + sizeof (MonoObject));
      session_buffered_write_char (b, ses);
    }
  return len;
no_obj:
  session_buffered_write_char (DV_DB_NULL, ses);
  return 1;
}
Exemple #3
0
PoolIntArray mono_array_to_PoolIntArray(MonoArray *p_array) {
	PoolIntArray ret;
	if (!p_array)
		return ret;
	int length = mono_array_length(p_array);
	ret.resize(length);
	for (int i = 0; i < length; i++) {
		int32_t elem = mono_array_get(p_array, int32_t, i);
		ret.set(i, elem);
	}

	return ret;
}
Exemple #4
0
static gboolean
string_icall_is_in_array (MonoArray *chars, gint32 arraylength, gunichar2 chr)
{
	gunichar2 cmpchar;
	gint32 arrpos;

	for (arrpos = 0; arrpos != arraylength; arrpos++) {
		cmpchar = mono_array_get(chars, gunichar2, arrpos);
		if (cmpchar == chr)
			return TRUE;
	}
	
	return FALSE;
}
Exemple #5
0
static int
memory_usage_array (MonoArray *array, GHashTable *visited)
{
        int total = 0;
        MonoClass *array_class = mono_object_get_class ((MonoObject *) array);
        MonoClass *element_class = mono_class_get_element_class (array_class);
        MonoType *element_type = mono_class_get_type (element_class);

        if (MONO_TYPE_IS_REFERENCE (element_type)) {
                int i;

                for (i = 0; i < mono_array_length (array); i++) {
                        MonoObject *element = mono_array_get (array, gpointer, i);

                        if (element != NULL)
                                total += memory_usage (element, visited);
                }
        }

        return total;
}
Exemple #6
0
char *
mono_exception_get_native_backtrace (MonoException *exc)
{
#ifdef HAVE_BACKTRACE_SYMBOLS
	MonoDomain *domain;
	MonoArray *arr = exc->native_trace_ips;
	int i, len;
	GString *text;
	char **messages;

	if (!arr)
		return g_strdup ("");
	domain = mono_domain_get ();
	len = mono_array_length (arr);
	text = g_string_new_len (NULL, len * 20);
	uint32_t gchandle = mono_gchandle_new (&arr->obj, TRUE); /* pinned */
	void* addr = mono_array_addr (arr, gpointer, 0);
	MONO_ENTER_GC_SAFE;
	messages = backtrace_symbols (addr, len);
	MONO_EXIT_GC_SAFE;
	mono_gchandle_free (gchandle);

	for (i = 0; i < len; ++i) {
		gpointer ip = mono_array_get (arr, gpointer, i);
		MonoJitInfo *ji = mono_jit_info_table_find (mono_domain_get (), (char *)ip);
		if (ji) {
			char *msg = mono_debug_print_stack_frame (mono_jit_info_get_method (ji), (char*)ip - (char*)ji->code_start, domain);
			g_string_append_printf (text, "%s\n", msg);
			g_free (msg);
		} else {
			g_string_append_printf (text, "%s\n", messages [i]);
		}
	}

	g_free (messages);
	return g_string_free (text, FALSE);
#else
	return g_strdup ("");
#endif
}
Exemple #7
0
int
dotnet_is_instance_of (int _clr_ret, caddr_t class_name)
{
  MonoDomain *domain = virtuoso_domain;
  MonoArray *v_args = NULL, *mono_list;
  MonoObject *arg = NULL;
  char *p1=NULL, *p2=NULL, *p3 = NULL;
  char t_class_name[200];
  int fl = 1, ret = 0;

  if (!class_name)
    return 0;

      strcpy (t_class_name, class_name);
      p1 = p3 = t_class_name;

      for (;;)
	{
	  p2 = strstr (p3, "/");
	  if (!p2)
	    break;
	  else
	    p3 = p2 + 1;
	  fl = fl - 1;
	}
      p1 [p3 - p1 - 1] = 0;

      get_mono_thread ();
      v_args = MAKE_PARAM_ARRAY (domain, 4);

      SET_INT_ARG (domain, v_args, 0, _clr_ret);
      SET_INT_ARG (domain, v_args, 1, fl);
      SET_STRING_ARG (domain, v_args, 2, p1);
      SET_STRING_ARG (domain, v_args, 3, p3);

  QR_RESET_CTX
    {
      mono_list = (MonoArray *) call_mono (VIRTCLR_NAME, "VInvoke:get_IsInstanceOf", v_args, domain);
    }
  QR_RESET_CODE
    {
      caddr_t err;
      err = thr_get_error_code (THREAD_CURRENT_THREAD);
      dk_free_tree (err);
      POP_QR_RESET;
      return 0;
    }
  END_QR_RESET;

  arg = (MonoObject *) mono_array_get (mono_list, gpointer, 0);
#ifdef MONO_DEBUG
  fprintf (stderr, "VInvoke:get_IsInstanceOf CLR ret=%s data_sz=%d gboolean_sz=%d guint8_sz=%d\n",
      arg->vtable->klass->name,
      (int) (arg->vtable->klass->instance_size - sizeof (MonoObject)),
      sizeof (gboolean),
      sizeof (guint8));
#endif
  ret = *(((guint8 *)arg) + sizeof (MonoObject));
#ifdef MONO_DEBUG
  fprintf (stderr, "VInvoke:get_IsInstanceOf C ret=%d\n", ret);
#endif
  return ret;
}
Exemple #8
0
static caddr_t
sa_to_dk (MonoArray *mono_list, int ofs, int mode, void *udt)
{
  guint32 ret_type;
  int clr_object = 0;
  MonoObject *type, *value;
  caddr_t ret = NULL;
  MonoClass *cls;
  int len = mono_array_length (mono_list), inx;
  dk_set_t ret_set = NULL;

  type = (MonoObject *)mono_array_get (mono_list, gpointer, ofs + 0);

  ret_type = *(guint32 *)((char *)type + sizeof (MonoObject));

  if (!ret_type)
    {
      char *error_text;
      caddr_t err = NULL;

      value = (MonoObject *)mono_array_get (mono_list, gpointer, ofs + 1);
      error_text = mono_string_to_utf8 ((MonoString *)value);
      if (error_text)
	err = srv_make_new_error ("42000", "MN002", "Mono error : %.200s",
	    mono_class_get_name (mono_object_get_class (value)), error_text);
      else
	err = srv_make_new_error ("42000", "MN003", "Unknown mono error");
      g_free (error_text);
      sqlr_resignal (err);
    }

  /* get type of object */
  clr_object = 0;
  if (ret_type == 5 || ret_type == 6)
    clr_object = 1;

  for (inx = 1; inx < len; inx++)
    {
      value = (MonoObject *)mono_array_get (mono_list, gpointer, ofs + inx);
      if (value)
	{
	  cls = mono_object_get_class (value);
	  if (cls == mono_get_int32_class ())
	    {
	      gint32 v = *(gint32 *)((char *)value + sizeof (MonoObject));
	      if (clr_object)
		{
		  void * what_udt;

		  if (mode)
		    {
		      /*add_id (v);*/
		      ret = box_num (v);
		    }
		  else
		    {
		      what_udt = udt_find_class_for_clr_instance (v, udt);
		      if (what_udt)
			{
			  /*add_id (v);*/
			  ret = cpp_udt_clr_instance_allocate (v, what_udt);
			}
		      else
			{
			  sqlr_new_error ("22023", "MN005", "Can't map Mono result to PL type");
			}
		    }
		}
	      else
		ret = box_num (v);
	    }
	  else if (cls == mono_get_uint32_class())
	    ret = box_num (*(guint32 *)((char *)value + sizeof (MonoObject)));
	  else if (cls == mono_get_single_class ())
	    ret = box_float (*(float *)((char *)value + sizeof (MonoObject)));
	  else if (cls == mono_get_double_class ())
	    ret = box_double (*(double *)((char *)value + sizeof (MonoObject)));
	  else if (cls == mono_get_boolean_class ())
	    ret = box_num (*(guint8 *)((guint8 *)value + sizeof (MonoObject)));
	  else if (cls == mono_get_string_class ())
	    {
	      char *utf8 = mono_string_to_utf8 ((MonoString *)value);
	      ret = box_utf8_as_wide_char (utf8, NULL, strlen (utf8), 0, DV_WIDE);
	      g_free (utf8);
	    }
	  else
	    {
	      const char *name = mono_class_get_name (cls);
	      sqlr_new_error ("22023", "MN006", "Can't map CLR result of type (%s) to PL type",
		  name ? name : "<unknown>");
	    }
	}
      else
	ret = NULL;
    if (ret_type != 3 && ret_type != 4 && ret_type != 5)
  	return ret;
      else
	dk_set_push (&ret_set, ret);
    }
  return list_to_array (dk_set_nreverse (ret_set));
}