summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2022-02-11 19:18:18 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2022-02-11 19:30:11 +0100
commit7e75f8126b00f3549d8c421559270508d39db0ed (patch)
tree5818ae6a80f6bd8be6201be4c9e10bacc3b3f5f5
parent85d01e10032068882d8834ec297c32a9557cdbaa (diff)
downloadvala-7e75f8126b00f3549d8c421559270508d39db0ed.tar.gz
vala: Only add catch clause if an inner error is possible
See d9f702289b4b39683d0c9361e1ea02fd51ecae22
-rw-r--r--tests/objects/bug629593.c-expected27
-rw-r--r--tests/objects/bug795521.c-expected100
-rw-r--r--tests/objects/fields.c-expected157
-rw-r--r--tests/objects/properties.c-expected39
-rw-r--r--tests/parser/lock-statement.c-expected14
-rw-r--r--vala/valalockstatement.vala18
6 files changed, 21 insertions, 334 deletions
diff --git a/tests/objects/bug629593.c-expected b/tests/objects/bug629593.c-expected
index bc99f4037..4f4814f01 100644
--- a/tests/objects/bug629593.c-expected
+++ b/tests/objects/bug629593.c-expected
@@ -25,7 +25,6 @@
typedef struct _Foo Foo;
typedef struct _FooClass FooClass;
typedef struct _FooPrivate FooPrivate;
-#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ParamSpecFoo ParamSpecFoo;
#define TYPE_BAR (bar_get_type ())
@@ -159,19 +158,6 @@ foo_run (Foo* self)
{
self->other_variable = 1;
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&self->priv->__lock_thing_to_lock_on);
@@ -413,19 +399,6 @@ bar_run (Bar* self)
{
self->other_variable = 1;
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&BAR_GET_CLASS_PRIVATE (BAR_GET_CLASS (self))->__lock_thing_to_lock_on);
diff --git a/tests/objects/bug795521.c-expected b/tests/objects/bug795521.c-expected
index a4d39a55c..07a627494 100644
--- a/tests/objects/bug795521.c-expected
+++ b/tests/objects/bug795521.c-expected
@@ -26,7 +26,6 @@ typedef struct _Foo Foo;
typedef struct _FooClass FooClass;
typedef struct _FooPrivate FooPrivate;
typedef struct _FooClassPrivate FooClassPrivate;
-#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ParamSpecFoo ParamSpecFoo;
struct _Foo {
@@ -109,19 +108,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&self->priv->__lock_faz);
{
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&self->priv->__lock_faz);
@@ -136,19 +122,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&FOO_GET_CLASS_PRIVATE (FOO_GET_CLASS (self))->__lock_baz);
{
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp1_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp1_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp1_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
g_rec_mutex_unlock (&FOO_GET_CLASS_PRIVATE (FOO_GET_CLASS (self))->__lock_baz);
@@ -163,19 +136,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&__lock_foo_maz);
{
}
- goto __finally2;
- __catch2_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp2_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp2_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp2_;
- _g_error_free0 (_lock_error_);
- goto __finally2;
- }
__finally2:
{
g_rec_mutex_unlock (&__lock_foo_maz);
@@ -190,19 +150,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&self->priv->__lock_foor);
{
}
- goto __finally3;
- __catch3_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp3_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp3_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp3_;
- _g_error_free0 (_lock_error_);
- goto __finally3;
- }
__finally3:
{
g_rec_mutex_unlock (&self->priv->__lock_foor);
@@ -217,19 +164,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&FOO_GET_CLASS_PRIVATE (FOO_GET_CLASS (self))->__lock_boor);
{
}
- goto __finally4;
- __catch4_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp4_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp4_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp4_;
- _g_error_free0 (_lock_error_);
- goto __finally4;
- }
__finally4:
{
g_rec_mutex_unlock (&FOO_GET_CLASS_PRIVATE (FOO_GET_CLASS (self))->__lock_boor);
@@ -244,19 +178,6 @@ foo_use (Foo* self)
g_rec_mutex_lock (&__lock_foo_foo_moor);
{
}
- goto __finally5;
- __catch5_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp5_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp5_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp5_;
- _g_error_free0 (_lock_error_);
- goto __finally5;
- }
__finally5:
{
g_rec_mutex_unlock (&__lock_foo_foo_moor);
@@ -268,28 +189,15 @@ foo_use (Foo* self)
}
}
{
- gint _tmp6_;
- _tmp6_ = self->priv->_foop;
+ gint _tmp0_;
+ _tmp0_ = self->priv->_foop;
g_rec_mutex_lock (&self->priv->__lock_foop);
{
}
- goto __finally6;
- __catch6_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp7_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp7_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp7_;
- _g_error_free0 (_lock_error_);
- goto __finally6;
- }
__finally6:
{
- gint _tmp8_;
- _tmp8_ = self->priv->_foop;
+ gint _tmp1_;
+ _tmp1_ = self->priv->_foop;
g_rec_mutex_unlock (&self->priv->__lock_foop);
}
if (G_UNLIKELY (_inner_error0_ != NULL)) {
diff --git a/tests/objects/fields.c-expected b/tests/objects/fields.c-expected
index d96e92721..c0fdf2f7c 100644
--- a/tests/objects/fields.c-expected
+++ b/tests/objects/fields.c-expected
@@ -40,7 +40,6 @@ typedef struct _Faz Faz;
typedef struct _FazClass FazClass;
typedef struct _FazPrivate FazPrivate;
typedef struct _FazClassPrivate FazClassPrivate;
-#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define TYPE_BAR (bar_get_type ())
#define BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR, Bar))
@@ -578,19 +577,6 @@ faz_lock_action (Faz* self)
faz_private_static_field = 1147;
_vala_assert (faz_private_static_field == 1147, "private_static_field == 1147");
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&__lock_faz_faz_private_static_field);
@@ -607,19 +593,6 @@ faz_lock_action (Faz* self)
faz_public_static_field = 1147;
_vala_assert (faz_public_static_field == 1147, "public_static_field == 1147");
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp1_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp1_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp1_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
g_rec_mutex_unlock (&__lock_faz_faz_public_static_field);
@@ -636,19 +609,6 @@ faz_lock_action (Faz* self)
self->priv->private_field = 1147;
_vala_assert (self->priv->private_field == 1147, "private_field == 1147");
}
- goto __finally2;
- __catch2_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp2_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp2_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp2_;
- _g_error_free0 (_lock_error_);
- goto __finally2;
- }
__finally2:
{
g_rec_mutex_unlock (&self->priv->__lock_private_field);
@@ -665,19 +625,6 @@ faz_lock_action (Faz* self)
self->public_field = 1147;
_vala_assert (self->public_field == 1147, "public_field == 1147");
}
- goto __finally3;
- __catch3_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp3_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp3_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp3_;
- _g_error_free0 (_lock_error_);
- goto __finally3;
- }
__finally3:
{
g_rec_mutex_unlock (&self->priv->__lock_public_field);
@@ -701,19 +648,6 @@ faz_lock_action_class (Faz* self)
FAZ_GET_CLASS_PRIVATE (FAZ_GET_CLASS (self))->private_class_field = 1147;
_vala_assert (FAZ_GET_CLASS_PRIVATE (FAZ_GET_CLASS (self))->private_class_field == 1147, "private_class_field == 1147");
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&FAZ_GET_CLASS_PRIVATE (FAZ_GET_CLASS (self))->__lock_private_class_field);
@@ -730,19 +664,6 @@ faz_lock_action_class (Faz* self)
FAZ_GET_CLASS (self)->public_class_field = 1147;
_vala_assert (FAZ_GET_CLASS (self)->public_class_field == 1147, "public_class_field == 1147");
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp1_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp1_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp1_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
g_rec_mutex_unlock (&FAZ_GET_CLASS_PRIVATE (FAZ_GET_CLASS (self))->__lock_public_class_field);
@@ -961,19 +882,6 @@ baz_lock_action (Baz* self)
baz_private_static_field = 1147;
_vala_assert (baz_private_static_field == 1147, "private_static_field == 1147");
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&__lock_baz_baz_private_static_field);
@@ -990,19 +898,6 @@ baz_lock_action (Baz* self)
baz_public_static_field = 1147;
_vala_assert (baz_public_static_field == 1147, "public_static_field == 1147");
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp1_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp1_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp1_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
g_rec_mutex_unlock (&__lock_baz_baz_public_static_field);
@@ -1019,19 +914,6 @@ baz_lock_action (Baz* self)
self->priv->private_field = 1147;
_vala_assert (self->priv->private_field == 1147, "private_field == 1147");
}
- goto __finally2;
- __catch2_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp2_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp2_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp2_;
- _g_error_free0 (_lock_error_);
- goto __finally2;
- }
__finally2:
{
g_rec_mutex_unlock (&self->priv->__lock_private_field);
@@ -1048,19 +930,6 @@ baz_lock_action (Baz* self)
self->public_field = 1147;
_vala_assert (self->public_field == 1147, "public_field == 1147");
}
- goto __finally3;
- __catch3_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp3_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp3_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp3_;
- _g_error_free0 (_lock_error_);
- goto __finally3;
- }
__finally3:
{
g_rec_mutex_unlock (&self->priv->__lock_public_field);
@@ -1084,19 +953,6 @@ baz_lock_action_class (Baz* self)
BAZ_GET_CLASS_PRIVATE (BAZ_GET_CLASS (self))->private_class_field = 1147;
_vala_assert (BAZ_GET_CLASS_PRIVATE (BAZ_GET_CLASS (self))->private_class_field == 1147, "private_class_field == 1147");
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&BAZ_GET_CLASS_PRIVATE (BAZ_GET_CLASS (self))->__lock_private_class_field);
@@ -1113,19 +969,6 @@ baz_lock_action_class (Baz* self)
BAZ_GET_CLASS (self)->public_class_field = 1147;
_vala_assert (BAZ_GET_CLASS (self)->public_class_field == 1147, "public_class_field == 1147");
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp1_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp1_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp1_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
g_rec_mutex_unlock (&BAZ_GET_CLASS_PRIVATE (BAZ_GET_CLASS (self))->__lock_public_class_field);
diff --git a/tests/objects/properties.c-expected b/tests/objects/properties.c-expected
index b8121f1dd..7e0785610 100644
--- a/tests/objects/properties.c-expected
+++ b/tests/objects/properties.c-expected
@@ -60,7 +60,6 @@ enum {
};
static GParamSpec* sample_properties[SAMPLE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
-#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define MAMAN_TYPE_IBAZ (maman_ibaz_get_type ())
#define MAMAN_IBAZ(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MAMAN_TYPE_IBAZ, MamanIbaz))
@@ -781,23 +780,10 @@ sample_run (Sample* self)
{
sample_set_public_prop (self, 42);
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp11_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp11_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp11_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
- gint _tmp12_;
- _tmp12_ = self->priv->_public_prop;
+ gint _tmp11_;
+ _tmp11_ = self->priv->_public_prop;
g_rec_mutex_unlock (&self->priv->__lock_public_prop);
}
if (G_UNLIKELY (_inner_error0_ != NULL)) {
@@ -807,29 +793,16 @@ sample_run (Sample* self)
}
}
{
- gint _tmp13_;
- _tmp13_ = self->priv->_private_prop;
+ gint _tmp12_;
+ _tmp12_ = self->priv->_private_prop;
g_rec_mutex_lock (&self->priv->__lock_private_prop);
{
sample_set_private_prop (self, 42);
}
- goto __finally1;
- __catch1_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp14_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp14_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp14_;
- _g_error_free0 (_lock_error_);
- goto __finally1;
- }
__finally1:
{
- gint _tmp15_;
- _tmp15_ = self->priv->_private_prop;
+ gint _tmp13_;
+ _tmp13_ = self->priv->_private_prop;
g_rec_mutex_unlock (&self->priv->__lock_private_prop);
}
if (G_UNLIKELY (_inner_error0_ != NULL)) {
diff --git a/tests/parser/lock-statement.c-expected b/tests/parser/lock-statement.c-expected
index 9d0ea89d7..6deb21ef3 100644
--- a/tests/parser/lock-statement.c-expected
+++ b/tests/parser/lock-statement.c-expected
@@ -25,7 +25,6 @@
typedef struct _Foo Foo;
typedef struct _FooClass FooClass;
typedef struct _FooPrivate FooPrivate;
-#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ParamSpecFoo ParamSpecFoo;
struct _Foo {
@@ -96,19 +95,6 @@ foo_implicit_unlocking (Foo* self)
g_rec_mutex_lock (&self->priv->__lock_lockable);
{
}
- goto __finally0;
- __catch0_g_error:
- {
- GError* _lock_error_ = NULL;
- GError* _tmp0_;
- _lock_error_ = _inner_error0_;
- _inner_error0_ = NULL;
- _tmp0_ = _lock_error_;
- _lock_error_ = NULL;
- _inner_error0_ = _tmp0_;
- _g_error_free0 (_lock_error_);
- goto __finally0;
- }
__finally0:
{
g_rec_mutex_unlock (&self->priv->__lock_lockable);
diff --git a/vala/valalockstatement.vala b/vala/valalockstatement.vala
index 1035e9efc..557123525 100644
--- a/vala/valalockstatement.vala
+++ b/vala/valalockstatement.vala
@@ -84,18 +84,22 @@ public class Vala.LockStatement : CodeNode, Statement {
public override bool check (CodeContext context) {
if (body != null) {
- // if the statement isn't empty, it is converted into a try statement
+ if (!body.check (context)) {
+ return false;
+ }
+ // if the statement isn't empty, it is converted into a try statement
var fin_body = new Block (source_reference);
fin_body.add_statement (new UnlockStatement (resource, source_reference));
- var catch_body = new Block (source_reference);
- catch_body.add_statement (new ThrowStatement (new ReferenceTransferExpression (new MemberAccess.simple ("_lock_error_")), source_reference));
- var catch_clause = new CatchClause (new ErrorType (null, null), "_lock_error_", catch_body, source_reference);
- catch_clause.error_type.value_owned = true;
-
var try_stmt = new TryStatement (body, fin_body, source_reference);
- try_stmt.add_catch_clause (catch_clause);
+ if (body.tree_can_fail) {
+ var catch_body = new Block (source_reference);
+ catch_body.add_statement (new ThrowStatement (new ReferenceTransferExpression (new MemberAccess.simple ("_lock_error_")), source_reference));
+ var catch_clause = new CatchClause (new ErrorType (null, null), "_lock_error_", catch_body, source_reference);
+ catch_clause.error_type.value_owned = true;
+ try_stmt.add_catch_clause (catch_clause);
+ }
var block = new Block (source_reference);
block.add_statement (new LockStatement (resource, null, source_reference));