[9] Review request: new macro for conversion to jboolean (original) (raw)

roger riggs roger.riggs at oracle.com
Sat Mar 29 15:52:40 UTC 2014


Hi Sergey,

I recall seeing two recommendations (Mine and Mikes) not to add the macro and just use the ternary form where it is needed.

How many places in the code (presumed to be AWT) is this needed?

With the name IS_JNI_TRUE, I would expect it to expand to:

#define IS_JNI_TRUE(obj) ((obj ==JNI_TRUE) ? JNI_TRUE : JNI_FALSE)

Roger

On 3/28/2014 3:23 PM, Sergey Bylokhov wrote:

On 3/24/14 3:11 PM, Anthony Petrov wrote:

How does ISJNITRUE sound? It looks good. If nobody objects, the final version will be: #define ISNULL(obj) ((obj) == NULL) #define JNUIsNull(env,obj) ((obj) == NULL) +#define ISJNITRUE(obj) ((obj) ? JNITRUE : JNIFALSE) without additional cast.

-- best regards, Anthony

On 3/23/2014 10:10 PM, Alan Bateman wrote: On 21/03/2014 15:22, Sergey Bylokhov wrote: On 3/21/14 7:10 PM, roger riggs wrote:

The macro would just as useful (if I understand the cases) without the cast.

How useful is a simple definition as: #define ISTRUE(obj) ((obj) ? JNITRUE : JNIFALSE) then it would look ok to see these in sources: return ISTRUE(obj); if (ISTRUE(obj)) {....} jboolean ret = ISTRUE(obj); The general purpose usage matches the general C conventions for true and false and match the JNI semantics. Actually that was my initial suggestion(name and usage). I think the concern with ISTRUE is that it's not obvious that it's a jboolean. Also just the potential for it to easily collide with a macro that casts to bool or (or Windows's BOOL). I can't tell from the JNI spec if JNIFALSE/JNITRUE are guaranteed to be defined as 0/1 but even if they are then I guess there is still a concern that a jboolean is defined as an unsigned 8 bits whereas a bool might not (and a Windows's BOOL is an int I think). So if a macro is really needed then I think it will need another name. I thought MIke's original proposal for JNUTOJBOOLEAN wasn't too bad. I see Mike's mail about adding the cases to the definitions but that isn't going to help with the cases that I think you are running into where you need to go from Window's BOOL to jboolean. -Alan.



More information about the core-libs-dev mailing list