Skip to content

Commit

Permalink
codegen: Fix conditional expression with only one void side
Browse files Browse the repository at this point in the history
Found by -pedantic-errors
  • Loading branch information
ricotz committed May 19, 2024
1 parent e2a4b7a commit 9688b0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions codegen/valaccodebasemodule.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3686,9 +3686,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
free_call.add_argument (new CCodeMemberAccess.pointer (new CCodeIdentifier("node"), "data"));

var data_isnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeMemberAccess.pointer (new CCodeIdentifier("node"), "data"), new CCodeConstant ("NULL"));
var ccomma_data = new CCodeCommaExpression ();
ccomma_data.append_expression (new CCodeConditionalExpression (data_isnull, new CCodeConstant ("NULL"), free_call));
ccode.add_expression (ccomma_data);
var ccomma_free = new CCodeCommaExpression ();
ccomma_free.append_expression (free_call);
ccomma_free.append_expression (new CCodeConstant ("NULL"));
ccode.add_expression (new CCodeConditionalExpression (data_isnull, new CCodeConstant ("NULL"), ccomma_free));

ccode.add_return (new CCodeConstant ("FALSE"));

Expand All @@ -3706,10 +3707,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
element_free_call.add_argument (new CCodeIdentifier ("free_func"));

var free_func_isnull = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeIdentifier ("free_func"), new CCodeConstant ("NULL"));
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression (new CCodeConditionalExpression (free_func_isnull, new CCodeConstant ("NULL"), element_free_call));

ccode.add_expression (ccomma);
var ccomma_element_free = new CCodeCommaExpression ();
ccomma_element_free.append_expression (element_free_call);
ccomma_element_free.append_expression (new CCodeConstant ("NULL"));
ccode.add_expression (new CCodeConditionalExpression (free_func_isnull, new CCodeConstant ("NULL"), ccomma_element_free));

var cfreecall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_free_function (gnode_type)));
cfreecall.add_argument (new CCodeIdentifier ("self"));
Expand Down
4 changes: 2 additions & 2 deletions tests/basic-types/glists.c-expected
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ static gboolean
_g_node_free_all_node (GNode* node,
GDestroyNotify free_func)
{
(node->data == NULL) ? NULL : free_func (node->data);
(node->data == NULL) ? NULL : (free_func (node->data), NULL);
return FALSE;
}

static void
_g_node_free_all (GNode* self,
GDestroyNotify free_func)
{
(free_func == NULL) ? NULL : g_node_traverse (self, G_POST_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) _g_node_free_all_node, free_func);
(free_func == NULL) ? NULL : (g_node_traverse (self, G_POST_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) _g_node_free_all_node, free_func), NULL);
g_node_destroy (self);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/generics/bug694765-2.c-expected
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,15 @@ static gboolean
_g_node_free_all_node (GNode* node,
GDestroyNotify free_func)
{
(node->data == NULL) ? NULL : free_func (node->data);
(node->data == NULL) ? NULL : (free_func (node->data), NULL);
return FALSE;
}

static void
_g_node_free_all (GNode* self,
GDestroyNotify free_func)
{
(free_func == NULL) ? NULL : g_node_traverse (self, G_POST_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) _g_node_free_all_node, free_func);
(free_func == NULL) ? NULL : (g_node_traverse (self, G_POST_ORDER, G_TRAVERSE_ALL, -1, (GNodeTraverseFunc) _g_node_free_all_node, free_func), NULL);
g_node_destroy (self);
}

Expand Down

0 comments on commit 9688b0c

Please sign in to comment.