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 e11c01931d9856c424a81b4c9dbb3060c5f593fe
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Aug 18 14:52:01 2026 -0600

    eolian: document and check the C API the generator produces
    
    Two independent binding generators, the in-tree C# one and the out-of-tree ego Go
    binding, each grew a hand-maintained blocklist of functions they believed had a
    wrong parameter count in the Eolian database. Checked against the tree, none of
    them do. Every entry was one of the generator's conventions: the implicit object
    receiver, @static dropping it, a single-value getter returning its value instead
    of taking an out-parameter, or a function-typed parameter expanding to a
    (data, callback, free_cb) triplet. None of that was written down anywhere except
    in the generator's own source, so each consumer rediscovered it as a bug report.
    
    Write it down: doc/eolian-c-conventions.md specifies each rule with a worked
    example copied from generated output, and Eolian.h's front page points at it.
    
    Add scripts/check-eo-c-fidelity.py as the executable version. It computes the
    expected argument count from the Eolian database for every method and property
    and compares it with the prototype in the generated header. Over this tree it
    audits 2056 functions against 2529 prototypes and finds 690 single-value getters,
    9 functions taking function-typed parameters, and no unexplained mismatch at all.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
---
 doc/eolian-c-conventions.md    | 208 +++++++++++++++++++++++++++++++++++++++++
 scripts/check-eo-c-fidelity.py | 134 ++++++++++++++++++++++++++
 src/lib/eolian/Eolian.h        |   9 ++
 3 files changed, 351 insertions(+)

diff --git a/doc/eolian-c-conventions.md b/doc/eolian-c-conventions.md
new file mode 100644
index 0000000000..6fac0a8542
--- /dev/null
+++ b/doc/eolian-c-conventions.md
@@ -0,0 +1,208 @@
+# The C API Eolian Generates
+
+This document specifies the mapping from an `.eo` declaration to the C function a
+caller must invoke. It exists because that mapping is a convention rather than a
+one-to-one translation: several `.eo` constructs expand into a different number of C
+parameters than they appear to declare, and a reader who assumes a literal translation
+will predict the wrong prototype.
+
+That is not hypothetical. Two independent binding generators, the in-tree C# one and
+the out-of-tree ego Go binding, each accumulated hand-maintained blocklists of
+functions they believed had a wrong parameter count in the Eolian database. Checked
+against the tree, none of them did: every entry was one of the conventions below,
+usually the implicit receiver or the callback triplet. `scripts/check-eo-c-fidelity.py`
+verifies this over the whole tree and is the executable version of this document.
+
+The authority for all of it is the generator itself, `src/bin/eolian/headers.c` and
+`src/bin/eolian/sources.c`. Every prototype quoted below is copied from generated
+output in a build of this tree.
+
+---
+
+## 1. Classes
+
+Each class gets one function returning its `Efl_Class`, plus an uppercase macro:
+
+```c
+#define EFL_UI_BUTTON_CLASS efl_ui_button_class_get()
+EAPI EAPI_WEAK const Efl_Class *efl_ui_button_class_get(void) EINA_CONST;
+```
+
+Interfaces use `_interface_get`, mixins `_mixin_get`. The class name is lowercased with
+`.` replaced by `_`.
+
+The class type itself is an alias of `Eo`, emitted in an include guard so any header
+may declare it:
+
+```c
+typedef Eo Efl_Ui_Spotlight_Manager;
+```
+
+These getters are declared `EWAPI`, that is `EAPI EAPI_WEAK`: **weak**. A weak
+undefined reference does not keep a library in `DT_NEEDED` under `--as-needed`, so
+taking the address of one without otherwise using the library may resolve to NULL at
+run time.
+
+## 2. The receiver is implicit
+
+An `.eo` method never declares its own object. Every non-static function takes it as
+the first C parameter:
+
+```
+   theme_apply @protected { return: Eina.Error; }
+```
+```c
+EAPI EAPI_WEAK Eina_Error efl_ui_widget_theme_apply(Eo *obj);
+```
+
+The receiver is `const Eo *obj` for property getters and for methods marked
+`@const`, and `Eo *obj` otherwise.
+
+**This is the single most common source of "wrong argument count" reports.** A
+declaration with N parameters produces a C function with N+1.
+
+## 3. `@static` removes the receiver
+
+A `@static` function belongs to the class, not to an instance, and takes no receiver:
+
+```
+   @property app_main @static { get { values { exe: Efl.App; } } }
+```
+```c
+EAPI EAPI_WEAK Efl_App *efl_app_main_get(void);
+```
+
+There is no way to tell this from the C prototype alone — `efl_app_main_get()` looks
+like a getter whose receiver was forgotten. Generators must consult
+`eolian_function_is_static()`. Treating a static function as an instance one produces
+a call with a spurious first argument.
+
+## 4. Properties
+
+A property generates up to two functions, suffixed `_get` and `_set`. Both are named
+after the property, not the class member:
+
+```
+   @property text { set { values { text: string; } } get { values { text: string; } } }
+```
+```c
+EAPI EAPI_WEAK void efl_ui_button_text_set(Eo *obj, const char *text);
+EAPI EAPI_WEAK const char *efl_ui_button_text_get(const Eo *obj);
+```
+
+Parameter order is: receiver, then `keys` in declaration order, then `values`.
+
+### 4.1 A getter with exactly one value returns it
+
+This is the rule with the widest reach — 684 functions in this tree. A getter whose
+`values` block holds exactly one entry, and which declares no `return`, returns that
+value rather than taking an out-parameter:
+
+```c
+EAPI EAPI_WEAK const char *efl_ui_button_text_get(const Eo *obj);   /* not (Eo *, char **) */
+```
+
+### 4.2 A getter that declares a return turns its values into out-parameters
+
+When the getter has its own `return`, or more than one value, every value becomes a
+pointer parameter:
+
+```
+   @property pointer_position { get { keys { seat: Efl.Input.Device; }
+                                     values { pos: Eina.Position2D; } return: bool; } }
+```
+```c
+EVAS_API Eina_Bool efl_canvas_scene_pointer_position_get(const Eo *obj,
+                                                        Efl_Input_Device *seat,
+                                                        Eina_Position2D *pos);
+```
+
+## 5. `function`-typed parameters expand to three C parameters
+
+A parameter whose type is a declared `function` is not one pointer. It becomes a
+**triplet** in this order: user data, the function pointer, and a free callback for
+the data.
+
+```
+   @property format_func { set { values { func: Efl.Ui.Format_Func; } } }
+```
+```c
+typedef Eina_Bool (*Efl_Ui_Format_Func)(void *data, Eina_Strbuf *str, const Eina_Value value);
+
+EAPI EAPI_WEAK void efl_ui_format_func_set(Eo *obj,
+                                           void *func_data,
+                                           Efl_Ui_Format_Func func,
+                                           Eina_Free_Cb func_free_cb);
+```
+
+One declared parameter, three C parameters: **+2 each**. The names are the parameter
+name with `_data` and `_free_cb` appended.
+
+Nine functions in this tree take function-typed parameters; two of them take two, and
+so expand by four. `scripts/check-eo-c-fidelity.py` lists them.
+
+## 6. `@out` and `@inout` are pointers
+
+An `@out` parameter is passed as a pointer to storage the callee fills:
+
+```
+   filter_state_prepare @protected { params { @out state: Efl.Canvas.Filter.State;
+                                              @in data: void_ptr; } }
+```
+```c
+EVAS_API void evas_filter_state_prepare(Eo *obj, Efl_Canvas_Filter_State *state, void *data);
+```
+
+The parameter count does not change; only the level of indirection does.
+
+## 7. Ownership: `@move`
+
+`@move` transfers ownership to the caller (on a return or out-parameter) or to the
+callee (on an in-parameter). It is visible in C as an annotation, not a type change:
+
+```
+   @property properties { get { values { properties: iterator<string> @move; } } }
+```
+```c
+EAPI EAPI_WEAK Eina_Iterator *efl_model_properties_get(const Eo *obj)
+    EFL_TRANSFER_OWNERSHIP EINA_WARN_UNUSED_RESULT;
+```
+
+Without `@move` the callee keeps ownership and the caller must not free.
+
+## 8. Events
+
+Each event becomes an `Efl_Event_Description` object plus a macro taking its address:
+
+```c
+EAPI EAPI_WEAK extern const Efl_Event_Description _EFL_UI_EVENT_ITEM_CLICKED;
+#define EFL_UI_EVENT_ITEM_CLICKED (&(_EFL_UI_EVENT_ITEM_CLICKED))
+```
+
+The event name is uppercased with `,` and `.` replaced by `_`, prefixed by the class's
+`event_c_prefix` when it declares one. The payload type is whatever the event declares;
+`ev->info` points at it.
+
+## 9. Visibility gating
+
+Two independent guards wrap generated declarations, and both must be satisfied before
+a declaration exists at all:
+
+- **`@beta`** entities are emitted inside `#ifdef EFL_BETA_API_SUPPORT`. A consumer
+  that does not define it sees only stable API.
+- **`@protected`** members are emitted inside `#ifdef EFL_<CLASS>_PROTECTED`, one macro
+  per owning class, e.g. `EFL_UI_WIDGET_PROTECTED`. Define it only for the classes
+  whose protected methods you actually override; needing more than that is a bug in
+  the headers, not something a consumer should work around.
+
+A declaration that is "missing" is almost always one of these two guards rather than a
+gap in the database.
+
+---
+
+## Checking
+
+`scripts/check-eo-c-fidelity.py` walks every class in `src/lib`, computes the expected
+argument count from the Eolian database using the rules above, compares it with the
+prototype in the generated header, and fails on any difference it cannot attribute to
+§4.1 or §5. Run it after any change to `.eo` files or to the generator.
diff --git a/scripts/check-eo-c-fidelity.py b/scripts/check-eo-c-fidelity.py
new file mode 100755
index 0000000000..03e17169c7
--- /dev/null
+++ b/scripts/check-eo-c-fidelity.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python3
+"""Check that every .eo declaration agrees with the C prototype eolian generates.
+
+A binding generator reads the Eolian database and has to predict the C function
+it will have to call. When the two disagree the generator emits a broken call,
+and historically each generator grew a hand-maintained blocklist instead. This
+script checks the whole tree at once.
+
+For every method and property it compares:
+
+  naive arg count = (0 if @static else 1 receiver) + keys + values/params
+  actual arg count = the prototype in the generated .eo.h
+
+and reports every difference. Only two differences are legitimate, and both are
+conventions a generator must implement rather than defects:
+
+  -1  a getter with exactly one value returns it instead of taking an out-param
+  +2  a `function`-typed parameter expands to (data, cb, free_cb) in C,
+      so +2 per such parameter (+4 for two, and so on)
+
+Anything else is a real .eo/C mismatch and fails the run.
+
+Usage: scripts/check-eo-c-fidelity.py [build-dir]      (default: build)
+"""
+
+import glob
+import os
+import re
+import sys
+
+BUILD = sys.argv[1] if len(sys.argv) > 1 else 'build'
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+sys.path.insert(0, os.path.join(ROOT, 'src', 'scripts', 'pyolian'))
+os.environ.setdefault('EOLIAN_LIB', os.path.join(BUILD, 'src/lib/eolian/libeolian.so.1'))
+
+import eolian                                    # noqa: E402
+from eolian import Eolian_Function_Type as FT    # noqa: E402
+
+
+def load_state():
+    st = eolian.Eolian_State()
+    dirs = set(os.path.dirname(p)
+               for p in glob.glob(os.path.join(ROOT, 'src/lib/**/*.eo*'), recursive=True))
+    for d in dirs:
+        st.directory_add(d)
+    if not st.all_eot_files_parse() or not st.all_eo_files_parse():
+        sys.exit('eolian failed to parse the tree')
+    return st
+
+
+PROTO_RE = re.compile(
+    r'\b[A-Z][A-Z0-9_]*API(?:\s+[A-Z][A-Z0-9_]*API_WEAK)?\s+[^;()]*?'
+    r'\b([a-z][a-z0-9_]*)\s*\(([^;]*?)\)\s*(?:EINA_[A-Z_]+\s*)*;', re.S)
+
+
+def load_prototypes():
+    """Actual generated C prototypes, by function name."""
+    protos = {}
+    for header in glob.glob(os.path.join(BUILD, 'src/lib/**/*.eo.h'), recursive=True):
+        text = open(header, encoding='utf-8', errors='replace').read()
+        text = re.sub(r'/\*.*?\*/', '', text, flags=re.S)
+        for match in PROTO_RE.finditer(text):
+            name, args = match.group(1), match.group(2).strip()
+            protos[name] = 0 if args in ('void', '') else args.count(',') + 1
+    return protos
+
+
+FTYPES = {
+    FT.METHOD: [FT.METHOD],
+    FT.PROPERTY: [FT.PROP_GET, FT.PROP_SET],
+    FT.PROP_GET: [FT.PROP_GET],
+    FT.PROP_SET: [FT.PROP_SET],
+}
+
+
+def declared_params(func, ftype):
+    if ftype in (FT.PROP_GET, FT.PROP_SET):
+        return list(func.keys_get(ftype)) + list(func.values_get(ftype))
+    return list(func.parameters)
+
+
+def main():
+    state = load_state()
+    protos = load_prototypes()
+
+    audited = 0
+    getter_return = 0
+    triplets = []
+    mismatches = []
+
+    seen = set()
+    for cls in state.classes:
+        funcs = list(cls.functions_get(FT.METHOD)) + list(cls.functions_get(FT.PROPERTY))
+        for func in funcs:
+            for ftype in FTYPES.get(func.type, []):
+                cname = func.full_c_name_get(ftype)
+                if not cname or cname in seen or cname not in protos:
+                    continue
+                seen.add(cname)
+                audited += 1
+
+                params = declared_params(func, ftype)
+                naive = (0 if func.is_static else 1) + len(params)
+                delta = protos[cname] - naive
+
+                if delta == 0:
+                    continue
+                if delta == -1 and ftype is FT.PROP_GET and len(params) >= 1:
+                    getter_return += 1
+                elif delta > 0 and delta % 2 == 0:
+                    triplets.append((cname, cls.name, delta // 2))
+                else:
+                    mismatches.append((cname, cls.name, naive, protos[cname], delta))
+
+    print('audited %d functions against %d generated prototypes' % (audited, len(protos)))
+    print('  %4d getters returning their single value (-1)' % getter_return)
+    print('  %4d functions with function-typed parameters (+2 each)' % len(triplets))
+    for cname, cls, n in sorted(triplets):
+        print('       %-56s %s (%d callback%s)' % (cname, cls, n, '' if n == 1 else 's'))
+
+    if mismatches:
+        print('  %4d UNEXPLAINED mismatches:' % len(mismatches))
+        for cname, cls, naive, actual, delta in sorted(mismatches):
+            print('       %-56s %s: eo says %d, C has %d (%+d)'
+                  % (cname, cls, naive, actual, delta))
+        return 1
+
+    print('no unexplained .eo/C mismatches')
+    return 0
+
+
+if __name__ == '__main__':
+    sys.exit(main())
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 4d2837d209..b402d2c11f 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -23,6 +23,15 @@ extern "C" {
  * @section eolian_main_intro Introduction
  *
  * The Eolian EO file parser and code generator.
+ *
+ * The mapping from an .eo declaration to the C function a caller must invoke is
+ * a convention, not a literal translation: the object receiver is implicit,
+ * \@static drops it, a getter with a single value returns it rather than taking
+ * an out-parameter, and a function-typed parameter expands to a (data, callback,
+ * free_cb) triplet. Anyone reading this database to predict C prototypes --- a
+ * binding generator above all --- should read doc/eolian-c-conventions.md in the
+ * EFL source tree, which specifies each rule with a worked example, and
+ * scripts/check-eo-c-fidelity.py, which checks the whole tree against them.
 
  * @section eolian_main_compiling How to compile
  *

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

Reply via email to