cvsuser     03/09/27 04:49:37

  Modified:    .        exit.c
               t/src    exit.t
  Log:
  reversed and simplified Parrot_on_exit handlers
  
  Revision  Changes    Path
  1.3       +9 -27     parrot/exit.c
  
  Index: exit.c
  ===================================================================
  RCS file: /cvs/public/parrot/exit.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- exit.c    21 Jul 2003 18:00:24 -0000      1.2
  +++ exit.c    27 Sep 2003 11:49:33 -0000      1.3
  @@ -1,7 +1,7 @@
   /*  exit.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: exit.c,v 1.2 2003/07/21 18:00:24 chromatic Exp $
  + *     $Id: exit.c,v 1.3 2003/09/27 11:49:33 leo Exp $
    *  Overview:
    *     Parrot's version of exit(), on_exit(), and friends.
    *  Data Structure and Algorithms:
  @@ -16,19 +16,14 @@
   
   #include <parrot/parrot.h>
   
  -typedef struct {
  +typedef struct _handler_node_t {
       void (*function)(int , void *);
       void *arg;
  -
  -    void *next;        
  +    struct _handler_node_t *next;
   } handler_node_t;
   
  -typedef struct {
  -    handler_node_t *first;
  -    handler_node_t *last;
  -} handler_list_t;
   
  -static handler_list_t exit_handler_list = { NULL, NULL};
  +static handler_node_t *exit_handler_list;
   
   
   int
  @@ -39,21 +34,8 @@
       handler_node_t* new_node = mem_sys_allocate(sizeof(handler_node_t));
       new_node->function = function;
       new_node->arg = arg;
  -    new_node->next = NULL;
  -    
  -    if (exit_handler_list.first == NULL) {
  -        exit_handler_list.first = new_node;
  -    }
  -
  -    if (exit_handler_list.last == NULL) {
  -        exit_handler_list.last = new_node;
  -    }
  -    else {
  -        exit_handler_list.last->next = new_node;
  -        exit_handler_list.last = new_node;
  -
  -    }
  -    
  +    new_node->next = exit_handler_list;
  +    exit_handler_list = new_node;
       return 0;
   }
   
  @@ -62,7 +44,7 @@
       handler_node_t *node, *next_node;
   
       /* call all the exit handlers */
  -    for (node = exit_handler_list.first; node != NULL; node = next_node) {
  +    for (node = exit_handler_list; node; node = next_node) {
           (node->function)(status, node->arg);        
           next_node = node->next;
   
  
  
  
  1.4       +46 -4     parrot/t/src/exit.t
  
  Index: exit.t
  ===================================================================
  RCS file: /cvs/public/parrot/t/src/exit.t,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- exit.t    14 May 2003 07:02:49 -0000      1.3
  +++ exit.t    27 Sep 2003 11:49:37 -0000      1.4
  @@ -1,6 +1,6 @@
   #! perl -w
   
  -use Parrot::Test tests => 2;
  +use Parrot::Test tests => 3;
   
   c_output_is(<<'CODE', <<'OUTPUT', "Parrot_exit");
           #include <stdio.h>
  @@ -33,8 +33,50 @@
           }
   CODE
   pre-exit
  -exit1
  -exit2
   exit3
  +exit2
  +exit1
  +OUTPUT
  +
  +c_output_is(<<'CODE', <<'OUTPUT', "on_exit - interpreter");
  +#include <stdio.h>
  +#include <parrot/parrot.h>
  +#include <parrot/embed.h>
  +
  +void ex1(int x, void*p)
  +{
  +    printf("ex1\n");
  +}
  +
  +void ex2(int x, void*p)
  +{
  +    printf("ex2\n");
  +}
  +
  +void ex3(int x, void*p)
  +{
  +    Parrot_Interp interpreter = (Parrot_Interp) p;
  +    PIO_printf(interpreter, "ex3\n");
  +}
  +
  +int main(int argc, char* argv[])
  +{
  +    struct Parrot_Interp *     interpreter;
  +
  +    interpreter = Parrot_new();
  +    if (!interpreter) {
  +        return 1;
  +    }
  +    Parrot_init(interpreter);
  +    Parrot_on_exit(ex1, 0);
  +    Parrot_on_exit(ex2, 0);
  +    Parrot_on_exit(ex3, interpreter);
  +    Parrot_exit(0);
  +    exit(0);
  +}
  +CODE
  +ex3
  +ex2
  +ex1
   OUTPUT
   1;
  
  
  

Reply via email to