Procházet zdrojové kódy

ncd: NCDModule: in NCDModuleInst_Init(), have the interpreter directly pass the method context pointer, not
the NCDObject which contains it

ambrop7 před 13 roky
rodič
revize
ffec659d2b
3 změnil soubory, kde provedl 12 přidání a 10 odebrání
  1. 4 4
      ncd/NCDInterpreter.c
  2. 2 2
      ncd/NCDModule.c
  3. 6 4
      ncd/NCDModule.h

+ 4 - 4
ncd/NCDInterpreter.c

@@ -789,8 +789,7 @@ void process_advance (struct process *p)
     
     // need to determine the module and object to use it on (if it's a method)
     const struct NCDModule *module;
-    NCDObject object;
-    NCDObject *object_ptr = NULL;
+    void *method_context = NULL;
     
     // get object names, e.g. "my.cat" in "my.cat->meow();"
     // (or NULL if this is not a method statement)
@@ -808,10 +807,11 @@ void process_advance (struct process *p)
         }
     } else {
         // get object
+        NCDObject object;
         if (!process_resolve_object_expr(p, p->ap, objnames, num_objnames, &object)) {
             goto fail0;
         }
-        object_ptr = &object;
+        method_context = object.user;
         
         // get object type
         NCD_string_id_t object_type = NCDObject_Type(&object);
@@ -862,7 +862,7 @@ void process_advance (struct process *p)
     process_assert_pointers(p);
     
     // initialize module instance
-    NCDModuleInst_Init(&ps->inst, module, object_ptr, args, &p->interp->module_params);
+    NCDModuleInst_Init(&ps->inst, module, method_context, args, &p->interp->module_params);
     return;
     
 fail1:

+ 2 - 2
ncd/NCDModule.c

@@ -66,7 +66,7 @@ static void inst_assert_backend (NCDModuleInst *n)
            n->state == STATE_DYING)
 }
 
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValRef args, const struct NCDModuleInst_params *params)
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, void *method_context, NCDValRef args, const struct NCDModuleInst_params *params)
 {
     ASSERT(m)
     ASSERT(m->func_new2)
@@ -97,7 +97,7 @@ void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDO
     DebugObject_Init(&n->d_obj);
     
     struct NCDModuleInst_new_params new_params;
-    new_params.method_user = (method_object ? method_object->user : NULL);
+    new_params.method_user = method_context;
     new_params.args = args;
     
     n->m->func_new2(n->mem, n, &new_params);

+ 6 - 4
ncd/NCDModule.h

@@ -385,15 +385,17 @@ typedef struct NCDModuleProcess_s {
  * 
  * @param n the instance
  * @param m structure of module functions implementing the module backend
- * @param method_object the base object if the module being initialized is a method, otherwise NULL.
- *                      The caller must ensure that this object is of the type expected by the module
- *                      being initialized.
+ * @param method_context a context pointer passed to the module backend, applicable to method-like
+ *                       statements only. This should be set to the 'user' member of the
+ *                       {@link NCDObject} which represents the base object for the method.
+ *                       The caller must ensure that the NCDObject that was used is of the type
+ *                       expected by the module being instanciated.
  * @param args arguments to the module. Must be a list value. Must be available and unchanged
  *             as long as the instance exists.
  * @param user argument to callback functions
  * @param params more parameters, see {@link NCDModuleInst_params}
  */
-void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, const NCDObject *method_object, NCDValRef args, const struct NCDModuleInst_params *params);
+void NCDModuleInst_Init (NCDModuleInst *n, const struct NCDModule *m, void *method_context, NCDValRef args, const struct NCDModuleInst_params *params);
 
 /**
  * Frees the instance.