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 33f5210147d17525541e6710d360e2709b1513cd
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Aug 18 21:35:59 2026 -0600

    eolian: implement @nullable
    
    @nullable has been a reserved keyword since Eolian was written: tokenized in the
    lexer, mentioned in a comment as "reserved for the future", with no parse site, no
    storage and no accessor. Meanwhile the tree expresses "may be NULL" by writing
    ptr(const(X)) @optional, which says something quite different -- it says the
    parameter is a pointer -- and leaves a generator no way to tell a genuinely
    optional argument from one that merely happens to be passed by address.
    
    Wire it through. A parameter or a return may now carry @nullable, the bit is
    stored alongside move and by_ref, and two accessors expose it:
    eolian_parameter_is_nullable() and eolian_function_return_is_nullable().
    
    The generated C is deliberately unchanged. @nullable is a statement about values,
    not about representation, so a nullable Efl.Object return is still Efl_Object *.
    That is what makes it usable on existing API: a signature can gain the annotation
    without any consumer noticing, while a binding that reads the database can finally
    emit an optional or a nullable reference instead of assuming every pointer is
    valid.
    
    Covered by src/tests/eolian/data/nullable.eo, which has one method where the
    first parameter and the return are nullable and the second parameter is not, and
    one where nothing is, so the test fails if the bit is stored too eagerly as well
    as if it is not stored at all. Verified non-vacuous.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
---
 src/lib/eolian/Eolian.h                          | 33 ++++++++++++++++++++
 src/lib/eolian/database_function_api.c           | 27 ++++++++++++++++
 src/lib/eolian/database_function_parameter_api.c |  7 +++++
 src/lib/eolian/eo_lexer.h                        |  2 --
 src/lib/eolian/eo_parser.c                       | 18 ++++++++++-
 src/lib/eolian/eolian_database.h                 |  3 ++
 src/tests/eolian/data/nullable.eo                | 25 +++++++++++++++
 src/tests/eolian/eolian_parsing.c                | 39 ++++++++++++++++++++++++
 8 files changed, 151 insertions(+), 3 deletions(-)

diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index b402d2c11f..3735228ba5 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -1802,6 +1802,23 @@ EOLIAN_API Eina_Bool eolian_parameter_is_optional(const Eolian_Function_Paramete
  */
 EOLIAN_API Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param_desc);
 
+/*
+ * @brief Get whether NULL is a meaningful value for a parameter.
+ *
+ * A generator should map a nullable parameter to whatever its language uses for
+ * "may be absent" -- an optional, a nullable reference -- rather than assuming a
+ * pointer is always valid. This says nothing about ownership; see
+ * @ref eolian_parameter_is_move.
+ *
+ * @param[in] param_desc The parameter handle.
+ * @return EINA_TRUE if NULL is meaningful, EINA_FALSE otherwise.
+ *
+ * @since 1.30
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_parameter_is_nullable(const Eolian_Function_Parameter *param_desc);
+
 /*
  * @brief Get whether a parameter is moved into the callee.
  *
@@ -1911,6 +1928,22 @@ EOLIAN_API Eina_Bool eolian_function_return_allow_unused(const Eolian_Function *
  */
 EOLIAN_API Eina_Bool eolian_function_return_is_by_ref(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
 
+/*
+ * @brief Get whether a function may return NULL.
+ *
+ * A generator should map a nullable return to whatever its language uses for "may
+ * be absent" rather than assuming the result is always valid.
+ *
+ * @param[in] foo_id The function handle.
+ * @param[in] ftype The function type, for property get/set distinction.
+ * @return EINA_TRUE if NULL is a possible return, EINA_FALSE otherwise.
+ *
+ * @since 1.30
+ *
+ * @ingroup Eolian
+ */
+EOLIAN_API Eina_Bool eolian_function_return_is_nullable(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
+
 /*
  * @brief Get whether a parameter is moved into the callee.
  *
diff --git a/src/lib/eolian/database_function_api.c b/src/lib/eolian/database_function_api.c
index 9fa41bf73b..5563aec87f 100644
--- a/src/lib/eolian/database_function_api.c
+++ b/src/lib/eolian/database_function_api.c
@@ -315,6 +315,33 @@ eolian_function_return_is_by_ref(const Eolian_Function *fid,
      }
 }
 
+EOLIAN_API Eina_Bool
+eolian_function_return_is_nullable(const Eolian_Function *fid,
+      Eolian_Function_Type ftype)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EINA_FALSE);
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EINA_FALSE);
+   switch (ftype)
+     {
+      case EOLIAN_METHOD:
+      case EOLIAN_FUNCTION_POINTER:
+        if (fid->type != ftype)
+          return EINA_FALSE;
+        return fid->get_return_nullable;
+      case EOLIAN_PROP_GET:
+        if ((fid->type != EOLIAN_PROP_GET) && (fid->type != EOLIAN_PROPERTY))
+          return EINA_FALSE;
+        return fid->get_return_nullable;
+      case EOLIAN_PROP_SET:
+        if ((fid->type != EOLIAN_PROP_SET) && (fid->type != EOLIAN_PROPERTY))
+          return EINA_FALSE;
+        return fid->set_return_nullable;
+      default:
+        return EINA_FALSE;
+     }
+}
+
 EOLIAN_API Eina_Bool
 eolian_function_return_is_move(const Eolian_Function *fid,
       Eolian_Function_Type ftype)
diff --git a/src/lib/eolian/database_function_parameter_api.c b/src/lib/eolian/database_function_parameter_api.c
index 80d7dbf7f3..4a3daee950 100644
--- a/src/lib/eolian/database_function_parameter_api.c
+++ b/src/lib/eolian/database_function_parameter_api.c
@@ -54,6 +54,13 @@ eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param)
    return param->by_ref;
 }
 
+EOLIAN_API Eina_Bool
+eolian_parameter_is_nullable(const Eolian_Function_Parameter *param)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE);
+   return param->nullable;
+}
+
 EOLIAN_API Eina_Stringshare *
 eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc,
                             Eina_Bool as_return)
diff --git a/src/lib/eolian/eo_lexer.h b/src/lib/eolian/eo_lexer.h
index 697f94685f..f9fd66d02e 100644
--- a/src/lib/eolian/eo_lexer.h
+++ b/src/lib/eolian/eo_lexer.h
@@ -22,8 +22,6 @@ enum Tokens
 
 /* all keywords in eolian, they can still be used as names (they're TOK_VALUE)
  * they just fill in the "kw" field of the token
- *
- * reserved for the future: @nullable
  */
 #define KEYWORDS KW(class), KW(const), KW(enum), KW(return), KW(struct), \
     \
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index e6d80dd611..7f9e9c53e2 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -1020,6 +1020,7 @@ typedef struct _Eo_Ret_Def
    Eina_Bool no_unused: 1;
    Eina_Bool move: 1;
    Eina_Bool by_ref: 1;
+   Eina_Bool nullable: 1;
 } Eo_Ret_Def;
 
 static void
@@ -1037,6 +1038,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
    ret->no_unused = EINA_FALSE;
    ret->move = EINA_FALSE;
    ret->by_ref = EINA_FALSE;
+   ret->nullable = EINA_FALSE;
    if (allow_def && (ls->t.token == '('))
      {
         int line = ls->line_number, col = ls->column;
@@ -1047,7 +1049,7 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
         check_match(ls, ')', '(', line, col);
      }
    Eina_Bool has_no_unused = EINA_FALSE, has_move = EINA_FALSE,
-             has_by_ref = EINA_FALSE;
+             has_by_ref = EINA_FALSE, has_nullable = EINA_FALSE;
    if (!is_funcptr) for (;;) switch (ls->t.kw)
      {
       case KW_at_no_unused:
@@ -1065,6 +1067,11 @@ parse_return(Eo_Lexer *ls, Eo_Ret_Def *ret, Eina_Bool allow_void,
         ret->by_ref = EINA_TRUE;
         eo_lexer_get(ls);
         break;
+      case KW_at_nullable:
+        CASE_LOCK(ls, nullable, "nullable qualifier");
+        ret->nullable = EINA_TRUE;
+        eo_lexer_get(ls);
+        break;
       default:
         goto end;
      }
@@ -1078,6 +1085,7 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
             Eina_Bool is_vals, const Eolian_Function *func)
 {
    Eina_Bool has_optional = EINA_FALSE,
+             has_nullable = EINA_FALSE,
              has_move     = EINA_FALSE,
              has_by_ref   = EINA_FALSE;
    Eolian_Function_Parameter *par = calloc(1, sizeof(Eolian_Function_Parameter));
@@ -1143,6 +1151,11 @@ type_done:
         par->by_ref = EINA_TRUE;
         eo_lexer_get(ls);
         break;
+      case KW_at_nullable:
+        CASE_LOCK(ls, nullable, "nullable qualifier");
+        par->nullable = EINA_TRUE;
+        eo_lexer_get(ls);
+        break;
       default:
         goto end;
      }
@@ -1257,6 +1270,7 @@ parse_accessor:
              prop->get_return_no_unused = ret.no_unused;
              prop->get_return_by_ref = ret.by_ref;
              prop->get_return_move = ret.move;
+             prop->get_return_nullable = ret.nullable;
           }
         else
           {
@@ -1266,6 +1280,7 @@ parse_accessor:
              prop->set_return_no_unused = ret.no_unused;
              prop->set_return_by_ref = ret.by_ref;
              prop->set_return_move = ret.move;
+             prop->set_return_nullable = ret.nullable;
           }
         break;
       case KW_keys:
@@ -1578,6 +1593,7 @@ body:
         meth->get_return_no_unused = ret.no_unused;
         meth->get_return_by_ref = ret.by_ref;
         meth->get_return_move = ret.move;
+        meth->get_return_nullable = ret.nullable;
         break;
       case KW_params:
         CASE_LOCK(ls, params, "params definition")
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 2aedd51432..2281c840d9 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -232,6 +232,8 @@ struct _Eolian_Function
    Eina_Bool set_return_no_unused :1;
    Eina_Bool get_return_move      :1;
    Eina_Bool set_return_move      :1;
+   Eina_Bool get_return_nullable  :1;
+   Eina_Bool set_return_nullable  :1;
    Eina_Bool get_return_by_ref    :1;
    Eina_Bool set_return_by_ref    :1;
    Eina_Bool is_static :1;
@@ -259,6 +261,7 @@ struct _Eolian_Function_Parameter
    Eina_Bool optional :1; /* True if this argument is optional */
    Eina_Bool by_ref   :1;
    Eina_Bool move     :1;
+   Eina_Bool nullable :1; /* True if NULL is a meaningful value here */
 };
 
 typedef enum
diff --git a/src/tests/eolian/data/nullable.eo b/src/tests/eolian/data/nullable.eo
new file mode 100644
index 0000000000..79cc93899d
--- /dev/null
+++ b/src/tests/eolian/data/nullable.eo
@@ -0,0 +1,25 @@
+import base;
+
+class Nullable {
+    [[A class exercising the nullable qualifier.
+
+      @since 1.66
+    ]]
+    methods {
+        find {
+            [[Looks something up, and may not find it.]]
+            params {
+                @in name: string @nullable; [[May be $NULL to match anything.]]
+                @in fallback: string; [[Never $NULL.]]
+            }
+            return: Base @nullable; [[$NULL when nothing matched.]]
+        }
+        exact {
+            [[Looks something up and always finds it.]]
+            params {
+                @in name: string; [[Never $NULL.]]
+            }
+            return: Base; [[Never $NULL.]]
+        }
+    }
+}
diff --git a/src/tests/eolian/eolian_parsing.c b/src/tests/eolian/eolian_parsing.c
index e2fc32601c..0190e59daf 100644
--- a/src/tests/eolian/eolian_parsing.c
+++ b/src/tests/eolian/eolian_parsing.c
@@ -1663,6 +1663,44 @@ EFL_START_TEST(eolian_future_opaque)
 }
 EFL_END_TEST
 
+EFL_START_TEST(eolian_nullable)
+{
+   const Eolian_Function *fid;
+   const Eolian_Class *cls;
+   const Eolian_Unit *unit;
+   Eina_Iterator *iter;
+   Eolian_Function_Parameter *param;
+
+   Eolian_State *eos = eolian_state_new();
+
+   fail_if(!eolian_state_directory_add(eos, TESTS_SRC_DIR"/data"));
+   fail_if(!(unit = eolian_state_file_parse(eos, "nullable.eo")));
+   fail_if(!(cls = eolian_unit_class_by_name_get(unit, "Nullable")));
+
+   /* find(): first param and the return are nullable, the second param is not */
+   fail_if(!(fid = eolian_class_function_by_name_get(cls, "find", EOLIAN_METHOD)));
+   fail_if(!eolian_function_return_is_nullable(fid, EOLIAN_METHOD));
+
+   iter = eolian_function_parameters_get(fid);
+   fail_if(!eina_iterator_next(iter, (void**)&param));
+   fail_if(!eolian_parameter_is_nullable(param));
+   fail_if(!eina_iterator_next(iter, (void**)&param));
+   fail_if(eolian_parameter_is_nullable(param));
+   eina_iterator_free(iter);
+
+   /* exact(): nothing is nullable */
+   fail_if(!(fid = eolian_class_function_by_name_get(cls, "exact", EOLIAN_METHOD)));
+   fail_if(eolian_function_return_is_nullable(fid, EOLIAN_METHOD));
+
+   iter = eolian_function_parameters_get(fid);
+   fail_if(!eina_iterator_next(iter, (void**)&param));
+   fail_if(eolian_parameter_is_nullable(param));
+   eina_iterator_free(iter);
+
+   eolian_state_free(eos);
+}
+EFL_END_TEST
+
 EFL_START_TEST(eolian_version)
 {
    Eolian_State *eos = eolian_state_new();
@@ -1708,5 +1746,6 @@ void eolian_parsing_test(TCase *tc)
    tcase_add_test(tc, eolian_class_unimpl_inherited_composite);
    tcase_add_test(tc, eolian_class_beta_inherit);
    tcase_add_test(tc, eolian_future_opaque);
+   tcase_add_test(tc, eolian_nullable);
    tcase_add_test(tc, eolian_version);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to