Bug 82573 - GNAT.Registry doesn't read/write with HKEY_LOCAL_MACHINE.
Summary: GNAT.Registry doesn't read/write with HKEY_LOCAL_MACHINE.
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 6.3.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-16 23:58 UTC by Jerry Hudson
Modified: 2017-10-17 13:50 UTC (History)
1 user (show)

See Also:
Host:
Target: i686-pc-mingw32
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry Hudson 2017-10-16 23:58:14 UTC
Bug report - GNAT.Registry
Submitted by Jerry Hudson, hudsonjk@astound.net

Nature of the bug:
-----------------
Package seems to work as advertized when reading/writing keys
in HKEY_CURRENT_USER.  It seems to work with HKEY_LOCAL_MACHINE,
until you do a regedit and see that nothing gets written there!

I don't know where it was putting the keys and strings.  I did
a registry search on the key SOFTWARE\TestGNATReg (see code
listing below), and it was nowhere in the registry.  On the other
hand, writing/reading with HKEY_CURRENT_USER made visible entries
in the registry as seen by regedit.

In the testing below, USER HAS ADMIN PRIVILEGES.

Test program
-------------

------------------------------------------------------------------
-- Test GNAT.Registry

with Ada.Text_IO;                    use Ada.Text_IO;
with GNAT.Registry;                  use GNAT.Registry;


procedure Test_GNAT_Registry is

   key    : HKEY;
   txt    : String(1..20);
   len    : Integer;
   skey   : HKEY;

begin

-- Choose which standard key to use
   Put( "Which standard key to use? (HKCU, HKLM): " );
   Get_Line( txt, len );
   if txt(1..4) = "HKCU" then
      skey  := HKEY_CURRENT_USER;
      Put_Line( "HKEY_CURRENT_USER" );
   elsif txt(1..4) = "HKLM" then
      skey  := HKEY_LOCAL_MACHINE;
      Put_Line( "HKEY_LOCAL_MACHINE" );
   else
      Put_Line( "Didn't understand: " & txt(1..len) );
      Put_Line( "Needs to be: HKCU or HKLM" );
      return;
   end if;

-- Create new registry key and a couple of strings
   if not Key_Exists(
      From_Key  => skey,
      Sub_Key   => "SOFTWARE\TestGNATReg" )
   then
      if skey = HKEY_LOCAL_MACHINE then
         Put_Line("Creating key under HKEY_LOCAL_MACHINE");
      else
         Put_Line("Creating key under HKEY_CURRENT_USER");
      end if;
      key  := Create_Key(
         From_Key  => skey,
         Sub_Key   => "SOFTWARE\TestGNATReg",
         Mode      => Read_Write );
      Set_Value(
         From_Key  => key,
         Sub_Key   => "State",
         Value     => "CA",
         Expand    => False );
      Set_Value(
         From_Key  => key,
         Sub_Key   => "City",
         Value     => "Concord",
         Expand    => False );
      Close_Key( key );
   end if;

-- Read back whatever is in the key
   if not Key_Exists(
      From_Key  => skey,
      Sub_Key   => "SOFTWARE\TestGNATReg" )
   then
      Put_Line( "Oops - no such key: SOFTWARE\TestGNATReg" );
      return;
   end if;
   if skey = HKEY_CURRENT_USER then
      Put_Line("Opening key under HKEY_CURRENT_USER");
   else
      Put_Line("Opening key under HKEY_LOCAL_MACHINE");
   end if;
   key   := Open_Key(
      From_Key   => skey,
      Sub_Key    => "SOFTWARE\TestGNATReg" );
   Put_Line( "State : " & Query_Value( key, "State" ) );
   Put_Line( "City  : " & Query_Value( key, "City" ) );
   Close_Key( key );
   Put_Line( "Looks good!" );

end Test_GNAT_Registry;
------------------------------------------------------------------

Build:
-----
C:\Users\Hektor\Documents\Code\Test\Registry>gnatmake test_gnat_registry.adb
gcc -c test_gnat_registry.adb
gnatbind -x test_gnat_registry.ali
gnatlink test_gnat_registry.ali

Successful run:
---------------

C:\Users\Hektor\Documents\Code\Test\Registry>test_gnat_registry
Which standard key to use? (HKCU, HKLM): HKCU
HKEY_CURRENT_USER
Creating key under HKEY_CURRENT_USER
Opening key under HKEY_CURRENT_USER
State : CA
City  : Concord
Looks good!

Key and data appear in the registry as seen by regedit.

Unsuccessful run:
----------------

Identical except user says "HKLM".  Program appears to have created
the key and string values, and to have read them correctly.  However,
NOTHING GETS IN THE REGISTRY! 

More detailed testing revealed that stuff that is REALLY in the
HKEY_LOCAL_MACHINE cannot be read/written.  I can provide a program
that does more detailed testing if you like, but it is more complex.



gcc Version
-----------

C:\Users\Hektor\Documents\Code\Test\Registry>gcc -c -v
Using built-in specs.
COLLECT_GCC=gcc
Target: i686-pc-mingw32
Configured with: ../src/configure --enable-languages=ada,c,c++ --enable-threads=win32 --enable-lto --with-fpmath=sse --enable-dual-exceptions --disable-sjlj-exceptions --enable-frame-pointer --with-bugurl=URL:mailto:report@adacore.com --disable-nls --without-libiconv-prefix --disable-libstdcxx-pch --disable-libada --enable-checking=release --with-mpfr=/gnatmail/sandbox/2017/x86-windows/mpfr_stable/install --with-gmp=/gnatmail/sandbox/2017/x86-windows/gmp_stable/install --with-mpc=/gnatmail/sandbox/2017/x86-windows/mpc_stable/install --with-build-time-tools=/gnatmail/sandbox/2017/x86-windows/gcc/build/buildtools/bin --prefix=/gnatmail/sandbox/2017/x86-windows/gcc/pkg --build=i686-pc-mingw32
Thread model: win32
gcc version 6.3.1 20170510 (for GNAT GPL 2017 20170515) (GCC)

C:\Users\Hektor\Documents\Code\Test\Registry>gnatmake test_gnat_registry.adb
gcc -c test_gnat_registry.adb
gnatbind -x test_gnat_registry.ali
gnatlink test_gnat_registry.ali

System info
-----------

Windows edition
	Windows 10 Home

System: 
	Processor:      Intel Pentium CPU N3700 @1.60GHz
	Installed RAM:  4.00 GB
	System type:    64-bit Operating System, x64-based processor
Comment 1 Andrew John Hughes 2017-10-17 02:03:02 UTC
This doesn't seem to be related to GNU Classpath.
Comment 2 Jerry Hudson 2017-10-17 13:50:33 UTC
I was confused by what you meant by "classpath."  The
earlier revision by Andrew Pinski better describes the
problem, but I don't recall seeing that option on the form.
Forgive me, this is the first bug report for me.  (I have used
Gnu products quite a bit, and bugs are RARE.)

- Jerry Hudson

On 10/17/2017 2:03 AM, gnu_andrew at member dot fsf.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82573
>
> Andrew John Hughes <gnu_andrew at member dot fsf.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                   CC|                            |gnu_andrew at member dot fsf.org
>
> --- Comment #1 from Andrew John Hughes <gnu_andrew at member dot fsf.org> ---
> This doesn't seem to be related to GNU Classpath.
>