Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 150b2df

Browse files
committed
Change the Don Beaudry hack into the Don B + Jim F hack; now, if *any*
base class is special it gets invoked. Make gcc -Wall happy.
1 parent 3afb595 commit 150b2df

1 file changed

Lines changed: 26 additions & 28 deletions

File tree

Python/ceval.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ eval_code2(co, globals, locals,
319319
object *owner;
320320
{
321321
register unsigned char *next_instr;
322-
register int opcode; /* Current opcode */
323-
register int oparg; /* Current opcode argument, if any */
322+
register int opcode = 0; /* Current opcode */
323+
register int oparg = 0; /* Current opcode argument, if any */
324324
register object **stack_pointer;
325325
register enum why_code why; /* Reason for block stack unwind */
326326
register int err; /* Error status -- nonzero if error */
@@ -330,8 +330,8 @@ eval_code2(co, globals, locals,
330330
register object *u;
331331
register object *t;
332332
register frameobject *f; /* Current frame */
333-
register object **fastlocals;
334-
object *retval; /* Return value */
333+
register object **fastlocals = NULL;
334+
object *retval = NULL; /* Return value */
335335
#ifdef SUPPORT_OBSOLETE_ACCESS
336336
int defmode = 0; /* Default access mode for new variables */
337337
#endif
@@ -1793,8 +1793,8 @@ eval_code2(co, globals, locals,
17931793
break;
17941794
}
17951795
if (b->b_type == SETUP_FINALLY ||
1796-
b->b_type == SETUP_EXCEPT &&
1797-
why == WHY_EXCEPTION) {
1796+
(b->b_type == SETUP_EXCEPT &&
1797+
why == WHY_EXCEPTION)) {
17981798
if (why == WHY_EXCEPTION) {
17991799
object *exc, *val, *tb;
18001800
err_fetch(&exc, &val, &tb);
@@ -2055,7 +2055,7 @@ or(v, w)
20552055
{
20562056
BINOP("__or__", "__ror__", or);
20572057
if (v->ob_type->tp_as_number != NULL) {
2058-
object *x;
2058+
object *x = NULL;
20592059
object * (*f) FPROTO((object *, object *));
20602060
if (coerce(&v, &w) != 0)
20612061
return NULL;
@@ -2076,7 +2076,7 @@ xor(v, w)
20762076
{
20772077
BINOP("__xor__", "__rxor__", xor);
20782078
if (v->ob_type->tp_as_number != NULL) {
2079-
object *x;
2079+
object *x = NULL;
20802080
object * (*f) FPROTO((object *, object *));
20812081
if (coerce(&v, &w) != 0)
20822082
return NULL;
@@ -2097,7 +2097,7 @@ and(v, w)
20972097
{
20982098
BINOP("__and__", "__rand__", and);
20992099
if (v->ob_type->tp_as_number != NULL) {
2100-
object *x;
2100+
object *x = NULL;
21012101
object * (*f) FPROTO((object *, object *));
21022102
if (coerce(&v, &w) != 0)
21032103
return NULL;
@@ -2118,7 +2118,7 @@ lshift(v, w)
21182118
{
21192119
BINOP("__lshift__", "__rlshift__", lshift);
21202120
if (v->ob_type->tp_as_number != NULL) {
2121-
object *x;
2121+
object *x = NULL;
21222122
object * (*f) FPROTO((object *, object *));
21232123
if (coerce(&v, &w) != 0)
21242124
return NULL;
@@ -2139,7 +2139,7 @@ rshift(v, w)
21392139
{
21402140
BINOP("__rshift__", "__rrshift__", rshift);
21412141
if (v->ob_type->tp_as_number != NULL) {
2142-
object *x;
2142+
object *x = NULL;
21432143
object * (*f) FPROTO((object *, object *));
21442144
if (coerce(&v, &w) != 0)
21452145
return NULL;
@@ -2379,7 +2379,7 @@ PyEval_CallObjectWithKeywords(func, arg, kw)
23792379
return NULL;
23802380
}
23812381

2382-
if (call = func->ob_type->tp_call)
2382+
if ((call = func->ob_type->tp_call) != NULL)
23832383
result = (*call)(func, arg, kw);
23842384
else if (is_instancemethodobject(func) || is_funcobject(func))
23852385
result = call_function(func, arg, kw);
@@ -2890,22 +2890,6 @@ build_class(methods, bases, name)
28902890
err_setstr(SystemError, "build_class with non-tuple bases");
28912891
return NULL;
28922892
}
2893-
if (gettuplesize(bases) > 0) {
2894-
object *base;
2895-
base = GETTUPLEITEM(bases, 0);
2896-
/* Call the base's *type*, if it is callable.
2897-
This code is a hook for Donald Beaudry's type extensions.
2898-
In unexended Python it will never be triggered since its
2899-
types are not callable. */
2900-
if (base->ob_type->ob_type->tp_call) {
2901-
object *args;
2902-
object *class;
2903-
args = mkvalue("(OOO)", name, bases, methods);
2904-
class = call_object((object *)base->ob_type, args);
2905-
DECREF(args);
2906-
return class;
2907-
}
2908-
}
29092893
if (!is_dictobject(methods)) {
29102894
err_setstr(SystemError, "build_class with non-dictionary");
29112895
return NULL;
@@ -2917,6 +2901,20 @@ build_class(methods, bases, name)
29172901
for (i = gettuplesize(bases); --i >= 0; ) {
29182902
object *base = GETTUPLEITEM(bases, i);
29192903
if (!is_classobject(base)) {
2904+
/* Call the base's *type*, if it is callable.
2905+
This code is a hook for Donald Beaudry's
2906+
and Jim Fulton's type extensions. In
2907+
unexended Python it will never be triggered
2908+
since its types are not callable. */
2909+
if (base->ob_type->ob_type->tp_call) {
2910+
object *args;
2911+
object *class;
2912+
args = mkvalue("(OOO)", name, bases, methods);
2913+
class = call_object((object *)base->ob_type,
2914+
args);
2915+
DECREF(args);
2916+
return class;
2917+
}
29202918
err_setstr(TypeError,
29212919
"base is not a class object");
29222920
return NULL;

0 commit comments

Comments
 (0)