[Mono-list] System.String::.ctor cant be resolved

Dietmar Maurer dietmar@ximian.com
23 Apr 2002 07:15:19 +0200


--=-OP8e1BpprT6CfI6kMS5w
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2002-04-22 at 07:22, Duncan Mak wrote: 

> On Sun, 2002-04-21 at 11:40, Duncan Mak wrote:
> > 
> > Yeah, I'm working on these. I should be done soon.
> > 
> 
> Attached is a patch for the 4 missing string constructors in
> string-icall.c
> 
> /* unsafe public String (char *value); */
> MonoString *
> mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)
> 
> /* unsafe public String (char *value, int startIndex, int length); */
> MonoString *
> mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2
> *value, gint32 sindex, gint32 length)
> 
> /* unsafe public String (sbyte *value); */
> MonoString *
> mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)
> 
> /* unsafe public String (sbyte *value, int startIndex, int length); */
> MonoString *
> mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value,
> gint32 sindex, gint32 length)
> 
> I took Dietmar's advice and simply looked at the original C#
> implementation of the constructors and translated them into the C
> equivalent.
> 
> The only testing I did is to try and build them, and they built.
> 
> I'm not an experienced C programmer, so please tell me if there is
> anything wrong with the patch and I'll fix them ASAP.
> 
> Also, Dietmar also told me to go thru the new string code and
> standardize the naming of the types -- ie, gunichar2 * and guint16 * are
> used interchangably right now. I'll go in and change them tomorrow
> afternoon. I'll be using mono/mono/docs/internal-call as my guide.
> 
> Duncan.

> ----
> 


> Index: mono/metadata/string-icalls.c
> ===================================================================
> RCS file: /cvs/public/mono/mono/metadata/string-icalls.c,v
> retrieving revision 1.4
> diff -u -b -r1.4 string-icalls.c
> --- mono/metadata/string-icalls.c	20 Apr 2002 13:49:34 -0000	1.4
> +++ mono/metadata/string-icalls.c	22 Apr 2002 01:33:03 -0000
> @@ -22,10 +22,20 @@
>  MonoString *
>  mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)
>  {
> -	MONO_CHECK_ARG_NULL (value);
> +	int i, length;
> +	MonoDomain *domain = mono_domain_get ();
> +	MonoString *res;
> +
> +	if (value == NULL)
> +		length = 0;
> +	else {
> +		for (i = 0; *(value + i) != '\0'; i++);
> +		length = i;
> +	}
> +
> +	res = mono_string_new_utf16 (domain, value, length);
>  
> -	g_assert_not_reached ();
> -	return NULL;
> +	return res;
>  }
>  
>  MonoString *
> @@ -47,28 +57,58 @@
>  MonoString *
>  mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2 *value, gint32 sindex, gint32 length)
>  {
> -	MONO_CHECK_ARG_NULL (value);
> +	MonoString *res;
> +	gunichar2 *begin;
> +	MonoDomain * domain = mono_domain_get ();
> +
> +	if ((value == NULL) && (sindex != 0) && (length != 0))

why do we need a check for sindex != 0 here? 


> +		mono_raise_exception (mono_get_exception_argument_null ("Argument null"));
>  
> -	g_assert_not_reached ();
> -	return NULL;
> +	if ((sindex < 0) || (length < 0))
> +		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
> +	
> +	begin = (gunichar2 *) (value + sindex);
> +
> +	res = mono_string_new_utf16 (domain, begin, length);

what happens when value == NULL (lenght == 0). We should return
String.Empty? 


> +	
> +	return res;
>  }
>  
>  MonoString *
>  mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)
>  {
> -	MONO_CHECK_ARG_NULL (value);
> +	int i, length;
> +	MonoString *res;
> +	MonoDomain *domain = mono_domain_get ();
> +
> +	if (value == NULL)
> +		length = 0;
> +	else {
> +		for (i = 0; *(value + i) != '\0'; i++);
> +		length = i;
> +	}
>  
> -	g_assert_not_reached ();
> -	return NULL;
> +	res = mono_string_new_utf16 (domain, (gunichar2 *) value, length);

value is not a utf16 String, instead it is utf8 (AFAIK). So we need to
call mono_string_new (). I value is null we must return String.Empty
(but thats not trivial to implement - simply add a
fixme/g_assert_not_reached()) 


> +
> +	return res;
>  }
>  
>  MonoString *
>  mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gint32 sindex, gint32 length)
>  {
> -	MONO_CHECK_ARG_NULL (value);
> +	MonoString *res;
> +	gunichar2 *begin;
> +	MonoDomain *domain = mono_domain_get ();
> +
> +	if ((value == NULL) && (sindex != 0) && (length != 0))
> +		mono_raise_exception (mono_get_exception_argument_null ("Argument null"));
> +
> +	if ((sindex > 0) || (length < 0))
> +		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
> +
> +	begin = (gunichar2 *) (value + sindex);
>  
> -	g_assert_not_reached ();
> -	return NULL;
> +	res = mono_string_new_utf16 (domain, begin, length);

same as above - its not an utf16 String AFAIK. Please can you check that
in the docs?

- Dietmar

--=-OP8e1BpprT6CfI6kMS5w
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.0.1.99">
</HEAD>
<BODY>
On Mon, 2002-04-22 at 07:22, Duncan Mak wrote: 
<PRE><FONT COLOR="#737373">&gt; On Sun, 2002-04-21 at 11:40, Duncan Mak wrote:</FONT>
<FONT COLOR="#737373">&gt; &gt; </FONT>
<FONT COLOR="#737373">&gt; &gt; Yeah, I'm working on these. I should be done soon.</FONT>
<FONT COLOR="#737373">&gt; &gt; </FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; Attached is a patch for the 4 missing string constructors in</FONT>
<FONT COLOR="#737373">&gt; string-icall.c</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; /* unsafe public String (char *value); */</FONT>
<FONT COLOR="#737373">&gt; MonoString *</FONT>
<FONT COLOR="#737373">&gt; mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; /* unsafe public String (char *value, int startIndex, int length); */</FONT>
<FONT COLOR="#737373">&gt; MonoString *</FONT>
<FONT COLOR="#737373">&gt; mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2</FONT>
<FONT COLOR="#737373">&gt; *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; /* unsafe public String (sbyte *value); */</FONT>
<FONT COLOR="#737373">&gt; MonoString *</FONT>
<FONT COLOR="#737373">&gt; mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; /* unsafe public String (sbyte *value, int startIndex, int length); */</FONT>
<FONT COLOR="#737373">&gt; MonoString *</FONT>
<FONT COLOR="#737373">&gt; mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value,</FONT>
<FONT COLOR="#737373">&gt; gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; I took Dietmar's advice and simply looked at the original C#</FONT>
<FONT COLOR="#737373">&gt; implementation of the constructors and translated them into the C</FONT>
<FONT COLOR="#737373">&gt; equivalent.</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; The only testing I did is to try and build them, and they built.</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; I'm not an experienced C programmer, so please tell me if there is</FONT>
<FONT COLOR="#737373">&gt; anything wrong with the patch and I'll fix them ASAP.</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; Also, Dietmar also told me to go thru the new string code and</FONT>
<FONT COLOR="#737373">&gt; standardize the naming of the types -- ie, gunichar2 * and guint16 * are</FONT>
<FONT COLOR="#737373">&gt; used interchangably right now. I'll go in and change them tomorrow</FONT>
<FONT COLOR="#737373">&gt; afternoon. I'll be using mono/mono/docs/internal-call as my guide.</FONT>
<FONT COLOR="#737373">&gt; </FONT>
<FONT COLOR="#737373">&gt; Duncan.</FONT></PRE>
<FONT COLOR="#737373">&gt; ----</FONT>
<BR>
<FONT COLOR="#737373">&gt; </FONT>
<BR>

<PRE><FONT COLOR="#737373">&gt; Index: mono/metadata/string-icalls.c</FONT>
<FONT COLOR="#737373">&gt; ===================================================================</FONT>
<FONT COLOR="#737373">&gt; RCS file: /cvs/public/mono/mono/metadata/string-icalls.c,v</FONT>
<FONT COLOR="#737373">&gt; retrieving revision 1.4</FONT>
<FONT COLOR="#737373">&gt; diff -u -b -r1.4 string-icalls.c</FONT>
<FONT COLOR="#737373">&gt; --- mono/metadata/string-icalls.c	20 Apr 2002 13:49:34 -0000	1.4</FONT>
<FONT COLOR="#737373">&gt; +++ mono/metadata/string-icalls.c	22 Apr 2002 01:33:03 -0000</FONT>
<FONT COLOR="#737373">&gt; @@ -22,10 +22,20 @@</FONT>
<FONT COLOR="#737373">&gt;  MonoString *</FONT>
<FONT COLOR="#737373">&gt;  mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)</FONT>
<FONT COLOR="#737373">&gt;  {</FONT>
<FONT COLOR="#737373">&gt; -	MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">&gt; +	int i, length;</FONT>
<FONT COLOR="#737373">&gt; +	MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">&gt; +	MonoString *res;</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	if (value == NULL)</FONT>
<FONT COLOR="#737373">&gt; +		length = 0;</FONT>
<FONT COLOR="#737373">&gt; +	else {</FONT>
<FONT COLOR="#737373">&gt; +		for (i = 0; *(value + i) != '\0'; i++);</FONT>
<FONT COLOR="#737373">&gt; +		length = i;</FONT>
<FONT COLOR="#737373">&gt; +	}</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	res = mono_string_new_utf16 (domain, value, length);</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt; -	g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">&gt; -	return NULL;</FONT>
<FONT COLOR="#737373">&gt; +	return res;</FONT>
<FONT COLOR="#737373">&gt;  }</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt;  MonoString *</FONT>
<FONT COLOR="#737373">&gt; @@ -47,28 +57,58 @@</FONT>
<FONT COLOR="#737373">&gt;  MonoString *</FONT>
<FONT COLOR="#737373">&gt;  mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2 *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">&gt;  {</FONT>
<FONT COLOR="#737373">&gt; -	MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">&gt; +	MonoString *res;</FONT>
<FONT COLOR="#737373">&gt; +	gunichar2 *begin;</FONT>
<FONT COLOR="#737373">&gt; +	MonoDomain * domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	if ((value == NULL) &amp;&amp; (sindex != 0) &amp;&amp; (length != 0))</FONT></PRE>
why do we need a check for sindex != 0 here? 
<BR>

<PRE><FONT COLOR="#737373">&gt; +		mono_raise_exception (mono_get_exception_argument_null (&quot;Argument null&quot;));</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt; -	g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">&gt; -	return NULL;</FONT>
<FONT COLOR="#737373">&gt; +	if ((sindex &lt; 0) || (length &lt; 0))</FONT>
<FONT COLOR="#737373">&gt; +		mono_raise_exception (mono_get_exception_argument_out_of_range (&quot;Out of range&quot;));</FONT>
<FONT COLOR="#737373">&gt; +	</FONT>
<FONT COLOR="#737373">&gt; +	begin = (gunichar2 *) (value + sindex);</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	res = mono_string_new_utf16 (domain, begin, length);</FONT></PRE>
what happens when value == NULL (lenght == 0). We should return String.Empty? 
<BR>

<PRE><FONT COLOR="#737373">&gt; +	</FONT>
<FONT COLOR="#737373">&gt; +	return res;</FONT>
<FONT COLOR="#737373">&gt;  }</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt;  MonoString *</FONT>
<FONT COLOR="#737373">&gt;  mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)</FONT>
<FONT COLOR="#737373">&gt;  {</FONT>
<FONT COLOR="#737373">&gt; -	MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">&gt; +	int i, length;</FONT>
<FONT COLOR="#737373">&gt; +	MonoString *res;</FONT>
<FONT COLOR="#737373">&gt; +	MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	if (value == NULL)</FONT>
<FONT COLOR="#737373">&gt; +		length = 0;</FONT>
<FONT COLOR="#737373">&gt; +	else {</FONT>
<FONT COLOR="#737373">&gt; +		for (i = 0; *(value + i) != '\0'; i++);</FONT>
<FONT COLOR="#737373">&gt; +		length = i;</FONT>
<FONT COLOR="#737373">&gt; +	}</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt; -	g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">&gt; -	return NULL;</FONT>
<FONT COLOR="#737373">&gt; +	res = mono_string_new_utf16 (domain, (gunichar2 *) value, length);</FONT></PRE>
value is not a utf16 String, instead it is utf8 (AFAIK). So we need to call mono_string_new (). I value is null we must return String.Empty (but thats not trivial to implement - simply add a fixme/g_assert_not_reached()) 
<BR>

<PRE><FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	return res;</FONT>
<FONT COLOR="#737373">&gt;  }</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt;  MonoString *</FONT>
<FONT COLOR="#737373">&gt;  mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">&gt;  {</FONT>
<FONT COLOR="#737373">&gt; -	MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">&gt; +	MonoString *res;</FONT>
<FONT COLOR="#737373">&gt; +	gunichar2 *begin;</FONT>
<FONT COLOR="#737373">&gt; +	MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	if ((value == NULL) &amp;&amp; (sindex != 0) &amp;&amp; (length != 0))</FONT>
<FONT COLOR="#737373">&gt; +		mono_raise_exception (mono_get_exception_argument_null (&quot;Argument null&quot;));</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	if ((sindex &gt; 0) || (length &lt; 0))</FONT>
<FONT COLOR="#737373">&gt; +		mono_raise_exception (mono_get_exception_argument_out_of_range (&quot;Out of range&quot;));</FONT>
<FONT COLOR="#737373">&gt; +</FONT>
<FONT COLOR="#737373">&gt; +	begin = (gunichar2 *) (value + sindex);</FONT>
<FONT COLOR="#737373">&gt;  </FONT>
<FONT COLOR="#737373">&gt; -	g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">&gt; -	return NULL;</FONT>
<FONT COLOR="#737373">&gt; +	res = mono_string_new_utf16 (domain, begin, length);</FONT></PRE>
same as above - its not an utf16 String AFAIK. Please can you check that in the docs?
<PRE>- Dietmar</PRE>
</BODY>
</HTML>

--=-OP8e1BpprT6CfI6kMS5w--