From: Simon Wright <simon@pushface.org>
Subject: Re: Dispatching callback handed over to C
Date: Fri, 06 Apr 2012 12:41:29 +0100
Date: 2012-04-06T12:41:29+01:00 [thread overview]
Message-ID: <m2398hhyty.fsf@pushface.org> (raw)
In-Reply-To: b7613390-e4f9-45e0-b599-32f941ea2e68@db5g2000vbb.googlegroups.com
Maciej Sobczak <see.my.homepage@gmail.com> writes:
> On 5 Kwi, 11:13, Natasha Kerensikova <lithium...@gmail.com> wrote:
>
>> So for my binding, what about something like :
>>
>> type Opaque_Data is null record;
>> pragma Convention (C, Opaque_Data);
>>
>> type Opaque_Pointer is access all Opaque_Data;
>> pragma Convention (C, Opaque_Pointer);
> [...]
>
> Looks good!
>
>> As far as I cen tell, Opaque_Pointer refers only to types compatibles
>> with C,
>
>> Or is there some trap in the above code that I'm missing?
>
> That according to AARM, the C counterpart needs to correspond to
> Opaque_Data, that is, a pointer to an empty struct with the same
> alignment requirements.
My approach in TASH[1] was to write a script in Tcl to write (at
installation) a C program which #include's tcl.h etc to generate an Ada
spec[2] containing eg
-- Size macros defined in tcl.h.
NUM_STATIC_TOKENS : constant := 20;
TCL_DSTRING_STATIC_SIZE : constant := 200;
-- Sizes of structs defined in tcl.h.
Tcl_Interp_Size : constant := 24;
Tcl_Interp_Alignment : constant := 8;
but this is only needed where the user has to declare an instance of an
object. Otherwise, and this must be especially true where the C type is
void *, the library gives you back a handle and your only responsibility
is to give it back when called for.
Typically I wrote
type Tcl_Interp_Rec (<>) is private;
type Tcl_Interp is access all Tcl_Interp_Rec;
pragma Convention (C, Tcl_Interp);
private
type Tcl_Interp_Rec is new Interfaces.C.char_array
(0 .. Tcl_Record_Sizes.Tcl_Interp_Size - 1);
for Tcl_Interp_Rec'Alignment
use Tcl_Record_Sizes.Tcl_Interp_Alignment;
I think I could easily have got away with
type Tcl_Interp_Rec is null record;
and left out all the size/alignment stuff!
[1] https://sourceforge.net/projects/tcladashell/
[2] this may have been a step further than necessary!
next prev parent reply other threads:[~2012-04-06 11:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 7:19 Dispatching callback handed over to C Natasha Kerensikova
2012-04-03 9:04 ` Brian Drummond
2012-04-03 9:21 ` Thomas Locke
2012-04-03 9:37 ` Maciej Sobczak
2012-04-03 12:02 ` Natasha Kerensikova
2012-04-03 14:42 ` Maciej Sobczak
2012-04-03 20:20 ` Randy Brukardt
2012-04-04 7:26 ` Georg Bauhaus
2012-04-04 7:56 ` Natasha Kerensikova
2012-04-04 19:28 ` Randy Brukardt
2012-04-05 8:59 ` Natasha Kerensikova
2012-04-05 21:04 ` Randy Brukardt
2012-04-04 19:55 ` Simon Wright
2012-04-04 11:34 ` Maciej Sobczak
2012-04-04 19:16 ` Randy Brukardt
2012-04-05 7:28 ` Maciej Sobczak
2012-04-05 21:32 ` Randy Brukardt
2012-04-07 8:55 ` Natasha Kerensikova
2012-04-07 11:32 ` Simon Wright
2012-04-07 13:28 ` Robert A Duff
2012-04-05 9:13 ` Natasha Kerensikova
2012-04-05 21:06 ` Randy Brukardt
2012-04-06 7:30 ` Maciej Sobczak
2012-04-06 11:41 ` Simon Wright [this message]
2012-04-10 7:15 ` Maciej Sobczak
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox