cvsuser 02/11/07 21:18:44
Modified: . MANIFEST core.ops disassemble.c embed.c
exceptions.c interpreter.c packout.c pdb.c
runops_cores.c test_main.c
config/gen/makefiles root.in
include/parrot parrot.h
Added: . exit.c
include/parrot exit.h
t/src exit.t
Log:
Added Parrot_exit(), a version of exit() which handles exit handlers
registered with Parrot_on_exit().
Revision Changes Path
1.247 +3 -0 parrot/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /cvs/public/parrot/MANIFEST,v
retrieving revision 1.246
retrieving revision 1.247
diff -u -w -r1.246 -r1.247
--- MANIFEST 4 Nov 2002 17:16:04 -0000 1.246
+++ MANIFEST 8 Nov 2002 05:18:39 -0000 1.247
@@ -200,6 +200,7 @@
examples/pxs/PQt.C
examples/pxs/QtHelloWorld.pasm
exceptions.c
+exit.c
fingerprint_c.pl
global_setup.c
hash.c
@@ -1209,6 +1210,7 @@
include/parrot/encoding.h
include/parrot/events.h
include/parrot/exceptions.h
+include/parrot/exit.h
include/parrot/global_setup.h
include/parrot/hash.h
include/parrot/headers.h
@@ -1631,6 +1633,7 @@
t/pmc/pmc.t
t/pmc/sub.t
t/src/basic.t
+t/src/exit.t
t/src/intlist.t
t/src/list.t
t/src/manifest.t
1.227 +1 -1 parrot/core.ops
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.226
retrieving revision 1.227
diff -u -w -r1.226 -r1.227
--- core.ops 6 Nov 2002 14:59:25 -0000 1.226
+++ core.ops 8 Nov 2002 05:18:39 -0000 1.227
@@ -129,7 +129,7 @@
$1 = PTR2OPCODE_T(fopen(string_to_cstring(interpreter, ($2)), "r+"));
if (!$1) {
perror("Can't open");
- exit(1);
+ Parrot_exit(1);
}
goto NEXT();
1.5 +2 -2 parrot/disassemble.c
Index: disassemble.c
===================================================================
RCS file: /cvs/public/parrot/disassemble.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -r1.4 -r1.5
--- disassemble.c 2 Nov 2002 14:57:47 -0000 1.4
+++ disassemble.c 8 Nov 2002 05:18:39 -0000 1.5
@@ -2,7 +2,7 @@
* disassemble.c
*
* CVS Info
- * $Id: disassemble.c,v 1.4 2002/11/02 14:57:47 josh Exp $
+ * $Id: disassemble.c,v 1.5 2002/11/08 05:18:39 josh Exp $
* Overview:
* Parrot disassembler
* History:
@@ -37,7 +37,7 @@
if (argc != 2) {
fprintf(stderr, "Usage: disassemble programfile \n");
- exit(1);
+ Parrot_exit(1);
}
na(argv[0]);
1.49 +2 -2 parrot/embed.c
Index: embed.c
===================================================================
RCS file: /cvs/public/parrot/embed.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -w -r1.48 -r1.49
--- embed.c 4 Nov 2002 11:17:08 -0000 1.48
+++ embed.c 8 Nov 2002 05:18:39 -0000 1.49
@@ -1,7 +1,7 @@
/* embed.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: embed.c,v 1.48 2002/11/04 11:17:08 leo Exp $
+ * $Id: embed.c,v 1.49 2002/11/08 05:18:39 josh Exp $
* Overview:
* The Parrot embedding interface.
* Data Structure and Algorithms:
@@ -292,7 +292,7 @@
if (Interp_flags_TEST(interpreter, PARROT_JIT_FLAG)) {
PIO_fprintf(interpreter, PIO_STDERR(interpreter),
"Parrot VM: Platform " JIT_ARCHNAME " is not JIT-capable.\n");
- exit(1);
+ Parrot_exit(1);
}
#endif
1.9 +2 -2 parrot/exceptions.c
Index: exceptions.c
===================================================================
RCS file: /cvs/public/parrot/exceptions.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- exceptions.c 21 Oct 2002 05:18:15 -0000 1.8
+++ exceptions.c 8 Nov 2002 05:18:39 -0000 1.9
@@ -1,7 +1,7 @@
/* exceptions.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: exceptions.c,v 1.8 2002/10/21 05:18:15 sfink Exp $
+ * $Id: exceptions.c,v 1.9 2002/11/08 05:18:39 josh Exp $
* Overview:
* define the internal interpreter exceptions
* Data Structure and Algorithms:
@@ -23,7 +23,7 @@
va_start(arglist, format);
vfprintf(stderr, format, arglist);
va_end(arglist);
- exit(exitcode);
+ Parrot_exit(exitcode);
}
/* Panic handler */
1.112 +3 -3 parrot/interpreter.c
Index: interpreter.c
===================================================================
RCS file: /cvs/public/parrot/interpreter.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -w -r1.111 -r1.112
--- interpreter.c 6 Nov 2002 20:22:37 -0000 1.111
+++ interpreter.c 8 Nov 2002 05:18:39 -0000 1.112
@@ -1,7 +1,7 @@
/* interpreter.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: interpreter.c,v 1.111 2002/11/06 20:22:37 leo Exp $
+ * $Id: interpreter.c,v 1.112 2002/11/08 05:18:39 josh Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -22,7 +22,7 @@
# include "parrot/oplib/core_ops_cg.h"
#endif
-/* #define ATEXIT_DESTROY */
+#define ATEXIT_DESTROY
extern op_lib_t *PARROT_CORE_PREDEREF_OPLIB_INIT(void);
@@ -561,7 +561,7 @@
interpreter->prederef_code = (void **)NULL;
#ifdef ATEXIT_DESTROY
- on_exit(Parrot_really_destroy, (void*)interpreter);
+ Parrot_on_exit(Parrot_really_destroy, (void*)interpreter);
#endif
return interpreter;
1.16 +4 -4 parrot/packout.c
Index: packout.c
===================================================================
RCS file: /cvs/public/parrot/packout.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -w -r1.15 -r1.16
--- packout.c 2 Nov 2002 14:57:47 -0000 1.15
+++ packout.c 8 Nov 2002 05:18:39 -0000 1.16
@@ -7,7 +7,7 @@
** This program is free software. It is subject to the same
** license as Parrot itself.
**
-** $Id: packout.c,v 1.15 2002/11/02 14:57:47 josh Exp $
+** $Id: packout.c,v 1.16 2002/11/08 05:18:39 josh Exp $
** History:
** Rework by Melvin; new bytecode format, make bytecode portable.
** (Do endian conversion and wordsize transforms on the fly.)
@@ -228,7 +228,7 @@
key->cache.num_val)
return i;
PIO_eprintf(NULL, "find_in_const: couldn't find const for key\n");
- exit(1);
+ Parrot_exit(1);
return 0;
}
@@ -368,7 +368,7 @@
default:
PIO_eprintf(NULL, "PackFile_Constant_pack: "
"unsupported constant type\n");
- exit(1);
+ Parrot_exit(1);
}
}
@@ -378,7 +378,7 @@
/* TODO: OK to be silent here? */
/* ARGH, don't be silent -lt */
PIO_eprintf(NULL, "PackFile_Constant_pack: unsupported constant\n");
- exit(1);
+ Parrot_exit(1);
break;
}
1.7 +2 -2 parrot/pdb.c
Index: pdb.c
===================================================================
RCS file: /cvs/public/parrot/pdb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -r1.6 -r1.7
--- pdb.c 2 Nov 2002 14:57:47 -0000 1.6
+++ pdb.c 8 Nov 2002 05:18:39 -0000 1.7
@@ -2,7 +2,7 @@
* pdb.c
*
* CVS Info
- * $Id: pdb.c,v 1.6 2002/11/02 14:57:47 josh Exp $
+ * $Id: pdb.c,v 1.7 2002/11/08 05:18:39 josh Exp $
* Overview:
* The Parrot debugger
* History:
@@ -39,7 +39,7 @@
if (argc < 2) {
fprintf(stderr, "Usage: pdb programfile [program-options]\n");
- exit(1);
+ Parrot_exit(1);
}
na(argv[0]);
1.28 +2 -2 parrot/runops_cores.c
Index: runops_cores.c
===================================================================
RCS file: /cvs/public/parrot/runops_cores.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -w -r1.27 -r1.28
--- runops_cores.c 4 Nov 2002 11:17:08 -0000 1.27
+++ runops_cores.c 8 Nov 2002 05:18:39 -0000 1.28
@@ -1,7 +1,7 @@
/* runops_cores.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: runops_cores.c,v 1.27 2002/11/04 11:17:08 leo Exp $
+ * $Id: runops_cores.c,v 1.28 2002/11/08 05:18:39 josh Exp $
* Overview:
* The switchable runops cores.
* Data Structure and Algorithms:
@@ -54,7 +54,7 @@
#else
PIO_eprintf(interpreter,
"Computed goto unavailable in this configuration.\n");
- exit(1);
+ Parrot_exit(1);
return NULL;
#endif
}
1.59 +4 -4 parrot/test_main.c
Index: test_main.c
===================================================================
RCS file: /cvs/public/parrot/test_main.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -w -r1.58 -r1.59
--- test_main.c 21 Oct 2002 08:46:59 -0000 1.58
+++ test_main.c 8 Nov 2002 05:18:39 -0000 1.59
@@ -1,7 +1,7 @@
/* test_main.c
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: test_main.c,v 1.58 2002/10/21 08:46:59 sfink Exp $
+ * $Id: test_main.c,v 1.59 2002/11/08 05:18:39 josh Exp $
* Overview:
* A sample test program (and the main function of Parrot)
* Data Structure and Algorithms:
@@ -125,7 +125,7 @@
default:
fprintf(stderr, "parrot: Invalid flag %c used\n",
(*argv)[0][1]);
- exit(1);
+ Parrot_exit(1);
}
(*argc)--;
@@ -165,7 +165,7 @@
cgoto_info
);
- exit(0);
+ Parrot_exit(0);
}
static void
@@ -184,7 +184,7 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either\n\
the GNU General Public License or the Artistic License for more details.\n\n");
- exit(0);
+ Parrot_exit(0);
}
/*
1.1 parrot/exit.c
Index: exit.c
===================================================================
/* exit.c
* Copyright: (When this is determined...it will go here)
* CVS Info
* $Id: exit.c,v 1.1 2002/11/08 05:18:39 josh Exp $
* Overview:
* Parrot's version of exit(), on_exit(), and friends.
* Data Structure and Algorithms:
*
* History:
* Initial version by Josh Wilmes
* Notes:
* References:
*/
#include <stdlib.h>
#include <parrot/parrot.h>
typedef struct {
void (*function)(int , void *);
void *arg;
void *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};
int
Parrot_on_exit(void (*function)(int , void *), void *arg) {
/* XXX we might want locking around the list access. I'm sure this
* will be the least of the threading issues. */
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;
}
return 0;
}
void Parrot_exit(int status) {
handler_node_t *node, *next_node;
/* call all the exit handlers */
for (node = exit_handler_list.first; node != NULL; node = next_node) {
(node->function)(status, node->arg);
next_node = node->next;
mem_sys_free(node);
}
exit(status);
}
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/
1.54 +4 -2 parrot/config/gen/makefiles/root.in
Index: root.in
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -w -r1.53 -r1.54
--- root.in 2 Nov 2002 06:02:05 -0000 1.53
+++ root.in 8 Nov 2002 05:18:41 -0000 1.54
@@ -80,7 +80,7 @@
$(INC)/method_util.h $(INC)/list.h $(INC)/datatypes.h \
$(INC)/regfuncs.h $(INC)/string_funcs.h $(INC)/encoding.h \
$(INC)/chartype.h $(INC)/oplib.h $(INC)/sub.h $(INC)/unicode.h \
- $(INC)/perltypes.h
+ $(INC)/perltypes.h $(INC)/exit.h
ALL_H_FILES = $(GENERAL_H_FILES)
@@ -104,7 +104,7 @@
${gc_o} rx$(O) rxstacks$(O) intlist$(O) list$(O) \
embed$(O) warnings$(O) ${cg_o} \
packout$(O) byteorder$(O) debug$(O) smallobject$(O) \
- headers$(O) dod$(O) method_util$(O) \
+ headers$(O) dod$(O) method_util$(O) exit$(O) \
misc$(O) spf_render$(O) spf_vtable$(O) datatypes$(O) fingerprint$(O)
O_FILES = $(INTERP_O_FILES) $(IO_O_FILES) $(CLASS_O_FILES) \
@@ -417,6 +417,8 @@
core_ops$(O) : $(GENERAL_H_FILES) core_ops.c
dataypes$(O) : $(GENERAL_H_FILES) dataypes.c
+
+exit$(O) : $(GENERAL_H_FILES) exit.c
#core_ops depends upon config.h so that it gets updated along with updates to
config.h's version numbers
core_ops.c $(INC)/oplib/core_ops.h : $(OPS_FILES) ops2c.pl lib/Parrot/OpsFile.pm
lib/Parrot/Op.pm $(INC)/config.h
1.54 +2 -1 parrot/include/parrot/parrot.h
Index: parrot.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/parrot.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -w -r1.53 -r1.54
--- parrot.h 24 Oct 2002 09:38:50 -0000 1.53
+++ parrot.h 8 Nov 2002 05:18:42 -0000 1.54
@@ -1,7 +1,7 @@
/* parrot.h
* Copyright: (When this is determined...it will go here)
* CVS Info
- * $Id: parrot.h,v 1.53 2002/10/24 09:38:50 leo Exp $
+ * $Id: parrot.h,v 1.54 2002/11/08 05:18:42 josh Exp $
* Overview:
* General header file includes for the parrot interpreter
* Data Structure and Algorithms:
@@ -202,6 +202,7 @@
#include "parrot/debug.h"
#include "parrot/sub.h"
#include "parrot/key.h"
+#include "parrot/exit.h"
#endif
/*
1.1 parrot/include/parrot/exit.h
Index: exit.h
===================================================================
/* exit.h
* Copyright: (When this is determined...it will go here)
* CVS Info
* $Id: exit.h,v 1.1 2002/11/08 05:18:42 josh Exp $
* Overview:
*
* Data Structure and Algorithms:
* History:
* Notes:
* References:
* exit.c
*/
#if !defined(PARROT_EXIT_H_GUARD)
#define PARROT_EXIT_H_GUARD
int Parrot_on_exit(void (*function)(int , void *), void *arg);
void Parrot_exit(int status);
#endif
/*
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/
1.1 parrot/t/src/exit.t
Index: exit.t
===================================================================
#! perl -w
use Parrot::Test tests => 2;
TODO: {
local $TODO="t/src doesn't work on Windows" if $^O =~ /Win32/;
$TODO=$TODO; #warnings
c_output_is(<<'CODE', <<'OUTPUT', "Parrot_exit");
#include <stdio.h>
#include "parrot/parrot.h"
int main(int argc, char* argv[]) {
printf("pre-exit\n");
Parrot_exit(0);
printf("post-exit\n");
}
CODE
pre-exit
OUTPUT
c_output_is(<<'CODE', <<'OUTPUT', "Parrot_on_exit / Parrot_exit");
#include <stdio.h>
#include "parrot/parrot.h"
void print_message(int status, void* arg) {
printf("%s", (char*)arg);
}
int main(int argc, char* argv[]) {
Parrot_on_exit(print_message, "exit1\n");
Parrot_on_exit(print_message, "exit2\n");
Parrot_on_exit(print_message, "exit3\n");
printf("pre-exit\n");
Parrot_exit(0);
printf("post-exit\n");
}
CODE
pre-exit
exit1
exit2
exit3
OUTPUT
}
1;