Quickly renamed.

This commit is contained in:
Guido van Rossum 1997-04-29 18:33:38 +00:00
parent 04e30c188a
commit 65bf9f265e
2 changed files with 204 additions and 200 deletions

View File

@ -44,140 +44,137 @@ Data members:
- ps1, ps2: optional primary and secondary prompts (strings) - ps1, ps2: optional primary and secondary prompts (strings)
*/ */
#include "allobjects.h" #include "Python.h"
#include "sysmodule.h"
#include "import.h"
#include "modsupport.h"
#include "osdefs.h" #include "osdefs.h"
object *sys_trace, *sys_profile; PyObject *_PySys_TraceFunc, *_PySys_ProfileFunc;
int sys_checkinterval = 10; int _PySys_CheckInterval = 10;
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
static object *sysdict; static PyObject *sysdict;
#ifdef MS_COREDLL #ifdef MS_COREDLL
extern void *PyWin_DLLhModule; extern void *PyWin_DLLhModule;
#endif #endif
object * PyObject *
sysget(name) PySys_GetObject(name)
char *name; char *name;
{ {
return dictlookup(sysdict, name); return PyDict_GetItemString(sysdict, name);
} }
FILE * FILE *
sysgetfile(name, def) PySys_GetFile(name, def)
char *name; char *name;
FILE *def; FILE *def;
{ {
FILE *fp = NULL; FILE *fp = NULL;
object *v = sysget(name); PyObject *v = PySys_GetObject(name);
if (v != NULL && is_fileobject(v)) if (v != NULL && PyFile_Check(v))
fp = getfilefile(v); fp = PyFile_AsFile(v);
if (fp == NULL) if (fp == NULL)
fp = def; fp = def;
return fp; return fp;
} }
int int
sysset(name, v) PySys_SetObject(name, v)
char *name; char *name;
object *v; PyObject *v;
{ {
if (v == NULL) { if (v == NULL) {
if (dictlookup(sysdict, name) == NULL) if (PyDict_GetItemString(sysdict, name) == NULL)
return 0; return 0;
else else
return dictremove(sysdict, name); return PyDict_DelItemString(sysdict, name);
} }
else else
return dictinsert(sysdict, name, v); return PyDict_SetItemString(sysdict, name, v);
} }
static object * static PyObject *
sys_exit(self, args) sys_exit(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
/* Raise SystemExit so callers may catch it or clean up. */ /* Raise SystemExit so callers may catch it or clean up. */
err_setval(SystemExit, args); PyErr_SetObject(PyExc_SystemExit, args);
return NULL; return NULL;
} }
static object * static PyObject *
sys_settrace(self, args) sys_settrace(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
if (args == None) if (args == Py_None)
args = NULL; args = NULL;
else else
XINCREF(args); Py_XINCREF(args);
XDECREF(sys_trace); Py_XDECREF(_PySys_TraceFunc);
sys_trace = args; _PySys_TraceFunc = args;
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
sys_setprofile(self, args) sys_setprofile(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
if (args == None) if (args == Py_None)
args = NULL; args = NULL;
else else
XINCREF(args); Py_XINCREF(args);
XDECREF(sys_profile); Py_XDECREF(_PySys_ProfileFunc);
sys_profile = args; _PySys_ProfileFunc = args;
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
static object * static PyObject *
sys_setcheckinterval(self, args) sys_setcheckinterval(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
if (!newgetargs(args, "i", &sys_checkinterval)) if (!PyArg_ParseTuple(args, "i", &_PySys_CheckInterval))
return NULL; return NULL;
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
#ifdef USE_MALLOPT #ifdef USE_MALLOPT
/* Link with -lmalloc (or -lmpc) on an SGI */ /* Link with -lmalloc (or -lmpc) on an SGI */
#include <malloc.h> #include <malloc.h>
static object * static PyObject *
sys_mdebug(self, args) sys_mdebug(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
int flag; int flag;
if (!getargs(args, "i", &flag)) if (!PyArg_Parse(args, "i", &flag))
return NULL; return NULL;
mallopt(M_DEBUG, flag); mallopt(M_DEBUG, flag);
INCREF(None); Py_INCREF(Py_None);
return None; return Py_None;
} }
#endif /* USE_MALLOPT */ #endif /* USE_MALLOPT */
static object * static PyObject *
sys_getrefcount(self, args) sys_getrefcount(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
object *arg; PyObject *arg;
if (!getargs(args, "O", &arg)) if (!PyArg_Parse(args, "O", &arg))
return NULL; return NULL;
return newintobject((long) arg->ob_refcnt); return PyInt_FromLong((long) arg->ob_refcnt);
} }
#ifdef COUNT_ALLOCS #ifdef COUNT_ALLOCS
@ -203,7 +200,7 @@ extern PyObject *_Py_GetObjects Py_PROTO((PyObject *, PyObject *));
extern PyObject *_Py_GetDXProfile Py_PROTO((PyObject *, PyObject *)); extern PyObject *_Py_GetDXProfile Py_PROTO((PyObject *, PyObject *));
#endif #endif
static struct methodlist sys_methods[] = { static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */ /* Might as well keep this in alphabetic order */
{"exit", sys_exit, 0}, {"exit", sys_exit, 0},
#ifdef COUNT_ALLOCS #ifdef COUNT_ALLOCS
@ -225,93 +222,100 @@ static struct methodlist sys_methods[] = {
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
static object *sysin, *sysout, *syserr; static PyObject *sysin, *sysout, *syserr;
static object * static PyObject *
list_builtin_module_names() list_builtin_module_names()
{ {
object *list = newlistobject(0); PyObject *list = PyList_New(0);
int i; int i;
if (list == NULL) if (list == NULL)
return NULL; return NULL;
for (i = 0; inittab[i].name != NULL; i++) { for (i = 0; inittab[i].name != NULL; i++) {
object *name = newstringobject(inittab[i].name); PyObject *name = PyString_FromString(inittab[i].name);
if (name == NULL) if (name == NULL)
break; break;
addlistitem(list, name); PyList_Append(list, name);
DECREF(name); Py_DECREF(name);
} }
if (sortlist(list) != 0) { if (PyList_Sort(list) != 0) {
DECREF(list); Py_DECREF(list);
list = NULL; list = NULL;
} }
if (list) { if (list) {
object *v = listtuple(list); PyObject *v = PyList_AsTuple(list);
DECREF(list); Py_DECREF(list);
list = v; list = v;
} }
return list; return list;
} }
void void
initsys() PySys_Init()
{ {
extern long getmaxint PROTO((void)); extern long PyInt_GetMax Py_PROTO((void));
extern char *getversion PROTO((void)); extern char *Py_GetVersion Py_PROTO((void));
extern char *getcopyright PROTO((void)); extern char *Py_GetCopyright Py_PROTO((void));
extern char *getplatform PROTO((void)); extern char *Py_GetPlatform Py_PROTO((void));
extern char *Py_GetPrefix PROTO((void)); extern char *Py_GetPrefix Py_PROTO((void));
extern char *Py_GetExecPrefix PROTO((void)); extern char *Py_GetExecPrefix Py_PROTO((void));
extern int fclose PROTO((FILE *)); extern int fclose Py_PROTO((FILE *));
object *m = initmodule("sys", sys_methods); PyObject *m = Py_InitModule("sys", sys_methods);
object *v; PyObject *v;
sysdict = getmoduledict(m); sysdict = PyModule_GetDict(m);
INCREF(sysdict); Py_INCREF(sysdict);
/* NB keep an extra ref to the std files to avoid closing them /* NB keep an extra ref to the std files to avoid closing them
when the user deletes them */ when the user deletes them */
sysin = newopenfileobject(stdin, "<stdin>", "r", fclose); sysin = PyFile_FromFile(stdin, "<stdin>", "r", fclose);
sysout = newopenfileobject(stdout, "<stdout>", "w", fclose); sysout = PyFile_FromFile(stdout, "<stdout>", "w", fclose);
syserr = newopenfileobject(stderr, "<stderr>", "w", fclose); syserr = PyFile_FromFile(stderr, "<stderr>", "w", fclose);
if (err_occurred()) if (PyErr_Occurred())
fatal("can't initialize sys.std{in,out,err}"); Py_FatalError("can't initialize sys.std{in,out,err}");
dictinsert(sysdict, "stdin", sysin); PyDict_SetItemString(sysdict, "stdin", sysin);
dictinsert(sysdict, "stdout", sysout); PyDict_SetItemString(sysdict, "stdout", sysout);
dictinsert(sysdict, "stderr", syserr); PyDict_SetItemString(sysdict, "stderr", syserr);
dictinsert(sysdict, "version", v = newstringobject(getversion())); PyDict_SetItemString(sysdict, "version",
XDECREF(v); v = PyString_FromString(Py_GetVersion()));
dictinsert(sysdict, "copyright", v = newstringobject(getcopyright())); Py_XDECREF(v);
XDECREF(v); PyDict_SetItemString(sysdict, "copyright",
dictinsert(sysdict, "platform", v = newstringobject(getplatform())); v = PyString_FromString(Py_GetCopyright()));
XDECREF(v); Py_XDECREF(v);
dictinsert(sysdict, "prefix", v = newstringobject(Py_GetPrefix())); PyDict_SetItemString(sysdict, "platform",
XDECREF(v); v = PyString_FromString(Py_GetPlatform()));
dictinsert(sysdict, "exec_prefix", Py_XDECREF(v);
v = newstringobject(Py_GetExecPrefix())); PyDict_SetItemString(sysdict, "prefix",
XDECREF(v); v = PyString_FromString(Py_GetPrefix()));
dictinsert(sysdict, "maxint", v = newintobject(getmaxint())); Py_XDECREF(v);
XDECREF(v); PyDict_SetItemString(sysdict, "exec_prefix",
dictinsert(sysdict, "modules", get_modules()); v = PyString_FromString(Py_GetExecPrefix()));
dictinsert(sysdict, "builtin_module_names", Py_XDECREF(v);
PyDict_SetItemString(sysdict, "maxint",
v = PyInt_FromLong(PyInt_GetMax()));
Py_XDECREF(v);
PyDict_SetItemString(sysdict, "modules", PyImport_GetModuleDict());
PyDict_SetItemString(sysdict, "builtin_module_names",
v = list_builtin_module_names()); v = list_builtin_module_names());
XDECREF(v); Py_XDECREF(v);
#ifdef MS_COREDLL #ifdef MS_COREDLL
dictinsert(sysdict, "dllhandle", v = newintobject((int)PyWin_DLLhModule)); PyDict_SetItemString(sysdict, "dllhandle",
XDECREF(v); v = PyInt_FromLong((int)PyWin_DLLhModule));
dictinsert(sysdict, "winver", v = newstringobject(MS_DLL_ID)); Py_XDECREF(v);
XDECREF(v); PyDict_SetItemString(sysdict, "winver",
v = PyString_FromString(MS_DLL_ID));
Py_XDECREF(v);
#endif #endif
if (err_occurred()) if (PyErr_Occurred())
fatal("can't insert sys.* objects in sys dict"); Py_FatalError("can't insert sys.* objects in sys dict");
} }
static object * static PyObject *
makepathobject(path, delim) makepathobject(path, delim)
char *path; char *path;
int delim; int delim;
{ {
int i, n; int i, n;
char *p; char *p;
object *v, *w; PyObject *v, *w;
n = 1; n = 1;
p = path; p = path;
@ -319,19 +323,19 @@ makepathobject(path, delim)
n++; n++;
p++; p++;
} }
v = newlistobject(n); v = PyList_New(n);
if (v == NULL) if (v == NULL)
return NULL; return NULL;
for (i = 0; ; i++) { for (i = 0; ; i++) {
p = strchr(path, delim); p = strchr(path, delim);
if (p == NULL) if (p == NULL)
p = strchr(path, '\0'); /* End of string */ p = strchr(path, '\0'); /* End of string */
w = newsizedstringobject(path, (int) (p - path)); w = PyString_FromStringAndSize(path, (int) (p - path));
if (w == NULL) { if (w == NULL) {
DECREF(v); Py_DECREF(v);
return NULL; return NULL;
} }
setlistitem(v, i, w); PyList_SetItem(v, i, w);
if (*p == '\0') if (*p == '\0')
break; break;
path = p+1; path = p+1;
@ -340,61 +344,61 @@ makepathobject(path, delim)
} }
void void
setpythonpath(path) PySys_SetPath(path)
char *path; char *path;
{ {
object *v; PyObject *v;
if ((v = makepathobject(path, DELIM)) == NULL) if ((v = makepathobject(path, DELIM)) == NULL)
fatal("can't create sys.path"); Py_FatalError("can't create sys.path");
if (sysset("path", v) != 0) if (PySys_SetObject("path", v) != 0)
fatal("can't assign sys.path"); Py_FatalError("can't assign sys.path");
DECREF(v); Py_DECREF(v);
} }
static object * static PyObject *
makeargvobject(argc, argv) makeargvobject(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
object *av; PyObject *av;
if (argc <= 0 || argv == NULL) { if (argc <= 0 || argv == NULL) {
/* Ensure at least one (empty) argument is seen */ /* Ensure at least one (empty) argument is seen */
static char *empty_argv[1] = {""}; static char *empty_argv[1] = {""};
argv = empty_argv; argv = empty_argv;
argc = 1; argc = 1;
} }
av = newlistobject(argc); av = PyList_New(argc);
if (av != NULL) { if (av != NULL) {
int i; int i;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
object *v = newstringobject(argv[i]); PyObject *v = PyString_FromString(argv[i]);
if (v == NULL) { if (v == NULL) {
DECREF(av); Py_DECREF(av);
av = NULL; av = NULL;
break; break;
} }
setlistitem(av, i, v); PyList_SetItem(av, i, v);
} }
} }
return av; return av;
} }
void void
setpythonargv(argc, argv) PySys_SetArgv(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
object *av = makeargvobject(argc, argv); PyObject *av = makeargvobject(argc, argv);
object *path = sysget("path"); PyObject *path = PySys_GetObject("path");
if (av == NULL) if (av == NULL)
fatal("no mem for sys.argv"); Py_FatalError("no mem for sys.argv");
if (sysset("argv", av) != 0) if (PySys_SetObject("argv", av) != 0)
fatal("can't assign sys.argv"); Py_FatalError("can't assign sys.argv");
if (path != NULL) { if (path != NULL) {
char *argv0 = argv[0]; char *argv0 = argv[0];
char *p = NULL; char *p = NULL;
int n = 0; int n = 0;
object *a; PyObject *a;
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
char link[MAXPATHLEN+1]; char link[MAXPATHLEN+1];
char argv0copy[2*MAXPATHLEN+1]; char argv0copy[2*MAXPATHLEN+1];
@ -448,12 +452,12 @@ setpythonargv(argc, argv)
#endif /* Unix */ #endif /* Unix */
} }
#endif /* All others */ #endif /* All others */
a = newsizedstringobject(argv0, n); a = PyString_FromStringAndSize(argv0, n);
if (a == NULL) if (a == NULL)
fatal("no mem for sys.path insertion"); Py_FatalError("no mem for sys.path insertion");
if (inslistitem(path, 0, a) < 0) if (PyList_Insert(path, 0, a) < 0)
fatal("sys.path.insert(0) failed"); Py_FatalError("sys.path.insert(0) failed");
DECREF(a); Py_DECREF(a);
} }
DECREF(av); Py_DECREF(av);
} }

View File

@ -31,19 +31,17 @@ PERFORMANCE OF THIS SOFTWARE.
/* Traceback implementation */ /* Traceback implementation */
#include "allobjects.h" #include "Python.h"
#include "sysmodule.h"
#include "compile.h" #include "compile.h"
#include "frameobject.h" #include "frameobject.h"
#include "traceback.h"
#include "structmember.h" #include "structmember.h"
#include "osdefs.h" #include "osdefs.h"
typedef struct _tracebackobject { typedef struct _tracebackobject {
OB_HEAD PyObject_HEAD
struct _tracebackobject *tb_next; struct _tracebackobject *tb_next;
frameobject *tb_frame; PyFrameObject *tb_frame;
int tb_lasti; int tb_lasti;
int tb_lineno; int tb_lineno;
} tracebackobject; } tracebackobject;
@ -58,28 +56,28 @@ static struct memberlist tb_memberlist[] = {
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
static object * static PyObject *
tb_getattr(tb, name) tb_getattr(tb, name)
tracebackobject *tb; tracebackobject *tb;
char *name; char *name;
{ {
return getmember((char *)tb, tb_memberlist, name); return PyMember_Get((char *)tb, tb_memberlist, name);
} }
static void static void
tb_dealloc(tb) tb_dealloc(tb)
tracebackobject *tb; tracebackobject *tb;
{ {
XDECREF(tb->tb_next); Py_XDECREF(tb->tb_next);
XDECREF(tb->tb_frame); Py_XDECREF(tb->tb_frame);
DEL(tb); PyMem_DEL(tb);
} }
#define Tracebacktype PyTraceBack_Type #define Tracebacktype PyTraceBack_Type
#define is_tracebackobject PyTraceBack_Check #define is_tracebackobject PyTraceBack_Check
typeobject Tracebacktype = { PyTypeObject Tracebacktype = {
OB_HEAD_INIT(&Typetype) PyObject_HEAD_INIT(&PyType_Type)
0, 0,
"traceback", "traceback",
sizeof(tracebackobject), sizeof(tracebackobject),
@ -98,20 +96,20 @@ typeobject Tracebacktype = {
static tracebackobject * static tracebackobject *
newtracebackobject(next, frame, lasti, lineno) newtracebackobject(next, frame, lasti, lineno)
tracebackobject *next; tracebackobject *next;
frameobject *frame; PyFrameObject *frame;
int lasti, lineno; int lasti, lineno;
{ {
tracebackobject *tb; tracebackobject *tb;
if ((next != NULL && !is_tracebackobject(next)) || if ((next != NULL && !is_tracebackobject(next)) ||
frame == NULL || !is_frameobject(frame)) { frame == NULL || !PyFrame_Check(frame)) {
err_badcall(); PyErr_BadInternalCall();
return NULL; return NULL;
} }
tb = NEWOBJ(tracebackobject, &Tracebacktype); tb = PyObject_NEW(tracebackobject, &Tracebacktype);
if (tb != NULL) { if (tb != NULL) {
XINCREF(next); Py_XINCREF(next);
tb->tb_next = next; tb->tb_next = next;
XINCREF(frame); Py_XINCREF(frame);
tb->tb_frame = frame; tb->tb_frame = frame;
tb->tb_lasti = lasti; tb->tb_lasti = lasti;
tb->tb_lineno = lineno; tb->tb_lineno = lineno;
@ -122,44 +120,45 @@ newtracebackobject(next, frame, lasti, lineno)
static tracebackobject *tb_current = NULL; static tracebackobject *tb_current = NULL;
int int
tb_here(frame) PyTraceBack_Here(frame)
frameobject *frame; PyFrameObject *frame;
{ {
tracebackobject *tb; tracebackobject *tb;
tb = newtracebackobject(tb_current, frame, frame->f_lasti, frame->f_lineno); tb = newtracebackobject(tb_current, frame,
frame->f_lasti, frame->f_lineno);
if (tb == NULL) if (tb == NULL)
return -1; return -1;
XDECREF(tb_current); Py_XDECREF(tb_current);
tb_current = tb; tb_current = tb;
return 0; return 0;
} }
object * PyObject *
tb_fetch() PyTraceBack_Fetch()
{ {
object *v; PyObject *v;
v = (object *)tb_current; v = (PyObject *)tb_current;
tb_current = NULL; tb_current = NULL;
return v; return v;
} }
int int
tb_store(v) PyTraceBack_Store(v)
object *v; PyObject *v;
{ {
if (v != NULL && !is_tracebackobject(v)) { if (v != NULL && !is_tracebackobject(v)) {
err_badcall(); PyErr_BadInternalCall();
return -1; return -1;
} }
XDECREF(tb_current); Py_XDECREF(tb_current);
XINCREF(v); Py_XINCREF(v);
tb_current = (tracebackobject *)v; tb_current = (tracebackobject *)v;
return 0; return 0;
} }
static void static void
tb_displayline(f, filename, lineno, name) tb_displayline(f, filename, lineno, name)
object *f; PyObject *f;
char *filename; char *filename;
int lineno; int lineno;
char *name; char *name;
@ -177,25 +176,25 @@ tb_displayline(f, filename, lineno, name)
xfp = fopen(filename, "r"); xfp = fopen(filename, "r");
if (xfp == NULL) { if (xfp == NULL) {
/* Search tail of filename in sys.path before giving up */ /* Search tail of filename in sys.path before giving up */
object *path; PyObject *path;
char *tail = strrchr(filename, SEP); char *tail = strrchr(filename, SEP);
if (tail == NULL) if (tail == NULL)
tail = filename; tail = filename;
else else
tail++; tail++;
path = sysget("path"); path = PySys_GetObject("path");
if (path != NULL && is_listobject(path)) { if (path != NULL && PyList_Check(path)) {
int npath = getlistsize(path); int npath = PyList_Size(path);
int taillen = strlen(tail); int taillen = strlen(tail);
char namebuf[MAXPATHLEN+1]; char namebuf[MAXPATHLEN+1];
for (i = 0; i < npath; i++) { for (i = 0; i < npath; i++) {
object *v = getlistitem(path, i); PyObject *v = PyList_GetItem(path, i);
if (is_stringobject(v)) { if (PyString_Check(v)) {
int len; int len;
len = getstringsize(v); len = PyString_Size(v);
if (len + 1 + taillen >= MAXPATHLEN) if (len + 1 + taillen >= MAXPATHLEN)
continue; /* Too long */ continue; /* Too long */
strcpy(namebuf, getstringvalue(v)); strcpy(namebuf, PyString_AsString(v));
if ((int)strlen(namebuf) != len) if ((int)strlen(namebuf) != len)
continue; /* v contains '\0' */ continue; /* v contains '\0' */
if (len > 0 && namebuf[len-1] != SEP) if (len > 0 && namebuf[len-1] != SEP)
@ -211,7 +210,7 @@ tb_displayline(f, filename, lineno, name)
} }
} }
sprintf(linebuf, FMT, filename, lineno, name); sprintf(linebuf, FMT, filename, lineno, name);
writestring(linebuf, f); PyFile_WriteString(linebuf, f);
if (xfp == NULL) if (xfp == NULL)
return; return;
for (i = 0; i < lineno; i++) { for (i = 0; i < lineno; i++) {
@ -222,10 +221,10 @@ tb_displayline(f, filename, lineno, name)
char *p = linebuf; char *p = linebuf;
while (*p == ' ' || *p == '\t' || *p == '\014') while (*p == ' ' || *p == '\t' || *p == '\014')
p++; p++;
writestring(" ", f); PyFile_WriteString(" ", f);
writestring(p, f); PyFile_WriteString(p, f);
if (strchr(p, '\n') == NULL) if (strchr(p, '\n') == NULL)
writestring("\n", f); PyFile_WriteString("\n", f);
} }
fclose(xfp); fclose(xfp);
} }
@ -233,7 +232,7 @@ tb_displayline(f, filename, lineno, name)
static void static void
tb_printinternal(tb, f, limit) tb_printinternal(tb, f, limit)
tracebackobject *tb; tracebackobject *tb;
object *f; PyObject *f;
int limit; int limit;
{ {
int depth = 0; int depth = 0;
@ -242,14 +241,15 @@ tb_printinternal(tb, f, limit)
depth++; depth++;
tb1 = tb1->tb_next; tb1 = tb1->tb_next;
} }
while (tb != NULL && !intrcheck()) { while (tb != NULL && !PyOS_InterruptOccurred()) {
if (depth <= limit) { if (depth <= limit) {
tb->tb_lineno = PyCode_Addr2Line(tb->tb_frame->f_code, tb->tb_lineno = PyCode_Addr2Line(tb->tb_frame->f_code,
tb->tb_lasti); tb->tb_lasti);
tb_displayline(f, tb_displayline(f,
getstringvalue(tb->tb_frame->f_code->co_filename), PyString_AsString(
tb->tb_frame->f_code->co_filename),
tb->tb_lineno, tb->tb_lineno,
getstringvalue(tb->tb_frame->f_code->co_name)); PyString_AsString(tb->tb_frame->f_code->co_name));
} }
depth--; depth--;
tb = tb->tb_next; tb = tb->tb_next;
@ -257,25 +257,25 @@ tb_printinternal(tb, f, limit)
} }
int int
tb_print(v, f) PyTraceBack_Print(v, f)
object *v; PyObject *v;
object *f; PyObject *f;
{ {
object *limitv; PyObject *limitv;
int limit = 1000; int limit = 1000;
if (v == NULL) if (v == NULL)
return 0; return 0;
if (!is_tracebackobject(v)) { if (!is_tracebackobject(v)) {
err_badcall(); PyErr_BadInternalCall();
return -1; return -1;
} }
limitv = sysget("tracebacklimit"); limitv = PySys_GetObject("tracebacklimit");
if (limitv && is_intobject(limitv)) { if (limitv && PyInt_Check(limitv)) {
limit = getintvalue(limitv); limit = PyInt_AsLong(limitv);
if (limit <= 0) if (limit <= 0)
return 0; return 0;
} }
writestring("Traceback (innermost last):\n", f); PyFile_WriteString("Traceback (innermost last):\n", f);
tb_printinternal((tracebackobject *)v, f, limit); tb_printinternal((tracebackobject *)v, f, limit);
return 0; return 0;
} }