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.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,130283ad9c6c2e69 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-20 06:35:22 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!ncar!csn!boulder!news.coop.net!news.den.mmc.com!iplmail.orl.mmc.com!alcyone!rgilbert From: rgilbert@orl.mmc.com (Bob Gilbert) Newsgroups: comp.lang.ada Subject: Re: Interfacing Ada to Unix/execl var. arg Date: 20 Oct 1994 12:42:25 GMT Organization: Martin Marietta Orlando Distribution: world Message-ID: <385ojh$2p8@theopolis.orl.mmc.com> References: <3823s3$ioq@goanna.cs.rmit.oz.au> Reply-To: rgilbert@orl.mmc.com NNTP-Posting-Host: alcyone.orl.mmc.com Date: 1994-10-20T12:42:25+00:00 List-Id: In article ioq@goanna.cs.rmit.oz.au, Dale Stanbrough () writes: -> ->The main problem lies in here - how do you assemble the various ->arguments into a call to a pragma import'ed C routine? -> ->The only solution appears to be to direct pass parameters via ->aggregates (as your solution suggests) and then call an equivalent ->non-variable argument list function (e.g. execl - execv). -> ->The code below works, but I am unsure of whether it is memory safe, ->and whether all memory gets reclaimed at the end of the function. -> -> ->function execv( path :string; -> argv :string_array := null_arg_list) return integer is -> -> C_path :constant interfaces.c.char_array(1..path'length+1) -> := interfaces.c.to_C(path); -> type address_array is array(1..argv'length + 1) of system.address; -> -> C_argv :address_array; -> index :integer; -> -> ------------------------------------------------------------ -> function C_execv( path :system.address; -> C_arg_list:system.address) -> return interfaces.c.int; -> pragma import(C, C_execv, "execv"); -> ------------------------------------------------------------ ->begin -> -- set up the array of pointers to the strings -> index := 0; -> for i in argv'range loop -> index := index + 1; -> -- can Ada release the memory pointed returned by -> -- interfaces.c.to_c after the loop (leaving the pointer -> -- pointing at nothing), or will it wait until the end of -> -- the function, or will it never free up the memory? -> -> C_argv(index) := interfaces.c.to_c(argv(i).all)(0)'address; -> end loop; -> -> -- append C style null to the end of the array of addresses -> -- (presumes that system.null_address = C style null). -> -> C_argv(C_argv'last) := system.null_address; -> -> -- pass the address of the first element of each -> -- parameter, as C expects. -> -> return integer(C_execv( C_path(1)'address, -> C_argv(1)'address)); ->end execv; -> -> ->Thanks, -> ->Dale Does interfaces.c.to_c cause memory to be allocated? If not, then there is no problem since the array C_argv is created on the calling stack and released upon exit from the function execv. -Bob