jdk/src/solaris/native/sun/awt/awt_util.h
author alitvinov
Tue, 21 May 2013 05:02:21 +0400
changeset 17679 a81555868357
parent 11093 e753252dc8a9
child 18754 3db51db1e3d5
permissions -rw-r--r--
8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux Reviewed-by: art, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
     2
 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef _AWT_UTIL_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define _AWT_UTIL_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "gdefs.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    32
/*
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    33
 * Expected types of arguments of the macro.
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    34
 * (JNIEnv*, const char*, const char*, jboolean, jobject)
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    35
 */
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    36
#define WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature,                          \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    37
                            handlerHasFlag, handlerRef) do {                                      \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    38
    handlerRef = JNU_CallStaticMethodByName(env, NULL, handlerClassName, "getInstance",           \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    39
        getInstanceSignature).l;                                                                  \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    40
    if (handlerHasFlag == JNI_TRUE) {                                                             \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    41
        JNU_CallMethodByName(env, NULL, handlerRef, "setErrorOccurredFlag", "(Z)V", JNI_FALSE);   \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    42
    }                                                                                             \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    43
    JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "WITH_XERROR_HANDLER", \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    44
        "(Lsun/awt/X11/XErrorHandler;)V", handlerRef);                                            \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
} while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/*
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    48
 * Expected types of arguments of the macro.
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    49
 * (JNIEnv*)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    51
#define RESTORE_XERROR_HANDLER(env) do {                                                          \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    52
    JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil",                        \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    53
        "RESTORE_XERROR_HANDLER", "()V");                                                         \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    54
} while (0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/*
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    57
 * Expected types of arguments of the macro.
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    58
 * (JNIEnv*, const char*, const char*, jboolean, jobject, jboolean, No type - C expression)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
17679
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    60
#define EXEC_WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag,     \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    61
                                 handlerRef, errorOccurredFlag, code) do {                        \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    62
    handlerRef = NULL;                                                                            \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    63
    WITH_XERROR_HANDLER(env, handlerClassName, getInstanceSignature, handlerHasFlag, handlerRef); \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    64
    do {                                                                                          \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    65
        code;                                                                                     \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    66
    } while (0);                                                                                  \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    67
    RESTORE_XERROR_HANDLER(env);                                                                  \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    68
    if (handlerHasFlag == JNI_TRUE) {                                                             \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    69
        errorOccurredFlag = JNU_CallMethodByName(env, NULL, handlerRef, "getErrorOccurredFlag",   \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    70
            "()Z").z;                                                                             \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    71
    }                                                                                             \
a81555868357 8005607: Recursion in J2DXErrHandler() Causes a Stack Overflow on Linux
alitvinov
parents: 11093
diff changeset
    72
} while (0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#ifndef INTERSECTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define INTERSECTS(r1_x1,r1_x2,r1_y1,r1_y2,r2_x1,r2_x2,r2_y1,r2_y2) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
!((r2_x2 <= r1_x1) ||\
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  (r2_y2 <= r1_y1) ||\
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  (r2_x1 >= r1_x2) ||\
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  (r2_y1 >= r1_y2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#ifndef MIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define MIN(a,b) ((a) < (b) ? (a) : (b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#ifndef MAX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define MAX(a,b) ((a) > (b) ? (a) : (b))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
struct DPos {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    int32_t x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int32_t y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int32_t mapped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    void *data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    void *peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    int32_t echoC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
extern void awtJNI_ThreadYield(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * Functions for accessing fields by name and signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
JNU_GetObjectField(JNIEnv *env, jobject self, const char *name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                   const char *sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
JNU_SetObjectField(JNIEnv *env, jobject self, const char *name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                   const char *sig, jobject val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
JNU_GetLongField(JNIEnv *env, jobject self, const char *name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
JNU_GetIntField(JNIEnv *env, jobject self, const char *name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
JNU_SetIntField(JNIEnv *env, jobject self, const char *name, jint val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
JNU_SetLongField(JNIEnv *env, jobject self, const char *name, jlong val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
JNU_GetBooleanField(JNIEnv *env, jobject self, const char *name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
JNU_SetBooleanField(JNIEnv *env, jobject self, const char *name, jboolean val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
JNU_GetCharField(JNIEnv *env, jobject self, const char *name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#endif           /* _AWT_UTIL_H_ */