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

Sergey Bylokhov Sergey.Bylokhov at oracle.com
Fri Mar 28 19:23:58 UTC 2014


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 IS_NULL(obj) ((obj) == NULL) #define JNU_IsNull(env,obj) ((obj) == NULL) +#define IS_JNI_TRUE(obj) ((obj) ? JNI_TRUE : JNI_FALSE)

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.

-- Best regards, Sergey.



More information about the core-libs-dev mailing list