0

I want a C routine, which is supplied with an Eiffel 'agent' to call the routine 'apply' in the class PROCEDURE.

int c_nng_aio_set_procedure_target(void *item, EIF_OBJECT target) {
    void **pptr = (void **) (item);
    EIF_TYPE_ID type_id;    /* Eiffel type identifier for class `class_name' */
    EIF_PROCEDURE e_proc;   /* Eiffel procedure `proc_name' */
    EIF_PROCEDURE *p_proc;
    EIF_OBJECT *p_object;

    type_id = eif_type (target);
    if (type_id == EIF_NO_TYPE) {
        printf ("PROCEDURE type_id not found\n");
        return (0);
    }
    e_proc = eif_procedure ("apply", type_id);
    if (e_proc == (EIF_PROCEDURE) 0) {
        printf ("'apply' procedure not found\n");
        return (0);
    }
    
    /* Success in finding procedure address, */
    /* now store that and the target into the storage block */
    pptr[4] = e_proc;
    pptr[5] = target;
    return (1);
}

My code currently prints [as above] that the 'apply' procedure is not found.

I have ensured that 'apply' is used from within the Eiffel code [apply_check is called]:

report_completion
    do
        print ("report_completion ... OK%N")
    end

apply_check
    local
        p: PROCEDURE
    do
        p := agent report_completion
        p.apply
    end

Any ideas ?

Craig Estey
  • 30,627
  • 4
  • 24
  • 48
  • How do you get `target`? Is it from Eiffel code? How does this code look like? – Alexander Kogtenkov Mar 04 '22 at 05:33
  • Hi Alexander, I am wrapping the nanomsg library [nanomsg.org]. The current test code look like: report_completion do print ("report_completion ... OK%N") end – Howard Thomson Mar 04 '22 at 16:44
  • The C routine c_nng_aio_set_procedure_target is called from Eiffel, the first argument providing a POINTER to space for the C code to use, the second argument is provide from Eiffel as an 'agent routine_name'. When I use a local, p: PROCEDURE, and assign to p [p := agent some_routine_name], p.apply executes some_routine_name as expected. However, when p is supplied to the C code, the procedure 'apply' is not found by eif_procedure ... – Howard Thomson Mar 04 '22 at 18:34
  • I have just created a new minimal project, with an external 'C' routine and a single Eiffel class APPLICATION. eif_type_id finds the type_id for the class APPLICATION. But eif_procedure fails to find the routine that I have defined in Eiffel. I have added the class APPLICATION to the Visible classes in the Project settings. Is this a bug, or am I missing something ? – Howard Thomson Mar 05 '22 at 13:36

0 Answers0