Adding an updated patch.  It seems I missed a file.

Testing done: compiled with both /permissive- set and without.

Thanks,

-Andrew

From: awt-dev <[email protected]> On Behalf Of Andrew Luo
Sent: Monday, May 13, 2019 5:40 PM
To: [email protected]
Subject: <AWT Dev> [PATCH] Fix some C++ conformance issues in AWT Windows code

I've been trying to get the JDK to compile with the new /permissive- switch in 
VS2017 (https://devblogs.microsoft.com/cppblog/permissive-switch/) however 
there have been a few issues in various parts of the code.

While testing this, I found some issues in the AWT code.  In one case we name a 
function with the class:: prefix when the function is declared inline in the 
class definition.  Other cases include where we are assigning string literals 
to non-const char* variables.  I took some time to fix these and attached a 
patch.  Let me know if there are any comments.

c:\Users\Andrew\Documents\mercurial\openjdk\jdk\src\java.desktop\windows\native\libawt\windows\awt.h(343):
 error C2440: 'return': cannot convert from 'const unsigned short *' to 'LPWSTR'
c:\Users\Andrew\Documents\mercurial\openjdk\jdk\src\java.desktop\windows\native\libawt\windows\awt.h(343):
 note: Conversion from string literal loses const qualifier (see 
/Zc:strictStrings)
c:\users\andrew\documents\mercurial\openjdk\jdk\src\java.desktop\windows\native\libawt\windows\awt_Component.h(455):
 error C2061: syntax error: identifier 'javaKey'
c:\users\andrew\documents\mercurial\openjdk\jdk\src\java.desktop\windows\native\libawt\windows\awt_Component.h(455):
 error C4430: missing type specifier - int assumed. Note: C++ does not support 
default-int

Thanks,

-Andrew
ÿþdiff -r 39814e0a8964 
src/java.desktop/windows/native/libawt/windows/awt.h

--- 
a/src/java.desktop/windows/native/libawt/windows/awt.h
   Sat May 18 22:11:25 2019 +0200

+++ 
b/src/java.desktop/windows/native/libawt/windows/awt.h
   Sat May 18 22:27:08 2019 -0700

@@ -337,7 +337,7 @@

 protected:

     LPWSTR m_pStr;

     jsize  m_dwSize;

-    LPWSTR getNonEmptyString() {

+    LPCWSTR getNonEmptyString() {

         return (NULL==m_pStr)

                 ? L""

                 : m_pStr;

@@ -378,9 +378,9 @@

         m_pStr = 
(LPWSTR)SAFE_SIZE_ARRAY_REALLOC(safe_Realloc,
 m_pStr, m_dwSize+1, sizeof(WCHAR) );

     }

     //we are in UNICODE now, so 
LPWSTR:=:LPTSTR

-    operator LPWSTR() { return 
getNonEmptyString(); }

+    operator LPCWSTR() { return 
getNonEmptyString(); }

     operator LPARAM() { return 
(LPARAM)getNonEmptyString(); }

-    void *GetData() { return (void 
*)getNonEmptyString(); }

+    const void *GetData() { return 
(const void *)getNonEmptyString(); }

     jsize  GetSize() { return 
m_dwSize; }

 };

 

diff -r 39814e0a8964 
src/java.desktop/windows/native/libawt/windows/awt_Component.h

--- 
a/src/java.desktop/windows/native/libawt/windows/awt_Component.h
       Sat May 18 22:11:25 2019 +0200

+++ 
b/src/java.desktop/windows/native/libawt/windows/awt_Component.h
       Sat May 18 22:27:08 2019 -0700

@@ -449,7 +449,7 @@

     static void 
JavaKeyToWindowsKey(UINT javaKey, UINT 
*windowsKey, UINT *modifiers, UINT 
originalWindowsKey);

     static void 
UpdateDynPrimaryKeymap(UINT wkey, UINT 
jkeyLegacy, jint keyLocation, UINT 
modifiers);

 

-    INLINE static void 
AwtComponent::JavaKeyToWindowsKey(UINT 
javaKey,

+    INLINE static void 
JavaKeyToWindowsKey(UINT javaKey,

                                        
UINT *windowsKey, UINT *modifiers)

     {

         JavaKeyToWindowsKey(javaKey, 
windowsKey, modifiers, IGNORE_KEY);

diff -r 39814e0a8964 
src/java.desktop/windows/native/libawt/windows/awt_PrintControl.cpp

--- 
a/src/java.desktop/windows/native/libawt/windows/awt_PrintControl.cpp
     Sat May 18 22:11:25 2019 +0200

+++ 
b/src/java.desktop/windows/native/libawt/windows/awt_PrintControl.cpp
     Sat May 18 22:27:08 2019 -0700

@@ -130,7 +130,7 @@

     DWORD cbBuf = *pcbBuf, dummyWord = 
0;

 

     JavaStringBuffer 
printerNameBuf(env, printerName);

-    LPTSTR lpcPrinterName = 
(LPTSTR)printerNameBuf;

+    LPCTSTR lpcPrinterName = 
(LPCTSTR)printerNameBuf;

     DASSERT(lpcPrinterName != NULL);

 

     // For NT, first do a quick check 
of all remote and local printers.

Reply via email to