comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: generic provokes segmentation fault
Date: Sun, 17 May 2020 20:34:08 +0200
Date: 2020-05-17T20:34:08+02:00	[thread overview]
Message-ID: <r9s02u$j01$1@gioia.aioe.org> (raw)
In-Reply-To: hicvepF6b7sU1@mid.individual.net

On 2020-05-17 16:19, hreba wrote:

> I'll try to describe the problem without posting loads of code. Still 
> working on my thick binding of GSL/Odeiv2, the API of my package odeiv2 
> consists of 3 procedures:
>   - Init_Solve
>   - Solve
>   - Finit_solve
> They basically copy values to variables which are global in odeiv, and 
> pass their addresses to the C library functions of the thin binding. 

Well, that is certainly not good. IMO it is not Ada way to do this and 
it does not look like intended way of odeiv2 either. I looked shortly 
the interface of. It is decently designed and has operations to allocate 
a new structure and free it.

As a side note. It is not clear if the structure must be allocated in 
the C's memory pool. I would not experiment with that. Which could be 
reason for memory corruption on its own. That is frequently the case 
when the library has some bookkeeping attached to memory allocation.

But clearly the proper way to write an Ada binding to this would be a 
Limited_Controlled object. It would allocate the C object(s) in its 
Initialize using the official library call (or at some later point, e.g. 
on demand) and free them in the Finalize, again by the official means.

> generic
>     dim:    Positive;
>     type Float is digits<>;
> package odeiv2 is

I don't see any reason making it generic. The C library can only double. 
It does not make much sense to have a generic instance for Float, 
Long_Float, IEEE_Float_32 etc if the underlying computations are all double.

> raised STORAGE_ERROR : stack overflow or erroneous memory access
> (SIGSEV, segmentation fault, when run under the debugger)
> just at the line starting "status:= ..." shown above.
> What would be an explication or a remedy for this behaviour?

In the code you posted the parameter n in the call is missing. If that 
is not a typo error in your post, then you have got the stack mangled.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2020-05-17 18:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 14:19 generic provokes segmentation fault hreba
2020-05-17 17:51 ` Dennis Lee Bieber
2020-05-17 18:34 ` Dmitry A. Kazakov [this message]
2020-05-18 11:29   ` hreba
2020-05-18 12:36     ` Dmitry A. Kazakov
2020-05-18 20:16       ` hreba
2020-05-18 21:30         ` Dmitry A. Kazakov
2020-05-17 21:02 ` Jeffrey R. Carter
2020-05-18 20:21   ` hreba
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox