Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XS seems not to like 'double' #4570

Open
p5pRT opened this issue Nov 10, 2001 · 2 comments
Open

XS seems not to like 'double' #4570

p5pRT opened this issue Nov 10, 2001 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 10, 2001

Migrated from rt.perl.org#7894 (status was 'open')

Searchable as RT7894$

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2001

From grommel@sears.com

-----------------------------------------------------------------

I am trying to rewrite Math​::Random, which now uses files generated by
SWIG, to use vanilla XS instead. The generated code for functions
that return doubles (NV's) is behaving very strangely indeed.

Much more detail is available if you want, but here are the most
relevant portions.

=== 1 of 6​: from Random.pm
  return genunf($low,$high);

=== 2 of 6​: from Random.xs
double
genunf (low,high)
  INPUT​:
  double low
  double high

=== 3 of 6​: generated code in Random.c
XS(XS_Math__Random_genunf)
{
  dXSARGS;
  if (items != 2)
  Perl_croak(aTHX_ "Usage​: Math​::Random​::genunf(low, high)");
  {
  double low = (double)SvNV(ST(0));
  double high = (double)SvNV(ST(1));
  double RETVAL;
  dXSTARG;

  RETVAL = genunf(low, high);
  XSprePUSH; PUSHn((double)RETVAL);
  }
  XSRETURN(1);
}

=== 4 of 6​: C function from randlib.c
double genunf(double low,double high)
{
static double genunf;

  if(!(low > high)) goto S10;
  fprintf(stderr,"LOW > HIGH in GENUNF​: LOW %16.6E HIGH​:
%16.6E\n",low,high);
  fputs("Abort\n",stderr);
  exit(1);
S10​:
  genunf = low+(high-low)*ranf();
  printf("in randlib, genunf about to return %f\n", genunf);
  return genunf;
}

=== 5 of 6​: from test.pl
print "random_uniform..................";
@​result = random_uniform(3, 0, 1.5);
  print "result was @​result ! expected 0.02021, 0.72981, 0.28370\n";
was_it_ok(2, eq5a(@​result, 0.02021, 0.72981, 0.28370));

=== 6 of 6​: output of 'make test'
random_uniform..................in randlib, genunf about to return 0.020208
in randlib, genunf about to return 0.729815
in randlib, genunf about to return 0.283704
result was 44 44 44 ! expected 0.02021, 0.72981, 0.28370
not ok 2

=== [end of outputs]

Now why on earth would the XS code think that RETVAL was 44 in all
of these cases? This seems to happen only when the return type of
the function is 'double'; longs work just fine.

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl v5.6.1 - Mon Oct  8 18:23:37 EDT 2001
It is being executed now by  Perl v5.6.1 - Wed Oct 31 09:33:20 EST 2001.

Site configuration information for perl v5.6.1:

Configured by priluts at Wed Oct 31 09:33:20 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=svr4.0, osvers=3.0, archname=4400-svr4.0-64all
    uname='s11a104 s11a104 4.0 3.0 4400 pentium ii(tm)-isapci '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
  Compiler:
    cc='/usr/bin/cc', ccflags ='-I/usr/include -I/usr/ucbinclude
-DDEBUGGING',
    optimize='-g',
    cppflags='-I/usr/include -I/usr/ucbinclude -DDEBUGGING'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=4, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='/usr/bin/cc', ldflags ='-L/usr/ccs/lib -L/usr/ucblib
-L/usr/local/lib -L/usr/gnu/lib'
    libpth=/usr/local/lib /usr/gnu/lib /lib /usr/lib /usr/ccs/lib
/usr/ucblib
    libs=-lsocket -lnsl -ldbm -ldl -lld -lm -lc -lcrypt -lucb -lx
    perllibs=-lsocket -lnsl -ldl -lld -lm -lc -lcrypt -lucb -lx
    libc=, so=so, useshrplib=true, libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-KPIC', lddlflags='-G -L/usr/ccs/lib -L/usr/ucblib
-L/usr/local/lib -L/usr/gnu/lib'

Locally applied patches:



@INC for perl v5.6.1:
    /usr/local/lib/perl5/5.6.1/4400-svr4.0-64all
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/4400-svr4.0-64all
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.6.1:
    HOME=/home/grommel
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/gnu/lib/perl5
    LOGDIR (unset)
    PATH=/usr/xpt/bin:/opt/plc/bin:/usr/bin:/usr/sbin:/usr/bin/X11:
/usr/lib:/etc:/usr/etc:/fs/fs01/bin:/fs/fs01/sched/bin:/usr/local/bin:/usr/local/ibin:
/usr/sbin::/usr/ntos/bin:/usr/local/bin:/home/grommel/bin:/usr/gnu/bin:/usr/X/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/ksh

@p5pRT
Copy link
Author

p5pRT commented Jan 17, 2013

From @bulk88

On Sat Nov 10 06​:10​:20 2001, grommel@​sears.com wrote​:

-----------------------------------------------------------------

I am trying to rewrite Math​::Random, which now uses files generated by
SWIG, to use vanilla XS instead. The generated code for functions
that return doubles (NV's) is behaving very strangely indeed.

Much more detail is available if you want, but here are the most
relevant portions.

=== 1 of 6​: from Random.pm
return genunf($low,$high);

=== 2 of 6​: from Random.xs
double
genunf (low,high)
INPUT​:
double low
double high

=== 3 of 6​: generated code in Random.c
XS(XS_Math__Random_genunf)
{
dXSARGS;
if (items != 2)
Perl_croak(aTHX_ "Usage​: Math​::Random​::genunf(low, high)");
{
double low = (double)SvNV(ST(0));
double high = (double)SvNV(ST(1));
double RETVAL;
dXSTARG;

    RETVAL = genunf\(low\, high\);
    XSprePUSH; PUSHn\(\(double\)RETVAL\);
\}
XSRETURN\(1\);

}

=== 4 of 6​: C function from randlib.c
double genunf(double low,double high)
{
static double genunf;

if\(\!\(low > high\)\) goto S10;
fprintf\(stderr\,"LOW > HIGH in GENUNF​: LOW %16\.6E HIGH​:

%16.6E\n",low,high);
fputs("Abort\n",stderr);
exit(1);
S10​:
genunf = low+(high-low)*ranf();
printf("in randlib, genunf about to return %f\n", genunf);
return genunf;
}

=== 5 of 6​: from test.pl
print "random_uniform..................";
@​result = random_uniform(3, 0, 1.5);
print "result was @​result ! expected 0.02021, 0.72981, 0.28370\n";
was_it_ok(2, eq5a(@​result, 0.02021, 0.72981, 0.28370));

=== 6 of 6​: output of 'make test'
random_uniform..................in randlib, genunf about to return
0.020208
in randlib, genunf about to return 0.729815
in randlib, genunf about to return 0.283704
result was 44 44 44 ! expected 0.02021, 0.72981, 0.28370
not ok 2

=== [end of outputs]

Now why on earth would the XS code think that RETVAL was 44 in all
of these cases? This seems to happen only when the return type of
the function is 'double'; longs work just fine.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=medium
---
This perlbug was built using Perl v5.6.1 - Mon Oct 8 18​:23​:37 EDT
2001
It is being executed now by Perl v5.6.1 - Wed Oct 31 09​:33​:20 EST
2001.

Site configuration information for perl v5.6.1​:

Configured by priluts at Wed Oct 31 09​:33​:20 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1)
configuration​:
Platform​:
osname=svr4.0, osvers=3.0, archname=4400-svr4.0-64all
uname='s11a104 s11a104 4.0 3.0 4400 pentium ii(tm)-isapci '
config_args=''
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
Compiler​:
cc='/usr/bin/cc', ccflags ='-I/usr/include -I/usr/ucbinclude
-DDEBUGGING',
optimize='-g',
cppflags='-I/usr/include -I/usr/ucbinclude -DDEBUGGING'
ccversion='', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
Off_t='off_t',
lseeksize=4
alignbytes=4, usemymalloc=y, prototype=define
Linker and Libraries​:
ld='/usr/bin/cc', ldflags ='-L/usr/ccs/lib -L/usr/ucblib
-L/usr/local/lib -L/usr/gnu/lib'
libpth=/usr/local/lib /usr/gnu/lib /lib /usr/lib /usr/ccs/lib
/usr/ucblib
libs=-lsocket -lnsl -ldbm -ldl -lld -lm -lc -lcrypt -lucb -lx
perllibs=-lsocket -lnsl -ldl -lld -lm -lc -lcrypt -lucb -lx
libc=, so=so, useshrplib=true, libperl=libperl.so
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-KPIC', lddlflags='-G -L/usr/ccs/lib -L/usr/ucblib
-L/usr/local/lib -L/usr/gnu/lib'

Locally applied patches​:

---
@​INC for perl v5.6.1​:
/usr/local/lib/perl5/5.6.1/4400-svr4.0-64all
/usr/local/lib/perl5/5.6.1
/usr/local/lib/perl5/site_perl/5.6.1/4400-svr4.0-64all
/usr/local/lib/perl5/site_perl/5.6.1
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.6.1​:
HOME=/home/grommel
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH=/usr/gnu/lib/perl5
LOGDIR (unset)
PATH=/usr/xpt/bin​:/opt/plc/bin​:/usr/bin​:/usr/sbin​:/usr/bin/X11​:

/usr/lib​:/etc​:/usr/etc​:/fs/fs01/bin​:/fs/fs01/sched/bin​:/usr/local/bin​:/usr/local/ibin​:

/usr/sbin​::/usr/ntos/bin​:/usr/local/bin​:/home/grommel/bin​:/usr/gnu/bin​:/usr/X/bin

PERL\_BADLANG \(unset\)
SHELL=/usr/bin/ksh

This ticket was created in 2001. I downloaded Math​::Random 0.71,
released 16 Sep 2008. Can not reproduce. genunf() is not returning all
44s (or same number) to Perl lang.

Adding the printf
________________________________________________________________
double genunf(double low,double high)
/*
**********************************************************************
  double genunf(double low,double high)
  GeNerate Uniform Real between LOW and HIGH
  Function
  Generates a real uniformly distributed between LOW and HIGH.
  Arguments
  low --> Low bound (exclusive) on real value to be generated
  high --> High bound (exclusive) on real value to be generated
**********************************************************************
*/
{
static double genunf;

  if(!(low > high)) goto S10;
  fprintf(stderr,"LOW > HIGH in GENUNF​: LOW %16.6E HIGH​:
%16.6E\n",low,high);
  fputs("Abort\n",stderr);
  exit(1);
S10​:
  genunf = low+(high-low)*ranf();
  printf("in randlib, genunf about to return %f\n", genunf);
  return genunf;
}
_____________________________________________________________________
Modifying test.pl to use the original test
_________________________________________________________________
print "random_uniform..................";
@​result = random_uniform(3, 0, 1.5);
print "result was @​result ! expected 0.02021, 0.72981, 0.28370\n";
was_it_ok(2, eq5a(@​result, 0.02021, 0.72981, 0.28370));
__________________________________________________________________
note today in .71 that test is written as
___________________________________________________________________
print "random_uniform..................";
@​result = random_uniform(3, 0, 1.5);
was_it_ok(2, eq5a(@​result, 0.05617, 0.51721, 0.83203));
___________________________________________________________________
Why IDK, but lets go on.

Then running test.pl with Win32 Perl 5.17
___________________________________________________________________
C​:\Documents and Settings\Owner\.cpan\build\Math-Random-0.71-RgPRXS>perl
test.pl

1..16
ok 1
random_uniform..................in randlib, genunf about to return 0.056166
in randlib, genunf about to return 0.517205
in randlib, genunf about to return 0.832033
result was 0.0561661435170668 0.51720505392292 0.832032654072519 !
expected 0.02
021, 0.72981, 0.28370
not ok 2
random_uniform_integer..........ok 3
random_permutation..............ok 4
random_permuted_index...........ok 5
random_normal...................ok 6
random_chi_square...............ok 7
random_f........................ok 8
random_beta.....................ok 9
random_binomial.................ok 10
random_poisson..................ok 11
random_exponential..............ok 12
random_gamma....................ok 13
random_multinomial..............ok 14
random_negative_binomial........ok 15
random_multivariate_normal......ok 16
1 test failed! There is no joy in Mudville.
___________________________________________________________________

So the author had wrong constants in the test I presume because it was
changed to what is there today. But all 3 calls were different numbers,
which is what this bug is about. If there ever was a bug in ParseXS (and
this wasn't a case of var typo/uninit memory), it has been fixed by now
(5.17). This could also be a bug in the platform the OP is using. The OS
name on this ticket is svr4, google (
http​://www.nntp.perl.org/group/perl.perl5.porters/2003/09/msg82202.html
) says this is NCR MP-RAS Unix. I don't think anyone will come by and
say with MP-RAS and blead they can reproduce it. I recommend to close
with rejected.

--
bulk88 ~ bulk88 at hotmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants