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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a6b:f00b:: with SMTP id w11-v6mr10511295ioc.31.1528120982584; Mon, 04 Jun 2018 07:03:02 -0700 (PDT) X-Received: by 2002:aca:a883:: with SMTP id r125-v6mr573490oie.7.1528120982383; Mon, 04 Jun 2018 07:03:02 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u74-v6no5165500itb.0!news-out.google.com!z3-v6ni611iti.0!nntp.google.com!u74-v6no5165498itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 4 Jun 2018 07:03:02 -0700 (PDT) In-Reply-To: <564cec8c-8da9-4e59-a687-5408fd3a429f@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=47.185.233.194; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 47.185.233.194 References: <564cec8c-8da9-4e59-a687-5408fd3a429f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <53a67bab-44f5-4199-b89d-b30de04a7f89@googlegroups.com> Subject: =?UTF-8?B?UmU6ICJQbHVnaW7CsC1iYXNlZCBjb2Rl?= From: "Dan'l Miller" Injection-Date: Mon, 04 Jun 2018 14:03:02 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:52923 Date: 2018-06-04T07:03:02-07:00 List-Id: On Monday, June 4, 2018 at 5:29:26 AM UTC-5, mockturtle wrote: > Dear.all,=20 > I have a doubt about what it could be the best solution for some code tha= t I am writing. I am afraid that the introduction before the actual questi= on is a bit long. =20 >=20 > ** The problem ** >=20 > Let me use an example. Suppose I am writing a program to plot, say, a GA= NTT chart. I want the user to be able to choose the output format (say, PD= F, SVG or even LaTeX) by giving a suitable option on the command line and I= want to be able to add new output format easily, maybe even load the "form= at handler" as a dynamic library at run-time (so I do not need recompilatio= n). (Incidentally, I did some experiments with the dynamic loading and it = works) >=20 > The structure I give to the code is as follows: first I define an interfa= ce for an "abstract plotter," for example >=20 > package Plotters is=20 > type Abstract_Plotter is interface; >=20 > procedure Line(P: Abstract_Plotter; > X1,Y1, X2, Y2:Float)=20 > is abstract; >=20 > -- And so on... > end Plotters; >=20 > Every actual plotter will be a descendant of Abstract_Plotters, for examp= le >=20 > package Plotters.SVG is > type SVG_Plotter is=20 > new Abstract_Plotter with private; >=20 > -- Blah, blah ... > end Plotters.SVG; >=20 > In order to allow the user to select the actual plotter via the command l= ine I use a generic package Plugin_Table that implements a kind of "map" fr= om names to descendant of Abstract_Plotter. Plugin_Table provides two oper= ations: >=20 > (1) Register_Plugin(T: Tag; Name: String) =20 >=20 > used by a concrete plotter to "register" itself to the table. U= sually it is called from the "initialization" part of the body of the packa= ge definynig the concrete plotter. For example, plotters-svg.adb could cal= l >=20 > Register_Plugin(SVG_Plotter'Tag, "svg"); >=20 > (2) Get_Plugin (Name:String) return Abstract_Plotter'Class >=20 > to be called to generate a concrete plotter. >=20 > In a future version Plugin_Table will be able to search for some dynamic = library to be loaded if a plugin with the given name is not registered. >=20 > ** The Question **=20 >=20 > In order to have all the built-in plugins registered in my executable, I = need to "with" them, No, that would make them elaborated too soon. You want to delay the elabor= ation to run-time, so that the DLL's link-load/elaboration occurs far after= the link-load/elaboration of the executable. Although your intuition is correct regarding what needs to happen: > so that they are linked to my code and the initialization part of their b= odies is elaborated. However, no part of my code call explicitly, say, SVG_= Plotter. Therefore, my solution is to add something like >=20 > with Plotters.SVG; > pragma Warnings(Off, Plotter.SVG); >=20 > in the "main." It works, but it leaves me a bit unsatisfied since it seem= s an "hack". Also, since no actual code is called directly I am not sure i= f the binder could take the liberty of not including them (maybe it cannot,= but I am not sure). >=20 > Do you have any better solution? https://stackoverflow.com/questions/18141643/create-an-dll-written-in-ada The StackOverflow question above points in the correct direction regarding = the creation of a DLL (e.g., .so file) with GNAT*. Next, link-load the DLL at run-time. For GNAT, that is covered for Microso= ft Windows at: https://gcc.gnu.org/onlinedocs/gnat_ugn/Building-DLLs-with-gnatdll.html =E2=80=A6 or for operating systems with .so shared-libraries (e.g., Linux, = Unix, MacOS X**), that is covered for GNAT* at: https://www.adacore.com/gems/gem-109-ada-plug-ins-and-shared-libraries-part= -1 and https://www.adacore.com/gems/gem-110-ada-plug-ins-and-shared-libraries-part= -2 * If you are using some other vendor's nonGNAT Ada compiler, the technique = would be somewhat similar. ** MacOS X has both .so shared libraries from BSD Unix heritage and .dylib = (Dylan libraries) from MachO heritage. Presumably the .dylib approach woul= d strongly resemble much of the .so approach, but .dylib is probably intere= sting only if mixing Ada with Objective-C or with Swift (which you did not = mention), and then the .dylib would need be supplemented Objective-C runtim= e framework API. If Ada-to-Ada strictly =E2=80=98on the backend processing= =E2=80=99 not invocable by UI/UX from Swift or from Objective-C, then stick= with .so shared libraries in MacOS if at all possible. And there is no de= bugger support on iDevices for GNAT (due to lack of LLDB support, due in tu= rn to lack of modern LLVM backend for GNAT), so don't even think about iOS = for the foreseeable future, which might be foreshadowing an increasing prob= lem when/if MacOS too goes to ARM: https://www.TheInquirer.net/inquirer/news/3033362/apple-reportedly-poaches-= senior-intel-staff-for-secret-oregon-hardware-lab > Also, I am not sure if I risk getting in trouble with Elaboration order. = I think not, but I am not 100% sure. > What do you think? The FSF & AdaCore references above seem to thoroughly cover elaboration ord= er. The topic gets impractically complex in GNAT if the DLL/.so creates it= s own Ada tasks, so avoid doing that by creating any needed Ada tasks in th= e parent executable instead.