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,55a8252137b5ef97 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!194.168.222.134.MISMATCH!news-out.ntli.net!newsrout1-gui.ntli.net!ntli.net!newspeer1-win.ntli.net!newsfe6-gui.ntli.net.POSTED!53ab2750!not-for-mail From: "Dr. Adrian Wrigley" Subject: Re: Efficiently setting up large quantities of constant data User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.ada References: <2508656.W3VlADmtU1@jellix.jlfencey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Date: Fri, 17 Dec 2004 13:53:43 GMT NNTP-Posting-Host: 81.100.88.147 X-Complaints-To: http://www.ntlworld.com/netreport X-Trace: newsfe6-gui.ntli.net 1103291623 81.100.88.147 (Fri, 17 Dec 2004 13:53:43 GMT) NNTP-Posting-Date: Fri, 17 Dec 2004 13:53:43 GMT Organization: ntl Cablemodem News Service Xref: g2news1.google.com comp.lang.ada:7033 Date: 2004-12-17T13:53:43+00:00 List-Id: OK I have just tried this. I have a plain text file "NigeriaScam4.txt", which I turn into an object file "nigeria.o", and link in. (Source below) I encountered one or two problems: I can't access the "..._size" value. This is an absolute value in the object file, not the location where the value is stored. If I try to Import the size, the program crashes at runtime, because the size is incorrectly interpreted as the location of the variable storing the size. The code works, but seems a bit messy. Calculating the size is a nuisance, and I can't "import" the Message (local type is not constant). Aside from these issues, the code works. The program outputs the contents of the text file as built into the executable. Any ideas for: 1) Importing the value of the ..._size symbol 2) Making the contents constant 3) Tidying it up a bit note that writing into the Message is possible, but probably shouldn't be. (is there an option to make the data read-only?) Of course, the Message could be copied into another value which was constant, but that would be wasteful. Or an access to constant value could be used. Thanks -- Adrian (using GNAT 3.15p on Athlon/Linux) with Text_IO; with System.Storage_Elements; -- Start out with two files, this source file, and a simple -- text file, NigeriaScam4.txt -- -- Build executable by creating object file containing txt data -- using objcopy. Include object file in link. -- -- objcopy --input-target=binary --binary-architecture=i386 --output-target=elf32-i386 NigeriaScam4.txt nigeria.o -- gnatmake demo procedure Demo is pragma Linker_Options ("nigeria.o"); Name : constant String := "NigeriaScam4_txt"; use System.Storage_Elements; MessageStart, MessageEnd : Character; pragma Import (C, MessageStart, "_binary_" & Name & "_start"); pragma Import (C, MessageEnd, "_binary_" & Name & "_end"); Message : String (1 .. Integer (MessageEnd'Address-MessageStart'Address)); for Message'Address use MessageStart'Address; begin Text_IO.Put_Line ("Length was : " & Integer'Image (Message'Length)); Text_IO.Put_Line ("Message was : " & Message); end Demo;