From: Luca Bruno Date: Wed, 17 Aug 2011 15:39:30 +0000 (+0200) Subject: codegen: Skip precondition check for parameters in the posix profile X-Git-Tag: 0.13.3~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=36808eb53bbcea1a1bc035fc33245ebcb5f4130b;p=thirdparty%2Fvala.git codegen: Skip precondition check for parameters in the posix profile Fixes bug 648204. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index b6e2ce14d..3bd3f8119 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -5446,51 +5446,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } - public void create_type_check_statement (CodeNode method_node, DataType ret_type, TypeSymbol t, bool non_null, string var_name) { - var ccheck = new CCodeFunctionCall (); - - if (!context.assert) { - return; - } else if (context.checking && ((t is Class && !((Class) t).is_compact) || t is Interface)) { - var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_check_function (t))); - ctype_check.add_argument (new CCodeIdentifier (var_name)); - - CCodeExpression cexpr = ctype_check; - if (!non_null) { - var cnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL")); - - cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cnull, ctype_check); - } - ccheck.add_argument (cexpr); - } else if (!non_null) { - return; - } else if (t == glist_type || t == gslist_type) { - // NULL is empty list - return; - } else { - var cnonnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL")); - ccheck.add_argument (cnonnull); - } - - var cm = method_node as CreationMethod; - if (cm != null && cm.parent_symbol is ObjectTypeSymbol) { - ccheck.call = new CCodeIdentifier ("g_return_val_if_fail"); - ccheck.add_argument (new CCodeConstant ("NULL")); - } else if (ret_type is VoidType) { - /* void function */ - ccheck.call = new CCodeIdentifier ("g_return_if_fail"); - } else { - ccheck.call = new CCodeIdentifier ("g_return_val_if_fail"); - - var cdefault = default_value_for_type (ret_type, false); - if (cdefault != null) { - ccheck.add_argument (cdefault); - } else { - return; - } - } - - ccode.add_expression (ccheck); + public virtual void create_type_check_statement (CodeNode method_node, DataType ret_type, TypeSymbol t, bool non_null, string var_name) { } public int get_param_pos (double param_pos, bool ellipsis = false) { diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 83be7408f..f366c35dc 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -2136,4 +2136,51 @@ public class Vala.GTypeModule : GErrorModule { } base.visit_property (prop); } + + public override void create_type_check_statement (CodeNode method_node, DataType ret_type, TypeSymbol t, bool non_null, string var_name) { + var ccheck = new CCodeFunctionCall (); + + if (!context.assert) { + return; + } else if (context.checking && ((t is Class && !((Class) t).is_compact) || t is Interface)) { + var ctype_check = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_check_function (t))); + ctype_check.add_argument (new CCodeIdentifier (var_name)); + + CCodeExpression cexpr = ctype_check; + if (!non_null) { + var cnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL")); + + cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.OR, cnull, ctype_check); + } + ccheck.add_argument (cexpr); + } else if (!non_null) { + return; + } else if (t == glist_type || t == gslist_type) { + // NULL is empty list + return; + } else { + var cnonnull = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier (var_name), new CCodeConstant ("NULL")); + ccheck.add_argument (cnonnull); + } + + var cm = method_node as CreationMethod; + if (cm != null && cm.parent_symbol is ObjectTypeSymbol) { + ccheck.call = new CCodeIdentifier ("g_return_val_if_fail"); + ccheck.add_argument (new CCodeConstant ("NULL")); + } else if (ret_type is VoidType) { + /* void function */ + ccheck.call = new CCodeIdentifier ("g_return_if_fail"); + } else { + ccheck.call = new CCodeIdentifier ("g_return_val_if_fail"); + + var cdefault = default_value_for_type (ret_type, false); + if (cdefault != null) { + ccheck.add_argument (cdefault); + } else { + return; + } + } + + ccode.add_expression (ccheck); + } }