public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* [Help Request]: GSL_RANGE_CHECK_OFF ?
@ 2004-06-02 10:08 Raimondo Giammanco
  2004-06-02 11:23 ` Brian Gough
  0 siblings, 1 reply; 6+ messages in thread
From: Raimondo Giammanco @ 2004-06-02 10:08 UTC (permalink / raw)
  To: gsl-discuss; +Cc: rongten

Hello,

 I am currently developing a small code using gsl, and was doing some
tests about the range checking, finding a strange behavior.

 I admit I am not using C from long time so it is possible that I am
asking a stupid question, in this case I apologize in advance.

 I have gsl 1.4 compiled on a Gentoo Base System version 1.4.10,
with gcc version 3.3.2 20031218 (Gentoo Linux 3.3.2-r5, propolice-3.3-7)
and glibc 2.3.2 on kernel 2.4.26.

 According to the documentation, if I compile a program  with
-DGSL_RANGE_CHECK_OFF, I should jump the range checking with 
hopefully beneficial effects on performance.

 However, when I run a program with an out of bound access,
the program, compiled with or without this macro declaration
gives me always the same error :

gsl: vector_source.c:29: ERROR: index out of range
Default GSL error handler invoked.
Aborted


Now, in /usr/include/gsl there is no mention GSL_RANGE_CHECK_OFF, only 
of GSL_RANGE_CHECK. Looking in the tar archive, I do find a mention
to GSL_RANGE_CHECK_OFF, but this recalls GSL_RANGE_CHECK.. I do not
really understand.

So the question is, I am doing some mistake without realizing it , or I
have an installation that somehow is broken? I have looked to the
install script and it does not do anything fancy, in other words
it uses mostly the default settings.

On a side note, since the index is a size_t, the checking is performed
only to see if the requested index is bigger than the admissible value.

What happens if at runtime to requested index is assigned a negative
number? It is promoted to unsigned and therefore automatically is a
very big number? I know I should look elsewhere for this answer, but 
since this question is somehow linked to the main topic..

Thanks in advance.

Raimondo Giammanco

-- 
Raimondo Giammanco <rongten@member.fsf.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Help Request]: GSL_RANGE_CHECK_OFF ?
  2004-06-02 10:08 [Help Request]: GSL_RANGE_CHECK_OFF ? Raimondo Giammanco
@ 2004-06-02 11:23 ` Brian Gough
  2004-06-02 14:38   ` Raimondo Giammanco
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Gough @ 2004-06-02 11:23 UTC (permalink / raw)
  To: Raimondo Giammanco; +Cc: gsl-discuss

Raimondo Giammanco writes:
 > Now, in /usr/include/gsl there is no mention GSL_RANGE_CHECK_OFF, only 
 > of GSL_RANGE_CHECK. Looking in the tar archive, I do find a mention
 > to GSL_RANGE_CHECK_OFF, but this recalls GSL_RANGE_CHECK.. I do not
 > really understand.

The documentation is unfortunately out of date there.  For maximum
speed use -DHAVE_INLINE=1 -DGSL_RANGE_CHECK=0 (the default) when
compiling your application.

I will try to put something in for backwards compatibility with
GSL_RANGE_CHECK_OFF.

 > On a side note, since the index is a size_t, the checking is performed
 > only to see if the requested index is bigger than the admissible value.
 > 
 > What happens if at runtime to requested index is assigned a negative
 > number? It is promoted to unsigned and therefore automatically is a
 > very big number? I know I should look elsewhere for this answer, but 
 > since this question is somehow linked to the main topic..

The warning option -Wconversion should detect that at compile-time.

-- 
Brian Gough

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Help Request]: GSL_RANGE_CHECK_OFF ?
  2004-06-02 11:23 ` Brian Gough
@ 2004-06-02 14:38   ` Raimondo Giammanco
  2004-06-02 15:23     ` Brian Gough
  0 siblings, 1 reply; 6+ messages in thread
From: Raimondo Giammanco @ 2004-06-02 14:38 UTC (permalink / raw)
  To: Brian Gough; +Cc: gsl-discuss

On Wed, 2004-06-02 at 13:11, Brian Gough wrote:

>  > Now, in /usr/include/gsl there is no mention GSL_RANGE_CHECK_OFF, only 
>  > of GSL_RANGE_CHECK. Looking in the tar archive, I do find a mention
>  > to GSL_RANGE_CHECK_OFF, but this recalls GSL_RANGE_CHECK.. I do not
>  > really understand.
> 
> The documentation is unfortunately out of date there.  For maximum
> speed use -DHAVE_INLINE=1 -DGSL_RANGE_CHECK=0 (the default) when
> compiling your application.
> 

 I see. I thought it was strange that "if" with HAVE_INLINE, 
with respect to what the manual was saying, so I tried
-DSL_RANGE_CHECK=0 but did not add -DHAVE_INLINE. 
Shouldn't the configure figure out if the compiler supports 
inlining, and behave accordingly?

In any case, I will follow your suggestion.

> The warning option -Wconversion should detect that at compile-time.

Yes, like when I declare size_t i and after I declare i=-1;
but I will have still to see what happens if at runtime i=a; where
int a and a is negative.. damn laziness.

In any case thanks very much Mr. Gough, I will report back in case
further difficulties should arise.

Best Regards,

-- 
Raimondo Giammanco <rongten@member.fsf.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Help Request]: GSL_RANGE_CHECK_OFF ?
  2004-06-02 14:38   ` Raimondo Giammanco
@ 2004-06-02 15:23     ` Brian Gough
  2004-06-04 12:53       ` Raimondo Giammanco
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Gough @ 2004-06-02 15:23 UTC (permalink / raw)
  To: Raimondo Giammanco; +Cc: gsl-discuss

Raimondo Giammanco writes:
 >  I see. I thought it was strange that "if" with HAVE_INLINE, 
 > with respect to what the manual was saying, so I tried
 > -DSL_RANGE_CHECK=0 but did not add -DHAVE_INLINE. 
 > Shouldn't the configure figure out if the compiler supports 
 > inlining, and behave accordingly?

The configure script checks for 'inline' when compiling the library
itself, but there is no way to do an equivalent check for user
applications.

-- 
Brian Gough

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Help Request]: GSL_RANGE_CHECK_OFF ?
  2004-06-02 15:23     ` Brian Gough
@ 2004-06-04 12:53       ` Raimondo Giammanco
  2004-06-04 16:08         ` Brian Gough
  0 siblings, 1 reply; 6+ messages in thread
From: Raimondo Giammanco @ 2004-06-04 12:53 UTC (permalink / raw)
  To: gsl-discuss

Hell Mr. Gough,

 Just to say that I have tested the "-DGSL_RANGE_CHECK=0
-DHAVE_INLINE=1" for having the optimized code, and now 
indeed the checks are removed, as valgrind confirms when 
accessing after the end of the gsl vectors.

 For good measure, I am using "-DGSL_RANGE_CHECK=1 -DHAVE_INLINE=1"
for the debug version of the code as well. 

Thank you very much for your help

-- 
Raimondo Giammanco <rongten@member.fsf.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Help Request]: GSL_RANGE_CHECK_OFF ?
  2004-06-04 12:53       ` Raimondo Giammanco
@ 2004-06-04 16:08         ` Brian Gough
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Gough @ 2004-06-04 16:08 UTC (permalink / raw)
  To: gsl-discuss; +Cc: Raimondo Giammanco

Raimondo Giammanco writes:
 >  Just to say that I have tested the "-DGSL_RANGE_CHECK=0
 > -DHAVE_INLINE=1" for having the optimized code, and now 
 > indeed the checks are removed, as valgrind confirms when 
 > accessing after the end of the gsl vectors.
 > 
 >  For good measure, I am using "-DGSL_RANGE_CHECK=1 -DHAVE_INLINE=1"
 > for the debug version of the code as well. 

Incidentally, while we are on this subject I should mention to the
list that I recently started using the C bounds-checking extension to
GCC listed at http://gcc.gnu.org/extensions.html

It works well, I find it very convenient as it can be mixed with
existing libraries.  Previously I used to use "checkergcc", which was
specific to x86 and not maintained --- the new extension is much
better.

For reference, I have posted a short article about it at
http://www.network-theory.co.uk/articles/boundschecking.html

I would recommend this patch to GCC.  I found a bug in GSL using it
(an off-by-one array overflow in gsl_randist_landau).

N.B. it works for C only, not C++.

-- 
Brian Gough

Network Theory Ltd,
Publishing Free Software Manuals --- http://www.network-theory.co.uk/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-06-04 16:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-02 10:08 [Help Request]: GSL_RANGE_CHECK_OFF ? Raimondo Giammanco
2004-06-02 11:23 ` Brian Gough
2004-06-02 14:38   ` Raimondo Giammanco
2004-06-02 15:23     ` Brian Gough
2004-06-04 12:53       ` Raimondo Giammanco
2004-06-04 16:08         ` Brian Gough

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).