summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-04-29 18:18:01 (GMT)
committerGuido van Rossum <guido@python.org>1997-04-29 18:18:01 (GMT)
commitb209a116cf4cde628535657d2c8be406b0e498cb (patch)
treee5eb352c3ec052efa01d9b0f816e2e7b5d17ee74
parente2b4f0906ddf998b51e1cb5c9aedce6b00d54534 (diff)
downloadcpython-b209a116cf4cde628535657d2c8be406b0e498cb.zip
cpython-b209a116cf4cde628535657d2c8be406b0e498cb.tar.gz
cpython-b209a116cf4cde628535657d2c8be406b0e498cb.tar.bz2
Quickly renamed.
-rw-r--r--Python/ceval.c1597
1 files changed, 798 insertions, 799 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 23fefe4..bca3386 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1,4 +1,3 @@
-
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
@@ -38,7 +37,7 @@ PERFORMANCE OF THIS SOFTWARE.
XXX document it!
*/
-#include "allobjects.h"
+#include "Python.h"
#include "compile.h"
#include "frameobject.h"
@@ -60,48 +59,48 @@ PERFORMANCE OF THIS SOFTWARE.
/* Forward declarations */
-static object *eval_code2 PROTO((codeobject *,
- object *, object *,
- object **, int,
- object **, int,
- object **, int,
- object *));
+static PyObject *eval_code2 Py_PROTO((PyCodeObject *,
+ PyObject *, PyObject *,
+ PyObject **, int,
+ PyObject **, int,
+ PyObject **, int,
+ PyObject *));
#ifdef LLTRACE
-static int prtrace PROTO((object *, char *));
+static int prtrace Py_PROTO((PyObject *, char *));
#endif
-static void call_exc_trace PROTO((object **, object**, frameobject *));
+static void call_exc_trace Py_PROTO((PyObject **, PyObject**, PyFrameObject *));
static int call_trace
- PROTO((object **, object **, frameobject *, char *, object *));
-static object *add PROTO((object *, object *));
-static object *sub PROTO((object *, object *));
-static object *powerop PROTO((object *, object *));
-static object *mul PROTO((object *, object *));
-static object *divide PROTO((object *, object *));
-static object *mod PROTO((object *, object *));
-static object *neg PROTO((object *));
-static object *pos PROTO((object *));
-static object *not PROTO((object *));
-static object *invert PROTO((object *));
-static object *lshift PROTO((object *, object *));
-static object *rshift PROTO((object *, object *));
-static object *and PROTO((object *, object *));
-static object *xor PROTO((object *, object *));
-static object *or PROTO((object *, object *));
-static object *call_builtin PROTO((object *, object *, object *));
-static object *call_function PROTO((object *, object *, object *));
-static object *apply_subscript PROTO((object *, object *));
-static object *loop_subscript PROTO((object *, object *));
-static int slice_index PROTO((object *, int, int *));
-static object *apply_slice PROTO((object *, object *, object *));
-static int assign_subscript PROTO((object *, object *, object *));
-static int assign_slice PROTO((object *, object *, object *, object *));
-static int cmp_exception PROTO((object *, object *));
-static int cmp_member PROTO((object *, object *));
-static object *cmp_outcome PROTO((int, object *, object *));
-static int import_from PROTO((object *, object *, object *));
-static object *build_class PROTO((object *, object *, object *));
-static int exec_statement PROTO((object *, object *, object *));
-static object *find_from_args PROTO((frameobject *, int));
+ Py_PROTO((PyObject **, PyObject **, PyFrameObject *, char *, PyObject *));
+static PyObject *add Py_PROTO((PyObject *, PyObject *));
+static PyObject *sub Py_PROTO((PyObject *, PyObject *));
+static PyObject *powerop Py_PROTO((PyObject *, PyObject *));
+static PyObject *mul Py_PROTO((PyObject *, PyObject *));
+static PyObject *divide Py_PROTO((PyObject *, PyObject *));
+static PyObject *mod Py_PROTO((PyObject *, PyObject *));
+static PyObject *neg Py_PROTO((PyObject *));
+static PyObject *pos Py_PROTO((PyObject *));
+static PyObject *not Py_PROTO((PyObject *));
+static PyObject *invert Py_PROTO((PyObject *));
+static PyObject *lshift Py_PROTO((PyObject *, PyObject *));
+static PyObject *rshift Py_PROTO((PyObject *, PyObject *));
+static PyObject *and Py_PROTO((PyObject *, PyObject *));
+static PyObject *xor Py_PROTO((PyObject *, PyObject *));
+static PyObject *or Py_PROTO((PyObject *, PyObject *));
+static PyObject *call_builtin Py_PROTO((PyObject *, PyObject *, PyObject *));
+static PyObject *call_function Py_PROTO((PyObject *, PyObject *, PyObject *));
+static PyObject *apply_subscript Py_PROTO((PyObject *, PyObject *));
+static PyObject *loop_subscript Py_PROTO((PyObject *, PyObject *));
+static int slice_index Py_PROTO((PyObject *, int, int *));
+static PyObject *apply_slice Py_PROTO((PyObject *, PyObject *, PyObject *));
+static int assign_subscript Py_PROTO((PyObject *, PyObject *, PyObject *));
+static int assign_slice Py_PROTO((PyObject *, PyObject *, PyObject *, PyObject *));
+static int cmp_exception Py_PROTO((PyObject *, PyObject *));
+static int cmp_member Py_PROTO((PyObject *, PyObject *));
+static PyObject *cmp_outcome Py_PROTO((int, PyObject *, PyObject *));
+static int import_from Py_PROTO((PyObject *, PyObject *, PyObject *));
+static PyObject *build_class Py_PROTO((PyObject *, PyObject *, PyObject *));
+static int exec_statement Py_PROTO((PyObject *, PyObject *, PyObject *));
+static PyObject *find_from_args Py_PROTO((PyFrameObject *, int));
/* Dynamic execution profile */
@@ -117,7 +116,7 @@ static long dxp[256];
/* Pointer to current frame, used to link new frames to */
-static frameobject *current_frame;
+static PyFrameObject *current_frame;
#ifdef WITH_THREAD
@@ -128,7 +127,7 @@ static type_lock interpreter_lock = 0;
static long main_thread = 0;
void
-init_save_thread()
+PyEval_InitThreads()
{
if (interpreter_lock)
return;
@@ -143,13 +142,13 @@ init_save_thread()
dynamically loaded modules needn't be compiled separately for use
with and without threads: */
-object *
-save_thread()
+PyObject *
+PyEval_SaveThread()
{
#ifdef WITH_THREAD
if (interpreter_lock) {
- object *res;
- res = (object *)current_frame;
+ PyObject *res;
+ res = (PyObject *)current_frame;
current_frame = NULL;
release_lock(interpreter_lock);
return res;
@@ -159,8 +158,8 @@ save_thread()
}
void
-restore_thread(x)
- object *x;
+PyEval_RestoreThread(x)
+ PyObject *x;
{
#ifdef WITH_THREAD
if (interpreter_lock) {
@@ -168,7 +167,7 @@ restore_thread(x)
err = errno;
acquire_lock(interpreter_lock, 1);
errno = err;
- current_frame = (frameobject *)x;
+ current_frame = (PyFrameObject *)x;
}
#endif
}
@@ -207,7 +206,7 @@ static int ticker = 0; /* main loop counter to do periodic things */
#define NPENDINGCALLS 32
static struct {
- int (*func) PROTO((ANY *));
+ int (*func) Py_PROTO((ANY *));
ANY *arg;
} pendingcalls[NPENDINGCALLS];
static volatile int pendingfirst = 0;
@@ -215,7 +214,7 @@ static volatile int pendinglast = 0;
int
Py_AddPendingCall(func, arg)
- int (*func) PROTO((ANY *));
+ int (*func) Py_PROTO((ANY *));
ANY *arg;
{
static int busy = 0;
@@ -256,7 +255,7 @@ Py_MakePendingCalls()
busy = 1;
for (;;) {
int i;
- int (*func) PROTO((ANY *));
+ int (*func) Py_PROTO((ANY *));
ANY *arg;
i = pendingfirst;
if (i == pendinglast)
@@ -285,23 +284,23 @@ enum why_code {
WHY_BREAK /* 'break' statement */
};
-static enum why_code do_raise PROTO((object *, object *, object *));
+static enum why_code do_raise Py_PROTO((PyObject *, PyObject *, PyObject *));
/* Backward compatible interface */
-object *
-eval_code(co, globals, locals)
- codeobject *co;
- object *globals;
- object *locals;
+PyObject *
+PyEval_EvalCode(co, globals, locals)
+ PyCodeObject *co;
+ PyObject *globals;
+ PyObject *locals;
{
return eval_code2(co,
globals, locals,
- (object **)NULL, 0,
- (object **)NULL, 0,
- (object **)NULL, 0,
- (object *)NULL);
+ (PyObject **)NULL, 0,
+ (PyObject **)NULL, 0,
+ (PyObject **)NULL, 0,
+ (PyObject *)NULL);
}
@@ -313,19 +312,19 @@ eval_code(co, globals, locals)
static int recursion_depth = 0;
-static object *
+static PyObject *
eval_code2(co, globals, locals,
args, argcount, kws, kwcount, defs, defcount, owner)
- codeobject *co;
- object *globals;
- object *locals;
- object **args;
+ PyCodeObject *co;
+ PyObject *globals;
+ PyObject *locals;
+ PyObject **args;
int argcount;
- object **kws; /* length: 2*kwcount */
+ PyObject **kws; /* length: 2*kwcount */
int kwcount;
- object **defs;
+ PyObject **defs;
int defcount;
- object *owner;
+ PyObject *owner;
{
#ifdef DXPAIRS
int lastopcode = 0;
@@ -333,23 +332,23 @@ eval_code2(co, globals, locals,
register unsigned char *next_instr;
register int opcode = 0; /* Current opcode */
register int oparg = 0; /* Current opcode argument, if any */
- register object **stack_pointer;
+ register PyObject **stack_pointer;
register enum why_code why; /* Reason for block stack unwind */
register int err; /* Error status -- nonzero if error */
- register object *x; /* Result object -- NULL if error */
- register object *v; /* Temporary objects popped off stack */
- register object *w;
- register object *u;
- register object *t;
- register frameobject *f; /* Current frame */
- register object **fastlocals = NULL;
- object *retval = NULL; /* Return value */
+ register PyObject *x; /* Result object -- NULL if error */
+ register PyObject *v; /* Temporary objects popped off stack */
+ register PyObject *w;
+ register PyObject *u;
+ register PyObject *t;
+ register PyFrameObject *f; /* Current frame */
+ register PyObject **fastlocals = NULL;
+ PyObject *retval = NULL; /* Return value */
#ifdef LLTRACE
int lltrace;
#endif
#if defined(Py_DEBUG) || defined(LLTRACE)
/* Make it easier to find out where we are with a debugger */
- char *filename = getstringvalue(co->co_filename);
+ char *filename = PyString_AsString(co->co_filename);
#endif
/* Code access macros */
@@ -383,26 +382,26 @@ eval_code2(co, globals, locals,
/* Local variable macros */
#define GETLOCAL(i) (fastlocals[i])
-#define SETLOCAL(i, value) do { XDECREF(GETLOCAL(i)); \
+#define SETLOCAL(i, value) do { Py_XDECREF(GETLOCAL(i)); \
GETLOCAL(i) = value; } while (0)
#ifdef USE_STACKCHECK
if (recursion_depth%10 == 0 && PyOS_CheckStack()) {
- err_setstr(MemoryError, "Stack overflow");
+ PyErr_SetString(PyExc_MemoryError, "Stack overflow");
return NULL;
}
#endif
if (globals == NULL) {
- err_setstr(SystemError, "eval_code2: NULL globals");
+ PyErr_SetString(PyExc_SystemError, "eval_code2: NULL globals");
return NULL;
}
#ifdef LLTRACE
- lltrace = dictlookup(globals, "__lltrace__") != NULL;
+ lltrace = PyDict_GetItemString(globals, "__lltrace__") != NULL;
#endif
- f = newframeobject(
+ f = PyFrame_New(
current_frame, /*back*/
co, /*code*/
globals, /*globals*/
@@ -417,9 +416,9 @@ eval_code2(co, globals, locals,
co->co_flags & (CO_VARARGS | CO_VARKEYWORDS)) {
int i;
int n = argcount;
- object *kwdict = NULL;
+ PyObject *kwdict = NULL;
if (co->co_flags & CO_VARKEYWORDS) {
- kwdict = newmappingobject();
+ kwdict = PyDict_New();
if (kwdict == NULL)
goto fail;
i = co->co_argcount;
@@ -429,53 +428,53 @@ eval_code2(co, globals, locals,
}
if (argcount > co->co_argcount) {
if (!(co->co_flags & CO_VARARGS)) {
- err_setstr(TypeError, "too many arguments");
+ PyErr_SetString(PyExc_TypeError, "too many arguments");
goto fail;
}
n = co->co_argcount;
}
for (i = 0; i < n; i++) {
x = args[i];
- INCREF(x);
+ Py_INCREF(x);
SETLOCAL(i, x);
}
if (co->co_flags & CO_VARARGS) {
- u = newtupleobject(argcount - n);
+ u = PyTuple_New(argcount - n);
if (u == NULL)
goto fail;
SETLOCAL(co->co_argcount, u);
for (i = n; i < argcount; i++) {
x = args[i];
- INCREF(x);
- SETTUPLEITEM(u, i-n, x);
+ Py_INCREF(x);
+ PyTuple_SET_ITEM(u, i-n, x);
}
}
for (i = 0; i < kwcount; i++) {
- object *keyword = kws[2*i];
- object *value = kws[2*i + 1];
+ PyObject *keyword = kws[2*i];
+ PyObject *value = kws[2*i + 1];
int j;
/* XXX slow -- speed up using dictionary? */
for (j = 0; j < co->co_argcount; j++) {
- object *nm = GETTUPLEITEM(co->co_varnames, j);
- if (cmpobject(keyword, nm) == 0)
+ PyObject *nm = PyTuple_GET_ITEM(co->co_varnames, j);
+ if (PyObject_Compare(keyword, nm) == 0)
break;
}
if (j >= co->co_argcount) {
if (kwdict == NULL) {
- PyErr_Format(TypeError,
+ PyErr_Format(PyExc_TypeError,
"unexpected keyword argument: %.400s",
- getstringvalue(keyword));
+ PyString_AsString(keyword));
goto fail;
}
- mappinginsert(kwdict, keyword, value);
+ PyDict_SetItem(kwdict, keyword, value);
}
else {
if (GETLOCAL(j) != NULL) {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"keyword parameter redefined");
goto fail;
}
- INCREF(value);
+ Py_INCREF(value);
SETLOCAL(j, value);
}
}
@@ -483,7 +482,7 @@ eval_code2(co, globals, locals,
int m = co->co_argcount - defcount;
for (i = argcount; i < m; i++) {
if (GETLOCAL(i) == NULL) {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"not enough arguments");
goto fail;
}
@@ -494,8 +493,8 @@ eval_code2(co, globals, locals,
i = 0;
for (; i < defcount; i++) {
if (GETLOCAL(m+i) == NULL) {
- object *def = defs[i];
- INCREF(def);
+ PyObject *def = defs[i];
+ Py_INCREF(def);
SETLOCAL(m+i, def);
}
}
@@ -503,12 +502,12 @@ eval_code2(co, globals, locals,
}
else {
if (argcount > 0 || kwcount > 0) {
- err_setstr(TypeError, "no arguments expected");
+ PyErr_SetString(PyExc_TypeError, "no arguments expected");
goto fail;
}
}
- if (sys_trace != NULL) {
+ if (_PySys_TraceFunc != NULL) {
/* sys_trace, if defined, is a function that will
be called on *every* entry to a code block.
Its return value, if not None, is a function that
@@ -521,27 +520,27 @@ eval_code2(co, globals, locals,
depends on the situation. The global trace function
(sys.trace) is also called whenever an exception
is detected. */
- if (call_trace(&sys_trace, &f->f_trace, f, "call",
- None/*XXX how to compute arguments now?*/)) {
+ if (call_trace(&_PySys_TraceFunc, &f->f_trace, f, "call",
+ Py_None/*XXX how to compute arguments now?*/)) {
/* Trace function raised an error */
goto fail;
}
}
- if (sys_profile != NULL) {
+ if (_PySys_ProfileFunc != NULL) {
/* Similar for sys_profile, except it needn't return
itself and isn't called for "line" events */
- if (call_trace(&sys_profile, (object**)0, f, "call",
- None/*XXX*/)) {
+ if (call_trace(&_PySys_ProfileFunc, (PyObject**)0, f, "call",
+ Py_None/*XXX*/)) {
goto fail;
}
}
if (++recursion_depth > MAX_RECURSION_DEPTH) {
--recursion_depth;
- err_setstr(RuntimeError, "Maximum recursion depth exceeded");
+ PyErr_SetString(PyExc_RuntimeError, "Maximum recursion depth exceeded");
current_frame = f->f_back;
- DECREF(f);
+ Py_DECREF(f);
return NULL;
}
@@ -550,7 +549,7 @@ eval_code2(co, globals, locals,
why = WHY_NOT;
err = 0;
- x = None; /* Not a reference, just anything non-NULL */
+ x = Py_None; /* Not a reference, just anything non-NULL */
for (;;) {
/* Do periodic things.
@@ -563,7 +562,7 @@ eval_code2(co, globals, locals,
Py_MakePendingCalls() above). */
if (--ticker < 0) {
- ticker = sys_checkinterval;
+ ticker = _PySys_CheckInterval;
if (pendingfirst != pendinglast) {
if (Py_MakePendingCalls() < 0) {
why = WHY_EXCEPTION;
@@ -577,7 +576,7 @@ eval_code2(co, globals, locals,
/* If we have true signals, the signal handler will call
Py_AddPendingCall() so we don't have to call sigcheck().
On the Mac and DOS, alas, we have to call it. */
- if (sigcheck()) {
+ if (PyErr_CheckSignals()) {
why = WHY_EXCEPTION;
goto on_error;
}
@@ -644,7 +643,7 @@ eval_code2(co, globals, locals,
case POP_TOP:
v = POP();
- DECREF(v);
+ Py_DECREF(v);
continue;
case ROT_TWO:
@@ -665,14 +664,14 @@ eval_code2(co, globals, locals,
case DUP_TOP:
v = TOP();
- INCREF(v);
+ Py_INCREF(v);
PUSH(v);
continue;
case UNARY_POSITIVE:
v = POP();
x = pos(v);
- DECREF(v);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
@@ -680,7 +679,7 @@ eval_code2(co, globals, locals,
case UNARY_NEGATIVE:
v = POP();
x = neg(v);
- DECREF(v);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
@@ -688,15 +687,15 @@ eval_code2(co, globals, locals,
case UNARY_NOT:
v = POP();
x = not(v);
- DECREF(v);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
case UNARY_CONVERT:
v = POP();
- x = reprobject(v);
- DECREF(v);
+ x = PyObject_Repr(v);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
@@ -704,7 +703,7 @@ eval_code2(co, globals, locals,
case UNARY_INVERT:
v = POP();
x = invert(v);
- DECREF(v);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
@@ -713,8 +712,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = powerop(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -723,8 +722,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = mul(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -733,8 +732,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = divide(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -743,8 +742,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = mod(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -753,8 +752,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = add(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -763,8 +762,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = sub(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -773,8 +772,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = apply_subscript(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -783,8 +782,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = lshift(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -793,8 +792,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = rshift(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -803,8 +802,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = and(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -813,8 +812,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = xor(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -823,8 +822,8 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = or(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -843,9 +842,9 @@ eval_code2(co, globals, locals,
v = NULL;
u = POP();
x = apply_slice(u, v, w);
- DECREF(u);
- XDECREF(v);
- XDECREF(w);
+ Py_DECREF(u);
+ Py_XDECREF(v);
+ Py_XDECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -865,10 +864,10 @@ eval_code2(co, globals, locals,
u = POP();
t = POP();
err = assign_slice(u, v, w, t); /* u[v:w] = t */
- DECREF(t);
- DECREF(u);
- XDECREF(v);
- XDECREF(w);
+ Py_DECREF(t);
+ Py_DECREF(u);
+ Py_XDECREF(v);
+ Py_XDECREF(w);
if (err == 0) continue;
break;
@@ -885,11 +884,11 @@ eval_code2(co, globals, locals,
else
v = NULL;
u = POP();
- err = assign_slice(u, v, w, (object *)NULL);
+ err = assign_slice(u, v, w, (PyObject *)NULL);
/* del u[v:w] */
- DECREF(u);
- XDECREF(v);
- XDECREF(w);
+ Py_DECREF(u);
+ Py_XDECREF(v);
+ Py_XDECREF(w);
if (err == 0) continue;
break;
@@ -899,9 +898,9 @@ eval_code2(co, globals, locals,
u = POP();
/* v[w] = u */
err = assign_subscript(v, w, u);
- DECREF(u);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(u);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (err == 0) continue;
break;
@@ -909,9 +908,9 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
/* del v[w] */
- err = assign_subscript(v, w, (object *)NULL);
- DECREF(v);
- DECREF(w);
+ err = assign_subscript(v, w, (PyObject *)NULL);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (err == 0) continue;
break;
@@ -919,44 +918,44 @@ eval_code2(co, globals, locals,
v = POP();
/* Print value except if procedure result */
/* Before printing, also assign to '_' */
- if (v != None &&
- (err = dictinsert(f->f_builtins, "_", v)) == 0 &&
- !suppress_print) {
- flushline();
- x = sysget("stdout");
- err = writeobject(v, x, 0);
- softspace(x, 1);
- flushline();
- }
- DECREF(v);
+ if (v != Py_None &&
+ (err = PyDict_SetItemString(f->f_builtins, "_", v)) == 0 &&
+ !Py_SuppressPrintingFlag) {
+ Py_FlushLine();
+ x = PySys_GetObject("stdout");
+ err = PyFile_WriteObject(v, x, 0);
+ PyFile_SoftSpace(x, 1);
+ Py_FlushLine();
+ }
+ Py_DECREF(v);
break;
case PRINT_ITEM:
v = POP();
- w = sysget("stdout");
- if (softspace(w, 1))
- writestring(" ", w);
- err = writeobject(v, w, PRINT_RAW);
- if (err == 0 && is_stringobject(v)) {
+ w = PySys_GetObject("stdout");
+ if (PyFile_SoftSpace(w, 1))
+ PyFile_WriteString(" ", w);
+ err = PyFile_WriteObject(v, w, Py_PRINT_RAW);
+ if (err == 0 && PyString_Check(v)) {
/* XXX move into writeobject() ? */
- char *s = getstringvalue(v);
- int len = getstringsize(v);
+ char *s = PyString_AsString(v);
+ int len = PyString_Size(v);
if (len > 0 &&
isspace(Py_CHARMASK(s[len-1])) &&
s[len-1] != ' ')
- softspace(w, 0);
+ PyFile_SoftSpace(w, 0);
}
- DECREF(v);
+ Py_DECREF(v);
if (err == 0) continue;
break;
case PRINT_NEWLINE:
- x = sysget("stdout");
+ x = PySys_GetObject("stdout");
if (x == NULL)
- err_setstr(RuntimeError, "lost sys.stdout");
+ PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
else {
- writestring("\n", x);
- softspace(x, 0);
+ PyFile_WriteString("\n", x);
+ PyFile_SoftSpace(x, 0);
}
break;
@@ -978,7 +977,7 @@ eval_code2(co, globals, locals,
why = do_raise(w, v, u);
break;
default:
- err_setstr(SystemError,
+ PyErr_SetString(PyExc_SystemError,
"bad RAISE_VARARGS oparg");
why = WHY_EXCEPTION;
break;
@@ -987,10 +986,10 @@ eval_code2(co, globals, locals,
case LOAD_LOCALS:
if ((x = f->f_locals) == NULL) {
- err_setstr(SystemError, "no locals");
+ PyErr_SetString(PyExc_SystemError, "no locals");
break;
}
- INCREF(x);
+ Py_INCREF(x);
PUSH(x);
break;
@@ -1004,41 +1003,41 @@ eval_code2(co, globals, locals,
v = POP();
u = POP();
err = exec_statement(u, v, w);
- DECREF(u);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(u);
+ Py_DECREF(v);
+ Py_DECREF(w);
break;
case POP_BLOCK:
{
- block *b = pop_block(f);
+ PyTryBlock *b = PyFrame_BlockPop(f);
while (STACK_LEVEL() > b->b_level) {
v = POP();
- DECREF(v);
+ Py_DECREF(v);
}
}
break;
case END_FINALLY:
v = POP();
- if (is_intobject(v)) {
- why = (enum why_code) getintvalue(v);
+ if (PyInt_Check(v)) {
+ why = (enum why_code) PyInt_AsLong(v);
if (why == WHY_RETURN)
retval = POP();
}
- else if (is_stringobject(v) || is_classobject(v)) {
+ else if (PyString_Check(v) || PyClass_Check(v)) {
w = POP();
u = POP();
- err_restore(v, w, u);
+ PyErr_Restore(v, w, u);
why = WHY_RERAISE;
break;
}
- else if (v != None) {
- err_setstr(SystemError,
+ else if (v != Py_None) {
+ PyErr_SetString(PyExc_SystemError,
"'finally' pops bad exception");
why = WHY_EXCEPTION;
}
- DECREF(v);
+ Py_DECREF(v);
break;
case BUILD_CLASS:
@@ -1047,30 +1046,30 @@ eval_code2(co, globals, locals,
w = POP();
x = build_class(u, v, w);
PUSH(x);
- DECREF(u);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(u);
+ Py_DECREF(v);
+ Py_DECREF(w);
break;
case STORE_NAME:
w = GETNAMEV(oparg);
v = POP();
if ((x = f->f_locals) == NULL) {
- err_setstr(SystemError, "no locals");
+ PyErr_SetString(PyExc_SystemError, "no locals");
break;
}
- err = dict2insert(x, w, v);
- DECREF(v);
+ err = PyDict_SetItem(x, w, v);
+ Py_DECREF(v);
break;
case DELETE_NAME:
w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) {
- err_setstr(SystemError, "no locals");
+ PyErr_SetString(PyExc_SystemError, "no locals");
break;
}
- if ((err = dict2remove(x, w)) != 0)
- err_setval(NameError, w);
+ if ((err = PyDict_DelItem(x, w)) != 0)
+ PyErr_SetObject(PyExc_NameError, w);
break;
#ifdef CASE_TOO_BIG
@@ -1079,128 +1078,128 @@ eval_code2(co, globals, locals,
case UNPACK_TUPLE:
v = POP();
- if (!is_tupleobject(v)) {
- err_setstr(TypeError, "unpack non-tuple");
+ if (!PyTuple_Check(v)) {
+ PyErr_SetString(PyExc_TypeError, "unpack non-tuple");
why = WHY_EXCEPTION;
}
- else if (gettuplesize(v) != oparg) {
- err_setstr(ValueError,
+ else if (PyTuple_Size(v) != oparg) {
+ PyErr_SetString(PyExc_ValueError,
"unpack tuple of wrong size");
why = WHY_EXCEPTION;
}
else {
for (; --oparg >= 0; ) {
- w = GETTUPLEITEM(v, oparg);
- INCREF(w);
+ w = PyTuple_GET_ITEM(v, oparg);
+ Py_INCREF(w);
PUSH(w);
}
}
- DECREF(v);
+ Py_DECREF(v);
break;
case UNPACK_LIST:
v = POP();
- if (!is_listobject(v)) {
- err_setstr(TypeError, "unpack non-list");
+ if (!PyList_Check(v)) {
+ PyErr_SetString(PyExc_TypeError, "unpack non-list");
why = WHY_EXCEPTION;
}
- else if (getlistsize(v) != oparg) {
- err_setstr(ValueError,
+ else if (PyList_Size(v) != oparg) {
+ PyErr_SetString(PyExc_ValueError,
"unpack list of wrong size");
why = WHY_EXCEPTION;
}
else {
for (; --oparg >= 0; ) {
- w = getlistitem(v, oparg);
- INCREF(w);
+ w = PyList_GetItem(v, oparg);
+ Py_INCREF(w);
PUSH(w);
}
}
- DECREF(v);
+ Py_DECREF(v);
break;
case STORE_ATTR:
w = GETNAMEV(oparg);
v = POP();
u = POP();
- err = setattro(v, w, u); /* v.w = u */
- DECREF(v);
- DECREF(u);
+ err = PyObject_SetAttr(v, w, u); /* v.w = u */
+ Py_DECREF(v);
+ Py_DECREF(u);
break;
case DELETE_ATTR:
w = GETNAMEV(oparg);
v = POP();
- err = setattro(v, w, (object *)NULL); /* del v.w */
- DECREF(v);
+ err = PyObject_SetAttr(v, w, (PyObject *)NULL); /* del v.w */
+ Py_DECREF(v);
break;
case STORE_GLOBAL:
w = GETNAMEV(oparg);
v = POP();
- err = dict2insert(f->f_globals, w, v);
- DECREF(v);
+ err = PyDict_SetItem(f->f_globals, w, v);
+ Py_DECREF(v);
break;
case DELETE_GLOBAL:
w = GETNAMEV(oparg);
- if ((err = dict2remove(f->f_globals, w)) != 0)
- err_setval(NameError, w);
+ if ((err = PyDict_DelItem(f->f_globals, w)) != 0)
+ PyErr_SetObject(PyExc_NameError, w);
break;
case LOAD_CONST:
x = GETCONST(oparg);
- INCREF(x);
+ Py_INCREF(x);
PUSH(x);
break;
case LOAD_NAME:
w = GETNAMEV(oparg);
if ((x = f->f_locals) == NULL) {
- err_setstr(SystemError, "no locals");
+ PyErr_SetString(PyExc_SystemError, "no locals");
break;
}
- x = dict2lookup(x, w);
+ x = PyDict_GetItem(x, w);
if (x == NULL) {
- err_clear();
- x = dict2lookup(f->f_globals, w);
+ PyErr_Clear();
+ x = PyDict_GetItem(f->f_globals, w);
if (x == NULL) {
- err_clear();
- x = dict2lookup(f->f_builtins, w);
+ PyErr_Clear();
+ x = PyDict_GetItem(f->f_builtins, w);
if (x == NULL) {
- err_setval(NameError, w);
+ PyErr_SetObject(PyExc_NameError, w);
break;
}
}
}
- INCREF(x);
+ Py_INCREF(x);
PUSH(x);
break;
case LOAD_GLOBAL:
w = GETNAMEV(oparg);
- x = dict2lookup(f->f_globals, w);
+ x = PyDict_GetItem(f->f_globals, w);
if (x == NULL) {
- err_clear();
- x = dict2lookup(f->f_builtins, w);
+ PyErr_Clear();
+ x = PyDict_GetItem(f->f_builtins, w);
if (x == NULL) {
- err_setval(NameError, w);
+ PyErr_SetObject(PyExc_NameError, w);
break;
}
}
- INCREF(x);
+ Py_INCREF(x);
PUSH(x);
break;
case LOAD_FAST:
x = GETLOCAL(oparg);
if (x == NULL) {
- err_setval(NameError,
- gettupleitem(co->co_varnames,
+ PyErr_SetObject(PyExc_NameError,
+ PyTuple_GetItem(co->co_varnames,
oparg));
break;
}
- INCREF(x);
+ Py_INCREF(x);
PUSH(x);
if (x != NULL) continue;
break;
@@ -1215,11 +1214,11 @@ eval_code2(co, globals, locals,
continue;
case BUILD_TUPLE:
- x = newtupleobject(oparg);
+ x = PyTuple_New(oparg);
if (x != NULL) {
for (; --oparg >= 0;) {
w = POP();
- SETTUPLEITEM(x, oparg, w);
+ PyTuple_SET_ITEM(x, oparg, w);
}
PUSH(x);
continue;
@@ -1227,11 +1226,11 @@ eval_code2(co, globals, locals,
break;
case BUILD_LIST:
- x = newlistobject(oparg);
+ x = PyList_New(oparg);
if (x != NULL) {
for (; --oparg >= 0;) {
w = POP();
- err = setlistitem(x, oparg, w);
+ err = PyList_SetItem(x, oparg, w);
if (err != 0)
break;
}
@@ -1241,7 +1240,7 @@ eval_code2(co, globals, locals,
break;
case BUILD_MAP:
- x = newdictobject();
+ x = PyDict_New();
PUSH(x);
if (x != NULL) continue;
break;
@@ -1249,8 +1248,8 @@ eval_code2(co, globals, locals,
case LOAD_ATTR:
w = GETNAMEV(oparg);
v = POP();
- x = getattro(v, w);
- DECREF(v);
+ x = PyObject_GetAttr(v, w);
+ Py_DECREF(v);
PUSH(x);
if (x != NULL) continue;
break;
@@ -1259,23 +1258,23 @@ eval_code2(co, globals, locals,
w = POP();
v = POP();
x = cmp_outcome(oparg, v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
case IMPORT_NAME:
w = GETNAMEV(oparg);
- x = dictlookup(f->f_builtins, "__import__");
+ x = PyDict_GetItemString(f->f_builtins, "__import__");
if (x == NULL) {
- err_setstr(ImportError,
+ PyErr_SetString(PyExc_ImportError,
"__import__ not found");
break;
}
- if (is_methodobject(x)) {
- u = None;
- INCREF(u);
+ if (PyCFunction_Check(x)) {
+ u = Py_None;
+ Py_INCREF(u);
}
else {
u = find_from_args(f, INSTR_OFFSET());
@@ -1284,18 +1283,18 @@ eval_code2(co, globals, locals,
break;
}
}
- w = mkvalue("(OOOO)",
+ w = Py_BuildValue("(OOOO)",
w,
f->f_globals,
- f->f_locals == NULL ? None : f->f_locals,
+ f->f_locals == NULL ? Py_None : f->f_locals,
u);
- DECREF(u);
+ Py_DECREF(u);
if (w == NULL) {
x = NULL;
break;
}
- x = call_object(x, w);
- DECREF(w);
+ x = PyEval_CallObject(x, w);
+ Py_DECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -1303,13 +1302,13 @@ eval_code2(co, globals, locals,
case IMPORT_FROM:
w = GETNAMEV(oparg);
v = TOP();
- fast_2_locals(f);
+ PyFrame_FastToLocals(f);
if ((x = f->f_locals) == NULL) {
- err_setstr(SystemError, "no locals");
+ PyErr_SetString(PyExc_SystemError, "no locals");
break;
}
err = import_from(x, v, w);
- locals_2_fast(f, 0);
+ PyFrame_LocalsToFast(f, 0);
if (err == 0) continue;
break;
@@ -1318,7 +1317,7 @@ eval_code2(co, globals, locals,
continue;
case JUMP_IF_FALSE:
- err = testbool(TOP());
+ err = PyObject_IsTrue(TOP());
if (err > 0)
err = 0;
else if (err == 0)
@@ -1328,7 +1327,7 @@ eval_code2(co, globals, locals,
continue;
case JUMP_IF_TRUE:
- err = testbool(TOP());
+ err = PyObject_IsTrue(TOP());
if (err > 0) {
err = 0;
JUMPBY(oparg);
@@ -1354,18 +1353,18 @@ eval_code2(co, globals, locals,
u = loop_subscript(v, w);
if (u != NULL) {
PUSH(v);
- x = newintobject(getintvalue(w)+1);
+ x = PyInt_FromLong(PyInt_AsLong(w)+1);
PUSH(x);
- DECREF(w);
+ Py_DECREF(w);
PUSH(u);
if (x != NULL) continue;
}
else {
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
/* A NULL can mean "s exhausted"
but also an error: */
- if (err_occurred())
+ if (PyErr_Occurred())
why = WHY_EXCEPTION;
else {
JUMPBY(oparg);
@@ -1377,7 +1376,7 @@ eval_code2(co, globals, locals,
case SETUP_LOOP:
case SETUP_EXCEPT:
case SETUP_FINALLY:
- setup_block(f, opcode, INSTR_OFFSET() + oparg,
+ PyFrame_BlockSetup(f, opcode, INSTR_OFFSET() + oparg,
STACK_LEVEL());
continue;
@@ -1392,7 +1391,7 @@ eval_code2(co, globals, locals,
/* Trace each line of code reached */
f->f_lasti = INSTR_OFFSET();
err = call_trace(&f->f_trace, &f->f_trace,
- f, "line", None);
+ f, "line", Py_None);
break;
case CALL_FUNCTION:
@@ -1400,19 +1399,19 @@ eval_code2(co, globals, locals,
int na = oparg & 0xff;
int nk = (oparg>>8) & 0xff;
int n = na + 2*nk;
- object **pfunc = stack_pointer - n - 1;
- object *func = *pfunc;
- object *self = NULL;
- object *class = NULL;
+ PyObject **pfunc = stack_pointer - n - 1;
+ PyObject *func = *pfunc;
+ PyObject *self = NULL;
+ PyObject *class = NULL;
f->f_lasti = INSTR_OFFSET() - 3; /* For tracing */
- if (is_instancemethodobject(func)) {
- self = instancemethodgetself(func);
- class = instancemethodgetclass(func);
- func = instancemethodgetfunc(func);
- INCREF(func);
+ if (PyMethod_Check(func)) {
+ self = PyMethod_Self(func);
+ class = PyMethod_Class(func);
+ func = PyMethod_Function(func);
+ Py_INCREF(func);
if (self != NULL) {
- INCREF(self);
- DECREF(*pfunc);
+ Py_INCREF(self);
+ Py_DECREF(*pfunc);
*pfunc = self;
na++;
n++;
@@ -1425,15 +1424,15 @@ eval_code2(co, globals, locals,
if (na > 0 &&
(self = stack_pointer[-n])
!= NULL &&
- is_instanceobject(self) &&
- issubclass(
- (object *)
- (((instanceobject *)self)
+ PyInstance_Check(self) &&
+ PyClass_IsSubclass(
+ (PyObject *)
+ (((PyInstanceObject *)self)
->in_class),
class))
/* Handy-dandy */ ;
else {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"unbound method must be called with class instance 1st argument");
x = NULL;
break;
@@ -1441,72 +1440,72 @@ eval_code2(co, globals, locals,
}
}
else
- INCREF(func);
- if (is_funcobject(func)) {
- object *co = getfunccode(func);
- object *globals = getfuncglobals(func);
- object *argdefs = PyFunction_GetDefaults(func);
- object **d;
+ Py_INCREF(func);
+ if (PyFunction_Check(func)) {
+ PyObject *co = PyFunction_GetCode(func);
+ PyObject *globals = PyFunction_GetGlobals(func);
+ PyObject *argdefs = PyFunction_GetDefaults(func);
+ PyObject **d;
int nd;
if (argdefs != NULL) {
- d = &GETTUPLEITEM(argdefs, 0);
- nd = ((tupleobject *)argdefs)->ob_size;
+ d = &PyTuple_GET_ITEM(argdefs, 0);
+ nd = ((PyTupleObject *)argdefs)->ob_size;
}
else {
d = NULL;
nd = 0;
}
x = eval_code2(
- (codeobject *)co,
- globals, (object *)NULL,
+ (PyCodeObject *)co,
+ globals, (PyObject *)NULL,
stack_pointer-n, na,
stack_pointer-2*nk, nk,
d, nd,
class);
}
else {
- object *args = newtupleobject(na);
- object *kwdict = NULL;
+ PyObject *args = PyTuple_New(na);
+ PyObject *kwdict = NULL;
if (args == NULL) {
x = NULL;
break;
}
if (nk > 0) {
- kwdict = newdictobject();
+ kwdict = PyDict_New();
if (kwdict == NULL) {
x = NULL;
break;
}
err = 0;
while (--nk >= 0) {
- object *value = POP();
- object *key = POP();
- err = mappinginsert(
+ PyObject *value = POP();
+ PyObject *key = POP();
+ err = PyDict_SetItem(
kwdict, key, value);
- DECREF(key);
- DECREF(value);
+ Py_DECREF(key);
+ Py_DECREF(value);
if (err)
break;
}
if (err) {
- DECREF(args);
- DECREF(kwdict);
+ Py_DECREF(args);
+ Py_DECREF(kwdict);
break;
}
}
while (--na >= 0) {
w = POP();
- SETTUPLEITEM(args, na, w);
+ PyTuple_SET_ITEM(args, na, w);
}
x = PyEval_CallObjectWithKeywords(
func, args, kwdict);
- DECREF(args);
- XDECREF(kwdict);
+ Py_DECREF(args);
+ Py_XDECREF(kwdict);
}
- DECREF(func);
+ Py_DECREF(func);
while (stack_pointer > pfunc) {
w = POP();
- DECREF(w);
+ Py_DECREF(w);
}
PUSH(x);
if (x != NULL) continue;
@@ -1515,22 +1514,22 @@ eval_code2(co, globals, locals,
case MAKE_FUNCTION:
v = POP(); /* code object */
- x = newfuncobject(v, f->f_globals);
- DECREF(v);
+ x = PyFunction_New(v, f->f_globals);
+ Py_DECREF(v);
/* XXX Maybe this should be a separate opcode? */
if (x != NULL && oparg > 0) {
- v = newtupleobject(oparg);
+ v = PyTuple_New(oparg);
if (v == NULL) {
- DECREF(x);
+ Py_DECREF(x);
x = NULL;
break;
}
while (--oparg >= 0) {
w = POP();
- SETTUPLEITEM(v, oparg, w);
+ PyTuple_SET_ITEM(v, oparg, w);
}
err = PyFunction_SetDefaults(x, v);
- DECREF(v);
+ Py_DECREF(v);
}
PUSH(x);
break;
@@ -1543,9 +1542,9 @@ eval_code2(co, globals, locals,
v = POP();
u = POP();
x = PySlice_New(u, v, w);
- DECREF(u);
- DECREF(v);
- XDECREF(w);
+ Py_DECREF(u);
+ Py_DECREF(v);
+ Py_XDECREF(w);
PUSH(x);
if (x != NULL) continue;
break;
@@ -1555,7 +1554,7 @@ eval_code2(co, globals, locals,
fprintf(stderr,
"XXX lineno: %d, opcode: %d\n",
f->f_lineno, opcode);
- err_setstr(SystemError, "unknown opcode");
+ PyErr_SetString(PyExc_SystemError, "unknown opcode");
why = WHY_EXCEPTION;
break;
@@ -1572,7 +1571,7 @@ eval_code2(co, globals, locals,
if (why == WHY_NOT) {
if (err == 0 && x != NULL) {
#ifdef CHECKEXC
- if (err_occurred())
+ if (PyErr_Occurred())
fprintf(stderr,
"XXX undetected error\n");
else
@@ -1580,7 +1579,7 @@ eval_code2(co, globals, locals,
continue; /* Normal, fast path */
}
why = WHY_EXCEPTION;
- x = None;
+ x = Py_None;
err = 0;
}
@@ -1588,14 +1587,14 @@ eval_code2(co, globals, locals,
/* Double-check exception status */
if (why == WHY_EXCEPTION || why == WHY_RERAISE) {
- if (!err_occurred()) {
+ if (!PyErr_Occurred()) {
fprintf(stderr, "XXX ghost error\n");
- err_setstr(SystemError, "ghost error");
+ PyErr_SetString(PyExc_SystemError, "ghost error");
why = WHY_EXCEPTION;
}
}
else {
- if (err_occurred()) {
+ if (PyErr_Occurred()) {
fprintf(stderr,
"XXX undetected error (why=%d)\n",
why);
@@ -1610,12 +1609,12 @@ eval_code2(co, globals, locals,
f->f_lasti = INSTR_OFFSET() - 1;
if (HAS_ARG(opcode))
f->f_lasti -= 2;
- tb_here(f);
+ PyTraceBack_Here(f);
if (f->f_trace)
call_exc_trace(&f->f_trace, &f->f_trace, f);
- if (sys_profile)
- call_exc_trace(&sys_profile, (object**)0, f);
+ if (_PySys_ProfileFunc)
+ call_exc_trace(&_PySys_ProfileFunc, (PyObject**)0, f);
}
/* For the rest, treat WHY_RERAISE as WHY_EXCEPTION */
@@ -1626,10 +1625,10 @@ eval_code2(co, globals, locals,
/* Unwind stacks if a (pseudo) exception occurred */
while (why != WHY_NOT && f->f_iblock > 0) {
- block *b = pop_block(f);
+ PyTryBlock *b = PyFrame_BlockPop(f);
while (STACK_LEVEL() > b->b_level) {
v = POP();
- XDECREF(v);
+ Py_XDECREF(v);
}
if (b->b_type == SETUP_LOOP && why == WHY_BREAK) {
why = WHY_NOT;
@@ -1640,11 +1639,11 @@ eval_code2(co, globals, locals,
(b->b_type == SETUP_EXCEPT &&
why == WHY_EXCEPTION)) {
if (why == WHY_EXCEPTION) {
- object *exc, *val, *tb;
- err_fetch(&exc, &val, &tb);
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
if (val == NULL) {
- val = None;
- INCREF(val);
+ val = Py_None;
+ Py_INCREF(val);
}
/* Make the raw exception data
available to the handler,
@@ -1652,9 +1651,9 @@ eval_code2(co, globals, locals,
Python main loop. Don't do
this for 'finally'. */
if (b->b_type == SETUP_EXCEPT) {
- sysset("exc_traceback", tb);
- sysset("exc_value", val);
- sysset("exc_type", exc);
+ PySys_SetObject("exc_traceback", tb);
+ PySys_SetObject("exc_value", val);
+ PySys_SetObject("exc_type", exc);
}
PUSH(tb);
PUSH(val);
@@ -1663,7 +1662,7 @@ eval_code2(co, globals, locals,
else {
if (why == WHY_RETURN)
PUSH(retval);
- v = newintobject((long)why);
+ v = PyInt_FromLong((long)why);
PUSH(v);
}
why = WHY_NOT;
@@ -1683,7 +1682,7 @@ eval_code2(co, globals, locals,
while (!EMPTY()) {
v = POP();
- XDECREF(v);
+ Py_XDECREF(v);
}
if (why != WHY_RETURN)
@@ -1693,17 +1692,17 @@ eval_code2(co, globals, locals,
if (why == WHY_RETURN) {
if (call_trace(&f->f_trace, &f->f_trace, f,
"return", retval)) {
- XDECREF(retval);
+ Py_XDECREF(retval);
retval = NULL;
why = WHY_EXCEPTION;
}
}
}
- if (sys_profile && why == WHY_RETURN) {
- if (call_trace(&sys_profile, (object**)0,
+ if (_PySys_ProfileFunc && why == WHY_RETURN) {
+ if (call_trace(&_PySys_ProfileFunc, (PyObject**)0,
f, "return", retval)) {
- XDECREF(retval);
+ Py_XDECREF(retval);
retval = NULL;
why = WHY_EXCEPTION;
}
@@ -1716,7 +1715,7 @@ eval_code2(co, globals, locals,
/* Restore previous frame and release the current one */
current_frame = f->f_back;
- DECREF(f);
+ Py_DECREF(f);
return retval;
}
@@ -1725,7 +1724,7 @@ eval_code2(co, globals, locals,
This *consumes* a reference count to each of its arguments. */
static enum why_code
do_raise(type, value, tb)
- object *type, *value, *tb;
+ PyObject *type, *value, *tb;
{
/* We support the following forms of raise:
raise <class>, <classinstance>
@@ -1748,233 +1747,233 @@ do_raise(type, value, tb)
/* First, check the traceback argument, replacing None with
NULL. */
- if (tb == None) {
- DECREF(tb);
+ if (tb == Py_None) {
+ Py_DECREF(tb);
tb = NULL;
}
else if (tb != NULL && !PyTraceBack_Check(tb)) {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"raise 3rd arg must be traceback or None");
goto raise_error;
}
/* Next, replace a missing value with None */
if (value == NULL) {
- value = None;
- INCREF(value);
+ value = Py_None;
+ Py_INCREF(value);
}
/* Next, repeatedly, replace a tuple exception with its first item */
- while (is_tupleobject(type) && gettuplesize(type) > 0) {
- object *tmp = type;
- type = GETTUPLEITEM(type, 0);
- INCREF(type);
- DECREF(tmp);
+ while (PyTuple_Check(type) && PyTuple_Size(type) > 0) {
+ PyObject *tmp = type;
+ type = PyTuple_GET_ITEM(type, 0);
+ Py_INCREF(type);
+ Py_DECREF(tmp);
}
/* Now switch on the exception's type */
- if (is_stringobject(type)) {
+ if (PyString_Check(type)) {
;
}
- else if (is_classobject(type)) {
+ else if (PyClass_Check(type)) {
/* Raising a class. If the value is an instance, it
better be an instance of the class. If it is not,
it will be used to create an instance. */
- if (is_instanceobject(value)) {
- object *inclass = (object*)
- (((instanceobject*)value)->in_class);
- if (!issubclass(inclass, type)) {
- err_setstr(TypeError,
+ if (PyInstance_Check(value)) {
+ PyObject *inclass = (PyObject*)
+ (((PyInstanceObject*)value)->in_class);
+ if (!PyClass_IsSubclass(inclass, type)) {
+ PyErr_SetString(PyExc_TypeError,
"raise <class>, <instance> requires that <instance> is a member of <class>");
goto raise_error;
}
}
else {
/* Go instantiate the class */
- object *args, *res;
- if (value == None)
- args = mkvalue("()");
- else if (is_tupleobject(value)) {
- INCREF(value);
+ PyObject *args, *res;
+ if (value == Py_None)
+ args = Py_BuildValue("()");
+ else if (PyTuple_Check(value)) {
+ Py_INCREF(value);
args = value;
}
else
- args = mkvalue("(O)", value);
+ args = Py_BuildValue("(O)", value);
if (args == NULL)
goto raise_error;
- res = call_object(type, args);
- DECREF(args);
+ res = PyEval_CallObject(type, args);
+ Py_DECREF(args);
if (res == NULL)
goto raise_error;
- DECREF(value);
+ Py_DECREF(value);
value = res;
}
}
- else if (is_instanceobject(type)) {
+ else if (PyInstance_Check(type)) {
/* Raising an instance. The value should be a dummy. */
- if (value != None) {
- err_setstr(TypeError,
+ if (value != Py_None) {
+ PyErr_SetString(PyExc_TypeError,
"instance exception may not have a separate value");
goto raise_error;
}
else {
/* Normalize to raise <class>, <instance> */
- DECREF(value);
+ Py_DECREF(value);
value = type;
- type = (object*) ((instanceobject*)type)->in_class;
- INCREF(type);
+ type = (PyObject*) ((PyInstanceObject*)type)->in_class;
+ Py_INCREF(type);
}
}
else {
/* Not something you can raise. You get an exception
anyway, just not what you specified :-) */
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"exceptions must be strings, classes, or instances");
goto raise_error;
}
- err_restore(type, value, tb);
+ PyErr_Restore(type, value, tb);
if (tb == NULL)
return WHY_EXCEPTION;
else
return WHY_RERAISE;
raise_error:
- XDECREF(value);
- XDECREF(type);
- XDECREF(tb);
+ Py_XDECREF(value);
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
return WHY_EXCEPTION;
}
#ifdef LLTRACE
static int
prtrace(v, str)
- object *v;
+ PyObject *v;
char *str;
{
printf("%s ", str);
- if (printobject(v, stdout, 0) != 0)
- err_clear(); /* Don't know what else to do */
+ if (PyObject_Print(v, stdout, 0) != 0)
+ PyErr_Clear(); /* Don't know what else to do */
printf("\n");
}
#endif
static void
call_exc_trace(p_trace, p_newtrace, f)
- object **p_trace, **p_newtrace;
- frameobject *f;
+ PyObject **p_trace, **p_newtrace;
+ PyFrameObject *f;
{
- object *type, *value, *traceback, *arg;
+ PyObject *type, *value, *traceback, *arg;
int err;
- err_fetch(&type, &value, &traceback);
+ PyErr_Fetch(&type, &value, &traceback);
if (value == NULL) {
- value = None;
- INCREF(value);
+ value = Py_None;
+ Py_INCREF(value);
}
- arg = mkvalue("(OOO)", type, value, traceback);
+ arg = Py_BuildValue("(OOO)", type, value, traceback);
if (arg == NULL) {
- err_restore(type, value, traceback);
+ PyErr_Restore(type, value, traceback);
return;
}
err = call_trace(p_trace, p_newtrace, f, "exception", arg);
- DECREF(arg);
+ Py_DECREF(arg);
if (err == 0)
- err_restore(type, value, traceback);
+ PyErr_Restore(type, value, traceback);
else {
- XDECREF(type);
- XDECREF(value);
- XDECREF(traceback);
+ Py_XDECREF(type);
+ Py_XDECREF(value);
+ Py_XDECREF(traceback);
}
}
static int
call_trace(p_trace, p_newtrace, f, msg, arg)
- object **p_trace; /* in/out; may not be NULL;
+ PyObject **p_trace; /* in/out; may not be NULL;
may not point to NULL variable initially */
- object **p_newtrace; /* in/out; may be NULL;
+ PyObject **p_newtrace; /* in/out; may be NULL;
may point to NULL variable;
may be same variable as p_newtrace */
- frameobject *f;
+ PyFrameObject *f;
char *msg;
- object *arg;
+ PyObject *arg;
{
- object *args, *what;
- object *res = NULL;
+ PyObject *args, *what;
+ PyObject *res = NULL;
static int tracing = 0;
if (tracing) {
/* Don't do recursive traces */
if (p_newtrace) {
- XDECREF(*p_newtrace);
+ Py_XDECREF(*p_newtrace);
*p_newtrace = NULL;
}
return 0;
}
- args = newtupleobject(3);
+ args = PyTuple_New(3);
if (args == NULL)
- goto cleanup;
- what = newstringobject(msg);
+ goto Py_Cleanup;
+ what = PyString_FromString(msg);
if (what == NULL)
- goto cleanup;
- INCREF(f);
- SETTUPLEITEM(args, 0, (object *)f);
- SETTUPLEITEM(args, 1, what);
+ goto Py_Cleanup;
+ Py_INCREF(f);
+ PyTuple_SET_ITEM(args, 0, (PyObject *)f);
+ PyTuple_SET_ITEM(args, 1, what);
if (arg == NULL)
- arg = None;
- INCREF(arg);
- SETTUPLEITEM(args, 2, arg);
+ arg = Py_None;
+ Py_INCREF(arg);
+ PyTuple_SET_ITEM(args, 2, arg);
tracing++;
- fast_2_locals(f);
- res = call_object(*p_trace, args); /* May clear *p_trace! */
- locals_2_fast(f, 1);
+ PyFrame_FastToLocals(f);
+ res = PyEval_CallObject(*p_trace, args); /* May clear *p_trace! */
+ PyFrame_LocalsToFast(f, 1);
tracing--;
- cleanup:
- XDECREF(args);
+ Py_Cleanup:
+ Py_XDECREF(args);
if (res == NULL) {
/* The trace proc raised an exception */
- tb_here(f);
- XDECREF(*p_trace);
+ PyTraceBack_Here(f);
+ Py_XDECREF(*p_trace);
*p_trace = NULL;
if (p_newtrace) {
- XDECREF(*p_newtrace);
+ Py_XDECREF(*p_newtrace);
*p_newtrace = NULL;
}
return -1;
}
else {
if (p_newtrace) {
- XDECREF(*p_newtrace);
- if (res == None)
+ Py_XDECREF(*p_newtrace);
+ if (res == Py_None)
*p_newtrace = NULL;
else {
- INCREF(res);
+ Py_INCREF(res);
*p_newtrace = res;
}
}
- DECREF(res);
+ Py_DECREF(res);
return 0;
}
}
-object *
-getbuiltins()
+PyObject *
+PyEval_GetBuiltins()
{
if (current_frame == NULL)
- return getbuiltinmod();
+ return PyBuiltin_GetModule();
else
return current_frame->f_builtins;
}
-object *
-getlocals()
+PyObject *
+PyEval_GetLocals()
{
if (current_frame == NULL)
return NULL;
- fast_2_locals(current_frame);
+ PyFrame_FastToLocals(current_frame);
return current_frame->f_locals;
}
-object *
-getglobals()
+PyObject *
+PyEval_GetGlobals()
{
if (current_frame == NULL)
return NULL;
@@ -1982,326 +1981,326 @@ getglobals()
return current_frame->f_globals;
}
-object *
-getframe()
+PyObject *
+PyEval_GetFrame()
{
- return (object *)current_frame;
+ return (PyObject *)current_frame;
}
int
-getrestricted()
+PyEval_GetRestricted()
{
return current_frame == NULL ? 0 : current_frame->f_restricted;
}
void
-flushline()
+Py_FlushLine()
{
- object *f = sysget("stdout");
- if (softspace(f, 0))
- writestring("\n", f);
+ PyObject *f = PySys_GetObject("stdout");
+ if (PyFile_SoftSpace(f, 0))
+ PyFile_WriteString("\n", f);
}
#define BINOP(opname, ropname, thisfunc) \
- if (!is_instanceobject(v) && !is_instanceobject(w)) \
+ if (!PyInstance_Check(v) && !PyInstance_Check(w)) \
; \
else \
- return instancebinop(v, w, opname, ropname, thisfunc)
+ return PyInstance_DoBinOp(v, w, opname, ropname, thisfunc)
-static object *
+static PyObject *
or(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__or__", "__ror__", or);
if (v->ob_type->tp_as_number != NULL) {
- object *x = NULL;
- object * (*f) FPROTO((object *, object *));
- if (coerce(&v, &w) != 0)
+ PyObject *x = NULL;
+ PyObject * (*f) Py_FPROTO((PyObject *, PyObject *));
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
if ((f = v->ob_type->tp_as_number->nb_or) != NULL)
x = (*f)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (f != NULL)
return x;
}
- err_setstr(TypeError, "bad operand type(s) for |");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for |");
return NULL;
}
-static object *
+static PyObject *
xor(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__xor__", "__rxor__", xor);
if (v->ob_type->tp_as_number != NULL) {
- object *x = NULL;
- object * (*f) FPROTO((object *, object *));
- if (coerce(&v, &w) != 0)
+ PyObject *x = NULL;
+ PyObject * (*f) Py_FPROTO((PyObject *, PyObject *));
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
if ((f = v->ob_type->tp_as_number->nb_xor) != NULL)
x = (*f)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (f != NULL)
return x;
}
- err_setstr(TypeError, "bad operand type(s) for ^");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for ^");
return NULL;
}
-static object *
+static PyObject *
and(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__and__", "__rand__", and);
if (v->ob_type->tp_as_number != NULL) {
- object *x = NULL;
- object * (*f) FPROTO((object *, object *));
- if (coerce(&v, &w) != 0)
+ PyObject *x = NULL;
+ PyObject * (*f) Py_FPROTO((PyObject *, PyObject *));
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
if ((f = v->ob_type->tp_as_number->nb_and) != NULL)
x = (*f)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (f != NULL)
return x;
}
- err_setstr(TypeError, "bad operand type(s) for &");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for &");
return NULL;
}
-static object *
+static PyObject *
lshift(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__lshift__", "__rlshift__", lshift);
if (v->ob_type->tp_as_number != NULL) {
- object *x = NULL;
- object * (*f) FPROTO((object *, object *));
- if (coerce(&v, &w) != 0)
+ PyObject *x = NULL;
+ PyObject * (*f) Py_FPROTO((PyObject *, PyObject *));
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
if ((f = v->ob_type->tp_as_number->nb_lshift) != NULL)
x = (*f)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (f != NULL)
return x;
}
- err_setstr(TypeError, "bad operand type(s) for <<");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for <<");
return NULL;
}
-static object *
+static PyObject *
rshift(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__rshift__", "__rrshift__", rshift);
if (v->ob_type->tp_as_number != NULL) {
- object *x = NULL;
- object * (*f) FPROTO((object *, object *));
- if (coerce(&v, &w) != 0)
+ PyObject *x = NULL;
+ PyObject * (*f) Py_FPROTO((PyObject *, PyObject *));
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
if ((f = v->ob_type->tp_as_number->nb_rshift) != NULL)
x = (*f)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
if (f != NULL)
return x;
}
- err_setstr(TypeError, "bad operand type(s) for >>");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for >>");
return NULL;
}
-static object *
+static PyObject *
add(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__add__", "__radd__", add);
if (v->ob_type->tp_as_sequence != NULL)
return (*v->ob_type->tp_as_sequence->sq_concat)(v, w);
else if (v->ob_type->tp_as_number != NULL) {
- object *x;
- if (coerce(&v, &w) != 0)
+ PyObject *x;
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
x = (*v->ob_type->tp_as_number->nb_add)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
return x;
}
- err_setstr(TypeError, "bad operand type(s) for +");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for +");
return NULL;
}
-static object *
+static PyObject *
sub(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__sub__", "__rsub__", sub);
if (v->ob_type->tp_as_number != NULL) {
- object *x;
- if (coerce(&v, &w) != 0)
+ PyObject *x;
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
x = (*v->ob_type->tp_as_number->nb_subtract)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
return x;
}
- err_setstr(TypeError, "bad operand type(s) for -");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for -");
return NULL;
}
-static object *
+static PyObject *
mul(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
- typeobject *tp;
+ PyTypeObject *tp;
tp = v->ob_type;
BINOP("__mul__", "__rmul__", mul);
if (tp->tp_as_number != NULL &&
w->ob_type->tp_as_sequence != NULL &&
- !is_instanceobject(v)) {
+ !PyInstance_Check(v)) {
/* number*sequence -- swap v and w */
- object *tmp = v;
+ PyObject *tmp = v;
v = w;
w = tmp;
tp = v->ob_type;
}
if (tp->tp_as_number != NULL) {
- object *x;
- if (is_instanceobject(v)) {
+ PyObject *x;
+ if (PyInstance_Check(v)) {
/* Instances of user-defined classes get their
other argument uncoerced, so they may
implement sequence*number as well as
number*number. */
- INCREF(v);
- INCREF(w);
+ Py_INCREF(v);
+ Py_INCREF(w);
}
- else if (coerce(&v, &w) != 0)
+ else if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
x = (*v->ob_type->tp_as_number->nb_multiply)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
return x;
}
if (tp->tp_as_sequence != NULL) {
- if (!is_intobject(w)) {
- err_setstr(TypeError,
+ if (!PyInt_Check(w)) {
+ PyErr_SetString(PyExc_TypeError,
"can't multiply sequence with non-int");
return NULL;
}
return (*tp->tp_as_sequence->sq_repeat)
- (v, (int)getintvalue(w));
+ (v, (int)PyInt_AsLong(w));
}
- err_setstr(TypeError, "bad operand type(s) for *");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for *");
return NULL;
}
-static object *
+static PyObject *
divide(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
BINOP("__div__", "__rdiv__", divide);
if (v->ob_type->tp_as_number != NULL) {
- object *x;
- if (coerce(&v, &w) != 0)
+ PyObject *x;
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
x = (*v->ob_type->tp_as_number->nb_divide)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
return x;
}
- err_setstr(TypeError, "bad operand type(s) for /");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for /");
return NULL;
}
-static object *
+static PyObject *
mod(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
- if (is_stringobject(v)) {
- return formatstring(v, w);
+ if (PyString_Check(v)) {
+ return PyString_Format(v, w);
}
BINOP("__mod__", "__rmod__", mod);
if (v->ob_type->tp_as_number != NULL) {
- object *x;
- if (coerce(&v, &w) != 0)
+ PyObject *x;
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
x = (*v->ob_type->tp_as_number->nb_remainder)(v, w);
- DECREF(v);
- DECREF(w);
+ Py_DECREF(v);
+ Py_DECREF(w);
return x;
}
- err_setstr(TypeError, "bad operand type(s) for %");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for %");
return NULL;
}
-static object *
+static PyObject *
powerop(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
- object *res;
+ PyObject *res;
BINOP("__pow__", "__rpow__", powerop);
if (v->ob_type->tp_as_number == NULL ||
w->ob_type->tp_as_number == NULL) {
- err_setstr(TypeError, "pow() requires numeric arguments");
+ PyErr_SetString(PyExc_TypeError, "pow() requires numeric arguments");
return NULL;
}
- if (coerce(&v, &w) != 0)
+ if (PyNumber_Coerce(&v, &w) != 0)
return NULL;
- res = (*v->ob_type->tp_as_number->nb_power)(v, w, None);
- DECREF(v);
- DECREF(w);
+ res = (*v->ob_type->tp_as_number->nb_power)(v, w, Py_None);
+ Py_DECREF(v);
+ Py_DECREF(w);
return res;
}
-static object *
+static PyObject *
neg(v)
- object *v;
+ PyObject *v;
{
if (v->ob_type->tp_as_number != NULL)
return (*v->ob_type->tp_as_number->nb_negative)(v);
- err_setstr(TypeError, "bad operand type(s) for unary -");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary -");
return NULL;
}
-static object *
+static PyObject *
pos(v)
- object *v;
+ PyObject *v;
{
if (v->ob_type->tp_as_number != NULL)
return (*v->ob_type->tp_as_number->nb_positive)(v);
- err_setstr(TypeError, "bad operand type(s) for unary +");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary +");
return NULL;
}
-static object *
+static PyObject *
invert(v)
- object *v;
+ PyObject *v;
{
- object * (*f) FPROTO((object *));
+ PyObject * (*f) Py_FPROTO((PyObject *));
if (v->ob_type->tp_as_number != NULL &&
(f = v->ob_type->tp_as_number->nb_invert) != NULL)
return (*f)(v);
- err_setstr(TypeError, "bad operand type(s) for unary ~");
+ PyErr_SetString(PyExc_TypeError, "bad operand type(s) for unary ~");
return NULL;
}
-static object *
+static PyObject *
not(v)
- object *v;
+ PyObject *v;
{
- int outcome = testbool(v);
- object *w;
+ int outcome = PyObject_IsTrue(v);
+ PyObject *w;
if (outcome < 0)
return NULL;
if (outcome == 0)
- w = True;
+ w = Py_True;
else
- w = False;
- INCREF(w);
+ w = Py_False;
+ Py_INCREF(w);
return w;
}
@@ -2309,168 +2308,168 @@ not(v)
/* External interface to call any callable object.
The arg must be a tuple or NULL. */
-object *
-call_object(func, arg)
- object *func;
- object *arg;
+PyObject *
+PyEval_CallObject(func, arg)
+ PyObject *func;
+ PyObject *arg;
{
- return PyEval_CallObjectWithKeywords(func, arg, (object *)NULL);
+ return PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL);
}
-object *
+PyObject *
PyEval_CallObjectWithKeywords(func, arg, kw)
- object *func;
- object *arg;
- object *kw;
+ PyObject *func;
+ PyObject *arg;
+ PyObject *kw;
{
ternaryfunc call;
- object *result;
+ PyObject *result;
if (arg == NULL)
- arg = newtupleobject(0);
- else if (!is_tupleobject(arg)) {
- err_setstr(TypeError, "argument list must be a tuple");
+ arg = PyTuple_New(0);
+ else if (!PyTuple_Check(arg)) {
+ PyErr_SetString(PyExc_TypeError, "argument list must be a tuple");
return NULL;
}
else
- INCREF(arg);
+ Py_INCREF(arg);
- if (kw != NULL && !is_dictobject(kw)) {
- err_setstr(TypeError, "keyword list must be a dictionary");
+ if (kw != NULL && !PyDict_Check(kw)) {
+ PyErr_SetString(PyExc_TypeError, "keyword list must be a dictionary");
return NULL;
}
if ((call = func->ob_type->tp_call) != NULL)
result = (*call)(func, arg, kw);
- else if (is_instancemethodobject(func) || is_funcobject(func))
+ else if (PyMethod_Check(func) || PyFunction_Check(func))
result = call_function(func, arg, kw);
else
result = call_builtin(func, arg, kw);
- DECREF(arg);
+ Py_DECREF(arg);
- if (result == NULL && !err_occurred())
- err_setstr(SystemError,
+ if (result == NULL && !PyErr_Occurred())
+ PyErr_SetString(PyExc_SystemError,
"NULL result without error in call_object");
return result;
}
-static object *
+static PyObject *
call_builtin(func, arg, kw)
- object *func;
- object *arg;
- object *kw;
+ PyObject *func;
+ PyObject *arg;
+ PyObject *kw;
{
- if (is_methodobject(func)) {
- method meth = getmethod(func);
- object *self = getself(func);
- int flags = getflags(func);
+ if (PyCFunction_Check(func)) {
+ PyCFunction meth = PyCFunction_GetFunction(func);
+ PyObject *self = PyCFunction_GetSelf(func);
+ int flags = PyCFunction_GetFlags(func);
if (!(flags & METH_VARARGS)) {
- int size = gettuplesize(arg);
+ int size = PyTuple_Size(arg);
if (size == 1)
- arg = GETTUPLEITEM(arg, 0);
+ arg = PyTuple_GET_ITEM(arg, 0);
else if (size == 0)
arg = NULL;
}
if (flags & METH_KEYWORDS)
return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
- if (kw != NULL && getmappingsize(kw) != 0) {
- err_setstr(TypeError,
+ if (kw != NULL && PyDict_Size(kw) != 0) {
+ PyErr_SetString(PyExc_TypeError,
"this function takes no keyword arguments");
return NULL;
}
return (*meth)(self, arg);
}
- if (is_classobject(func)) {
- return newinstanceobject(func, arg, kw);
+ if (PyClass_Check(func)) {
+ return PyInstance_New(func, arg, kw);
}
- if (is_instanceobject(func)) {
- object *res, *call = getattr(func,"__call__");
+ if (PyInstance_Check(func)) {
+ PyObject *res, *call = PyObject_GetAttrString(func,"__call__");
if (call == NULL) {
- err_clear();
- err_setstr(AttributeError,
+ PyErr_Clear();
+ PyErr_SetString(PyExc_AttributeError,
"no __call__ method defined");
return NULL;
}
res = PyEval_CallObjectWithKeywords(call, arg, kw);
- DECREF(call);
+ Py_DECREF(call);
return res;
}
- err_setstr(TypeError, "call of non-function");
+ PyErr_SetString(PyExc_TypeError, "call of non-function");
return NULL;
}
-static object *
+static PyObject *
call_function(func, arg, kw)
- object *func;
- object *arg;
- object *kw;
+ PyObject *func;
+ PyObject *arg;
+ PyObject *kw;
{
- object *class = NULL; /* == owner */
- object *argdefs;
- object **d, **k;
+ PyObject *class = NULL; /* == owner */
+ PyObject *argdefs;
+ PyObject **d, **k;
int nk, nd;
- object *result;
+ PyObject *result;
- if (kw != NULL && !is_dictobject(kw)) {
- err_badcall();
+ if (kw != NULL && !PyDict_Check(kw)) {
+ PyErr_BadInternalCall();
return NULL;
}
- if (is_instancemethodobject(func)) {
- object *self = instancemethodgetself(func);
- class = instancemethodgetclass(func);
- func = instancemethodgetfunc(func);
+ if (PyMethod_Check(func)) {
+ PyObject *self = PyMethod_Self(func);
+ class = PyMethod_Class(func);
+ func = PyMethod_Function(func);
if (self == NULL) {
/* Unbound methods must be called with an instance of
the class (or a derived class) as first argument */
- if (gettuplesize(arg) >= 1) {
- self = GETTUPLEITEM(arg, 0);
+ if (PyTuple_Size(arg) >= 1) {
+ self = PyTuple_GET_ITEM(arg, 0);
if (self != NULL &&
- is_instanceobject(self) &&
- issubclass((object *)
- (((instanceobject *)self)->in_class),
+ PyInstance_Check(self) &&
+ PyClass_IsSubclass((PyObject *)
+ (((PyInstanceObject *)self)->in_class),
class))
/* Handy-dandy */ ;
else
self = NULL;
}
if (self == NULL) {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"unbound method must be called with class instance 1st argument");
return NULL;
}
- INCREF(arg);
+ Py_INCREF(arg);
}
else {
- int argcount = gettuplesize(arg);
- object *newarg = newtupleobject(argcount + 1);
+ int argcount = PyTuple_Size(arg);
+ PyObject *newarg = PyTuple_New(argcount + 1);
int i;
if (newarg == NULL)
return NULL;
- INCREF(self);
- SETTUPLEITEM(newarg, 0, self);
+ Py_INCREF(self);
+ PyTuple_SET_ITEM(newarg, 0, self);
for (i = 0; i < argcount; i++) {
- object *v = GETTUPLEITEM(arg, i);
- XINCREF(v);
- SETTUPLEITEM(newarg, i+1, v);
+ PyObject *v = PyTuple_GET_ITEM(arg, i);
+ Py_XINCREF(v);
+ PyTuple_SET_ITEM(newarg, i+1, v);
}
arg = newarg;
}
}
else {
- if (!is_funcobject(func)) {
- err_setstr(TypeError, "call of non-function");
+ if (!PyFunction_Check(func)) {
+ PyErr_SetString(PyExc_TypeError, "call of non-function");
return NULL;
}
- INCREF(arg);
+ Py_INCREF(arg);
}
argdefs = PyFunction_GetDefaults(func);
- if (argdefs != NULL && is_tupleobject(argdefs)) {
- d = &GETTUPLEITEM((tupleobject *)argdefs, 0);
- nd = gettuplesize(argdefs);
+ if (argdefs != NULL && PyTuple_Check(argdefs)) {
+ d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
+ nd = PyTuple_Size(argdefs);
}
else {
d = NULL;
@@ -2479,15 +2478,15 @@ call_function(func, arg, kw)
if (kw != NULL) {
int pos, i;
- nk = getmappingsize(kw);
- k = NEW(object *, 2*nk);
+ nk = PyDict_Size(kw);
+ k = PyMem_NEW(PyObject *, 2*nk);
if (k == NULL) {
- err_nomem();
- DECREF(arg);
+ PyErr_NoMemory();
+ Py_DECREF(arg);
return NULL;
}
pos = i = 0;
- while (mappinggetnext(kw, &pos, &k[i], &k[i+1]))
+ while (PyDict_Next(kw, &pos, &k[i], &k[i+1]))
i += 2;
nk = i/2;
/* XXX This is broken if the caller deletes dict items! */
@@ -2498,15 +2497,15 @@ call_function(func, arg, kw)
}
result = eval_code2(
- (codeobject *)getfunccode(func),
- getfuncglobals(func), (object *)NULL,
- &GETTUPLEITEM(arg, 0), gettuplesize(arg),
+ (PyCodeObject *)PyFunction_GetCode(func),
+ PyFunction_GetGlobals(func), (PyObject *)NULL,
+ &PyTuple_GET_ITEM(arg, 0), PyTuple_Size(arg),
k, nk,
d, nd,
class);
- DECREF(arg);
- XDEL(k);
+ Py_DECREF(arg);
+ PyMem_XDEL(k);
return result;
}
@@ -2514,13 +2513,13 @@ call_function(func, arg, kw)
#define SLICE_ERROR_MSG \
"standard sequence type does not support step size other than one"
-static object *
+static PyObject *
apply_subscript(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
- typeobject *tp = v->ob_type;
+ PyTypeObject *tp = v->ob_type;
if (tp->tp_as_sequence == NULL && tp->tp_as_mapping == NULL) {
- err_setstr(TypeError, "unsubscriptable object");
+ PyErr_SetString(PyExc_TypeError, "unsubscriptable object");
return NULL;
}
if (tp->tp_as_mapping != NULL) {
@@ -2528,16 +2527,16 @@ apply_subscript(v, w)
}
else {
int i;
- if (!is_intobject(w)) {
+ if (!PyInt_Check(w)) {
if (PySlice_Check(w)) {
- err_setstr(ValueError, SLICE_ERROR_MSG);
+ PyErr_SetString(PyExc_ValueError, SLICE_ERROR_MSG);
} else {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"sequence subscript not int");
}
return NULL;
}
- i = getintvalue(w);
+ i = PyInt_AsLong(w);
if (i < 0) {
int len = (*tp->tp_as_sequence->sq_length)(v);
if (len < 0)
@@ -2548,51 +2547,51 @@ apply_subscript(v, w)
}
}
-static object *
+static PyObject *
loop_subscript(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
- sequence_methods *sq = v->ob_type->tp_as_sequence;
+ PySequenceMethods *sq = v->ob_type->tp_as_sequence;
int i;
if (sq == NULL) {
- err_setstr(TypeError, "loop over non-sequence");
+ PyErr_SetString(PyExc_TypeError, "loop over non-sequence");
return NULL;
}
- i = getintvalue(w);
+ i = PyInt_AsLong(w);
v = (*sq->sq_item)(v, i);
if (v)
return v;
- if (err_occurred() == IndexError)
- err_clear();
+ if (PyErr_Occurred() == PyExc_IndexError)
+ PyErr_Clear();
return NULL;
}
static int
slice_index(v, isize, pi)
- object *v;
+ PyObject *v;
int isize;
int *pi;
{
if (v != NULL) {
- if (!is_intobject(v)) {
- err_setstr(TypeError, "slice index must be int");
+ if (!PyInt_Check(v)) {
+ PyErr_SetString(PyExc_TypeError, "slice index must be int");
return -1;
}
- *pi = getintvalue(v);
+ *pi = PyInt_AsLong(v);
if (*pi < 0)
*pi += isize;
}
return 0;
}
-static object *
+static PyObject *
apply_slice(u, v, w) /* return u[v:w] */
- object *u, *v, *w;
+ PyObject *u, *v, *w;
{
- typeobject *tp = u->ob_type;
+ PyTypeObject *tp = u->ob_type;
int ilow, ihigh, isize;
if (tp->tp_as_sequence == NULL) {
- err_setstr(TypeError, "only sequences can be sliced");
+ PyErr_SetString(PyExc_TypeError, "only sequences can be sliced");
return NULL;
}
ilow = 0;
@@ -2608,13 +2607,13 @@ apply_slice(u, v, w) /* return u[v:w] */
static int
assign_subscript(w, key, v) /* w[key] = v */
- object *w;
- object *key;
- object *v;
+ PyObject *w;
+ PyObject *key;
+ PyObject *v;
{
- typeobject *tp = w->ob_type;
- sequence_methods *sq;
- mapping_methods *mp;
+ PyTypeObject *tp = w->ob_type;
+ PySequenceMethods *sq;
+ PyMappingMethods *mp;
int (*func1)();
int (*func2)();
if ((mp = tp->tp_as_mapping) != NULL &&
@@ -2623,13 +2622,13 @@ assign_subscript(w, key, v) /* w[key] = v */
}
else if ((sq = tp->tp_as_sequence) != NULL &&
(func2 = sq->sq_ass_item) != NULL) {
- if (!is_intobject(key)) {
- err_setstr(TypeError,
+ if (!PyInt_Check(key)) {
+ PyErr_SetString(PyExc_TypeError,
"sequence subscript must be integer (assign or del)");
return -1;
}
else {
- int i = getintvalue(key);
+ int i = PyInt_AsLong(key);
if (i < 0) {
int len = (*sq->sq_length)(w);
if (len < 0)
@@ -2640,7 +2639,7 @@ assign_subscript(w, key, v) /* w[key] = v */
}
}
else {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"can't assign to this subscripted object");
return -1;
}
@@ -2648,16 +2647,16 @@ assign_subscript(w, key, v) /* w[key] = v */
static int
assign_slice(u, v, w, x) /* u[v:w] = x */
- object *u, *v, *w, *x;
+ PyObject *u, *v, *w, *x;
{
- sequence_methods *sq = u->ob_type->tp_as_sequence;
+ PySequenceMethods *sq = u->ob_type->tp_as_sequence;
int ilow, ihigh, isize;
if (sq == NULL) {
- err_setstr(TypeError, "assign to slice of non-sequence");
+ PyErr_SetString(PyExc_TypeError, "assign to slice of non-sequence");
return -1;
}
if (sq == NULL || sq->sq_ass_slice == NULL) {
- err_setstr(TypeError, "unassignable slice");
+ PyErr_SetString(PyExc_TypeError, "unassignable slice");
return -1;
}
ilow = 0;
@@ -2673,42 +2672,42 @@ assign_slice(u, v, w, x) /* u[v:w] = x */
static int
cmp_exception(err, v)
- object *err, *v;
+ PyObject *err, *v;
{
- if (is_tupleobject(v)) {
+ if (PyTuple_Check(v)) {
int i, n;
- n = gettuplesize(v);
+ n = PyTuple_Size(v);
for (i = 0; i < n; i++) {
/* Test recursively */
- if (cmp_exception(err, GETTUPLEITEM(v, i)))
+ if (cmp_exception(err, PyTuple_GET_ITEM(v, i)))
return 1;
}
return 0;
}
- if (is_classobject(v) && is_classobject(err))
- return issubclass(err, v);
+ if (PyClass_Check(v) && PyClass_Check(err))
+ return PyClass_IsSubclass(err, v);
return err == v;
}
static int
cmp_member(v, w)
- object *v, *w;
+ PyObject *v, *w;
{
int i, cmp;
- object *x;
- sequence_methods *sq;
+ PyObject *x;
+ PySequenceMethods *sq;
/* Special case for char in string */
- if (is_stringobject(w)) {
+ if (PyString_Check(w)) {
register char *s, *end;
register char c;
- if (!is_stringobject(v) || getstringsize(v) != 1) {
- err_setstr(TypeError,
+ if (!PyString_Check(v) || PyString_Size(v) != 1) {
+ PyErr_SetString(PyExc_TypeError,
"string member test needs char left operand");
return -1;
}
- c = getstringvalue(v)[0];
- s = getstringvalue(w);
- end = s + getstringsize(w);
+ c = PyString_AsString(v)[0];
+ s = PyString_AsString(w);
+ end = s + PyString_Size(w);
while (s < end) {
if (c == *s++)
return 1;
@@ -2717,32 +2716,32 @@ cmp_member(v, w)
}
sq = w->ob_type->tp_as_sequence;
if (sq == NULL) {
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"'in' or 'not in' needs sequence right argument");
return -1;
}
for (i = 0; ; i++) {
x = (*sq->sq_item)(w, i);
if (x == NULL) {
- if (err_occurred() == IndexError) {
- err_clear();
+ if (PyErr_Occurred() == PyExc_IndexError) {
+ PyErr_Clear();
break;
}
return -1;
}
- cmp = cmpobject(v, x);
- XDECREF(x);
+ cmp = PyObject_Compare(v, x);
+ Py_XDECREF(x);
if (cmp == 0)
return 1;
}
return 0;
}
-static object *
+static PyObject *
cmp_outcome(op, v, w)
int op;
- register object *v;
- register object *w;
+ register PyObject *v;
+ register PyObject *w;
{
register int cmp;
register int res = 0;
@@ -2765,7 +2764,7 @@ cmp_outcome(op, v, w)
res = cmp_exception(v, w);
break;
default:
- cmp = cmpobject(v, w);
+ cmp = PyObject_Compare(v, w);
switch (op) {
case LT: res = cmp < 0; break;
case LE: res = cmp <= 0; break;
@@ -2776,184 +2775,184 @@ cmp_outcome(op, v, w)
/* XXX no default? (res is initialized to 0 though) */
}
}
- v = res ? True : False;
- INCREF(v);
+ v = res ? Py_True : Py_False;
+ Py_INCREF(v);
return v;
}
static int
import_from(locals, v, name)
- object *locals;
- object *v;
- object *name;
+ PyObject *locals;
+ PyObject *v;
+ PyObject *name;
{
- object *w, *x;
- if (!is_moduleobject(v)) {
- err_setstr(TypeError, "import-from requires module object");
+ PyObject *w, *x;
+ if (!PyModule_Check(v)) {
+ PyErr_SetString(PyExc_TypeError, "import-from requires module object");
return -1;
}
- w = getmoduledict(v);
- if (getstringvalue(name)[0] == '*') {
+ w = PyModule_GetDict(v);
+ if (PyString_AsString(name)[0] == '*') {
int pos, err;
- object *name, *value;
+ PyObject *name, *value;
pos = 0;
- while (mappinggetnext(w, &pos, &name, &value)) {
- if (!is_stringobject(name) ||
- getstringvalue(name)[0] == '_')
+ while (PyDict_Next(w, &pos, &name, &value)) {
+ if (!PyString_Check(name) ||
+ PyString_AsString(name)[0] == '_')
continue;
- INCREF(value);
- err = dict2insert(locals, name, value);
- DECREF(value);
+ Py_INCREF(value);
+ err = PyDict_SetItem(locals, name, value);
+ Py_DECREF(value);
if (err != 0)
return -1;
}
return 0;
}
else {
- x = dict2lookup(w, name);
+ x = PyDict_GetItem(w, name);
if (x == NULL) {
char buf[250];
sprintf(buf, "cannot import name %.230s",
- getstringvalue(name));
- err_setstr(ImportError, buf);
+ PyString_AsString(name));
+ PyErr_SetString(PyExc_ImportError, buf);
return -1;
}
else
- return dict2insert(locals, name, x);
+ return PyDict_SetItem(locals, name, x);
}
}
-static object *
+static PyObject *
build_class(methods, bases, name)
- object *methods; /* dictionary */
- object *bases; /* tuple containing classes */
- object *name; /* string */
+ PyObject *methods; /* dictionary */
+ PyObject *bases; /* tuple containing classes */
+ PyObject *name; /* string */
{
int i;
- if (!is_tupleobject(bases)) {
- err_setstr(SystemError, "build_class with non-tuple bases");
+ if (!PyTuple_Check(bases)) {
+ PyErr_SetString(PyExc_SystemError, "build_class with non-tuple bases");
return NULL;
}
- if (!is_dictobject(methods)) {
- err_setstr(SystemError, "build_class with non-dictionary");
+ if (!PyDict_Check(methods)) {
+ PyErr_SetString(PyExc_SystemError, "build_class with non-dictionary");
return NULL;
}
- if (!is_stringobject(name)) {
- err_setstr(SystemError, "build_class witn non-string name");
+ if (!PyString_Check(name)) {
+ PyErr_SetString(PyExc_SystemError, "build_class witn non-string name");
return NULL;
}
- for (i = gettuplesize(bases); --i >= 0; ) {
- object *base = GETTUPLEITEM(bases, i);
- if (!is_classobject(base)) {
+ for (i = PyTuple_Size(bases); --i >= 0; ) {
+ PyObject *base = PyTuple_GET_ITEM(bases, i);
+ if (!PyClass_Check(base)) {
/* Call the base's *type*, if it is callable.
This code is a hook for Donald Beaudry's
and Jim Fulton's type extensions. In
unexended Python it will never be triggered
since its types are not callable. */
if (base->ob_type->ob_type->tp_call) {
- object *args;
- object *class;
- args = mkvalue("(OOO)", name, bases, methods);
- class = call_object((object *)base->ob_type,
+ PyObject *args;
+ PyObject *class;
+ args = Py_BuildValue("(OOO)", name, bases, methods);
+ class = PyEval_CallObject((PyObject *)base->ob_type,
args);
- DECREF(args);
+ Py_DECREF(args);
return class;
}
- err_setstr(TypeError,
+ PyErr_SetString(PyExc_TypeError,
"base is not a class object");
return NULL;
}
}
- return newclassobject(bases, methods, name);
+ return PyClass_New(bases, methods, name);
}
static int
exec_statement(prog, globals, locals)
- object *prog;
- object *globals;
- object *locals;
+ PyObject *prog;
+ PyObject *globals;
+ PyObject *locals;
{
char *s;
int n;
- object *v;
+ PyObject *v;
int plain = 0;
- if (is_tupleobject(prog) && globals == None && locals == None &&
- ((n = gettuplesize(prog)) == 2 || n == 3)) {
+ if (PyTuple_Check(prog) && globals == Py_None && locals == Py_None &&
+ ((n = PyTuple_Size(prog)) == 2 || n == 3)) {
/* Backward compatibility hack */
- globals = gettupleitem(prog, 1);
+ globals = PyTuple_GetItem(prog, 1);
if (n == 3)
- locals = gettupleitem(prog, 2);
- prog = gettupleitem(prog, 0);
+ locals = PyTuple_GetItem(prog, 2);
+ prog = PyTuple_GetItem(prog, 0);
}
- if (globals == None) {
- globals = getglobals();
- if (locals == None) {
- locals = getlocals();
+ if (globals == Py_None) {
+ globals = PyEval_GetGlobals();
+ if (locals == Py_None) {
+ locals = PyEval_GetLocals();
plain = 1;
}
}
- else if (locals == None)
+ else if (locals == Py_None)
locals = globals;
- if (!is_stringobject(prog) &&
- !is_codeobject(prog) &&
- !is_fileobject(prog)) {
- err_setstr(TypeError,
+ if (!PyString_Check(prog) &&
+ !PyCode_Check(prog) &&
+ !PyFile_Check(prog)) {
+ PyErr_SetString(PyExc_TypeError,
"exec 1st arg must be string, code or file object");
return -1;
}
- if (!is_dictobject(globals) || !is_dictobject(locals)) {
- err_setstr(TypeError,
+ if (!PyDict_Check(globals) || !PyDict_Check(locals)) {
+ PyErr_SetString(PyExc_TypeError,
"exec 2nd/3rd args must be dict or None");
return -1;
}
- if (dictlookup(globals, "__builtins__") == NULL)
- dictinsert(globals, "__builtins__", current_frame->f_builtins);
- if (is_codeobject(prog)) {
- if (eval_code((codeobject *) prog, globals, locals) == NULL)
+ if (PyDict_GetItemString(globals, "__builtins__") == NULL)
+ PyDict_SetItemString(globals, "__builtins__", current_frame->f_builtins);
+ if (PyCode_Check(prog)) {
+ if (PyEval_EvalCode((PyCodeObject *) prog, globals, locals) == NULL)
return -1;
return 0;
}
- if (is_fileobject(prog)) {
- FILE *fp = getfilefile(prog);
- char *name = getstringvalue(getfilename(prog));
- if (run_file(fp, name, file_input, globals, locals) == NULL)
+ if (PyFile_Check(prog)) {
+ FILE *fp = PyFile_AsFile(prog);
+ char *name = PyString_AsString(PyFile_Name(prog));
+ if (PyRun_File(fp, name, file_input, globals, locals) == NULL)
return -1;
return 0;
}
- s = getstringvalue(prog);
- if (strlen(s) != getstringsize(prog)) {
- err_setstr(ValueError, "embedded '\\0' in exec string");
+ s = PyString_AsString(prog);
+ if (strlen(s) != PyString_Size(prog)) {
+ PyErr_SetString(PyExc_ValueError, "embedded '\\0' in exec string");
return -1;
}
- v = run_string(s, file_input, globals, locals);
+ v = PyRun_String(s, file_input, globals, locals);
if (v == NULL)
return -1;
- DECREF(v);
+ Py_DECREF(v);
if (plain)
- locals_2_fast(current_frame, 0);
+ PyFrame_LocalsToFast(current_frame, 0);
return 0;
}
/* Hack for ni.py */
-static object *
+static PyObject *
find_from_args(f, nexti)
- frameobject *f;
+ PyFrameObject *f;
int nexti;
{
int opcode;
int oparg;
- object *list, *name;
+ PyObject *list, *name;
unsigned char *next_instr;
next_instr = GETUSTRINGVALUE(f->f_code->co_code) + nexti;
opcode = (*next_instr++);
if (opcode != IMPORT_FROM) {
- INCREF(None);
- return None;
+ Py_INCREF(Py_None);
+ return Py_None;
}
- list = newlistobject(0);
+ list = PyList_New(0);
if (list == NULL)
return NULL;
@@ -2961,8 +2960,8 @@ find_from_args(f, nexti)
oparg = (next_instr[1]<<8) + next_instr[0];
next_instr += 2;
name = Getnamev(f, oparg);
- if (addlistitem(list, name) < 0) {
- DECREF(list);
+ if (PyList_Append(list, name) < 0) {
+ Py_DECREF(list);
break;
}
opcode = (*next_instr++);