1
-----------------------------------------------------------------------
2
-- GtkAda - Ada95 binding for the Gimp Toolkit --
4
-- Copyright (C) 2006, AdaCore --
6
-- This library is free software; you can redistribute it and/or --
7
-- modify it under the terms of the GNU General Public --
8
-- License as published by the Free Software Foundation; either --
9
-- version 2 of the License, or (at your option) any later version. --
11
-- This library is distributed in the hope that it will be useful, --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
14
-- General Public License for more details. --
16
-- You should have received a copy of the GNU General Public --
17
-- License along with this library; if not, write to the --
18
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
19
-- Boston, MA 02111-1307, USA. --
21
-----------------------------------------------------------------------
23
-- This package is purely internal to GtkAda.
24
-- It was moved out of Gtkada.Bindings for elaboration circularity issues
26
with Ada.Unchecked_Conversion;
34
-- The following functions ease bindings: when a C function returns an
35
-- array or a pointer to an array, it returns a C array, ie which doesn't
36
-- contain bounds. The size of the array is generally reported separately.
37
-- The following definitions are suitable for use internally in the
38
-- binding, but should not, when possible, be made visble to the user,
39
-- since they don't behave like usual Ada arrays ('Last is irrelevant for
42
-- For instance, if a C function has the following profile:
43
-- gint* get_sizes (GtkIconTheme* theme); -- 0 terminated array
44
-- when the binding is:
45
-- function Internal (Theme) return Unbounded_Gint_Array_Access;
46
-- and you need to compute for yourself the number of elements, and
47
-- return a Glib.Gint_Array to the user.
49
-- If the C function has the following profile:
50
-- gboolean get_attach_points (theme, GdkPoint** p, gint* n);
51
-- then the binding is:
52
-- function Internal (Theme : System.Address;
53
-- Points : out Unbounded_Points_Array_Access;
54
-- N : access Gint) return Gboolean;
55
-- and you do the following:
56
-- R : aliased Unbounded_Points_Array_Access;
58
-- Tmp : constant Gboolean :=
59
-- Internal (.., R'Unchecked_Access, N'Unchecked_Access);
60
-- Result : Gdk_Points_Array (1 .. Natural (N)) :=
61
-- To_Gint_Array (R, Natural (N));
69
type T_Array is array (Index range <>) of T;
70
package Unbounded_Arrays is
72
is array (Index range Index'Val (1) .. Index'Last) of T;
73
pragma Convention (C, Unbounded_Array);
74
type Unbounded_Array_Access is access Unbounded_Array;
76
procedure G_Free (Arr : Unbounded_Array_Access);
79
(Arr : Unbounded_Array_Access; N : Index) return T_Array;
81
function Convert is new Ada.Unchecked_Conversion
82
(System.Address, Unbounded_Array_Access);
85
pragma Import (C, G_Free, "g_free");