summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-10-18 18:53:57 (GMT)
committerGuido van Rossum <guido@python.org>1992-10-18 18:53:57 (GMT)
commita9e7dc10816dcf5eda63d3ef00930ef9d55e0675 (patch)
tree5454bc7a52a71fe9639ec7f0cef856c413b25157 /Python
parent2db91358def94cf8081f27b736988320d14eba39 (diff)
downloadcpython-a9e7dc10816dcf5eda63d3ef00930ef9d55e0675.zip
cpython-a9e7dc10816dcf5eda63d3ef00930ef9d55e0675.tar.gz
cpython-a9e7dc10816dcf5eda63d3ef00930ef9d55e0675.tar.bz2
* bltinmodule.c: added built-in function cmp(a, b)
* flmodule.c: added {do,check}_only_forms to fl's list of functions; and don't print a message when an unknown object is returned. * pythonrun.c: catch SIGHUP and SIGTERM to do essential cleanup. * Made jpegmodule.c smaller by using getargs() and mkvalue() consistently. * Increased parser stack size to 500 in parser.h. * Implemented custom allocation of stack frames to frameobject.c and added dynamic stack overflow checks (value stack only) to ceval.c. (There seems to be a bug left: sometimes stack traces don't make sense.)
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c12
-rw-r--r--Python/ceval.c20
-rw-r--r--Python/pythonrun.c49
3 files changed, 77 insertions, 4 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 9ba07af..18fae5c 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -78,6 +78,17 @@ builtin_chr(self, args)
}
static object *
+builtin_cmp(self, args)
+ object *self;
+ object *args;
+{
+ object *a, *b;
+ if (!getargs(args, "(OO)", &a, &b))
+ return NULL;
+ return newintobject((long)cmpobject(a, b));
+}
+
+static object *
builtin_coerce(self, args)
object *self;
object *args;
@@ -608,6 +619,7 @@ static struct methodlist builtin_methods[] = {
{"abs", builtin_abs},
{"apply", builtin_apply},
{"chr", builtin_chr},
+ {"cmp", builtin_cmp},
{"coerce", builtin_coerce},
{"dir", builtin_dir},
{"divmod", builtin_divmod},
diff --git a/Python/ceval.c b/Python/ceval.c
index 4637d35..d3a732a 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -204,6 +204,9 @@ eval_code(co, globals, locals, arg)
#define BASIC_PUSH(v) (*stack_pointer++ = (v))
#define BASIC_POP() (*--stack_pointer)
+#define CHECK_STACK(n) (STACK_LEVEL() + (n) < f->f_nvalues || \
+ (stack_pointer = extend_stack(f, STACK_LEVEL(), n)))
+
#ifdef LLTRACE
#define PUSH(v) (BASIC_PUSH(v), lltrace && prtrace(TOP(), "push"))
#define POP() (lltrace && prtrace(TOP(), "pop"), BASIC_POP())
@@ -324,6 +327,11 @@ eval_code(co, globals, locals, arg)
}
#endif
+ if (!CHECK_STACK(3)) {
+ x = NULL;
+ break;
+ }
+
/* Main switch on opcode */
switch (opcode) {
@@ -763,6 +771,10 @@ eval_code(co, globals, locals, arg)
x = gettupleslice(v, oparg, gettuplesize(v));
if (x != NULL) {
PUSH(x);
+ if (!CHECK_STACK(oparg)) {
+ x = NULL;
+ break;
+ }
for (; --oparg >= 0; ) {
w = gettupleitem(v, oparg);
INCREF(w);
@@ -858,6 +870,10 @@ eval_code(co, globals, locals, arg)
why = WHY_EXCEPTION;
}
else {
+ if (!CHECK_STACK(oparg)) {
+ x = NULL;
+ break;
+ }
for (; --oparg >= 0; ) {
w = gettupleitem(v, oparg);
INCREF(w);
@@ -879,6 +895,10 @@ eval_code(co, globals, locals, arg)
why = WHY_EXCEPTION;
}
else {
+ if (!CHECK_STACK(oparg)) {
+ x = NULL;
+ break;
+ }
for (; --oparg >= 0; ) {
w = getlistitem(v, oparg);
INCREF(w);
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 90a4294..1bcc083 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -38,10 +38,21 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "pythonrun.h"
#include "import.h"
+#ifdef unix
+#define HANDLE_SIGNALS
+#endif
+
+#ifdef HANDLE_SIGNALS
+#include <signal.h>
+#include "sigtype.h"
+#endif
+
extern char *getpythonpath();
extern grammar gram; /* From graminit.c */
+void initsigs(); /* Forward */
+
int debugging; /* Needed by parser.c */
int verbose; /* Needed by import.c */
@@ -67,10 +78,10 @@ initall()
initsys();
initcalls(); /* Configuration-dependent initializations */
-
- initintr(); /* For intrcheck() */
setpythonpath(getpythonpath());
+
+ initsigs(); /* Signal handling stuff, including initintr() */
}
/* Parse input from a file and execute it */
@@ -372,8 +383,7 @@ extern int threads_started;
#endif
void
-goaway(sts)
- int sts;
+cleanup()
{
object *exitfunc = sysget("exitfunc");
@@ -395,6 +405,13 @@ goaway(sts)
}
flushline();
+}
+
+void
+goaway(sts)
+ int sts;
+{
+ cleanup();
#ifdef USE_THREAD
@@ -433,6 +450,30 @@ goaway(sts)
/*NOTREACHED*/
}
+#ifdef HANDLE_SIGNALS
+SIGTYPE
+sighandler(sig)
+ int sig;
+{
+ signal(sig, SIG_DFL); /* Don't catch recursive signals */
+ cleanup(); /* Do essential clean-up */
+ kill(getpid(), sig); /* Pretend the signal killed us */
+ /*NOTREACHED*/
+}
+#endif
+
+void
+initsigs()
+{
+ initintr();
+#ifdef HANDLE_SIGNALS
+ if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
+ signal(SIGHUP, sighandler);
+ if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
+ signal(SIGTERM, sighandler);
+#endif
+}
+
#ifdef TRACE_REFS
/* Ask a yes/no question */