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

Scalar Win32::GetOSVersion() broken in 5.8.3 #7150

Closed
p5pRT opened this issue Mar 3, 2004 · 7 comments
Closed

Scalar Win32::GetOSVersion() broken in 5.8.3 #7150

p5pRT opened this issue Mar 3, 2004 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 3, 2004

Migrated from rt.perl.org#27357 (status was 'resolved')

Searchable as RT27357$

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2004

From Chris.Madsen@trx.com

Created by chris.madsen@trx.com

Win32​::GetOSVersion() is broken when called in scalar context in perl
5.8.3. It's documented as follows (from Win32.pod)​:

  Returns the list (STRING, MAJOR, MINOR, BUILD, ID), ....
  In scalar context it returns just the ID.
  ....
  On Windows NT 4 SP6 and later this function returns the following
  additional values​: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.

Test case​:

  printf "%d\n", (scalar Win32​::GetOSVersion());
  printf "%d\n", (Win32​::GetOSVersion())[4];

These two lines should produce identical output. On Win2K
Professional, I get​:
  1
  2

It should have produced​:
  2
  2

I think it's returning PRODUCTTYPE instead of ID.

This worked correctly in 5.8.0. I'm not sure about the intervening
versions.

A suggested test​:
  ok(Win32​::GetOSVersion() == (Win32​::GetOSVersion())[4],
  'scalar Win32​::GetOSVersion');

--
Chris Madsen http​://www.trx.com Chris.Madsen@​trx.com
TRX Technology Services (214) 346-4611

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.3:

Configured by cjmadsen at Fri Feb 20 14:37:07 2004.

Summary of my perl5 (revision 5 version 8 subversion 3) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release  -libpath:"C:\Prog\Perl\lib\MSWin32-x86-multi-thread\CORE"  -machine:x86'
    libpth=\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release  -libpath:"C:\Prog\Perl\lib\MSWin32-x86-multi-thread\CORE"  -machine:x86'

Locally applied patches:



@INC for perl v5.8.3:
    C:/lib/local/perl
    C:/Prog/Perl/lib/MSWin32-x86-multi-thread
    C:/Prog/Perl/lib
    C:/Prog/Perl/site/lib/MSWin32-x86-multi-thread
    C:/Prog/Perl/site/lib
    .


Environment for perl v5.8.3:
    HOME=C:/home
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Prog\TCL\bin;C:\orant\bin;C:\PROGRA~1\Borland\CBUILD~1\Bin;C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Util\bin;C:\Util\cvsnt;C:\Apps\Subversion\bin;C:\Prog\Perl\bin\MSWin32-x86-multi-thread;C:\Prog\Perl\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Prog\DevStudio\VC98\bin;C:\Prog\BTI\Win32\bin;C:\j2sdk1.4.2\bin
    PERL5LIB=C:/lib/local/perl
    PERLOPTS=-w
    PERL_BADLANG (unset)
    SHELL (unset)


@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

From @steve-m-hay

Christopher J. Madsen (via RT) wrote​:

Win32​::GetOSVersion() is broken when called in scalar context in perl
5.8.3. It's documented as follows (from Win32.pod)​:

Returns the list (STRING, MAJOR, MINOR, BUILD, ID), ....
In scalar context it returns just the ID.
....
On Windows NT 4 SP6 and later this function returns the following
additional values​: SPMAJOR, SPMINOR, SUITEMASK, PRODUCTTYPE.

Test case​:

printf "%d\n", (scalar Win32​::GetOSVersion());
printf "%d\n", (Win32​::GetOSVersion())[4];

These two lines should produce identical output. On Win2K
Professional, I get​:
1
2

It should have produced​:
2
2

I think it's returning PRODUCTTYPE instead of ID.

This worked correctly in 5.8.0. I'm not sure about the intervening
versions.

A suggested test​:
ok(Win32​::GetOSVersion() == (Win32​::GetOSVersion())[4],
'scalar Win32​::GetOSVersion');

It is indeed returning ProductType instead of PlatformId. It is broken
in Perl 5.8.1 onwards (change 20331).

Perl 5.8.0 did this in w32_GetOSVersion() (win32/win32.c)​:

  ...
  XPUSHs(newSViv(osver.dwMajorVersion));
  XPUSHs(newSViv(osver.dwMinorVersion));
  XPUSHs(newSViv(osver.dwBuildNumber));
  XPUSHs(newSViv(osver.dwPlatformId));
  PUTBACK;

which means PlatformId is returned in scalar context, but as of Perl
5.8.1 we now have​:

  ...
  XPUSHs(newSViv(osver.dwMajorVersion));
  XPUSHs(newSViv(osver.dwMinorVersion));
  XPUSHs(newSViv(osver.dwBuildNumber));
  XPUSHs(newSViv(osver.dwPlatformId));
  if (bEx) {
  XPUSHs(newSViv(osver.wServicePackMajor));
  XPUSHs(newSViv(osver.wServicePackMinor));
  XPUSHs(newSViv(osver.wSuiteMask));
  XPUSHs(newSViv(osver.wProductType));
  }
  PUTBACK;

so ProductType is returned in scalar context if the extra items were
successfully retrieved.

The attached patch against bleadperl (incorporating your test) fixes it.

- Steve


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

From @steve-m-hay

Inline Patch
diff -ruN perl-5.9.x.orig/MANIFEST perl-5.9.x/MANIFEST
--- perl-5.9.x.orig/MANIFEST	2004-02-20 11:10:03.000000000 +0000
+++ perl-5.9.x/MANIFEST	2004-03-04 09:36:04.864585100 +0000
@@ -2949,6 +2949,7 @@
 t/uni/tr_utf8.t			See if Unicode tr/// works
 t/uni/upper.t			See if Unicode casing works
 t/uni/write.t			See if Unicode formats work
+t/win32/getosversion.t		Test if Win32::GetOSVersion() works
 t/win32/longpath.t		Test if Win32::GetLongPathName() works
 t/win32/system.t		See if system works in Win*
 t/win32/system_tests		Test runner for system.t
diff -ruN perl-5.9.x.orig/t/win32/getosversion.t perl-5.9.x/t/win32/getosversion.t
--- perl-5.9.x.orig/t/win32/getosversion.t	1970-01-01 00:00:00.000000000 +0000
+++ perl-5.9.x/t/win32/getosversion.t	2004-03-04 09:34:56.397149700 +0000
@@ -0,0 +1,13 @@
+#!perl -w
+
+# tests for Win32::GetOSVersion()
+
+$^O =~ /^MSWin/ or print("1..0 # not win32\n" ), exit;
+
+print "1..1\n";
+
+my $scalar = Win32::GetOSVersion();
+my @array  = Win32::GetOSVersion();
+
+print "not " unless $scalar == $array[4];
+print "ok 1\n";
diff -ruN perl-5.9.x.orig/win32/win32.c perl-5.9.x/win32/win32.c
--- perl-5.9.x.orig/win32/win32.c	2003-12-29 10:50:38.000000000 +0000
+++ perl-5.9.x/win32/win32.c	2004-03-04 09:30:55.231352800 +0000
@@ -4618,6 +4618,9 @@
                 XSRETURN_EMPTY;
             }
 	}
+	if (GIMME_V == G_SCALAR) {
+	    XSRETURN_IV(osverw.dwPlatformId);
+	}
 	W2AHELPER(osverw.szCSDVersion, szCSDVersion, sizeof(szCSDVersion));
 	XPUSHs(newSVpvn(szCSDVersion, strlen(szCSDVersion)));
         osver.dwMajorVersion    = osverw.dwMajorVersion;
@@ -4638,6 +4641,9 @@
                 XSRETURN_EMPTY;
             }
 	}
+	if (GIMME_V == G_SCALAR) {
+	    XSRETURN_IV(osver.dwPlatformId);
+	}
 	XPUSHs(newSVpvn(osver.szCSDVersion, strlen(osver.szCSDVersion)));
     }
     XPUSHs(newSViv(osver.dwMajorVersion));

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 4, 2004

From @rgs

Steve Hay wrote in perl.perl5.porters :

It is indeed returning ProductType instead of PlatformId. It is broken
in Perl 5.8.1 onwards (change 20331).

The attached patch against bleadperl (incorporating your test) fixes it.

Thanks, applied as 22431 to bleadperl.

@p5pRT
Copy link
Author

p5pRT commented Jun 1, 2004

From @steve-m-hay

Fixed in perl-5.8.4 by change 22431 (see previous correspondence).

@p5pRT
Copy link
Author

p5pRT commented Jun 1, 2004

@steve-m-hay - Status changed from 'open' to 'resolved'

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

1 participant