From: hreba <f_hreba@yahoo.com.br>
Subject: Interfaces.C + generics: stack overflow
Date: Thu, 23 Mar 2017 08:43:10 +0100
Date: 2017-03-23T08:43:10+01:00 [thread overview]
Message-ID: <ejhckeF1tg7U1@mid.individual.net> (raw)
My last posting was buried deep inside the thread and somewhat lengthy,
so here in a compact form. What works is (everything compiles and test
application executes):
--------------------------------------------------------------------
with Interfaces;
package GSL is
subtype Real is Interfaces.IEEE_Float_32;
gsl_Ex: Exception;
error_code: Integer; -- of the last operation
type Real_Function is access function (x: Real) return Real;
procedure Integration_QNG
(f: Real_Function;
a, b, epsabs, epsrel: Real;
result, abserr: out Real;
neval: out Natural);
end GSL;
---------------------------------------------------------------------
Now when pass the type real as a generic parameter:
---------------------------------------------------------------------
generic
type Real is digits <>;
when not used.
package GSL is
...
---------------------------------------------------------------------
and instanciate GSL with exactly the same type as above, I get a
STORAGE_ERROR : stack overflow or erroneous memory access.
I wrote a simpler example too, where just a function (gsl_bessl_j0) is
called from the C library, and no function reference is passed as a
parameter. This worked in the non-generic as well in the generic version.
For completeness, here follows the body of GSL
----------------------------------------------------------------------
with Interfaces.C; use Interfaces;
package body GSL is
type Void_Ptr is access all Integer;
pragma Convention (C, Void_Ptr);
type GSL_Inner_Function is
access function (x: C.double; params: Void_Ptr) return C.double;
pragma Convention (C, GSL_Inner_Function);
type GSL_Function is record
func: GSL_Inner_Function;
params: Void_Ptr;
end record;
real_func: Real_Function;
---------------------------------------------------------------------
-- Auxiliary Subprograms
---------------------------------------------------------------------
function func (x: C.double; params: Void_Ptr) return C.double;
pragma Convention (C, func);
function func (x: C.double; params: Void_Ptr) return C.double is
begin return C.double (real_func (Real(x)));
end func;
function gsl_integration_qng
(f: access GSL_Function;
a, b, epsabs, epsrel: C.double;
result, abserr: out C.double;
neval: out C.size_t)
return C.int;
pragma Import (C, gsl_integration_qng, "gsl_integration_qng");
---------------------------------------------------------------------
-- Exported Subprograms
---------------------------------------------------------------------
procedure Integration_QNG
(f: Real_Function;
a, b, epsabs, epsrel: Real;
result, abserr: out Real;
neval: out Natural)
is
use type C.int;
gslf: aliased GSL_Function;
status: C.int;
res, ae: C.double;
ne: C.size_t;
begin
real_func:= f;
gslf.func:= func'Access;
gslf.params:= null;
status:= gsl_integration_qng
(gslf'Access,
C.double(a), C.double(b), C.double(epsabs), C.double(epsrel),
res, ae, ne);
if status /= 0 then
error_code:= Integer (status);
raise gsl_Ex with
"gsl_integration_qng() returns error code " & C.int'Image(status);
end if;
result:= Real(res);
abserr:= Real(ae);
neval:= Natural(ne);
end Integration_QNG;
----------------------------------------------------------------------
--
Frank Hrebabetzky +49 / 6355 / 989 5070
next reply other threads:[~2017-03-23 7:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-23 7:43 hreba [this message]
2017-03-23 7:46 ` Interfaces.C + generics: stack overflow hreba
2017-03-23 17:45 ` Jeffrey R. Carter
2017-03-24 12:20 ` hreba
2017-03-23 20:03 ` Randy Brukardt
2017-03-24 12:42 ` hreba
2017-03-24 20:13 ` Randy Brukardt
2017-03-24 22:03 ` Dmitry A. Kazakov
2017-03-25 14:17 ` hreba
2017-03-25 15:21 ` hreba
2017-03-26 22:34 ` Robert Eachus
2017-03-27 7:21 ` Dmitry A. Kazakov
2017-03-30 17:12 ` Robert Eachus
2017-03-25 15:23 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox