www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Seg-fault interfacing C library (GSL)

reply "Stephan" <ss27 sanger.ac.uk> writes:
Hi,

I am currently trying to call functions from the GNU Scientific
Library (GSL) with my code, and I observed a very strange
behaviour. The following test-program compiles, but generates a
Segmentation fault when run.


gsltest.d
--------------------------
import std.stdio;

extern (C) double gsl_sf_hyperg_2F1(double a, double b, double c,
double x);

void main() {
   double f = 0.0025;
   // The following line causes a crash
   auto ret = f * gsl_sf_hyperg_2F1(1.0, 10.0, 11.0, 1.0 - f /
0.025);

   // The following line should be identical, but it does not
cause the seg fault.
   // auto ret = 0.0025 * gsl_sf_hyperg_2F1(1.0, 10.0, 11.0, 1.0 -
f / 0.025);

   writeln(ret);
}
---------------------------

If you comment out the crashing line and comment in the line
below, the program runs and returns 0.015681, which is the
numerically correct result.

To compile and run the code, I used the following command line:

rdmd -L-L/opt/local/lib -L-lgsl -L-lgslcblas gsltest.d


I tested this on Unix and Mac OS X. Can anyone reproduce the
error and have an idea what is going on?

Cheers,

Stephan
May 26 2012
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday, May 26, 2012 18:41:34 Stephan wrote:
 Hi,
Please do not post to this list directly. It's intended for those wishing to receive updates to all of the bug reports on bugzilla. If you have a question about learning d, please post it in digitalsmarsD.Learn. If you have a question or something that you want to discuss about D in general, then post it in digitalmars.D. And if you have a bug report, please report it on bugzilla ( http://d.puremagic.com/issues ). - Jonathan M Davis
May 26 2012
parent "Stephan" <ss27 sanger.ac.uk> writes:
OK, sorry. I will post it on bugzilla then.

Best,

Stephan

On Saturday, 26 May 2012 at 18:12:20 UTC, Jonathan M Davis wrote:
 On Saturday, May 26, 2012 18:41:34 Stephan wrote:
 Hi,
Please do not post to this list directly. It's intended for those wishing to receive updates to all of the bug reports on bugzilla. If you have a question about learning d, please post it in digitalsmarsD.Learn. If you have a question or something that you want to discuss about D in general, then post it in digitalmars.D. And if you have a bug report, please report it on bugzilla ( http://d.puremagic.com/issues ). - Jonathan M Davis
May 26 2012