C++ and Java CNI: Check Java references

Fergus Henderson fjh@cs.mu.oz.au
Mon Apr 23 21:39:00 GMT 2001


On 23-Apr-2001, Andrew Haley <aph@cambridge.redhat.com> wrote:
> --- call.c	2001/04/23 17:18:18
> *************** initialize_reference (type, expr)
> *** 5534,5535 ****
> --- 5534,5591 ----
>     return convert_like (conv, expr);
>   }
> + 
> + static tree java_nullpointer_exception;
> + 
> + tree
> + check_java_reference (exp)
> +      tree exp;
> + {
> +   tree e = exp;
> +   
> +   if (!flag_check_java_references)
> +     return exp;
> +   
> +   /* Strip off all pointer conversions and if the thing at the root is
> +      an integer we won't bother to check it.  The main reason for this
> +      is that offsetof is often defined as
> + 
> +      ((size_t)&((type *)0)->memb)
> + 
> +      which implicitly dereferences a null pointer.  Let's not check that.  */

Hmm... that seems like a bit of a hack.

It's also common to write expressions such as `&p[0]',
and I don't think it's a good idea to check for null
pointers in that case.

It would be nicer, I think, to skip the check iff the pointer dereference
is the operand of unary `&' (address-of).  Though it may not be as easy
to implement...

> +     tree cond = build (NE_EXPR, boolean_type_node, exp, integer_zero_node);

I'm not sure if it makes any difference, but wouldn't it be more
appropriate to use null_pointer_node rather than integer_zero_node?

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: < http://www.cs.mu.oz.au/~fjh >  |     -- the last words of T. S. Garp.



More information about the Java mailing list