From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: hreba Newsgroups: comp.lang.ada Subject: Plugin with controlled variable for initialization. Date: Wed, 2 Feb 2022 18:21:03 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net QJ9L1dzGWHM7V0PbG/hRCA+Z9D3+DIVezJETzW9+nPqw8TDMNd Cancel-Lock: sha1:QagPJ9/9xf5/c2x0XNG8JhQk7+I= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-GB Xref: reader02.eternal-september.org comp.lang.ada:63442 List-Id: For the plugin scheme in my actual program I worked along the corresponding gnat example, but while the original works, mine doesn't. So I boiled it down to a minimum. plugin.ads ---------- package Plugin is procedure Empty; end Plugin; plugin.adb ---------- with Ada.Finalization; with Ada.Text_IO; package body Plugin is type Life_Controller is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (lc: in out Life_Controller); overriding procedure Finalize (lc: in out Life_Controller); procedure Empty is begin null; end Empty; overriding procedure Initialize (lc: in out Life_Controller) is begin Ada.Text_IO.Put_Line("Hello world!"); end Initialize; overriding procedure Finalize (lc: in out Life_Controller) is begin Ada.Text_IO.Put_Line("Bye world!"); end Finalize; lc: Life_Controller; end Plugin; main.adb -------- with System; with Interfaces.C.Strings; with Ada.Text_IO; procedure Main is use type System.Address; RTLD_LAZY: constant := 1; handle: System.Address; function dlopen (Lib_Name: String; Mode: Interfaces.C.int) return System.Address; pragma Import (C, dlopen, "dlopen"); begin handle:= dlopen ("../Plugin/lib/libplugin.so" & ASCII.NUL, RTLD_LAZY); if handle = System.Null_Address then Ada.Text_IO.Put_Line("unable to load plugin"); end if; end Main; Main executes without any output. My understanding is the following: - When plugin loading with dlopen fails, I get an error message. - Otherwise, the controlled variable lc in plugin.adb comes to life and I get an output from the Initialize procedure. Where is my misconception? -- Frank Hrebabetzky, Kronach +49 / 9261 / 950 0565