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,235855e3822c83d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.230 with SMTP id sd6mr9608822pbc.8.1335545294366; Fri, 27 Apr 2012 09:48:14 -0700 (PDT) Path: r9ni105034pbh.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Natasha Kerensikova Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Date: Fri, 27 Apr 2012 16:48:13 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> <1288794.275.1334249936588.JavaMail.geo-discussion-forums@ynlp2> <87wr51a5yg.fsf@adaheads.sparre-andersen.dk> Mime-Version: 1.0 Injection-Date: Fri, 27 Apr 2012 16:48:13 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="Mda950WjNwNLAFOE7yJXQw"; logging-data="5249"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+30FD5WuoiOt+/KfulMSg" User-Agent: slrn/0.9.9p1 (FreeBSD) Cancel-Lock: sha1:oUk0GaursR4HX97179ub5KlDJJM= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: 2012-04-27T16:48:13+00:00 List-Id: Hello, On 2012-04-27, Jacob Sparre Andersen wrote: > I'm afraid I have to disappoint you. Your example (here with test > driver) works fine on Debian/stable (armv6l): OK. Let's pour in some more unsafety then (what an unusual for this forums, isn't it?) As I said, the previous example would fail to fail when C.short is actually the same type as C.int, so let's fix that by using C.signed_char, though I doubt that's the case here. It would also fail to fail the extra space required by the type promotion is already readable, so let's write stuff too. And lastly, some alignment constraints might also cover up a failure, so let's use several C.signed_char, assuming they will be packed. That leads to the following example: procedure Test is function Printf_Faulty (Format : in Interfaces.C.char_array; Value_1 : in Interfaces.C.signed_char; Value_2 : in Interfaces.C.signed_char; Value_3 : in Interfaces.C.signed_char; Result : out Interfaces.C.int) return Interfaces.C.int; pragma Import (C, Printf_Faulty, "printf"); Result, Bytes_Written : Interfaces.C.int; begin Bytes_Written := Printf_Faulty ("Values: %hhd, %hhd, %hhd\n%n", 42, 89, 5, Result); pragma Assert (Bytes_Written = Result); end Test; Of course there would still be no symptoms if the calling convention somehow already includes the type promotion. For example when the first few parameters are passed through registers rather than a stack, or when C.signed_char values have to be aligned like C.int. I guess that's about as far as we can go in terms of failure rate. Natasha