Răsfoiți Sursa

ncd: NCDModule: don't store a callback state pointer for NCDModuleProcess user callbacks. Instead, pass the
NCDModuleProcess pointer.

ambrop7 13 ani în urmă
părinte
comite
ad34835ccf

+ 7 - 8
ncd/NCDModule.c

@@ -322,7 +322,7 @@ btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n)
     return n->params->iparams->func_interp_getretrytime(n->params->iparams->user);
 }
 
-int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, void *user, NCDModuleProcess_handler_event handler_event)
+int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event)
 {
     DebugObject_Access(&n->d_obj);
     ASSERT(n->state == STATE_DOWN_UNCLEAN || n->state == STATE_DOWN_CLEAN ||
@@ -334,7 +334,6 @@ int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_i
     
     // init arguments
     o->args = args;
-    o->user = user;
     o->handler_event = handler_event;
     
     // set no special functions
@@ -365,7 +364,7 @@ fail1:
     return 0;
 }
 
-int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, void *user, NCDModuleProcess_handler_event handler_event)
+int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event)
 {
     DebugObject_Access(&n->d_obj);
     ASSERT(n->state == STATE_DOWN_UNCLEAN || n->state == STATE_DOWN_CLEAN ||
@@ -395,7 +394,7 @@ int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef
         }
     }
     
-    return NCDModuleProcess_InitId(o, n, template_name_id, args, user, handler_event);
+    return NCDModuleProcess_InitId(o, n, template_name_id, args, handler_event);
 }
 
 void NCDModuleProcess_Free (NCDModuleProcess *o)
@@ -479,7 +478,7 @@ void NCDModuleProcess_Interp_Up (NCDModuleProcess *o)
     
     set_process_state(o, PROCESS_STATE_UP);
     
-    o->handler_event(o->user, NCDMODULEPROCESS_EVENT_UP);
+    o->handler_event(o, NCDMODULEPROCESS_EVENT_UP);
     return;
 }
 
@@ -491,7 +490,7 @@ void NCDModuleProcess_Interp_Down (NCDModuleProcess *o)
     
     set_process_state(o, PROCESS_STATE_DOWN_WAITING);
     
-    o->handler_event(o->user, NCDMODULEPROCESS_EVENT_DOWN);
+    o->handler_event(o, NCDMODULEPROCESS_EVENT_DOWN);
     return;
 }
 
@@ -503,7 +502,7 @@ void NCDModuleProcess_Interp_Terminated (NCDModuleProcess *o)
     
     set_process_state(o, PROCESS_STATE_TERMINATED);
     
-    o->handler_event(o->user, NCDMODULEPROCESS_EVENT_TERMINATED);
+    o->handler_event(o, NCDMODULEPROCESS_EVENT_TERMINATED);
     return;
 }
 
@@ -530,7 +529,7 @@ int NCDModuleProcess_Interp_GetSpecialObj (NCDModuleProcess *o, NCD_string_id_t
         return 0;
     }
     
-    int res = o->func_getspecialobj(o->user, name, out_object);
+    int res = o->func_getspecialobj(o, name, out_object);
     ASSERT(res == 0 || res == 1)
     
     return res;

+ 8 - 8
ncd/NCDModule.h

@@ -173,22 +173,24 @@ typedef btime_t (*NCDModuleInst_func_interp_getretrytime) (void *user);
  *   The process was in terminating state.
  *   The process enters terminated state.
  * 
- * @param user as in {@link NCDModuleProcess_Init}
+ * @param user pointer to the process. Use {@link UPPER_OBJECT} to retrieve the pointer
+ *             to the containing struct.
  * @param event event number
  */
-typedef void (*NCDModuleProcess_handler_event) (void *user, int event);
+typedef void (*NCDModuleProcess_handler_event) (struct NCDModuleProcess_s *process, int event);
 
 /**
  * Function called when the interpreter wants to resolve a special
  * object in the process.
  * This function must have no side effects.
  * 
- * @param user as in {@link NCDModuleProcess_Init}
+ * @param user pointer to the process. Use {@link UPPER_OBJECT} to retrieve the pointer
+ *             to the containing struct.
  * @param name name of the object as an {@link NCDStringIndex} identifier
  * @param out_object the object will be returned here
  * @return 1 on success, 0 on failure
  */
-typedef int (*NCDModuleProcess_func_getspecialobj) (void *user, NCD_string_id_t name, NCDObject *out_object);
+typedef int (*NCDModuleProcess_func_getspecialobj) (struct NCDModuleProcess_s *process, NCD_string_id_t name, NCDObject *out_object);
 
 #define NCDMODULEPROCESS_INTERP_EVENT_CONTINUE 1
 #define NCDMODULEPROCESS_INTERP_EVENT_TERMINATE 2
@@ -357,7 +359,6 @@ typedef struct NCDModuleInst_s {
  */
 typedef struct NCDModuleProcess_s {
     NCDValRef args;
-    void *user;
     NCDModuleProcess_handler_event handler_event;
     NCDModuleProcess_func_getspecialobj func_getspecialobj;
     void *interp_user;
@@ -555,18 +556,17 @@ btime_t NCDModuleInst_Backend_InterpGetRetryTime (NCDModuleInst *n);
  * @param template_name name of the process template as an {@link NCDStringIndex} identifier
  * @param args arguments to the process. Must be an invalid value or a list value.
  *             The value must be available and unchanged while the process exists.
- * @param user argument to handlers
  * @param handler_event handler which reports events about the process from the
  *                      interpreter
  * @return 1 on success, 0 on failure
  */
-int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, void *user, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
+int NCDModuleProcess_InitId (NCDModuleProcess *o, NCDModuleInst *n, NCD_string_id_t template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
 
 /**
  * Wrapper around {@link NCDModuleProcess_InitId} which takes the template name as an
  * {@link NCDValRef}, which must point to a string value.
  */
-int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, void *user, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
+int NCDModuleProcess_InitValue (NCDModuleProcess *o, NCDModuleInst *n, NCDValRef template_name, NCDValRef args, NCDModuleProcess_handler_event handler_event) WARN_UNUSED;
 
 /**
  * Frees the process.

+ 8 - 5
ncd/modules/call.c

@@ -105,8 +105,10 @@ static struct NCD_string_request strings[] = {
     {"_caller"}, {"_ref"}, {NULL}
 };
 
-static void process_handler_event (struct instance *o, int event)
+static void process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     switch (event) {
         case NCDMODULEPROCESS_EVENT_UP: {
             ASSERT(o->state == STATE_WORKING)
@@ -140,8 +142,10 @@ static void process_handler_event (struct instance *o, int event)
     }
 }
 
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     if (name == strings[STRING_CALLER].id) {
         *out_object = NCDObject_Build(-1, o, NULL, (NCDObject_func_getobj)caller_obj_func_getobj);
         return 1;
@@ -219,15 +223,14 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new
         }
         
         // create process
-        if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name_arg, args, o, (NCDModuleProcess_handler_event)process_handler_event)) {
+        if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name_arg, args, process_handler_event)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
             NCDValMem_Free(&o->args_mem);
             goto fail0;
         }
         
         // set special functions
-        NCDModuleProcess_SetSpecialFuncs(&o->process,
-                                        (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+        NCDModuleProcess_SetSpecialFuncs(&o->process, process_func_getspecialobj);
         
         // set callrefhere
         o->crh = (params->method_user ? NCDModuleInst_Backend_GetUser((NCDModuleInst *)params->method_user) : NULL);

+ 11 - 6
ncd/modules/call2.c

@@ -42,6 +42,7 @@
 #include <string.h>
 
 #include <misc/debug.h>
+#include <misc/offset.h>
 #include <ncd/NCDModule.h>
 #include <ncd/static_strings.h>
 #include <ncd/value_utils.h>
@@ -63,8 +64,8 @@ struct instance {
     int state;
 };
 
-static void process_handler_event (struct instance *o, int event);
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
+static void process_handler_event (NCDModuleProcess *process, int event);
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int caller_obj_func_getobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
 static void func_new_templ (void *vo, NCDModuleInst *i, NCDValRef template_name, NCDValRef args, int embed);
 static void instance_free (struct instance *o);
@@ -75,8 +76,10 @@ static struct NCD_string_request strings[] = {
     {"_caller"}, {NULL}
 };
 
-static void process_handler_event (struct instance *o, int event)
+static void process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     switch (event) {
         case NCDMODULEPROCESS_EVENT_UP: {
             ASSERT(o->state == STATE_WORKING)
@@ -110,8 +113,10 @@ static void process_handler_event (struct instance *o, int event)
     }
 }
 
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     if (o->embed) {
         return NCDModuleInst_Backend_GetObj(o->i, name, out_object);
     }
@@ -149,13 +154,13 @@ static void func_new_templ (void *vo, NCDModuleInst *i, NCDValRef template_name,
         o->state = STATE_NONE;
     } else {
         // create process
-        if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name, args, o, (NCDModuleProcess_handler_event)process_handler_event)) {
+        if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name, args, process_handler_event)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
             goto fail0;
         }
         
         // set special functions
-        NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+        NCDModuleProcess_SetSpecialFuncs(&o->process, process_func_getspecialobj);
         
         // set state working
         o->state = STATE_WORKING;

+ 9 - 6
ncd/modules/foreach.c

@@ -71,6 +71,7 @@
 #include <misc/balloc.h>
 #include <misc/string_begins_with.h>
 #include <misc/debug.h>
+#include <misc/offset.h>
 #include <system/BReactor.h>
 #include <ncd/NCDModule.h>
 #include <ncd/static_strings.h>
@@ -128,8 +129,8 @@ static void assert_state (struct instance *o);
 static void work (struct instance *o);
 static void advance (struct instance *o);
 static void timer_handler (struct instance *o);
-static void element_process_handler_event (struct element *e, int event);
-static int element_process_func_getspecialobj (struct element *e, NCD_string_id_t name, NCDObject *out_object);
+static void element_process_handler_event (NCDModuleProcess *process, int event);
+static int element_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int element_caller_object_func_getobj (struct element *e, NCD_string_id_t name, NCDObject *out_object);
 static int element_list_index_object_func_getvar (struct element *e, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out);
 static int element_list_elem_object_func_getvar (struct element *e, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out);
@@ -272,13 +273,13 @@ static void advance (struct instance *o)
     struct element *e = &o->elems[o->gp];
     
     // init process
-    if (!NCDModuleProcess_InitValue(&e->process, o->i, o->template_name, o->args, e, (NCDModuleProcess_handler_event)element_process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&e->process, o->i, o->template_name, o->args, element_process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail;
     }
     
     // set special functions
-    NCDModuleProcess_SetSpecialFuncs(&e->process, (NCDModuleProcess_func_getspecialobj)element_process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&e->process, element_process_func_getspecialobj);
     
     // set element state down
     e->state = ESTATE_DOWN;
@@ -305,8 +306,9 @@ static void timer_handler (struct instance *o)
     return;
 }
 
-static void element_process_handler_event (struct element *e, int event)
+static void element_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct element *e = UPPER_OBJECT(process, struct element, process);
     struct instance *o = e->inst;
     assert_state(o);
     ASSERT(e->i < o->ip)
@@ -356,8 +358,9 @@ static void element_process_handler_event (struct element *e, int event)
     return;
 }
 
-static int element_process_func_getspecialobj (struct element *e, NCD_string_id_t name, NCDObject *out_object)
+static int element_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct element *e = UPPER_OBJECT(process, struct element, process);
     struct instance *o = e->inst;
     ASSERT(e->state != ESTATE_FORGOTTEN)
     

+ 15 - 10
ncd/modules/imperative.c

@@ -53,6 +53,7 @@
 #include <string.h>
 
 #include <misc/string_begins_with.h>
+#include <misc/offset.h>
 #include <ncd/NCDModule.h>
 #include <ncd/value_utils.h>
 
@@ -78,9 +79,9 @@ struct instance {
 
 static int start_process (struct instance *o, NCDValRef template_name, NCDValRef args, NCDModuleProcess_handler_event handler);
 static void go_deinit (struct instance *o);
-static void init_process_handler_event (struct instance *o, int event);
-static void deinit_process_handler_event (struct instance *o, int event);
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
+static void init_process_handler_event (NCDModuleProcess *process, int event);
+static void deinit_process_handler_event (NCDModuleProcess *process, int event);
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int process_caller_object_func_getobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
 static void deinit_timer_handler (struct instance *o);
 static void instance_free (struct instance *o);
@@ -97,13 +98,13 @@ static int start_process (struct instance *o, NCDValRef template_name, NCDValRef
     ASSERT(NCDVal_IsList(args))
     
     // create process
-    if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name, args, o, handler)) {
+    if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name, args, handler)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         return 0;
     }
     
     // set special functions
-    NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&o->process, process_func_getspecialobj);
     return 1;
 }
 
@@ -118,7 +119,7 @@ static void go_deinit (struct instance *o)
     }
     
     // start deinit process
-    if (!start_process(o, o->deinit_template, o->deinit_args, (NCDModuleProcess_handler_event)deinit_process_handler_event)) {
+    if (!start_process(o, o->deinit_template, o->deinit_args, deinit_process_handler_event)) {
         instance_free(o);
         return;
     }
@@ -130,8 +131,10 @@ static void go_deinit (struct instance *o)
     o->state = STATE_DEINIT_WORKING;
 }
 
-static void init_process_handler_event (struct instance *o, int event)
+static void init_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     switch (event) {
         case NCDMODULEPROCESS_EVENT_UP: {
             ASSERT(o->state == STATE_INIT_WORKING)
@@ -166,8 +169,9 @@ static void init_process_handler_event (struct instance *o, int event)
     }
 }
 
-static void deinit_process_handler_event (struct instance *o, int event)
+static void deinit_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
     ASSERT(o->dying)
     
     switch (event) {
@@ -199,8 +203,9 @@ static void deinit_process_handler_event (struct instance *o, int event)
     }
 }
 
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
     ASSERT(o->state != STATE_UP)
     
     if (name == strings[STRING_CALLER].id) {
@@ -272,7 +277,7 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new
         o->state = STATE_UP;
     } else {
         // start init process
-        if (!start_process(o, init_template_arg, init_args, (NCDModuleProcess_handler_event)init_process_handler_event)) {
+        if (!start_process(o, init_template_arg, init_args, init_process_handler_event)) {
             goto fail0;
         }
         

+ 4 - 3
ncd/modules/ondemand.c

@@ -84,7 +84,7 @@ struct demand {
 
 static int ondemand_start_process (struct ondemand *o);
 static void ondemand_terminate_process (struct ondemand *o);
-static void ondemand_process_handler (struct ondemand *o, int event);
+static void ondemand_process_handler (NCDModuleProcess *process, int event);
 static void ondemand_free (struct ondemand *o);
 static void demand_free (struct demand *o);
 
@@ -94,7 +94,7 @@ static int ondemand_start_process (struct ondemand *o)
     ASSERT(!o->have_process)
     
     // start process
-    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->template_name, o->args, o, (NCDModuleProcess_handler_event)ondemand_process_handler)) {
+    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->template_name, o->args, ondemand_process_handler)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail0;
     }
@@ -138,8 +138,9 @@ static void ondemand_terminate_process (struct ondemand *o)
     }
 }
 
-static void ondemand_process_handler (struct ondemand *o, int event)
+static void ondemand_process_handler (NCDModuleProcess *process, int event)
 {
+    struct ondemand *o = UPPER_OBJECT(process, struct ondemand, process);
     ASSERT(o->have_process)
     
     switch (event) {

+ 8 - 6
ncd/modules/process_manager.c

@@ -92,8 +92,8 @@ static struct process * find_process (struct instance *o, const char *name);
 static int process_new (struct instance *o, const char *name, NCDValRef template_name, NCDValRef args);
 static void process_free (struct process *p);
 static void process_retry_timer_handler (struct process *p);
-static void process_module_process_handler_event (struct process *p, int event);
-static int process_module_process_func_getspecialobj (struct process *p, NCD_string_id_t name, NCDObject *out_object);
+static void process_module_process_handler_event (NCDModuleProcess *process, int event);
+static int process_module_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int process_module_process_caller_obj_func_getobj (struct process *p, NCD_string_id_t name, NCDObject *out_object);
 static void process_stop (struct process *p);
 static int process_restart (struct process *p, NCDValRef template_name, NCDValRef args);
@@ -221,8 +221,9 @@ void process_retry_timer_handler (struct process *p)
     process_try(p);
 }
 
-void process_module_process_handler_event (struct process *p, int event)
+void process_module_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct process *p = UPPER_OBJECT(process, struct process, module_process);
     struct instance *o = p->manager;
     ASSERT(p->have_module_process)
     
@@ -269,8 +270,9 @@ void process_module_process_handler_event (struct process *p, int event)
     }
 }
 
-int process_module_process_func_getspecialobj (struct process *p, NCD_string_id_t name, NCDObject *out_object)
+int process_module_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct process *p = UPPER_OBJECT(process, struct process, module_process);
     ASSERT(p->have_module_process)
     
     if (name == strings[STRING_CALLER].id) {
@@ -376,7 +378,7 @@ void process_try (struct process *p)
     p->process_args = NCDVal_Moved(&p->process_mem, p->params_args);
     
     // init module process
-    if (!NCDModuleProcess_InitId(&p->module_process, o->i, p->params_template_name, p->process_args, p, (NCDModuleProcess_handler_event)process_module_process_handler_event)) {
+    if (!NCDModuleProcess_InitId(&p->module_process, o->i, p->params_template_name, p->process_args, process_module_process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         
         // set timer
@@ -388,7 +390,7 @@ void process_try (struct process *p)
     }
     
     // set special objects function
-    NCDModuleProcess_SetSpecialFuncs(&p->module_process, (NCDModuleProcess_func_getspecialobj)process_module_process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&p->module_process, process_module_process_func_getspecialobj);
     
     // free params
     p->have_params = 0;

+ 9 - 6
ncd/modules/spawn.c

@@ -85,8 +85,8 @@ struct join_instance {
 };
 
 static void assert_dirty_state (struct instance *o);
-static void process_handler_event (struct instance *o, int event);
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
+static void process_handler_event (NCDModuleProcess *process, int event);
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int caller_obj_func_getobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
 static void bring_joins_down (struct instance *o);
 static void continue_working (struct instance *o);
@@ -104,8 +104,9 @@ static void assert_dirty_state (struct instance *o)
     ASSERT(!LinkedList0_IsEmpty(&o->dirty_list) == (o->state == STATE_WAITING || o->state == STATE_WAITING_TERMINATING))
 }
 
-static void process_handler_event (struct instance *o, int event)
+static void process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
     assert_dirty_state(o);
     
     switch (event) {
@@ -155,8 +156,10 @@ static void process_handler_event (struct instance *o, int event)
     }
 }
 
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     if (name == strings[STRING_CALLER].id) {
         *out_object = NCDObject_Build(-1, o, NULL, (NCDObject_func_getobj)caller_obj_func_getobj);
         return 1;
@@ -230,13 +233,13 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new
     NCDModuleInst_Backend_Up(o->i);
     
     // create process
-    if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name_arg, args_arg, o, (NCDModuleProcess_handler_event)process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&o->process, o->i, template_name_arg, args_arg, process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail0;
     }
     
     // set object resolution function
-    NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&o->process, process_func_getspecialobj);
     
     // init lists
     LinkedList0_Init(&o->clean_list);

+ 10 - 8
ncd/modules/sys_request_client.c

@@ -149,8 +149,8 @@ static void client_handler_connected (struct instance *o);
 static void request_handler_sent (struct request_instance *o);
 static void request_handler_reply (struct request_instance *o, NCDValMem reply_mem, NCDValRef reply_value);
 static void request_handler_finished (struct request_instance *o, int is_error);
-static void request_process_handler_event (struct request_instance *o, int event);
-static int request_process_func_getspecialobj (struct request_instance *o, NCD_string_id_t name, NCDObject *out_object);
+static void request_process_handler_event (NCDModuleProcess *process, int event);
+static int request_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int request_process_caller_obj_func_getobj (struct request_instance *o, NCD_string_id_t name, NCDObject *out_object);
 static int request_process_reply_obj_func_getvar (struct request_instance *o, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out);
 static void request_gone (struct request_instance *o, int is_bad);
@@ -254,8 +254,9 @@ fail:
     request_die(o, 1);
 }
 
-static void request_process_handler_event (struct request_instance *o, int event)
+static void request_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct request_instance *o = UPPER_OBJECT(process, struct request_instance, process);
     ASSERT(o->pstate != RPSTATE_NONE)
     
     switch (event) {
@@ -318,8 +319,9 @@ static void request_process_handler_event (struct request_instance *o, int event
     }
 }
 
-static int request_process_func_getspecialobj (struct request_instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int request_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct request_instance *o = UPPER_OBJECT(process, struct request_instance, process);
     ASSERT(o->pstate != RPSTATE_NONE)
     
     if (name == strings[STRING_CALLER].id) {
@@ -430,13 +432,13 @@ static int request_init_reply_process (struct request_instance *o, NCDValMem rep
     o->process_reply_data = NCDVal_FromSafe(&o->process_reply_mem, reply_data);
     
     // init process
-    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->reply_handler, o->args, o, (NCDModuleProcess_handler_event)request_process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->reply_handler, o->args, request_process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail0;
     }
     
     // set special objects function
-    NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)request_process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&o->process, request_process_func_getspecialobj);
     
     // set process state working
     o->pstate = RPSTATE_WORKING;
@@ -454,13 +456,13 @@ static int request_init_finished_process (struct request_instance *o)
     o->process_is_finished = 1;
     
     // init process
-    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->finished_handler, o->args, o, (NCDModuleProcess_handler_event)request_process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&o->process, o->i, o->finished_handler, o->args, request_process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail0;
     }
     
     // set special objects function
-    NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)request_process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&o->process, request_process_func_getspecialobj);
     
     // set process state working
     o->pstate = RPSTATE_WORKING;

+ 9 - 6
ncd/modules/sys_request_server.c

@@ -160,8 +160,8 @@ static void connection_recv_if_handler_send (struct connection *c, uint8_t *data
 static int request_init (struct connection *c, uint32_t request_id, const uint8_t *data, int data_len);
 static void request_free (struct request *r);
 static struct request * find_request (struct connection *c, uint32_t request_id);
-static void request_process_handler_event (struct request *r, int event);
-static int request_process_func_getspecialobj (struct request *r, NCD_string_id_t name, NCDObject *out_object);
+static void request_process_handler_event (NCDModuleProcess *process, int event);
+static int request_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int request_process_request_obj_func_getvar (struct request *r, NCD_string_id_t name, NCDValMem *mem, NCDValRef *out_value);
 static void request_terminate (struct request *r);
 static struct reply * reply_init (struct connection *c, uint32_t request_id, NCDValRef reply_data);
@@ -394,12 +394,12 @@ static int request_init (struct connection *c, uint32_t request_id, const uint8_
         goto fail1;
     }
     
-    if (!NCDModuleProcess_InitValue(&r->process, o->i, o->request_handler_template, o->args, r, (NCDModuleProcess_handler_event)request_process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&r->process, o->i, o->request_handler_template, o->args, request_process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail3;
     }
     
-    NCDModuleProcess_SetSpecialFuncs(&r->process, (NCDModuleProcess_func_getspecialobj)request_process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&r->process, request_process_func_getspecialobj);
     
     r->terminating = 0;
     r->got_finished = 0;
@@ -445,8 +445,9 @@ static struct request * find_request (struct connection *c, uint32_t request_id)
     return NULL;
 }
 
-static void request_process_handler_event (struct request *r, int event)
+static void request_process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct request *r = UPPER_OBJECT(process, struct request, process);
     struct connection *c = r->con;
     struct instance *o = c->inst;
     
@@ -480,8 +481,10 @@ static void request_process_handler_event (struct request *r, int event)
     }
 }
 
-static int request_process_func_getspecialobj (struct request *r, NCD_string_id_t name, NCDObject *out_object)
+static int request_process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct request *r = UPPER_OBJECT(process, struct request, process);
+    
     if (name == strings[STRING_REQUEST].id) {
         *out_object = NCDObject_Build(strings[STRING_SYS_REQUEST_SERVER_REQUEST].id, r, (NCDObject_func_getvar)request_process_request_obj_func_getvar, NULL);
         return 1;

+ 10 - 6
ncd/modules/try.c

@@ -59,6 +59,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <misc/offset.h>
 #include <ncd/NCDModule.h>
 
 #include <generated/blog_channel_ncd_try.h>
@@ -77,8 +78,8 @@ struct instance {
 #define STATE_DEINIT 2
 #define STATE_FINISHED 3
 
-static void process_handler_event (struct instance *o, int event);
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
+static void process_handler_event (NCDModuleProcess *process, int event);
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object);
 static int process_caller_object_func_getobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object);
 static void start_terminating (struct instance *o);
 static void instance_free (struct instance *o);
@@ -89,8 +90,10 @@ static struct NCD_string_request strings[] = {
     {"_caller"}, {"_try"}, {"try.try"}, {"succeeded"}, {NULL}
 };
 
-static void process_handler_event (struct instance *o, int event)
+static void process_handler_event (NCDModuleProcess *process, int event)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
+    
     switch (event) {
         case NCDMODULEPROCESS_EVENT_UP: {
             ASSERT(o->state == STATE_INIT)
@@ -127,8 +130,9 @@ static void process_handler_event (struct instance *o, int event)
     }
 }
 
-static int process_func_getspecialobj (struct instance *o, NCD_string_id_t name, NCDObject *out_object)
+static int process_func_getspecialobj (NCDModuleProcess *process, NCD_string_id_t name, NCDObject *out_object)
 {
+    struct instance *o = UPPER_OBJECT(process, struct instance, process);
     ASSERT(o->state == STATE_INIT || o->state == STATE_DEINIT)
     
     if (name == strings[STRING_CALLER].id) {
@@ -180,13 +184,13 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new
     }
     
     // start process
-    if (!NCDModuleProcess_InitValue(&o->process, i, template_name_arg, args_arg, o, (NCDModuleProcess_handler_event)process_handler_event)) {
+    if (!NCDModuleProcess_InitValue(&o->process, i, template_name_arg, args_arg, process_handler_event)) {
         ModuleLog(o->i, BLOG_ERROR, "NCDModuleProcess_Init failed");
         goto fail0;
     }
     
     // set special object function
-    NCDModuleProcess_SetSpecialFuncs(&o->process, (NCDModuleProcess_func_getspecialobj)process_func_getspecialobj);
+    NCDModuleProcess_SetSpecialFuncs(&o->process, process_func_getspecialobj);
     
     // set state init, not dying, assume succeeded
     o->state = STATE_INIT;