[gtkada] Addition of Gdk_New_From_Data into Gdk.Pixbuf

Anne et Damien Carbonne aetdcarbonne at free.fr
Mon Jul 13 23:57:09 CEST 2009


Thanks for answer,

I tried to provide a higher level of abstraction than the C one.
But I left a System.Address for user data!

1) There would be the solution to use an interface for destruction, but 
that would be Ada 2005.
I guess it would not be acceptable!

   type Gdk_Finalizer is interface;
   tytpe Gdk_Finalizer_ref is access all Gdk_Finalizer'Class;
   procedure Clean (Finalizer : in out | access Finalizer;
                    Pixels : in out Guchar_Array_Ptr);

   function Gdk_New_From_Data
     (Data            : Guchar_Array_Ptr;
      Colorspace      : Gdk_Colorspace := Colorspace_RGB;
      Has_Alpha       : Boolean := False;
      Bits_Per_Sample : Gint := 8;
      Width           : Gint;
      Height          : Gint;
      Rowstride       : Gint;
      Finalizer       : Gdk_Finalizer_Ref)
      return Gdk_Pixbuf;


2) The other solution would consist in defining an abstract base class 
instead of an interface.

   type Gdk_Finalizer is abstract tagged null record;
   procedure Clean (Finalizer : in out | access Finalizer;
                    Pixels : in out Guchar_Array_Ptr);

   function Gdk_New_From_Data
     (Data            : Guchar_Array_Ptr;
      Colorspace      : Gdk_Colorspace := Colorspace_RGB;
      Has_Alpha       : Boolean := False;
      Bits_Per_Sample : Gint := 8;
      Width           : Gint;
      Height          : Gint;
      Rowstride       : Gint;
      Finalizer       : Gdk_Finalizer_Ref)
      return Gdk_Pixbuf;

In both cases the user could attach its own data for handling 
destruction of allocated memory, by deriving Finalizer.

3) If we want to only allow destruction of the allocated data (without 
distinction), then we could suppress the second parameter of the destroy 
procedure.

   type Gdk_Finalizer is access procedure (Pixels : in out 
Guchar_Array_Ptr);

   function Gdk_New_From_Data
     (Data            : Guchar_Array_Ptr;
      Colorspace      : Gdk_Colorspace := Colorspace_RGB;
      Has_Alpha       : Boolean := False;
      Bits_Per_Sample : Gint := 8;
      Width           : Gint;
      Height          : Gint;
      Rowstride       : Gint;
      Finalizer       : Gdk_Finalizer)
      return Gdk_Pixbuf;


Is that what you have in mind?
I suppose one could find examples where this second parameter would be 
missing!

Or do you imagine that data would be automatically destroyed by the Ada 
binding?
In which case one would not need to pass the 2 last parameters 
(destroy_fn and destroy_fn_data).

4) We could then simply pass a boolean telling whether memory must be 
deallocated or not.

   function Gdk_New_From_Data
     (Data              : Guchar_Array_Ptr;
      Colorspace        : Gdk_Colorspace := Colorspace_RGB;
      Has_Alpha         : Boolean := False;
      Bits_Per_Sample   : Gint := 8;
      Width             : Gint;
      Height            : Gint;
      Rowstride         : Gint;
      Auto_Destroy_Data : Boolean := True)
      return Gdk_Pixbuf;


Any of these solutions would fit the usage I did of this binding.

What do you have in mind exactly ? One of those solutions or another one ?

Best regards,
Damien Carbonne


Arnaud Charlet a écrit :
>> As Gdk_New_From_Data is currently missing from Gdk.Pixbuf, I created a 
>> binding for it (in a child package of Gtk.Pixbuf).
>> Would you consider adding this directly into to Gtk.Pixbuf?
>> Is the attached code sufficient or would you prefer a diff?
>>     
>
> A patch (diff) against svn trunk as well as a ChangeLog would be better.
>
> The patch will probably need to be reworked before integration, since
> the API you provide is pretty low-level (in particular the handling of
> Destroy_Fn/Destroy_Fn_Data).
>
> I'd suggest either remove the two last parameters, or perhaps provide a single
> extra parameter: Destroy_Fn, removing the use of user data from the spec
> (and still use it under the hood in the body).
>
> The spec (comments) should probably also reflect/explain this business
> of destroy/user data.
>
> Arno
>
>
>   




More information about the gtkada mailing list