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 0936307a30fb06902575e5701ad723da8d47e596
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Aug 18 22:51:30 2026 -0600
eolian: allow @nullable on struct fields and event payloads
Parameters and returns carry @nullable; struct fields and events are the
two other places a pointer reaches a binding, and they are where
nullability is currently least visible -- a struct field's type says
nothing about whether the producer fills it in, and an event's payload
pointer is documented as "may be NULL" in prose or not at all.
On a struct field the qualifier joins @by_ref and @move after the type. On
an event it follows the type rather than joining @beta/@hot/@restart before
the colon, because it describes the payload and not the event; that also
keeps @nullable reading the same way in all four positions. An event with no
payload rejects it outright, since there is nothing there to be NULL.
eolian_typedecl_struct_field_is_nullable() and eolian_event_is_nullable()
complete the four accessors, and both sites gain the "May be @c NULL."
hint in generated headers.
The nullable fixture grows a struct with one annotated field beside an
unannotated one, and two events likewise, so the test fails if the bit is
stored too eagerly as well as if it is not stored at all.
Co-Authored-By: Claude Opus 5 <[email protected]>
---
src/bin/eolian/docs.c | 4 +++-
src/bin/eolian/types.c | 8 ++++++++
src/lib/eolian/Eolian.h | 26 ++++++++++++++++++++++++++
src/lib/eolian/database_event_api.c | 7 +++++++
src/lib/eolian/database_type_api.c | 7 +++++++
src/lib/eolian/eo_parser.c | 17 ++++++++++++++++-
src/lib/eolian/eolian_database.h | 2 ++
src/tests/eolian/data/nullable.eo | 10 ++++++++++
src/tests/eolian/eolian_parsing.c | 16 ++++++++++++++++
9 files changed, 95 insertions(+), 2 deletions(-)
diff --git a/src/bin/eolian/docs.c b/src/bin/eolian/docs.c
index f5ca47da8b..10ad86a725 100644
--- a/src/bin/eolian/docs.c
+++ b/src/bin/eolian/docs.c
@@ -421,7 +421,9 @@ eo_gen_docs_event_gen(const Eolian_State *state, const Eolian_Event *ev,
{
p = buf;
Eina_Stringshare *rts = eolian_type_c_type_get(rt);
- snprintf(buf, sizeof(buf), "@return %s", rts);
+ /* same reason as for parameters: say it in the header */
+ snprintf(buf, sizeof(buf), "@return %s%s", rts,
+ eolian_event_is_nullable(ev) ? " May be @c NULL." : "");
eina_stringshare_del(rts);
}
diff --git a/src/bin/eolian/types.c b/src/bin/eolian/types.c
index 974b7a3eef..d5c4ea2dd8 100644
--- a/src/bin/eolian/types.c
+++ b/src/bin/eolian/types.c
@@ -58,6 +58,14 @@ _type_generate(const Eolian_State *state, const Eolian_Typedecl *tp,
{
Eina_Strbuf *fbuf = eo_gen_docs_full_gen(state, fdoc, NULL,
strlen(nl));
+ /* say it in the header, as for parameters and returns */
+ if (fbuf && eolian_typedecl_struct_field_is_nullable(memb))
+ {
+ const char *cl = strstr(eina_strbuf_string_get(fbuf), " */");
+ if (cl)
+ eina_strbuf_insert(fbuf, " May be @c NULL.",
+ cl - eina_strbuf_string_get(fbuf));
+ }
if (fbuf)
eina_strbuf_append_printf(buf, " %s",
eina_strbuf_string_get(fbuf));
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 3735228ba5..5f929add00 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -2277,6 +2277,22 @@ eolian_event_is_beta(const Eolian_Event *event)
*/
EOLIAN_API Eina_Bool eolian_event_is_hot(const Eolian_Event *event);
+/**
+ * @brief Get whether an event's payload may be NULL.
+ *
+ * An event with no type is never nullable; an event whose payload is annotated
+ * @nullable hands NULL to its callbacks under conditions its documentation
+ * describes.
+ *
+ * @param[in] event the event handle
+ * @return EINA_TRUE and EINA_FALSE respectively
+ *
+ * @since 1.30
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_event_is_nullable(const Eolian_Event *event);
+
/*
* @brief Get whether an event is a restartable event.
*
@@ -2528,6 +2544,16 @@ EOLIAN_API const Eolian_Type *eolian_typedecl_struct_field_type_get(const Eolian
*/
EOLIAN_API Eina_Bool eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_Field *fl);
+/*
+ * @brief Get whether a struct field may be NULL.
+ *
+ * @param[in] fl the field.
+ * @return EINA_TRUE and EINA_FALSE respectively
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_typedecl_struct_field_is_nullable(const Eolian_Struct_Type_Field *fl);
+
/*
* @brief Get whether a struct field is moved with the struct.
*
diff --git a/src/lib/eolian/database_event_api.c b/src/lib/eolian/database_event_api.c
index cde812fdc8..a61c88a2a6 100644
--- a/src/lib/eolian/database_event_api.c
+++ b/src/lib/eolian/database_event_api.c
@@ -42,6 +42,13 @@ eolian_event_is_hot(const Eolian_Event *event)
return event->is_hot;
}
+EOLIAN_API Eina_Bool
+eolian_event_is_nullable(const Eolian_Event *event)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(event, EINA_FALSE);
+ return event->nullable;
+}
+
EOLIAN_API Eina_Bool
eolian_event_is_restart(const Eolian_Event *event)
{
diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c
index 14f1b088ab..960217c3c5 100644
--- a/src/lib/eolian/database_type_api.c
+++ b/src/lib/eolian/database_type_api.c
@@ -70,6 +70,13 @@ eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_Field *fl)
return fl->by_ref;
}
+EOLIAN_API Eina_Bool
+eolian_typedecl_struct_field_is_nullable(const Eolian_Struct_Type_Field *fl)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(fl, EINA_FALSE);
+ return fl->nullable;
+}
+
EOLIAN_API Eina_Bool
eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl)
{
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 7f9e9c53e2..ed6b888636 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -515,7 +515,8 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
FILL_BASE(fdef->base, ls, fline, fcol, STRUCT_FIELD);
fdef->type = eo_lexer_type_release(ls, tp);
fdef->base.name = eina_stringshare_ref(fname);
- Eina_Bool has_move = EINA_FALSE, has_by_ref = EINA_FALSE;
+ Eina_Bool has_move = EINA_FALSE, has_by_ref = EINA_FALSE,
+ has_nullable = EINA_FALSE;
for (;;) switch (ls->t.kw)
{
case KW_at_by_ref:
@@ -523,6 +524,11 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
fdef->by_ref = EINA_TRUE;
eo_lexer_get(ls);
break;
+ case KW_at_nullable:
+ CASE_LOCK(ls, nullable, "nullable qualifier");
+ fdef->nullable = EINA_TRUE;
+ eo_lexer_get(ls);
+ break;
case KW_at_move:
CASE_LOCK(ls, move, "move qualifier");
fdef->move = EINA_TRUE;
@@ -1927,6 +1933,15 @@ parse_event(Eo_Lexer *ls)
end:
check_next(ls, ':');
ev->type = eo_lexer_type_release(ls, parse_type_void(ls, EINA_TRUE, EINA_TRUE));
+ /* @nullable describes the payload, so it follows the type the way it does on
+ * parameters and struct fields, rather than joining the qualifiers above. */
+ if (ls->t.kw == KW_at_nullable)
+ {
+ if (ev->type->type == EOLIAN_TYPE_VOID)
+ eo_lexer_syntax_error(ls, "@nullable on an event with no payload");
+ ev->nullable = EINA_TRUE;
+ eo_lexer_get(ls);
+ }
check(ls, ';');
eo_lexer_get(ls);
FILL_DOC(ls, ev, doc);
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 2281c840d9..1c2d21cd6f 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -340,6 +340,7 @@ struct _Eolian_Event
Eolian_Object_Scope scope;
Eina_Bool is_hot :1;
Eina_Bool is_restart :1;
+ Eina_Bool nullable :1;
};
struct _Eolian_Error
@@ -357,6 +358,7 @@ struct _Eolian_Struct_Type_Field
Eolian_Documentation *doc;
Eina_Bool move :1;
Eina_Bool by_ref :1;
+ Eina_Bool nullable :1;
};
struct _Eolian_Enum_Type_Field
diff --git a/src/tests/eolian/data/nullable.eo b/src/tests/eolian/data/nullable.eo
index 79746883a3..d4df135959 100644
--- a/src/tests/eolian/data/nullable.eo
+++ b/src/tests/eolian/data/nullable.eo
@@ -6,6 +6,12 @@ struct Nullable_Box {
h: int; [[Height.]]
}
+struct Nullable_Named {
+ [[A struct with a field that may be unset. @since 1.66]]
+ name: string @nullable; [[$NULL when unnamed.]]
+ kind: string; [[Never $NULL.]]
+}
+
class Nullable {
[[A class exercising the nullable qualifier.
@@ -34,4 +40,8 @@ class Nullable {
return: Base; [[Never $NULL.]]
}
}
+ events {
+ maybe,found: Base @nullable; [[$NULL when nothing matched.]]
+ always,found: Base; [[Never $NULL.]]
+ }
}
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index 58afd5813e..bde3934e2a 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -1667,7 +1667,10 @@ EFL_START_TEST(eolian_nullable)
{
const Eolian_Function *fid;
const Eolian_Class *cls;
+ const Eolian_Struct_Type_Field *field;
+ const Eolian_Typedecl *tdl;
const Eolian_Unit *unit;
+ const Eolian_Event *ev;
Eina_Iterator *iter;
Eolian_Function_Parameter *param;
@@ -1705,6 +1708,19 @@ EFL_START_TEST(eolian_nullable)
fail_if(eolian_parameter_is_nullable(param));
eina_iterator_free(iter);
+ /* a struct field may be nullable, and its neighbour is not */
+ fail_if(!(tdl = eolian_unit_struct_by_name_get(unit, "Nullable_Named")));
+ fail_if(!(field = eolian_typedecl_struct_field_get(tdl, "name")));
+ fail_if(!eolian_typedecl_struct_field_is_nullable(field));
+ fail_if(!(field = eolian_typedecl_struct_field_get(tdl, "kind")));
+ fail_if(eolian_typedecl_struct_field_is_nullable(field));
+
+ /* so may an event payload */
+ fail_if(!(ev = eolian_class_event_by_name_get(cls, "maybe,found")));
+ fail_if(!eolian_event_is_nullable(ev));
+ fail_if(!(ev = eolian_class_event_by_name_get(cls, "always,found")));
+ fail_if(eolian_event_is_nullable(ev));
+
eolian_state_free(eos);
}
EFL_END_TEST
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.