widl: Move the pointer check functionality to typegen.c.

This commit is contained in:
Alexandre Julliard 2011-06-14 12:55:39 +02:00
parent fa2b886d1d
commit c173399d62
5 changed files with 32 additions and 43 deletions

View file

@ -50,19 +50,6 @@ static void print_client( const char *format, ... )
va_end(va);
}
static void check_pointers(const var_t *func)
{
const var_t *var;
if (!type_get_function_args(func->type))
return;
LIST_FOR_EACH_ENTRY( var, type_get_function_args(func->type), const var_t, entry )
if (cant_be_null(var))
print_client("if (!%s) RpcRaiseException(RPC_X_NULL_REF_POINTER);\n", var->name);
}
static void write_client_func_decl( const type_t *iface, const var_t *func )
{
const char *callconv = get_attrp(func->type->attrs, ATTR_CALLCONV);
@ -173,7 +160,7 @@ static void write_function_stub( const type_t *iface, const var_t *func,
write_full_pointer_init(client, indent, func, FALSE);
/* check pointers */
check_pointers(func);
write_pointer_checks( client, indent, func );
print_client("RpcTryFinally\n");
print_client("{\n");

View file

@ -120,23 +120,6 @@ static void clear_output_vars( const var_list_t *args )
}
}
int cant_be_null(const var_t *v)
{
switch (typegen_detect_type(v->type, v->attrs, TDT_IGNORE_STRINGS))
{
case TGT_ARRAY:
if (!type_array_is_decl_as_ptr( v->type )) return 0;
/* fall through */
case TGT_POINTER:
return (get_pointer_fc(v->type, v->attrs, TRUE) == RPC_FC_RP);
case TGT_CTXT_HANDLE_POINTER:
return TRUE;
default:
return 0;
}
}
static int need_delegation(const type_t *iface)
{
const type_t *parent = type_iface_get_inherit( iface );
@ -161,16 +144,6 @@ static int need_delegation_indirect(const type_t *iface)
return get_delegation_indirect(iface, NULL);
}
static void proxy_check_pointers( const var_list_t *args )
{
const var_t *arg;
if (!args) return;
LIST_FOR_EACH_ENTRY( arg, args, const var_t, entry )
if (cant_be_null(arg))
print_proxy( "if (!%s) RpcRaiseException(RPC_X_NULL_REF_POINTER);\n", arg->name );
}
static void free_variable( const var_t *arg, const char *local_var_prefix )
{
unsigned int type_offset = arg->type->typestring_offset;
@ -303,7 +276,7 @@ static void gen_proxy(type_t *iface, const var_t *func, int idx,
print_proxy( "{\n" );
indent++;
print_proxy( "NdrProxyInitialize(This, &_RpcMessage, &__frame->_StubMsg, &Object_StubDesc, %d);\n", idx);
proxy_check_pointers( type_get_function_args(func->type) );
write_pointer_checks( proxy, indent, func );
print_proxy( "RpcTryFinally\n" );
print_proxy( "{\n" );

View file

@ -373,6 +373,23 @@ enum typegen_type typegen_detect_type(const type_t *type, const attr_list_t *att
return TGT_INVALID;
}
static int cant_be_null(const var_t *v)
{
switch (typegen_detect_type(v->type, v->attrs, TDT_IGNORE_STRINGS))
{
case TGT_ARRAY:
if (!type_array_is_decl_as_ptr( v->type )) return 0;
/* fall through */
case TGT_POINTER:
return (get_pointer_fc(v->type, v->attrs, TRUE) == RPC_FC_RP);
case TGT_CTXT_HANDLE_POINTER:
return TRUE;
default:
return 0;
}
}
static int get_padding(const var_list_t *fields)
{
unsigned short offset = 0;
@ -4720,6 +4737,18 @@ void write_func_param_struct( FILE *file, const type_t *iface, const type_t *fun
print_file( file, 0, "\n" );
}
void write_pointer_checks( FILE *file, int indent, const var_t *func )
{
const var_list_t *args = type_get_function_args( func->type );
const var_t *var;
if (!args) return;
LIST_FOR_EACH_ENTRY( var, args, const var_t, entry )
if (cant_be_null( var ))
print_file( file, indent, "if (!%s) RpcRaiseException(RPC_X_NULL_REF_POINTER);\n", var->name );
}
int write_expr_eval_routines(FILE *file, const char *iface)
{
static const char *var_name = "pS";

View file

@ -77,6 +77,7 @@ void assign_stub_out_args( FILE *file, int indent, const var_t *func, const char
void declare_stub_args( FILE *file, int indent, const var_t *func );
void write_func_param_struct( FILE *file, const type_t *iface, const type_t *func,
const char *var_decl, int add_retval );
void write_pointer_checks( FILE *file, int indent, const var_t *func );
int write_expr_eval_routines(FILE *file, const char *iface);
void write_expr_eval_routine_list(FILE *file, const char *iface);
void write_user_quad_list(FILE *file);

View file

@ -544,7 +544,6 @@ void clear_all_offsets(void);
int is_ptr(const type_t *t);
int is_array(const type_t *t);
int cant_be_null(const var_t *v);
#define tsENUM 1
#define tsSTRUCT 2