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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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,UTF8 Received: by 10.68.74.201 with SMTP id w9mr6291909pbv.0.1333712492340; Fri, 06 Apr 2012 04:41:32 -0700 (PDT) Path: r9ni25011pbh.0!nntp.google.com!news2.google.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Dispatching callback handed over to C Date: Fri, 06 Apr 2012 12:41:29 +0100 Organization: A noiseless patient Spider Message-ID: 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> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="6405"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pWdDUyE8B2+nn6U3+9sW3cOJX8VqTCmY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:91tVG0gjwu+ogLRcSdN5xd4I5jQ= sha1:cHicxEhr5EnlzpeNvurt4WBToNY= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Date: 2012-04-06T12:41:29+01:00 List-Id: Maciej Sobczak writes: > On 5 Kwi, 11:13, Natasha Kerensikova 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!