This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch eolian/improvements
in repository efl.
View the commit online.
commit 2b5eefbb2b092897e6db4890d8bb785a163fea36
Author: [email protected] <[email protected]>
AuthorDate: Thu Oct 29 21:22:24 2026 -0600
eo: functions that can only be called during construction
Some properties only make sense while an object is being built: a
window's name cannot change once the window exists, for instance. The
generated API had no way to refuse the late call, so it silently did
whatever the implementation happened to do.
Add EFL_FUNC_BODY_CONSTRUCT_ONLY and the matching _CONST, _OPT and
FALLBACK variants of the other body macros. The private
_EFL_OBJECT_*FUNC_BODY* macros gain a Guard parameter so both families
share one implementation, and Eo.h now includes errno.h for the
EPERM the reflection setters report.
The check, _efl_object_call_construct_only_check, runs after the call
is resolved, so efl_super/efl_cast state and auto-unref have already
been consumed by the real call. It reads the object's finalized flag
directly and, when set, logs in the eo domain naming the function and
the object. It then ends the call and takes the error path, so a
FALLBACK body still frees the arguments it owns and the default return
value is returned.
Every finalize implementation and the efl_add construction block run
before the object is marked finalized, so they can still call these
functions. A new eo suite test covers calls before and after
finalization, through efl_super, and the fallback ownership case.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/eo/Eo.h | 73 +++++--
src/lib/eo/eo.c | 12 ++
src/tests/eo/suite/eo_suite.c | 1 +
src/tests/eo/suite/eo_suite.h | 1 +
src/tests/eo/suite/eo_test_construct_only.c | 282 ++++++++++++++++++++++++++++
src/tests/eo/suite/meson.build | 3 +-
6 files changed, 351 insertions(+), 21 deletions(-)
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index e6d470750b..16571e3175 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -2,6 +2,7 @@
#define EO_H
#include <stdarg.h>
+#include <errno.h> /* EPERM, from generated construct only reflection */
#include <Eina.h>
#ifdef EO_API
@@ -1316,13 +1317,14 @@ __##Name##_failed: EINA_COLD; \
#define _EFL_OBJECT_API_CALL_HOOK(x) x
// to define an EO_API function
-#define _EFL_OBJECT_FUNC_BODY(Name, ObjType, Ret, DefRet, ErrorCase) \
+#define _EFL_OBJECT_FUNC_BODY(Name, ObjType, Ret, DefRet, ErrorCase, Guard) \
Ret \
Name(ObjType obj) \
{ \
typedef Ret (*_Eo_##Name##_func)(Eo *, void *obj_data); \
Ret _r; \
EFL_FUNC_COMMON_OP(obj, Name, DefRet); \
+ Guard \
_EFL_OBJECT_API_BEFORE_HOOK \
_r = _EFL_OBJECT_API_CALL_HOOK(_func_(___call.eo_id, ___call.data)); \
_efl_object_call_end(&___call); \
@@ -1331,12 +1333,13 @@ __##Name##_failed: EINA_COLD; \
EFL_FUNC_COMMON_OP_END(obj, Name, DefRet, ErrorCase); \
}
-#define _EFL_OBJECT_VOID_FUNC_BODY(Name, ObjType, ErrorCase) \
+#define _EFL_OBJECT_VOID_FUNC_BODY(Name, ObjType, ErrorCase, Guard) \
void \
Name(ObjType obj) \
{ \
typedef void (*_Eo_##Name##_func)(Eo *, void *obj_data); \
EFL_FUNC_COMMON_OP(obj, Name, ); \
+ Guard \
_EFL_OBJECT_API_BEFORE_HOOK \
_EFL_OBJECT_API_CALL_HOOK(_func_(___call.eo_id, ___call.data)); \
_efl_object_call_end(&___call); \
@@ -1345,13 +1348,14 @@ __##Name##_failed: EINA_COLD; \
EFL_FUNC_COMMON_OP_END(obj, Name, , ErrorCase); \
}
-#define _EFL_OBJECT_FUNC_BODYV(Name, ObjType, Ret, DefRet, ErrorCase, Arguments, ...) \
+#define _EFL_OBJECT_FUNC_BODYV(Name, ObjType, Ret, DefRet, ErrorCase, Guard, Arguments, ...) \
Ret \
Name(ObjType obj, __VA_ARGS__) \
{ \
typedef Ret (*_Eo_##Name##_func)(Eo *, void *obj_data, __VA_ARGS__); \
Ret _r; \
EFL_FUNC_COMMON_OP(obj, Name, DefRet); \
+ Guard \
_EFL_OBJECT_API_BEFORE_HOOK \
_r = _EFL_OBJECT_API_CALL_HOOK(_func_(___call.eo_id, ___call.data, Arguments)); \
_efl_object_call_end(&___call); \
@@ -1360,12 +1364,13 @@ __##Name##_failed: EINA_COLD; \
EFL_FUNC_COMMON_OP_END(obj, Name, DefRet, ErrorCase); \
}
-#define _EFL_OBJECT_VOID_FUNC_BODYV(Name, ObjType, ErrorCase, Arguments, ...) \
+#define _EFL_OBJECT_VOID_FUNC_BODYV(Name, ObjType, ErrorCase, Guard, Arguments, ...) \
void \
Name(ObjType obj, __VA_ARGS__) \
{ \
typedef void (*_Eo_##Name##_func)(Eo *, void *obj_data, __VA_ARGS__); \
EFL_FUNC_COMMON_OP(obj, Name, ); \
+ Guard \
_EFL_OBJECT_API_BEFORE_HOOK \
_EFL_OBJECT_API_CALL_HOOK(_func_(___call.eo_id, ___call.data, Arguments)); \
_efl_object_call_end(&___call); \
@@ -1374,28 +1379,52 @@ __##Name##_failed: EINA_COLD; \
EFL_FUNC_COMMON_OP_END(obj, Name, , ErrorCase); \
}
-#define EFL_FUNC_BODY(Name, Ret, DefRet) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, )
-#define EFL_VOID_FUNC_BODY(Name) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, )
-#define EFL_FUNC_BODYV(Name, Ret, DefRet, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_VOID_FUNC_BODYV(Name, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_FUNC_BODY(Name, Ret, DefRet) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, , )
+#define EFL_VOID_FUNC_BODY(Name) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, , )
+#define EFL_FUNC_BODYV(Name, Ret, DefRet, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, , , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV(Name, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, , , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_FUNC_BODY_CONST(Name, Ret, DefRet) _EFL_OBJECT_FUNC_BODY(Name, const Eo *, Ret, DefRet, )
-#define EFL_VOID_FUNC_BODY_CONST(Name) _EFL_OBJECT_VOID_FUNC_BODY(Name, const Eo *, )
-#define EFL_FUNC_BODYV_CONST(Name, Ret, DefRet, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, const Eo *, Ret, DefRet, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_VOID_FUNC_BODYV_CONST(Name, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, const Eo *, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_FUNC_BODY_CONST(Name, Ret, DefRet) _EFL_OBJECT_FUNC_BODY(Name, const Eo *, Ret, DefRet, , )
+#define EFL_VOID_FUNC_BODY_CONST(Name) _EFL_OBJECT_VOID_FUNC_BODY(Name, const Eo *, , )
+#define EFL_FUNC_BODYV_CONST(Name, Ret, DefRet, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, const Eo *, Ret, DefRet, , , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV_CONST(Name, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, const Eo *, , , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
// The following macros are also taking a FallbackCall the call you specify there will be called once the call cannot be redirected to a object,
// which means eo will be the deepest scope this call will ever get.
-#define EFL_FUNC_BODY_FALLBACK(Name, Ret, DefRet, FallbackCall) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, FallbackCall)
-#define EFL_VOID_FUNC_BODY_FALLBACK(Name, FallbackCall) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, FallbackCall)
-#define EFL_FUNC_BODYV_FALLBACK(Name, Ret, DefRet, FallbackCall, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, FallbackCall, EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_VOID_FUNC_BODYV_FALLBACK(Name, FallbackCall, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, FallbackCall, EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_FUNC_BODY_FALLBACK(Name, Ret, DefRet, FallbackCall) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, FallbackCall, )
+#define EFL_VOID_FUNC_BODY_FALLBACK(Name, FallbackCall) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, FallbackCall, )
+#define EFL_FUNC_BODYV_FALLBACK(Name, Ret, DefRet, FallbackCall, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, FallbackCall, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV_FALLBACK(Name, FallbackCall, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, FallbackCall, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_FUNC_BODY_CONST_FALLBACK(Name, Ret, DefRet, FallbackCall) _EFL_OBJECT_FUNC_BODY(Name, const Eo *, Ret, DefRet, FallbackCall)
-#define EFL_VOID_FUNC_BODY_CONST_FALLBACK(Name, FallbackCall) _EFL_OBJECT_VOID_FUNC_BODY(Name, const Eo *, FallbackCall)
-#define EFL_FUNC_BODYV_CONST_FALLBACK(Name, Ret, DefRet, FallbackCall, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, const Eo *, Ret, DefRet, FallbackCall, EFL_FUNC_CALL(Arguments), __VA_ARGS__)
-#define EFL_VOID_FUNC_BODYV_CONST_FALLBACK(Name, FallbackCall, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, const Eo *, FallbackCall, EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_FUNC_BODY_CONST_FALLBACK(Name, Ret, DefRet, FallbackCall) _EFL_OBJECT_FUNC_BODY(Name, const Eo *, Ret, DefRet, FallbackCall, )
+#define EFL_VOID_FUNC_BODY_CONST_FALLBACK(Name, FallbackCall) _EFL_OBJECT_VOID_FUNC_BODY(Name, const Eo *, FallbackCall, )
+#define EFL_FUNC_BODYV_CONST_FALLBACK(Name, Ret, DefRet, FallbackCall, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, const Eo *, Ret, DefRet, FallbackCall, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV_CONST_FALLBACK(Name, FallbackCall, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, const Eo *, FallbackCall, , EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+
+// The following macros are for the functions an .eo file marks @construct_only:
+// once the object is finalized the call is refused with an error, the
+// implementation is not called and DefRet (or nothing) is returned. The
+// FALLBACK variants run FallbackCall in that case too, so the arguments the
+// function would have taken ownership of are still released. The check runs
+// after the call is resolved, so efl_super() and efl_cast() state has already
+// been consumed by the right call, and it reads the finalized flag of the
+// resolved object directly: no extra Eo call. These are for generated code,
+// and there is no CONST variant: a function that only reads the object has
+// nothing to protect.
+#define _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name) \
+ if (EINA_UNLIKELY(_efl_object_call_construct_only_check(&___call, #Name, __FILE__, __LINE__))) \
+ goto __##Name##_failed;
+
+#define EFL_FUNC_BODY_CONSTRUCT_ONLY(Name, Ret, DefRet) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, , _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name))
+#define EFL_VOID_FUNC_BODY_CONSTRUCT_ONLY(Name) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, , _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name))
+#define EFL_FUNC_BODYV_CONSTRUCT_ONLY(Name, Ret, DefRet, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, , _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name), EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY(Name, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, , _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name), EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+
+#define EFL_FUNC_BODY_CONSTRUCT_ONLY_FALLBACK(Name, Ret, DefRet, FallbackCall) _EFL_OBJECT_FUNC_BODY(Name, Eo *, Ret, DefRet, FallbackCall, _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name))
+#define EFL_VOID_FUNC_BODY_CONSTRUCT_ONLY_FALLBACK(Name, FallbackCall) _EFL_OBJECT_VOID_FUNC_BODY(Name, Eo *, FallbackCall, _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name))
+#define EFL_FUNC_BODYV_CONSTRUCT_ONLY_FALLBACK(Name, Ret, DefRet, FallbackCall, Arguments, ...) _EFL_OBJECT_FUNC_BODYV(Name, Eo *, Ret, DefRet, FallbackCall, _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name), EFL_FUNC_CALL(Arguments), __VA_ARGS__)
+#define EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY_FALLBACK(Name, FallbackCall, Arguments, ...) _EFL_OBJECT_VOID_FUNC_BODYV(Name, Eo *, FallbackCall, _EFL_OBJECT_CONSTRUCT_ONLY_GUARD(Name), EFL_FUNC_CALL(Arguments), __VA_ARGS__)
#ifndef _WIN32
# define _EFL_OBJECT_OP_API_ENTRY(a) (void*)a
@@ -1415,6 +1444,10 @@ EO_API Eina_Bool _efl_object_call_resolve(Eo *obj, const char *func_name, Efl_Ob
// end of the eo call barrier, unref the obj
EO_API void _efl_object_call_end(Efl_Object_Op_Call_Data *call);
+// for @construct_only functions, after resolve: EINA_TRUE (and the call is
+// ended, error logged) if the resolved object is already finalized
+EO_API Eina_Bool _efl_object_call_construct_only_check(Efl_Object_Op_Call_Data *call, const char *func_name, const char *file, int line);
+
// end of the efl_add. Calls finalize among others
EO_API Eo * _efl_add_end(Eo *obj, Eina_Bool is_ref, Eina_Bool is_fallback);
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index df8544b294..d16d21d3d8 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -703,6 +703,18 @@ _efl_object_call_end(Efl_Object_Op_Call_Data *call)
}
}
+EO_API Eina_Bool
+_efl_object_call_construct_only_check(Efl_Object_Op_Call_Data *call, const char *func_name, const char *file, int line)
+{
+ // obj->finalized is only set once every finalize has returned
+ if (EINA_LIKELY(!call->obj->finalized)) return EINA_FALSE;
+
+ ERR("in %s:%d: '%s' is only allowed during construction, but %s is already finalized.",
+ file, line, func_name, efl_debug_name_get(call->eo_id));
+ _efl_object_call_end(call);
+ return EINA_TRUE;
+}
+
static inline Eina_Bool
_eo_api_func_equal(const void *api_func1, const void *api_func2)
{
diff --git a/src/tests/eo/suite/eo_suite.c b/src/tests/eo/suite/eo_suite.c
index fe8e419e0f..e0c53def14 100644
--- a/src/tests/eo/suite/eo_suite.c
+++ b/src/tests/eo/suite/eo_suite.c
@@ -21,6 +21,7 @@ static const Efl_Test_Case etc[] = {
{ "Eo event calls", eo_test_event},
{ "Eo lifecycle", eo_test_lifecycle},
{ "Eo Reflection", eo_test_reflection},
+ { "Eo construct only", eo_test_construct_only},
{ NULL, NULL }
};
diff --git a/src/tests/eo/suite/eo_suite.h b/src/tests/eo/suite/eo_suite.h
index 84da2054f8..9cbf4a3700 100644
--- a/src/tests/eo/suite/eo_suite.h
+++ b/src/tests/eo/suite/eo_suite.h
@@ -13,4 +13,5 @@ void eo_test_threaded_calls(TCase *tc);
void eo_test_event(TCase *tc);
void eo_test_lifecycle(TCase *tc);
void eo_test_reflection(TCase *tc);
+void eo_test_construct_only(TCase *tc);
#endif /* _EO_SUITE_H */
diff --git a/src/tests/eo/suite/eo_test_construct_only.c b/src/tests/eo/suite/eo_test_construct_only.c
new file mode 100644
index 0000000000..d9e36716a9
--- /dev/null
+++ b/src/tests/eo/suite/eo_test_construct_only.c
@@ -0,0 +1,282 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <Eo.h>
+
+#include "eo_suite.h"
+#include "eo_error_msgs.h"
+
+/* A class written the way eolian_gen writes one whose .eo has
+ * constructors { .value @construct_only; .reset @construct_only; }
+ * with a finalize that configures itself, as the classes using it will. */
+
+typedef struct
+{
+ int value;
+ int resets;
+ Eina_Bool finalize_set;
+} Co_Data;
+
+#define CO_CLASS co_class_get()
+const Efl_Class *co_class_get(void);
+#define CO_CHILD_CLASS co_child_class_get()
+const Efl_Class *co_child_class_get(void);
+
+static struct log_ctx ctx;
+
+Eina_Bool co_value_set(Eo *obj, int value);
+int co_value_get(const Eo *obj);
+void co_reset(Eo *obj);
+void co_free_set(Eo *obj, Eina_List *list);
+
+EFL_FUNC_BODYV_CONSTRUCT_ONLY(co_value_set, Eina_Bool, EINA_FALSE, EFL_FUNC_CALL(value), int value);
+EFL_FUNC_BODY_CONST(co_value_get, int, -1);
+EFL_VOID_FUNC_BODY_CONSTRUCT_ONLY(co_reset);
+
+static Eina_Bool fallback_called;
+
+static void
+_co_free_set_fallback(Eina_List *list)
+{
+ fallback_called = EINA_TRUE;
+ eina_list_free(list);
+}
+
+EFL_VOID_FUNC_BODYV_CONSTRUCT_ONLY_FALLBACK(co_free_set, _co_free_set_fallback(list);, EFL_FUNC_CALL(list), Eina_List *list);
+
+static Eina_Bool
+_co_value_set(Eo *obj EINA_UNUSED, Co_Data *pd, int value)
+{
+ pd->value = value;
+ return EINA_TRUE;
+}
+
+static int
+_co_value_get(const Eo *obj EINA_UNUSED, Co_Data *pd)
+{
+ return pd->value;
+}
+
+static void
+_co_reset(Eo *obj EINA_UNUSED, Co_Data *pd)
+{
+ pd->resets++;
+}
+
+static void
+_co_free_set(Eo *obj EINA_UNUSED, Co_Data *pd EINA_UNUSED, Eina_List *list)
+{
+ eina_list_free(list);
+}
+
+static Eo *
+_co_finalize(Eo *obj, Co_Data *pd)
+{
+ /* finalize runs before the object is flagged as finalized */
+ if (!pd->value) pd->finalize_set = co_value_set(obj, 7);
+ return efl_finalize(efl_super(obj, CO_CLASS));
+}
+
+static Eina_Bool
+_co_class_initializer(Efl_Class *klass)
+{
+ EFL_OPS_DEFINE(ops,
+ EFL_OBJECT_OP_FUNC(co_value_set, _co_value_set),
+ EFL_OBJECT_OP_FUNC(co_value_get, _co_value_get),
+ EFL_OBJECT_OP_FUNC(co_reset, _co_reset),
+ EFL_OBJECT_OP_FUNC(co_free_set, _co_free_set),
+ EFL_OBJECT_OP_FUNC(efl_finalize, _co_finalize),
+ );
+
+ return efl_class_functions_set(klass, &ops, NULL);
+}
+
+static const Efl_Class_Description _co_class_desc = {
+ EO_VERSION,
+ "Construct_Only_Test",
+ EFL_CLASS_TYPE_REGULAR,
+ sizeof(Co_Data),
+ _co_class_initializer,
+ NULL,
+ NULL
+};
+
+EFL_DEFINE_CLASS(co_class_get, &_co_class_desc, EFL_OBJECT_CLASS, NULL)
+
+static Eo *
+_co_add_with_value(Eo *obj, void *data)
+{
+ Eina_Bool *ok = data;
+ *ok = co_value_set(obj, 42);
+ co_reset(obj);
+ return obj;
+}
+
+EFL_START_TEST(eo_test_construct_only_in_add)
+{
+ Eina_Bool ok = EINA_FALSE;
+ Eo *obj = efl_add_ref(CO_CLASS, NULL, _co_add_with_value(efl_added, &ok));
+
+ fail_if(!obj);
+ fail_if(!ok);
+ ck_assert_int_eq(co_value_get(obj), 42);
+ /* the class own finalize left a value that was given alone */
+ fail_if(((Co_Data *)efl_data_scope_get(obj, CO_CLASS))->finalize_set);
+ ck_assert_int_eq(((Co_Data *)efl_data_scope_get(obj, CO_CLASS))->resets, 1);
+
+ efl_unref(obj);
+}
+EFL_END_TEST
+
+EFL_START_TEST(eo_test_construct_only_own_finalize)
+{
+ Eo *obj = efl_add_ref(CO_CLASS, NULL);
+
+ fail_if(!obj);
+ /* the setter was accepted from the finalize of the class itself */
+ fail_if(!((Co_Data *)efl_data_scope_get(obj, CO_CLASS))->finalize_set);
+ ck_assert_int_eq(co_value_get(obj), 7);
+
+ efl_unref(obj);
+}
+EFL_END_TEST
+
+EFL_START_TEST(eo_test_construct_only_after_finalize)
+{
+ Eo *obj = efl_add_ref(CO_CLASS, NULL);
+ Eina_List *list;
+
+ fail_if(!obj);
+ fail_if(!efl_finalized_get(obj));
+ eina_log_print_cb_set(eo_test_print_cb, &ctx);
+
+ /* refused: logged, nothing changed, the default is returned */
+ TEST_EO_ERROR("_efl_object_call_construct_only_check", NULL);
+ fail_if(co_value_set(obj, 99));
+ fail_unless(ctx.did);
+ ck_assert_int_eq(co_value_get(obj), 7);
+
+ TEST_EO_ERROR("_efl_object_call_construct_only_check", NULL);
+ co_reset(obj);
+ fail_unless(ctx.did);
+ ck_assert_int_eq(((Co_Data *)efl_data_scope_get(obj, CO_CLASS))->resets, 0);
+
+ /* the fallback still releases what the call would have owned */
+ fallback_called = EINA_FALSE;
+ list = eina_list_append(NULL, "a");
+ TEST_EO_ERROR("_efl_object_call_construct_only_check", NULL);
+ co_free_set(obj, list);
+ fail_unless(ctx.did);
+ fail_unless(fallback_called);
+
+ /* a getter is never refused */
+ ck_assert_int_eq(co_value_get(obj), 7);
+
+ eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+ efl_unref(obj);
+}
+EFL_END_TEST
+
+/* A subclass that chains up to the construct-only setter of its parent: the
+ * guard must not eat the efl_super() state of the call. */
+static int _child_depth;
+
+static Eina_Bool
+_co_child_value_set(Eo *obj, void *pd EINA_UNUSED, int value)
+{
+ _child_depth++;
+ ck_assert_int_lt(_child_depth, 4);
+ return co_value_set(efl_super(obj, CO_CHILD_CLASS), value + 1);
+}
+
+static Eina_Bool
+_co_child_class_initializer(Efl_Class *klass)
+{
+ EFL_OPS_DEFINE(ops,
+ EFL_OBJECT_OP_FUNC(co_value_set, _co_child_value_set),
+ );
+
+ return efl_class_functions_set(klass, &ops, NULL);
+}
+
+static const Efl_Class_Description _co_child_class_desc = {
+ EO_VERSION,
+ "Construct_Only_Test_Child",
+ EFL_CLASS_TYPE_REGULAR,
+ 0,
+ _co_child_class_initializer,
+ NULL,
+ NULL
+};
+
+EFL_DEFINE_CLASS(co_child_class_get, &_co_child_class_desc, CO_CLASS, NULL)
+
+static Eo *
+_co_child_add(Eo *obj, void *data)
+{
+ Eina_Bool *ok = data;
+ *ok = co_value_set(obj, 10);
+ return obj;
+}
+
+EFL_START_TEST(eo_test_construct_only_super)
+{
+ Eina_Bool ok = EINA_FALSE;
+ Eo *obj;
+
+ _child_depth = 0;
+ obj = efl_add_ref(CO_CHILD_CLASS, NULL, _co_child_add(efl_added, &ok));
+ fail_if(!obj);
+ fail_if(!ok);
+ /* during construction the override ran once and reached the base */
+ ck_assert_int_eq(_child_depth, 1);
+ ck_assert_int_eq(co_value_get(obj), 11);
+
+ /* after finalize the override is refused once, before it runs */
+ eina_log_print_cb_set(eo_test_print_cb, &ctx);
+ TEST_EO_ERROR("_efl_object_call_construct_only_check", NULL);
+ fail_if(co_value_set(obj, 50));
+ fail_unless(ctx.did);
+ ck_assert_int_eq(_child_depth, 1);
+ ck_assert_int_eq(co_value_get(obj), 11);
+ eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+
+ efl_unref(obj);
+}
+EFL_END_TEST
+
+static int _null_logs;
+
+static void
+_null_print_cb(const Eina_Log_Domain *d EINA_UNUSED, Eina_Log_Level level, const char *file EINA_UNUSED, const char *fnc EINA_UNUSED, int line EINA_UNUSED, const char *fmt EINA_UNUSED, void *data EINA_UNUSED, va_list args EINA_UNUSED)
+{
+ if (level <= EINA_LOG_LEVEL_WARN) _null_logs++;
+}
+
+EFL_START_TEST(eo_test_construct_only_null)
+{
+ eina_log_print_cb_set(_null_print_cb, NULL);
+
+ /* one message from the failed resolve, none from the guard, no crash */
+ _null_logs = 0;
+ fail_if(co_value_set(NULL, 1));
+ ck_assert_int_le(_null_logs, 1);
+ _null_logs = 0;
+ co_reset(NULL);
+ ck_assert_int_le(_null_logs, 1);
+
+ eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+}
+EFL_END_TEST
+
+void eo_test_construct_only(TCase *tc)
+{
+ tcase_add_test(tc, eo_test_construct_only_in_add);
+ tcase_add_test(tc, eo_test_construct_only_own_finalize);
+ tcase_add_test(tc, eo_test_construct_only_after_finalize);
+ tcase_add_test(tc, eo_test_construct_only_super);
+ tcase_add_test(tc, eo_test_construct_only_null);
+}
diff --git a/src/tests/eo/suite/meson.build b/src/tests/eo/suite/meson.build
index a0249c5c8a..f46e7bc99c 100644
--- a/src/tests/eo/suite/meson.build
+++ b/src/tests/eo/suite/meson.build
@@ -18,7 +18,8 @@ eo_suite_src = [
'eo_test_threaded_calls.c',
'eo_test_init.c',
'eo_test_lifecycle.c',
- 'eo_test_reflection.c'
+ 'eo_test_reflection.c',
+ 'eo_test_construct_only.c'
]
eo_suite = executable('eo_suite',
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.