Skip to content

Commit

Permalink
8311380: Prepare java.desktop for C++17
Browse files Browse the repository at this point in the history
Reviewed-by: azvegint
  • Loading branch information
TheShermanTanker committed Jul 13, 2023
1 parent 743e8b8 commit fb90af8
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* questions.
*/

#include <cmath>
#include <malloc.h>
#include <math.h>
#include <jlong.h>

#include "sun_java2d_d3d_D3DTextRenderer.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* questions.
*/

#include <cmath>

#include "D3DPipeline.h"
#include "D3DVertexCacher.h"
#include "D3DPaints.h"

#include "math.h"

// non-texturized macros

#define ADD_VERTEX_XYC(X, Y, VCOLOR) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* questions.
*/

#include <cmath> /* for cos(), sin(), etc */

#include "jni_util.h"
#include "awt.h"
#include "sun_java2d_windows_GDIRenderer.h"
Expand All @@ -35,8 +37,6 @@

#include "GraphicsPrimitiveMgr.h"

#include <math.h> /* for cos(), sin(), etc */

#define MAX_CLAMP_BND (1<<26)
#define MIN_CLAMP_BND (-MAX_CLAMP_BND)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* questions.
*/

#include <cmath>

#include "sun_awt_windows_ThemeReader.h"

#include "awt.h"
#include "awt_Toolkit.h"

#include "math.h"

#include <uxtheme.h>

#define ALPHA_MASK 0xff000000
Expand Down
22 changes: 9 additions & 13 deletions src/java.desktop/windows/native/libawt/windows/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ ExceptionOccurred_Instead
// These three functions throw std::bad_alloc in an out of memory condition
// instead of returning 0. safe_Realloc will return 0 if memblock is not
// NULL and size is 0. safe_Malloc and safe_Calloc will never return 0.
void *safe_Malloc(size_t size) throw (std::bad_alloc);
void *safe_Calloc(size_t num, size_t size) throw (std::bad_alloc);
void *safe_Realloc(void *memblock, size_t size) throw (std::bad_alloc);
void *safe_Malloc(size_t size);
void *safe_Calloc(size_t num, size_t size);
void *safe_Realloc(void *memblock, size_t size);

// This function should be called instead of ExceptionOccurred. It throws
// std::bad_alloc if a java.lang.OutOfMemoryError is currently pending
// on the calling thread.
jthrowable safe_ExceptionOccurred(JNIEnv *env) throw (std::bad_alloc);
jthrowable safe_ExceptionOccurred(JNIEnv *env);

// This function is called at the beginning of an entry point.
// Entry points are functions which are declared:
Expand All @@ -111,7 +111,7 @@ void entry_point(void);
void hang_if_shutdown(void);

// This function throws awt_toolkit_shutdown if the Toolkit is not active
void throw_if_shutdown(void) throw (awt_toolkit_shutdown);
void throw_if_shutdown(void);

// This function is called when a std::bad_alloc exception is caught
void handle_bad_alloc(void);
Expand All @@ -120,14 +120,10 @@ void handle_bad_alloc(void);
// #define OUTOFMEM_TEST

#ifdef OUTOFMEM_TEST
void *safe_Malloc_outofmem(size_t size, const char *, int)
throw (std::bad_alloc);
void *safe_Calloc_outofmem(size_t num, size_t size, const char *, int)
throw (std::bad_alloc);
void *safe_Realloc_outofmem(void *memblock, size_t size, const char *, int)
throw (std::bad_alloc);
void * CDECL operator new(size_t size, const char *, int)
throw (std::bad_alloc);
void *safe_Malloc_outofmem(size_t size, const char *, int);
void *safe_Calloc_outofmem(size_t num, size_t size, const char *, int);
void *safe_Realloc_outofmem(void *memblock, size_t size, const char *, int);
void * CDECL operator new(size_t size, const char *, int);

#define safe_Malloc(size) \
safe_Malloc_outofmem(size, __FILE__, __LINE__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* questions.
*/

#include <cmath>

#include "awt.h"

#include <windowsx.h>
Expand All @@ -47,7 +49,6 @@
#include "awt_Win32GraphicsDevice.h"
#include "Hashtable.h"
#include "ComCtl32Util.h"
#include "math.h"

#include <Region.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* questions.
*/

#include <cmath>

#include "awt.h"
#include "mmsystem.h"
#include "jlong.h"
Expand All @@ -35,8 +37,6 @@
#include <shellapi.h>
#include <shlobj.h>

#include "math.h"

// WDesktopProperties fields
jfieldID AwtDesktopProperties::pDataID = 0;
jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* questions.
*/

#include <cmath>
#include "awt.h"
#include <math.h>
#include <strsafe.h>
#include "jlong.h"
#include "awt_Font.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* questions.
*/

#include <cmath>
#include <cfloat>
#include "awt_Component.h"
#include "awt_PrintControl.h"
#include "awt.h"
#include "awt_PrintDialog.h"
#include <winspool.h>
#include <float.h>
#include <math.h>

#define ROUNDTOINT(x) ((int)((x)+0.5))
static const int DEFAULT_RES = 72;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* questions.
*/

#include <cmath>
#include "awt.h"
#include <strsafe.h>
#include <math.h>
#include <windef.h>
#include <wtypes.h>
#include <winuser.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ void AwtToolkit::SetHeapCheck(long flag) {
}
}

void throw_if_shutdown(void) throw (awt_toolkit_shutdown)
void throw_if_shutdown(void)
{
AwtToolkit::GetInstance().VerifyActive();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@
* array index.
*/

#include <cmath> // ceil()
#include <awt.h>
#include <sun_awt_Win32GraphicsDevice.h>
#include "awt_Canvas.h"
#include "awt_Win32GraphicsDevice.h"
#include "awt_Window.h"
#include "java_awt_Transparency.h"
#include "java_awt_color_ColorSpace.h"
#include "sun_awt_Win32GraphicsDevice.h"
#include "java_awt_image_DataBuffer.h"
#include "dither.h"
#include "img_util_md.h"
#include "Devices.h"
#include "systemScale.h"
Expand Down
4 changes: 2 additions & 2 deletions src/java.desktop/windows/native/libawt/windows/awt_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* questions.
*/

#include <cmath>
#include "awt.h"
#include <jlong.h>

Expand All @@ -45,9 +46,8 @@
#include "sun_awt_windows_WCanvasPeer.h"

#include <windowsx.h>
#include <math.h>
#if !defined(__int3264)
typedef __int32 LONG_PTR;
typedef int32_t LONG_PTR;
#endif // __int3264

// Used for Swing's Menu/Tooltip animation Support
Expand Down
51 changes: 21 additions & 30 deletions src/java.desktop/windows/native/libawt/windows/awt_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,37 @@ NewHandler::handler(size_t) {
// These three functions throw std::bad_alloc in an out of memory condition
// instead of returning 0. safe_Realloc will return 0 if memblock is not
// NULL and size is 0. safe_Malloc and safe_Calloc will never return 0.
void *safe_Malloc(size_t size) throw (std::bad_alloc) {
register void *ret_val = malloc(size);
if (ret_val == NULL) {
void *safe_Malloc(size_t size) {
void *ptr = malloc(size);
if (ptr == nullptr) {
throw std::bad_alloc();
}

return ret_val;
return ptr;
}

void *safe_Calloc(size_t num, size_t size) throw (std::bad_alloc) {
register void *ret_val = calloc(num, size);
if (ret_val == NULL) {
void *safe_Calloc(size_t num, size_t size) {
void *ptr = calloc(num, size);
if (ptr == nullptr) {
throw std::bad_alloc();
}

return ret_val;
return ptr;
}

void *safe_Realloc(void *memblock, size_t size) throw (std::bad_alloc) {
register void *ret_val = realloc(memblock, size);
void *safe_Realloc(void *memblock, size_t size) {
void *ptr = realloc(memblock, size);

// Special case for realloc.
if (memblock != NULL && size == 0) {
return ret_val; // even if it's NULL
if (memblock != nullptr && size == 0) {
return ptr; // even if it's NULL
}

if (ret_val == NULL) {
if (ptr == nullptr) {
throw std::bad_alloc();
}

return ret_val;
return ptr;
}

#if !defined(DEBUG)
Expand All @@ -120,7 +120,7 @@ void *safe_Realloc(void *memblock, size_t size) throw (std::bad_alloc) {
// std::bad_alloc in an out of memory situation. Instead, VC++ 5.0 returns 0.
//
// This function can be safely removed when the problem is corrected.
void * CDECL operator new(size_t size) throw (std::bad_alloc) {
void * CDECL operator new(size_t size) {
return safe_Malloc(size);
}
#endif
Expand Down Expand Up @@ -160,7 +160,7 @@ handle_bad_alloc(void) {
// std::bad_alloc if a java.lang.OutOfMemoryError is currently pending
// on the calling thread.
jthrowable
safe_ExceptionOccurred(JNIEnv *env) throw (std::bad_alloc) {
safe_ExceptionOccurred(JNIEnv *env) {
jthrowable xcp = env->ExceptionOccurred();
if (xcp != NULL) {
env->ExceptionClear(); // if we don't do this, isInstanceOf will fail
Expand Down Expand Up @@ -188,8 +188,7 @@ safe_ExceptionOccurred(JNIEnv *env) throw (std::bad_alloc) {
#include <limits.h>

static void
rand_alloc_fail(const char *file, int line) throw (std::bad_alloc)
{
rand_alloc_fail(const char *file, int line) {
if (alloc_lock == NULL) { // Not yet initialized
return;
}
Expand All @@ -213,31 +212,23 @@ rand_alloc_fail(const char *file, int line) throw (std::bad_alloc)
}
}

void *safe_Malloc_outofmem(size_t size, const char *file, int line)
throw (std::bad_alloc)
{
void *safe_Malloc_outofmem(size_t size, const char *file, int line) {
rand_alloc_fail(file, line);
return safe_Malloc(size);
}

void *safe_Calloc_outofmem(size_t num, size_t size, const char *file, int line)
throw (std::bad_alloc)
{
void *safe_Calloc_outofmem(size_t num, size_t size, const char *file, int line) {
rand_alloc_fail(file, line);
return safe_Calloc(num, size);
}

void *safe_Realloc_outofmem(void *memblock, size_t size, const char *file,
int line)
throw (std::bad_alloc)
{
int line) {
rand_alloc_fail(file, line);
return safe_Realloc(memblock, size);
}

void * CDECL operator new(size_t size, const char *file, int line)
throw (std::bad_alloc)
{
void * CDECL operator new(size_t size, const char *file, int line) {
rand_alloc_fail(file, line);
return operator new(size);
}
Expand Down

1 comment on commit fb90af8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.