[Gtk-sharp-list] patch for simple pointer types (broken)

Mike Kestner mkestner@ximian.com
10 Oct 2002 19:56:06 -0500


Opened bug 32104 to track this.  Non-trivial solution.  We are currently
Triming the *'s off the end of types in the SymbolTable class.  This
works fine for Objects and most everything else, but obviously falls
down for passbyref base type params.

Mike

On Tue, 2002-10-08 at 03:22, Vladimir Vukicevic wrote:
> So, this started out as me needing to get gdk_drawable_get_size()
> working [*].  Its prototype is:
> 
> void gdk_drawable_get_size (GdkDrawable *d, int *width, int *height);
> 
> So, with only a vague understanding of how the whole generator system
> worked, I plunged in, assuming that all such things tend to be written
> in similar ways, so it Can't Be That Hard (tm).  I split up simple_types
> into native_types and simple_types -- native_types being things that
> have a direct 1-1 mapping between C and C# types, such as gint -> int.
> 
> The attached patch sort-of works.  gdk_drawable_get_size does indeed
> become "Gdk.Drawable.GetSize (out int width, out int height)", with the
> appropriate bindings to C Generated.  However, there's a number of
> (broken) side effects:
> 
> 1) It doesn't (and can't) distinguish between out params and input array
> params.  It would be /really/ nice if the C api writers forced
> themselves to use "gint stuff[]" for input array values and "gint
> *stuff" for an output of one gint.  However, in this respect, things
> aren't any more broken than they were previously.
> 
> 2) Signals that have basic pointer types get horribly broken.  You end
> up with stuff like:
> 
> 	object[] _args = new object[1];
> 	_args[0] = out pixels;
> 	_managed ((out byte) _args[0]);
> 
> 3) A few functions for which bindings were generated before don't get
> generated.  I'm not sure why this is.
> 
> 4) Stuff like:
> 
> -		static extern unsafe bool gdk_pixbuf_loader_write(IntPtr raw, byte[]
> buf, uint count, out IntPtr error);
> +		static extern unsafe bool gdk_pixbuf_loader_write(IntPtr raw, out
> byte[] buf, uint count, out IntPtr error);
>  
>  		/// <summary> Write Method </summary>
>  		/// <remarks> To be completed </remarks>
> -		public unsafe bool Write(byte[] buf, uint count) {
> +		public unsafe bool Write(out byte[] buf, uint count) {
> 
> (- is old, + is with the patch)
> 
> i.e. it's munging stuff that has attributes applied to it from the
> metadata (in this case that param has the array attribute applied).
> 
> So, it's fairly broken.  I'm only sending it along in case someone is
> interested :)
> 
> 	- Vlad
> 
> * I abandoned gdk_drawable_get_size and used the widget's allocation
> instead, which has much saner getters/setters.
> 
> -- 
> Vladimir Vukicevic <vladimir@pobox.com>
-- 
Mike Kestner <mkestner@ximian.com>