summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-22 11:38:00 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-23 18:09:36 +0200
commit3eb7b3793b0afcc79143a74a4052cb6179334f08 (patch)
tree116799cf117a08a098860f09c278b46a94c1cb9e
parent253e18159bbc601972cad4b3b42bbbe23cbf390d (diff)
eolian: start to express ownership transfere
before @owned was not even expressed in the api definitions of the generated APIs, this adds support for it. @owned is now expressed with EFL_TRANSFER_OWNERSHIP in a arguments. And that preprocessor directive is documented. Reviewed-by: Daniel Kolesa <daniel@octaforge.org> Differential Revision: https://phab.enlightenment.org/D9369
-rw-r--r--src/bin/eolian/headers.c4
-rw-r--r--src/lib/eo/Eo.h14
-rw-r--r--src/tests/eolian/data/function_as_argument_ref.h2
-rw-r--r--src/tests/eolian/data/function_types_ref.h2
-rw-r--r--src/tests/eolian/data/struct_ref.h2
-rw-r--r--src/tests/eolian/data/typedef_ref.h2
6 files changed, 22 insertions, 4 deletions
diff --git a/src/bin/eolian/headers.c b/src/bin/eolian/headers.c
index 7aab7552ef..a4a20c495c 100644
--- a/src/bin/eolian/headers.c
+++ b/src/bin/eolian/headers.c
@@ -35,6 +35,8 @@ _gen_param(Eina_Strbuf *buf, Eolian_Function_Parameter *pr,
35 eina_strbuf_append(buf, _get_add_star(ftype, eolian_parameter_direction_get(pr))); 35 eina_strbuf_append(buf, _get_add_star(ftype, eolian_parameter_direction_get(pr)));
36 eina_strbuf_append(buf, prn); 36 eina_strbuf_append(buf, prn);
37 eina_stringshare_del(prtn); 37 eina_stringshare_del(prtn);
38 if (eolian_type_is_owned(eolian_parameter_type_get(pr)))
39 eina_strbuf_append(buf, " EFL_TRANSFER_OWNERSHIP");
38 *rpid = 0; 40 *rpid = 0;
39 return 1; 41 return 1;
40} 42}
@@ -166,6 +168,8 @@ _gen_func(const Eolian_State *state, const Eolian_Function *fid,
166 flagbuf = eina_strbuf_new(); 168 flagbuf = eina_strbuf_new();
167 eina_strbuf_prepend(flagbuf, " EINA_WARN_UNUSED_RESULT"); 169 eina_strbuf_prepend(flagbuf, " EINA_WARN_UNUSED_RESULT");
168 } 170 }
171 if (rtp && eolian_type_is_owned(rtp))
172 eina_strbuf_append(buf, " EFL_TRANSFER_OWNERSHIP");
169 if (flagbuf) 173 if (flagbuf)
170 { 174 {
171 eina_strbuf_append(buf, eina_strbuf_string_get(flagbuf)); 175 eina_strbuf_append(buf, eina_strbuf_string_get(flagbuf));
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 34c8a8c4b2..69fd84a560 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -212,6 +212,19 @@ EAPI extern unsigned int _efl_object_init_generation;
212 */ 212 */
213typedef void (*Efl_Del_Intercept) (Eo *obj_id); 213typedef void (*Efl_Del_Intercept) (Eo *obj_id);
214 214
215/**
216 * This is a no-operation. Its presence behind a function parameter indicates that
217 * ownership of the parameter is transferred to the callee.
218 * When present after a method, it indicates that the return value of the method is
219 * transferred to the caller.
220 * For objects, ownership transfer means that exactly one reference is transferred.
221 * If you transfer ownership without owning a reference in the first place, you will
222 * get unexpected behavior.
223 * For non-Objects, ownership transfer means that the responsibility of freeing a
224 * segment of memory is passed on.
225 */
226#define EFL_TRANSFER_OWNERSHIP
227
215#include "efl_object_override.eo.h" 228#include "efl_object_override.eo.h"
216#include "efl_object.eo.h" 229#include "efl_object.eo.h"
217 230
@@ -2369,6 +2382,7 @@ EAPI Eina_Iterator *eo_objects_iterator_new(void);
2369 * @return EINA_TRUE if the object is ownable. EINA_FALSE if not. 2382 * @return EINA_TRUE if the object is ownable. EINA_FALSE if not.
2370 */ 2383 */
2371EAPI Eina_Bool efl_ownable_get(const Eo *obj); 2384EAPI Eina_Bool efl_ownable_get(const Eo *obj);
2385
2372/** 2386/**
2373 * @} 2387 * @}
2374 */ 2388 */
diff --git a/src/tests/eolian/data/function_as_argument_ref.h b/src/tests/eolian/data/function_as_argument_ref.h
index 7ab0479a9f..2b677aefb3 100644
--- a/src/tests/eolian/data/function_as_argument_ref.h
+++ b/src/tests/eolian/data/function_as_argument_ref.h
@@ -19,6 +19,6 @@ EWAPI const Efl_Class *function_as_argument_class_get(void);
19 19
20EOAPI void function_as_argument_set_cb(Eo *obj, void *cb_data, SimpleFunc cb, Eina_Free_Cb cb_free_cb); 20EOAPI void function_as_argument_set_cb(Eo *obj, void *cb_data, SimpleFunc cb, Eina_Free_Cb cb_free_cb);
21 21
22EOAPI char *function_as_argument_call_cb(Eo *obj, int a, double b); 22EOAPI char *function_as_argument_call_cb(Eo *obj, int a, double b) EFL_TRANSFER_OWNERSHIP;
23 23
24#endif 24#endif
diff --git a/src/tests/eolian/data/function_types_ref.h b/src/tests/eolian/data/function_types_ref.h
index a53ba715d2..45564c6893 100644
--- a/src/tests/eolian/data/function_types_ref.h
+++ b/src/tests/eolian/data/function_types_ref.h
@@ -8,7 +8,7 @@ typedef void (*VoidFunc)(void *data);
8 8
9typedef const char * (*SimpleFunc)(void *data, int a, double b); 9typedef const char * (*SimpleFunc)(void *data, int a, double b);
10 10
11typedef double (*ComplexFunc)(void *data, const char *c, char **d); 11typedef double (*ComplexFunc)(void *data, const char *c, char **d EFL_TRANSFER_OWNERSHIP);
12 12
13typedef void (*FuncAsArgFunc)(void *data, void *cb_data, VoidFunc cb, Eina_Free_Cb cb_free_cb, void *another_cb_data, SimpleFunc another_cb, Eina_Free_Cb another_cb_free_cb); 13typedef void (*FuncAsArgFunc)(void *data, void *cb_data, VoidFunc cb, Eina_Free_Cb cb_free_cb, void *another_cb_data, SimpleFunc another_cb, Eina_Free_Cb another_cb_free_cb);
14 14
diff --git a/src/tests/eolian/data/struct_ref.h b/src/tests/eolian/data/struct_ref.h
index 6e6299b3dc..ddcb20a752 100644
--- a/src/tests/eolian/data/struct_ref.h
+++ b/src/tests/eolian/data/struct_ref.h
@@ -38,7 +38,7 @@ EWAPI const Efl_Class *struct_class_get(void);
38 * 38 *
39 * @ingroup Struct 39 * @ingroup Struct
40 */ 40 */
41EOAPI char *struct_foo(Eo *obj, int idx); 41EOAPI char *struct_foo(Eo *obj, int idx) EFL_TRANSFER_OWNERSHIP;
42 42
43EOAPI Named *struct_bar(Eo *obj); 43EOAPI Named *struct_bar(Eo *obj);
44 44
diff --git a/src/tests/eolian/data/typedef_ref.h b/src/tests/eolian/data/typedef_ref.h
index ffae7bc332..1f220b87b2 100644
--- a/src/tests/eolian/data/typedef_ref.h
+++ b/src/tests/eolian/data/typedef_ref.h
@@ -43,6 +43,6 @@ typedef enum
43 43
44EWAPI const Efl_Class *typedef_class_get(void); 44EWAPI const Efl_Class *typedef_class_get(void);
45 45
46EOAPI char *typedef_foo(Eo *obj, int idx); 46EOAPI char *typedef_foo(Eo *obj, int idx) EFL_TRANSFER_OWNERSHIP;
47 47
48#endif 48#endif