[Gtk-sharp-list] Upcoming problems.

Rachel Hestilow rachel@nullenvoid.com
27 May 2003 17:58:09 -0500


--=-lC10ab4T9jWi1/yCcM0P
Content-Type: multipart/mixed; boundary="=-EhaL0c0YQadyhoY5ir/M"


--=-EhaL0c0YQadyhoY5ir/M
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Tue, 2003-05-27 at 17:21, Mike Kestner wrote:
> Sounds good. No patch was attached, so I'm wondering if you subclassed
> SimpleGen?  Seems like that should be doable, since only the one prop
> and one method changed.

Ah, forgot the patch. I have attached it to this message. I did indeed
subclass SimpleGen.

> It doesn't sound like you addressed Paolo's g_free concern though.  We
> probably need to add a SringGen class that also uses MarshalReturnType
> of IntPtr and PtrToStringAnsi, but additionally calls g_free on the
> IntPtr. Then we can map the non-const strings to that IGeneratable.
> Sounds like a subclass overriding just the FromNativeReturn method of
> your ConstStringGen class.

I didn't get the message until after writing the fix, so no I
didn't...I'm not entirely sure on what needs to be done for that fix in
terms of free/g_free, though, so I have a question for lupus:

The problem is that, in theory, all the allocated strings we are getting
from glib/gtk/etc are using g_malloc and g_free, but a correct JIT will
use free() and thus could potentially be incompatible with g_malloc'ed
results. Is that correct? If so, what needs to be done? Will wrapping
the returned value in, say,

char* gtksharp_realloc_string (char *str) {
	char *newstr =3D strdup (str);
	g_free (str);
	return newstr;
}

work?

>=20
> > Shall I commit?
>=20
> Do you have time to incorporate the above too?  Let me know.  If not,
> you can commit what you have now and I'll try to get to the rest
> tonight.
>=20

I'll try to incorporate the above.

-- Rachel


--=-EhaL0c0YQadyhoY5ir/M
Content-Disposition: inline; filename=const-string.patch
Content-Type: text/x-patch; name=const-string.patch; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: quoted-printable

Index: ConstStringGen.cs
=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: ConstStringGen.cs
diff -N ConstStringGen.cs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ConstStringGen.cs	27 May 2003 22:36:11 -0000
@@ -0,0 +1,30 @@
+// GtkSharp.Generation.ConstStringGen.cs - The Const String type Generatab=
le.
+//
+// Author: Rachel Hestilow <rachel@nullenvoid.com>
+//
+// (c) 2003 Rachel Hestilow
+
+namespace GtkSharp.Generation {
+
+	using System;
+
+	public class ConstStringGen : SimpleGen {
+	=09
+		public ConstStringGen (string ctype) : base (ctype, "string")
+		{
+		}
+
+		public override String MarshalReturnType {
+			get
+			{
+				return "IntPtr";
+			}
+		}
+	=09
+		public override String FromNativeReturn(String var)
+		{
+			return "Marshal.PtrToStringAuto(" + var + ")";
+		}
+	}
+}
+
Index: SymbolTable.cs
=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/gtk-sharp/generator/SymbolTable.cs,v
retrieving revision 1.43
diff -u -r1.43 SymbolTable.cs
--- SymbolTable.cs	19 May 2003 02:45:17 -0000	1.43
+++ SymbolTable.cs	27 May 2003 22:36:11 -0000
@@ -39,8 +39,10 @@
 			AddType (new SimpleGen ("gushort", "ushort"));
 			AddType (new SimpleGen ("guint32", "uint"));
 			AddType (new SimpleGen ("guint64", "ulong"));
-			AddType (new SimpleGen ("const-gchar", "string"));
-			AddType (new SimpleGen ("const-char", "string"));
+			// Const returned strings must be generated=20
+			// differently from memory-managed strings
+			AddType (new ConstStringGen ("const-gchar"));
+			AddType (new ConstStringGen ("const-char"));
 			AddType (new SimpleGen ("gchar", "string"));
 			AddType (new SimpleGen ("gfloat", "float"));
 			AddType (new SimpleGen ("gdouble", "double"));
@@ -127,6 +129,10 @@
 			if (type =3D=3D "void*" || type =3D=3D "const-void*") return "gpointer"=
;
=20
 			string trim_type =3D type.TrimEnd('*');
+
+			// HACK: Similar to above, but for const strings
+			if (trim_type =3D=3D "const-gchar" || trim_type =3D=3D "const-char") re=
turn trim_type;
+		=09
 			if (trim_type.StartsWith("const-")) return trim_type.Substring(6);
 			return trim_type;
 		}

--=-EhaL0c0YQadyhoY5ir/M--

--=-lC10ab4T9jWi1/yCcM0P
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA+0+1/apOJdUj74F4RAk/oAJ9SV3bazgI2ftzOOITfSFL1P0zwrACeI3Ni
dbm7gcPrrB58gbHd4TGfi/8=
=YSze
-----END PGP SIGNATURE-----

--=-lC10ab4T9jWi1/yCcM0P--