From a964396771194f0e7eb80ab63cac25e518c16214 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 4 Jun 2016 17:51:45 +0200 Subject: [PATCH] Deprecate signal_add() on C-API objects This commit makes the code automatically add signals when they are first used. Signed-off-by: Uli Schlachter --- common/array.h | 7 ------- common/luaclass.c | 3 --- common/luaclass.h | 2 +- common/luaobject.c | 6 +----- common/luaobject.h | 1 - common/signal.h | 49 ++++++++-------------------------------------- spawn.c | 4 ---- 7 files changed, 10 insertions(+), 62 deletions(-) diff --git a/common/array.h b/common/array.h index b988621f..a5671fbd 100644 --- a/common/array.h +++ b/common/array.h @@ -34,13 +34,6 @@ int len, size; \ } pfx##_array_t; -#define ARRAY_TYPE_EXTRA(type_t, pfx, extra) \ - typedef struct pfx##_array_t { \ - type_t *tab; \ - int len, size; \ - extra; \ - } pfx##_array_t; - #define foreach(var, array) \ for(int __foreach_index_##var = 0; \ __foreach_index_##var < (array).len; \ diff --git a/common/luaclass.c b/common/luaclass.c index 33c99a80..fa234cdc 100644 --- a/common/luaclass.c +++ b/common/luaclass.c @@ -256,9 +256,6 @@ luaA_class_setup(lua_State *L, lua_class_t *class, signal_add(&class->signals, "new"); - if (parent) - class->signals.inherits_from = &parent->signals; - lua_class_array_append(&luaA_classes, class); } diff --git a/common/luaclass.h b/common/luaclass.h index 8f731469..a5ed642a 100644 --- a/common/luaclass.h +++ b/common/luaclass.h @@ -123,7 +123,7 @@ luaA_checkudataornil(lua_State *L, int udx, lua_class_t *class) static inline int \ luaA_##prefix##_class_add_signal(lua_State *L) \ { \ - signal_add(&(lua_class).signals, luaL_checkstring(L, 1)); \ + luaA_deprecate(L, "signal usage without add_signal()"); \ return 0; \ } \ \ diff --git a/common/luaobject.c b/common/luaobject.c index 4f833d4f..8f55ed0a 100644 --- a/common/luaobject.c +++ b/common/luaobject.c @@ -253,8 +253,7 @@ signal_object_emit(lua_State *L, signal_array_t *arr, const char *name, int narg lua_remove(L, - nargs - nbfunc - 1 + i); luaA_dofunction(L, nargs, 0); } - } else - luaA_warn(L, "Trying to emit unknown signal '%s'", name); + } /* remove args */ lua_pop(L, nargs); @@ -304,9 +303,6 @@ luaA_object_emit_signal(lua_State *L, int oud, lua_remove(L, - nargs - nbfunc - 2 + i); luaA_dofunction(L, nargs + 1, 0); } - } else { - luaA_warn(L, "Trying to emit unknown signal '%s'", name); - return; } /* Then emit signal on the class */ diff --git a/common/luaobject.h b/common/luaobject.h index c3e1f056..b57ec43a 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -175,7 +175,6 @@ int luaA_object_emit_signal_simple(lua_State *); lua_setmetatable(L, -2); \ luaA_setuservalue(L, -2); \ lua_pushvalue(L, -1); \ - p->signals.inherits_from = &(lua_class).signals; \ luaA_class_emit_signal(L, &(lua_class), "new", 1); \ return p; \ } diff --git a/common/signal.h b/common/signal.h index f9a4cc1b..22dc7cb4 100644 --- a/common/signal.h +++ b/common/signal.h @@ -45,54 +45,18 @@ signal_wipe(signal_t *sig) cptr_array_wipe(&sig->sigfuncs); } -ARRAY_TYPE_EXTRA(signal_t, signal, struct signal_array_t *inherits_from) -BARRAY_FUNCS(signal_t, signal, signal_wipe, signal_cmp) +DO_BARRAY(signal_t, signal, signal_wipe, signal_cmp) static inline signal_t * signal_array_getbyid(signal_array_t *arr, unsigned long id) { signal_t sig = { .id = id }; - signal_t *result; - - result = signal_array_lookup(arr, &sig); - if(result) - return result; - - /* The signal doesn't exist yet. Check if some of our inherits_from have the - * signal and if yes, add it. - */ - signal_array_t *inherit = arr->inherits_from; - while(inherit != NULL) - { - if(signal_array_lookup(inherit, &sig)) - break; - inherit = inherit->inherits_from; - } - if(inherit) - { - /* Add the signal to this array to pretend it always existed */ - signal_array_insert(arr, sig); - result = signal_array_lookup(arr, &sig); - assert(result != NULL); - } - return result; + return signal_array_lookup(arr, &sig); } -/** Add a signal to a signal array. - * Signals have to be added before they can be added or emitted. - * \param arr The signal array. - * \param name The signal name. - */ static inline void signal_add(signal_array_t *arr, const char *name) { - unsigned long tok = a_strhash((const unsigned char *) name); - signal_t *sigfound = signal_array_getbyid(arr, tok); - if(!sigfound) - { - signal_t sig = { .id = tok }; - signal_array_insert(arr, sig); - } } /** Connect a signal inside a signal array. @@ -109,7 +73,11 @@ signal_connect(signal_array_t *arr, const char *name, const void *ref) if(sigfound) cptr_array_append(&sigfound->sigfuncs, ref); else - warn("Trying to connect to unknown signal '%s'", name); + { + signal_t sig = { .id = tok }; + cptr_array_append(&sig.sigfuncs, ref); + signal_array_insert(arr, sig); + } } /** Disconnect a signal inside a signal array. @@ -131,8 +99,7 @@ signal_disconnect(signal_array_t *arr, const char *name, const void *ref) cptr_array_remove(&sigfound->sigfuncs, func); break; } - } else - warn("Trying to disconnect from unknown signal '%s'", name); + } } #endif diff --git a/spawn.c b/spawn.c index b289b7f4..b7863e5f 100644 --- a/spawn.c +++ b/spawn.c @@ -112,8 +112,6 @@ spawn_monitor_timeout(gpointer sequence) } lua_pop(L, 1); } - else - warn("spawn::timeout signal is missing"); } sn_startup_sequence_unref(sequence); return FALSE; @@ -218,8 +216,6 @@ spawn_monitor_event(SnMonitorEvent *event, void *data) } lua_pop(L, 1); } - else - warn("%s signal is missing", event_type_str); } /** Tell the spawn module that an app has been started.