[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">> On Sun, 2002-04-21 at 11:40, Duncan Mak wrote:</FONT>
<FONT COLOR="#737373">> > </FONT>
<FONT COLOR="#737373">> > Yeah, I'm working on these. I should be done soon.</FONT>
<FONT COLOR="#737373">> > </FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> Attached is a patch for the 4 missing string constructors in</FONT>
<FONT COLOR="#737373">> string-icall.c</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> /* unsafe public String (char *value); */</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> /* unsafe public String (char *value, int startIndex, int length); */</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2</FONT>
<FONT COLOR="#737373">> *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> /* unsafe public String (sbyte *value); */</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> /* unsafe public String (sbyte *value, int startIndex, int length); */</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value,</FONT>
<FONT COLOR="#737373">> gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> I took Dietmar's advice and simply looked at the original C#</FONT>
<FONT COLOR="#737373">> implementation of the constructors and translated them into the C</FONT>
<FONT COLOR="#737373">> equivalent.</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> The only testing I did is to try and build them, and they built.</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> I'm not an experienced C programmer, so please tell me if there is</FONT>
<FONT COLOR="#737373">> anything wrong with the patch and I'll fix them ASAP.</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> Also, Dietmar also told me to go thru the new string code and</FONT>
<FONT COLOR="#737373">> standardize the naming of the types -- ie, gunichar2 * and guint16 * are</FONT>
<FONT COLOR="#737373">> used interchangably right now. I'll go in and change them tomorrow</FONT>
<FONT COLOR="#737373">> afternoon. I'll be using mono/mono/docs/internal-call as my guide.</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> Duncan.</FONT></PRE>
<FONT COLOR="#737373">> ----</FONT>
<BR>
<FONT COLOR="#737373">> </FONT>
<BR>
<PRE><FONT COLOR="#737373">> Index: mono/metadata/string-icalls.c</FONT>
<FONT COLOR="#737373">> ===================================================================</FONT>
<FONT COLOR="#737373">> RCS file: /cvs/public/mono/mono/metadata/string-icalls.c,v</FONT>
<FONT COLOR="#737373">> retrieving revision 1.4</FONT>
<FONT COLOR="#737373">> diff -u -b -r1.4 string-icalls.c</FONT>
<FONT COLOR="#737373">> --- mono/metadata/string-icalls.c 20 Apr 2002 13:49:34 -0000 1.4</FONT>
<FONT COLOR="#737373">> +++ mono/metadata/string-icalls.c 22 Apr 2002 01:33:03 -0000</FONT>
<FONT COLOR="#737373">> @@ -22,10 +22,20 @@</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_charp (gpointer dummy, gunichar2 *value)</FONT>
<FONT COLOR="#737373">> {</FONT>
<FONT COLOR="#737373">> - MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">> + int i, length;</FONT>
<FONT COLOR="#737373">> + MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">> + MonoString *res;</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + if (value == NULL)</FONT>
<FONT COLOR="#737373">> + length = 0;</FONT>
<FONT COLOR="#737373">> + else {</FONT>
<FONT COLOR="#737373">> + for (i = 0; *(value + i) != '\0'; i++);</FONT>
<FONT COLOR="#737373">> + length = i;</FONT>
<FONT COLOR="#737373">> + }</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + res = mono_string_new_utf16 (domain, value, length);</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> - g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">> - return NULL;</FONT>
<FONT COLOR="#737373">> + return res;</FONT>
<FONT COLOR="#737373">> }</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> @@ -47,28 +57,58 @@</FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_charp_int_int (gpointer dummy, gunichar2 *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">> {</FONT>
<FONT COLOR="#737373">> - MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">> + MonoString *res;</FONT>
<FONT COLOR="#737373">> + gunichar2 *begin;</FONT>
<FONT COLOR="#737373">> + MonoDomain * domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + if ((value == NULL) && (sindex != 0) && (length != 0))</FONT></PRE>
why do we need a check for sindex != 0 here?
<BR>
<PRE><FONT COLOR="#737373">> + mono_raise_exception (mono_get_exception_argument_null ("Argument null"));</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> - g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">> - return NULL;</FONT>
<FONT COLOR="#737373">> + if ((sindex < 0) || (length < 0))</FONT>
<FONT COLOR="#737373">> + mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));</FONT>
<FONT COLOR="#737373">> + </FONT>
<FONT COLOR="#737373">> + begin = (gunichar2 *) (value + sindex);</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + 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">> + </FONT>
<FONT COLOR="#737373">> + return res;</FONT>
<FONT COLOR="#737373">> }</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)</FONT>
<FONT COLOR="#737373">> {</FONT>
<FONT COLOR="#737373">> - MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">> + int i, length;</FONT>
<FONT COLOR="#737373">> + MonoString *res;</FONT>
<FONT COLOR="#737373">> + MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + if (value == NULL)</FONT>
<FONT COLOR="#737373">> + length = 0;</FONT>
<FONT COLOR="#737373">> + else {</FONT>
<FONT COLOR="#737373">> + for (i = 0; *(value + i) != '\0'; i++);</FONT>
<FONT COLOR="#737373">> + length = i;</FONT>
<FONT COLOR="#737373">> + }</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> - g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">> - return NULL;</FONT>
<FONT COLOR="#737373">> + 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">> +</FONT>
<FONT COLOR="#737373">> + return res;</FONT>
<FONT COLOR="#737373">> }</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> MonoString *</FONT>
<FONT COLOR="#737373">> mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gint32 sindex, gint32 length)</FONT>
<FONT COLOR="#737373">> {</FONT>
<FONT COLOR="#737373">> - MONO_CHECK_ARG_NULL (value);</FONT>
<FONT COLOR="#737373">> + MonoString *res;</FONT>
<FONT COLOR="#737373">> + gunichar2 *begin;</FONT>
<FONT COLOR="#737373">> + MonoDomain *domain = mono_domain_get ();</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + if ((value == NULL) && (sindex != 0) && (length != 0))</FONT>
<FONT COLOR="#737373">> + mono_raise_exception (mono_get_exception_argument_null ("Argument null"));</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + if ((sindex > 0) || (length < 0))</FONT>
<FONT COLOR="#737373">> + mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));</FONT>
<FONT COLOR="#737373">> +</FONT>
<FONT COLOR="#737373">> + begin = (gunichar2 *) (value + sindex);</FONT>
<FONT COLOR="#737373">> </FONT>
<FONT COLOR="#737373">> - g_assert_not_reached ();</FONT>
<FONT COLOR="#737373">> - return NULL;</FONT>
<FONT COLOR="#737373">> + 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--