cvsuser     04/02/09 08:53:38

  Modified:    include/parrot events.h
               src      events.c interpreter.c
               t/pmc    nci.t
  Log:
  pdd16-5
  * callback_info is now really user_data not the Sub
  * this is the more natural way things work - user_data is passed
    on to the NCI function
  
  Revision  Changes    Path
  1.13      +4 -5      parrot/include/parrot/events.h
  
  Index: events.h
  ===================================================================
  RCS file: /cvs/public/parrot/include/parrot/events.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- events.h  9 Feb 2004 14:46:56 -0000       1.12
  +++ events.h  9 Feb 2004 16:53:31 -0000       1.13
  @@ -1,7 +1,7 @@
   /* events.h
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: events.h,v 1.12 2004/02/09 14:46:56 leo Exp $
  + *     $Id: events.h,v 1.13 2004/02/09 16:53:31 leo Exp $
    *  Overview:
    *     This api will handle parrot events
    *  Data Structure and Algorithms:
  @@ -41,8 +41,7 @@
   } parrot_timer_event;
   
   typedef struct {
  -    PMC*                        sub;
  -    PMC*                        user_data;
  +    PMC*                        cbi;    /* callback info */
       void*                       external_data;
   } _call_back_info;
   
  @@ -79,8 +78,8 @@
   void disable_event_checking(Parrot_Interp);
   void enable_event_checking(Parrot_Interp);
   
  -void Parrot_new_cb_event(Parrot_Interp, PMC*sub, void*ext);
  -void Parrot_run_callback(Parrot_Interp, PMC*sub, void*ext);
  +void Parrot_new_cb_event(Parrot_Interp, PMC* cbi, void*ext);
  +void Parrot_run_callback(Parrot_Interp, PMC* cbi, void*ext);
   
   void Parrot_kill_event_loop(void);
   void* Parrot_sleep_on_event(Parrot_Interp, FLOATVAL t, void* next);
  
  
  
  1.35      +5 -5      parrot/src/events.c
  
  Index: events.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/events.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -w -r1.34 -r1.35
  --- events.c  9 Feb 2004 14:47:04 -0000       1.34
  +++ events.c  9 Feb 2004 16:53:33 -0000       1.35
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: events.c,v 1.34 2004/02/09 14:47:04 leo Exp $
  +$Id: events.c,v 1.35 2004/02/09 16:53:33 leo Exp $
   
   =head1 NAME
   
  @@ -400,7 +400,7 @@
   /*
   
   =item C<void
  -Parrot_new_cb_event(Parrot_Interp, PMC*sub, void*ext)>
  +Parrot_new_cb_event(Parrot_Interp, PMC*cbi, void*ext)>
   
   Prepare and schedul a callback event
   
  @@ -409,11 +409,11 @@
   */
   
   void
  -Parrot_new_cb_event(Parrot_Interp interpreter, PMC* sub, void* ext)
  +Parrot_new_cb_event(Parrot_Interp interpreter, PMC* cbi, void* ext)
   {
       parrot_event* ev = mem_sys_allocate(sizeof(parrot_event));
       ev->type = EVENT_TYPE_CALL_BACK;
  -    ev->u.call_back.sub = sub;
  +    ev->u.call_back.cbi = cbi;
       ev->u.call_back.external_data = ext;
       Parrot_schedule_event(interpreter, ev);
   }
  @@ -1093,7 +1093,7 @@
               break;
           case EVENT_TYPE_CALL_BACK:
               edebug((stderr, "starting user cb\n"));
  -            Parrot_run_callback(interpreter, event->u.call_back.sub,
  +            Parrot_run_callback(interpreter, event->u.call_back.cbi,
                       event->u.call_back.external_data);
               break;
           case EVENT_TYPE_SLEEP:
  
  
  
  1.266     +30 -21    parrot/src/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/interpreter.c,v
  retrieving revision 1.265
  retrieving revision 1.266
  diff -u -w -r1.265 -r1.266
  --- interpreter.c     9 Feb 2004 15:54:46 -0000       1.265
  +++ interpreter.c     9 Feb 2004 16:53:33 -0000       1.266
  @@ -1,7 +1,7 @@
   /*
   ################################################################################
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: interpreter.c,v 1.265 2004/02/09 15:54:46 leo Exp $
  +$Id: interpreter.c,v 1.266 2004/02/09 16:53:33 leo Exp $
   ################################################################################
   
   =head1 NAME
  @@ -1150,17 +1150,17 @@
       int type;
       char * sig_str;
       /*
  -     * we stuff all the information into the Sub PMC and pass that
  +     * we stuff all the information into the user_data PMC and pass that
        * on to the external sub
        */
       interp_pmc = VTABLE_get_pmc_keyed_int(interpreter, interpreter->iglobals,
               (INTVAL) IGLOBALS_INTERPRETER);
  -    VTABLE_setprop(interpreter, sub,
  +    VTABLE_setprop(interpreter, user_data,
               const_string(interpreter, "_interpreter"),
               interp_pmc);
  -    VTABLE_setprop(interpreter, sub,
  -            const_string(interpreter, "_user_data"),
  -            user_data);
  +    VTABLE_setprop(interpreter, user_data,
  +            const_string(interpreter, "_sub"),
  +            sub);
       /* only ASCII sigs supported */
       sig_str = cb_signature->strstart;
       if (*sig_str == 'U') {
  @@ -1179,7 +1179,7 @@
   
       cb_sig = pmc_new(interpreter, enum_class_PerlString);
       VTABLE_set_string_native(interpreter, cb_sig, cb_signature);
  -    VTABLE_setprop(interpreter, sub,
  +    VTABLE_setprop(interpreter, user_data,
               const_string(interpreter, "_signature"),
               cb_sig);
       /*
  @@ -1189,7 +1189,7 @@
        *
        * so anchor the PMC
        */
  -    dod_register_pmc(interpreter, sub);
  +    dod_register_pmc(interpreter, user_data);
   
       /*
        * finally the external lib awaits a function pointer
  @@ -1258,6 +1258,7 @@
           PANIC("interpreter not found for callback");
   
       /*
  +     * 2) some more checks
        * now we should have the interpreter where that callback
        * did originate - do some further checks on the PMC
        */
  @@ -1266,14 +1267,8 @@
       if (!PObj_is_PMC_TEST(callback_info))
           PANIC("callback_info isn't a PMC");
   
  -    /*
  -     * 2) some more checks: callback info is a Sub PMC
  -     *    we have passed a Sub PMC as user_data so check that
  -     */
       if (!callback_info->vtable)
           PANIC("callback_info hasn't a vtable");
  -    if (callback_info->vtable->base_type != enum_class_Sub)
  -        PANIC("callback_info isn't a Sub PMC");
       /*
        * ok fine till here
        */
  @@ -1298,7 +1293,7 @@
       PMC *passed_interp;         /* the interp that originated the CB */
       int async = 1;              /* cb is hitting this sub somewhen inmidst */
       /*
  -     * 3) extract user_data, func signature, check interpreter ...
  +     * 3) check interpreter ...
        */
       passed_interp = VTABLE_getprop(interpreter, callback_info,
               const_string(interpreter, "_interpreter"));
  @@ -1313,7 +1308,7 @@
   
       if (async) {
           /*
  -         * create a CB_EVENT, put Sub and data inside and finito
  +         * create a CB_EVENT, put user_data and data inside and finito
            *
            * *if* this function is finally no void, i.e. the calling
            * C program awaits a return result from the callback,
  @@ -1329,10 +1324,22 @@
       }
   }
   
  +/*
  +
  +=item C<void
  +Parrot_run_callback(Parrot_Interp interpreter, PMC* cbi, void* ext)>
  +
  +Run a callback function. The PMC* cbi (callback_info) holds all
  +necessary items in its props.
  +
  +=cut
  +
  +*/
  +
   void
  -Parrot_run_callback(Parrot_Interp interpreter, PMC* sub, void* ext)
  +Parrot_run_callback(Parrot_Interp interpreter, PMC* cbi, void* ext)
   {
  -    PMC* user_data, *sig;
  +    PMC* user_data, *sig, *sub;
       STRING* sig_str;
       char *p;
       char pasm_sig[4];
  @@ -1340,10 +1347,12 @@
       INTVAL   i_param;
       void*    param;
   
  -    user_data = VTABLE_getprop(interpreter, sub,
  -            const_string(interpreter, "_user_data"));
  -    sig = VTABLE_getprop(interpreter, sub,
  +    sub = VTABLE_getprop(interpreter, cbi,
  +            const_string(interpreter, "_sub"));
  +    sig = VTABLE_getprop(interpreter, cbi,
               const_string(interpreter, "_signature"));
  +    user_data = cbi;
  +
       sig_str = VTABLE_get_string(interpreter, sig);
       p = sig_str->strstart;
   
  
  
  
  1.33      +6 -3      parrot/t/pmc/nci.t
  
  Index: nci.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/pmc/nci.t,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -w -r1.32 -r1.33
  --- nci.t     9 Feb 2004 15:54:51 -0000       1.32
  +++ nci.t     9 Feb 2004 16:53:38 -0000       1.33
  @@ -840,7 +840,8 @@
     dlfunc P0, P1, "nci_cb_C1", "vpP"
     print "ok 2\n"
     # P5 is the cb
  -  # P6 is user_data - the Sub
  +  # P6 is user_data
  +  set P6, P7
     invoke
     # call_back will be called at any time
     # so spin a bit
  @@ -897,7 +898,8 @@
     dlfunc P0, P1, "nci_cb_D1", "vpP"
     print "ok 2\n"
     # P5 is the cb
  -  # P6 is user_data - the Sub
  +  # P6 is user_data
  +  set P6, P7
     invoke
     # call_back will be called at any time
     # so spin a bit
  @@ -953,7 +955,8 @@
     dlfunc P0, P1, "nci_cb_C2", "vpP"
     print "ok 2\n"
     # P5 is the cb
  -  # P6 is user_data - the Sub
  +  # P6 is user_data
  +  set P6, P7
     invoke
     # call_back will be called at any time
     # so spin a bit
  
  
  

Reply via email to