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 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: generic provokes segmentation fault Date: Mon, 18 May 2020 23:30:35 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: 2uCIJahv+a4XEBqttj5Vkw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:58740 Date: 2020-05-18T23:30:35+02:00 List-Id: On 2020-05-18 22:16, hreba wrote: > On 2020-05-18 14:36, Dmitry A. Kazakov wrote: > >> What is global variables you are talking about? gsl_odeiv2_driver >> seems to be allocated and initialized using library functions. > > Initially, I tried the following: > >  - the library defines a type with that driver as a private component >  - the client declares a variable of that type >  - the client calls the library's initialization function, which >    instanciates this variable (and the driver within) > > I just was not able to get around that local/non-local object/pointer > problem, and for now the driver is a global variable hidden in the > library, initialized as a side effect of Init_Solve, as a workaround. This what possibly crashes it because you don't not use official "constructors". As I said it should be kind of type Driver is new Ada.Finalization.Limited_Controlled with private; procedure Apply (Object : in out Driver; ...); procedure Set (Object : in out Driver; ...); -- Set standard driver procedure Set (Object : in out Driver; ...); -- Set scaled driver ... overriding procedure Finalize (Object : in out Driver); private type gsl_odeiv2_driver_struct is record ... end record; pragma Convention (C, gsl_odeiv2_driver_struct); type gsl_odeiv2_driver is access all gsl_odeiv2_driver_struct; pragma Convention (C, gsl_odeiv2_driver); type Driver is new Ada.Finalization.Limited_Controlled with record odeiv2 : gsl_odeiv2_driver; end record; procedure Set (Object : in out Driver; ...) is begin if Object.odeiv2 /= null then -- Delete old, if any gsl_odeiv2_driver_free (Object.odeiv2); -- Could store and Object.odeiv2 := null; -- check its type end if; Object.odeiv2 := gsl_odeiv2_driver_alloc_standard_new (...); end Set ; procedure Finalize (Object : in out Driver) is begin if Object.odeiv2 /= null then gsl_odeiv2_driver_free (Object.odeiv2); Object.odeiv2 := null; end if; end Initialize; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de