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,235855e3822c83d1 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.236.198 with SMTP id uw6mr658179pbc.3.1334088182501; Tue, 10 Apr 2012 13:03:02 -0700 (PDT) Path: r9ni41371pbh.0!nntp.google.com!news2.google.com!goblin3!goblin.stu.neva.ru!inn5.news.alteholz.net!easy.in-chemnitz.de!feeder.erje.net!feeder2.news.elisa.fi!fi.sn.net!newsfeed2.tdcnet.fi!news.song.fi!not-for-mail Date: Tue, 10 Apr 2012 23:02:15 +0300 From: Tero Koskinen Newsgroups: comp.lang.ada Subject: Re: Importing C function with variable argument list Message-Id: <20120410230215.502473d3a9f0287850900775@iki.fi> References: <610ee323-4c7f-413d-8568-aed4955f5152@z38g2000vbu.googlegroups.com> X-Newsreader: Sylpheed 3.2.0beta6 (GTK+ 2.24.8; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Organization: NBL Networks Oy NNTP-Posting-Host: 217.30.184.161 X-Trace: 1334088135 news.nbl.fi 2762 217.30.184.161:30814 X-Complaints-To: abuse@nblnetworks.fi Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: 2012-04-10T23:02:15+03:00 List-Id: Hi, On Tue, 10 Apr 2012 02:21:59 -0700 (PDT) Maxim Reznik wrote: > Hi, All > > It seems it's impossible to call C function variable argument lists > from Ada. > Even when one knows in advace all arguments at compile time. > > Functions with Variable Argument Lists have their own ABI. For > instance, in x86_64: > > > When a function taking variable-arguments is called, %rax must be set to the > > total number of floating point parameters passed to the function in vector registers. ... > But it's impossible to specify this fact in pragma Import (C, ... ... > What do you think? To work-around this, I use a small wrapper for x86_64 (Linux) environments in my curl bindings: https://bitbucket.org/tkoskine/curl-ada/src/ebd5156f7334/Makefile#cl-6 https://bitbucket.org/tkoskine/curl-ada/src/ebd5156f7334/utils/easywrap.pl https://bitbucket.org/tkoskine/curl-ada/src/ebd5156f7334/src/template/curl-easy.adb.tmpl#cl-144 Ada code is following: procedure curl_easy_setopt (C_Handle : CURL_Private_Access; C_Option : CURL.Options.CURL_Option_Type; C_Action : C_Action_Callback); pragma Import (C, curl_easy_setopt, "wrap_setopt"); procedure curl_easy_setopt_data (C_Handle : CURL_Private_Access; C_Option : CURL.Options.CURL_Option_Type; Data : Callback_Interface_Class_Access); pragma Import (C, curl_easy_setopt_data, "wrap_setopt"); And C wrapper: CURLcode wrap_setopt(CURL* handle, CURLoption option, void* param) { return curl_easy_setopt(handle, option, param); } For i386, I do s/wrap_setopt/curl_easy_setopt/ replacement before compiling: if ($Config{archname} =~ m/x86_86/) { $use_wrap = 1; } while (<>) { if ($use_wrap == 0) { $_ =~ s/wrap_setopt/curl_easy_setopt/g; } print $_; } -- Tero Koskinen - http://iki.fi/tero.koskinen/