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

Duncan Mak duncan@ximian.com
22 Apr 2002 01:22:43 -0400


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

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.

--=-6iRSE1BqsMwpkPcXsfD9
Content-Disposition: attachment; filename=string-icall.patch
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=string-icall.patch; charset=ISO-8859-1

Index: mono/metadata/string-icalls.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
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 =3D mono_domain_get ();
+	MonoString *res;
+
+	if (value =3D=3D NULL)
+		length =3D 0;
+	else {
+		for (i =3D 0; *(value + i) !=3D '\0'; i++);
+		length =3D i;
+	}
+
+	res =3D mono_string_new_utf16 (domain, value, length);
=20
-	g_assert_not_reached ();
-	return NULL;
+	return res;
 }
=20
 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 =3D mono_domain_get ();
+
+	if ((value =3D=3D NULL) && (sindex !=3D 0) && (length !=3D 0))
+		mono_raise_exception (mono_get_exception_argument_null ("Argument null")=
);
=20
-	g_assert_not_reached ();
-	return NULL;
+	if ((sindex < 0) || (length < 0))
+		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of =
range"));
+=09
+	begin =3D (gunichar2 *) (value + sindex);
+
+	res =3D mono_string_new_utf16 (domain, begin, length);
+=09
+	return res;
 }
=20
 MonoString *
 mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)
 {
-	MONO_CHECK_ARG_NULL (value);
+	int i, length;
+	MonoString *res;
+	MonoDomain *domain =3D mono_domain_get ();
+
+	if (value =3D=3D NULL)
+		length =3D 0;
+	else {
+		for (i =3D 0; *(value + i) !=3D '\0'; i++);
+		length =3D i;
+	}
=20
-	g_assert_not_reached ();
-	return NULL;
+	res =3D mono_string_new_utf16 (domain, (gunichar2 *) value, length);
+
+	return res;
 }
=20
 MonoString *
 mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gi=
nt32 sindex, gint32 length)
 {
-	MONO_CHECK_ARG_NULL (value);
+	MonoString *res;
+	gunichar2 *begin;
+	MonoDomain *domain =3D mono_domain_get ();
+
+	if ((value =3D=3D NULL) && (sindex !=3D 0) && (length !=3D 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 =3D (gunichar2 *) (value + sindex);
=20
-	g_assert_not_reached ();
-	return NULL;
+	res =3D mono_string_new_utf16 (domain, begin, length);
 }
=20
 MonoString *
Index: docs/internal-calls
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/public/mono/docs/internal-calls,v
retrieving revision 1.2
diff -u -b -r1.2 internal-calls
--- docs/internal-calls	16 Apr 2002 11:28:11 -0000	1.2
+++ docs/internal-calls	22 Apr 2002 01:33:03 -0000
@@ -4,7 +4,7 @@
 	C# type 	C type
 	char 		gunichar2
 	bool 		MonoBoolean
-	sbyte 		signed char
+	sbyte 		signed char (gint8)
 	byte 		guchar
 	short 		gint16
 	ushort 		guint16

--=-6iRSE1BqsMwpkPcXsfD9--