From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,73975695cdfcb86f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.205.123.6 with SMTP id gi6mr982216bkc.5.1334042111008; Tue, 10 Apr 2012 00:15:11 -0700 (PDT) Path: h15ni106780bkw.0!nntp.google.com!news2.google.com!postnews.google.com!d17g2000vba.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Dispatching callback handed over to C Date: Tue, 10 Apr 2012 00:15:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <09970dc6-94da-480d-a831-d87da7652a7f@d17g2000vba.googlegroups.com> References: <6fb83c74-b2a4-4ae8-9c89-d755b737198f@v22g2000vby.googlegroups.com> <85d1ad51-c02b-44fa-87b6-02aa1d8ba1b2@x17g2000vba.googlegroups.com> <62246369-6b9f-4a96-9c67-fd1774c02e78@k24g2000yqe.googlegroups.com> NNTP-Posting-Host: 213.77.7.66 Mime-Version: 1.0 X-Trace: posting.google.com 1334042110 2377 127.0.0.1 (10 Apr 2012 07:15:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 10 Apr 2012 07:15:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d17g2000vba.googlegroups.com; posting-host=213.77.7.66; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-04-10T00:15:10-07:00 List-Id: On 6 Kwi, 13:41, Simon Wright wrote: > 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 > =A0 =A0-- =A0Sizes of structs defined in tcl.h. > > =A0 =A0Tcl_Interp_Size : constant :=3D 24; > =A0 =A0Tcl_Interp_Alignment : constant :=3D 8; > > but this is only needed where the user has to declare an instance of an > object. I have implemented it dynamically - you can export a similar constant from C and read it from Ada in order to know the size of memory block to allocate. This can have an impact on some object-allocation language constructs, which will become runtime dependent (returning object from a function, for example), which is incompatible with the No_Implicit_Allocation pragma (part of Ravenscar), but in general-purpose code it works fine without the need to complicate the installation process. -- Maciej Sobczak * http://www.inspirel.com 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 > > =A0 =A0type Tcl_Interp_Rec (<>) is private; > =A0 =A0type Tcl_Interp is access all Tcl_Interp_Rec; > =A0 =A0pragma Convention (C, Tcl_Interp); > > private > > =A0 =A0type Tcl_Interp_Rec is new Interfaces.C.char_array > =A0 =A0 =A0(0 .. Tcl_Record_Sizes.Tcl_Interp_Size - 1); > =A0 =A0for Tcl_Interp_Rec'Alignment > =A0 =A0 =A0use Tcl_Record_Sizes.Tcl_Interp_Alignment; > > I think I could easily have got away with > > =A0 =A0type 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!