Finish thread state machine: fixes global destruction of threads,
[p5sagit/p5-mst-13.2.git] / run.c
1 /*    run.c
2  *
3  *    Copyright (c) 1991-1997, Larry Wall
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  */
9
10 #include "EXTERN.h"
11 #include "perl.h"
12
13 /*
14  * "Away now, Shadowfax!  Run, greatheart, run as you have never run before!
15  * Now we are come to the lands where you were foaled, and every stone you
16  * know.  Run now!  Hope is in speed!"  --Gandalf
17  */
18
19 dEXT char **watchaddr = 0;
20 dEXT char *watchok;
21
22 int
23 runops_standard() {
24     dTHR;
25     SAVEI32(runlevel);
26     runlevel++;
27
28     while ( op = (*op->op_ppaddr)(ARGS) ) ;
29
30     TAINT_NOT;
31     return 0;
32 }
33
34 #ifdef DEBUGGING
35 static void debprof _((OP*o));
36
37 int
38 runops_debug() {
39     dTHR;
40     if (!op) {
41         warn("NULL OP IN RUN");
42         return 0;
43     }
44
45     SAVEI32(runlevel);
46     runlevel++;
47
48     do {
49         if (debug) {
50             if (watchaddr != 0 && *watchaddr != watchok)
51                 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
52                     (long)watchaddr, (long)watchok, (long)*watchaddr);
53             DEBUG_s(debstack());
54             DEBUG_t(debop(op));
55             DEBUG_P(debprof(op));
56         }
57     } while ( op = (*op->op_ppaddr)(ARGS) );
58
59     TAINT_NOT;
60     return 0;
61 }
62
63 I32
64 debop(o)
65 OP *o;
66 {
67     SV *sv;
68     deb("%s", op_name[o->op_type]);
69     switch (o->op_type) {
70     case OP_CONST:
71         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
72         break;
73     case OP_GVSV:
74     case OP_GV:
75         if (cGVOPo->op_gv) {
76             sv = NEWSV(0,0);
77             gv_fullname3(sv, cGVOPo->op_gv, Nullch);
78             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, na));
79             SvREFCNT_dec(sv);
80         }
81         else
82             PerlIO_printf(Perl_debug_log, "(NULL)");
83         break;
84     default:
85         break;
86     }
87     PerlIO_printf(Perl_debug_log, "\n");
88     return 0;
89 }
90
91 void
92 watch(addr)
93 char **addr;
94 {
95     watchaddr = addr;
96     watchok = *addr;
97     PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
98         (long)watchaddr, (long)watchok);
99 }
100
101 static void
102 debprof(o)
103 OP* o;
104 {
105     if (!profiledata)
106         New(000, profiledata, MAXO, U32);
107     ++profiledata[o->op_type];
108 }
109
110 void
111 debprofdump()
112 {
113     unsigned i;
114     if (!profiledata)
115         return;
116     for (i = 0; i < MAXO; i++) {
117         if (profiledata[i])
118             PerlIO_printf(Perl_debug_log,
119                           "%u\t%lu\n", i, (unsigned long)profiledata[i]);
120     }
121 }
122
123 #endif
124