diff options
author | Guido van Rossum <guido@python.org> | 1995-01-10 15:26:20 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-10 15:26:20 (GMT) |
commit | 5524a59b0930638413ab44b150a3e66818a34cf9 (patch) | |
tree | c33deeb26fb8eed084b3906faebf83ebe1a0bd7e /Python/bltinmodule.c | |
parent | 879c581826ec9c0356dbf137cface7a27f51810c (diff) | |
download | cpython-5524a59b0930638413ab44b150a3e66818a34cf9.zip cpython-5524a59b0930638413ab44b150a3e66818a34cf9.tar.gz cpython-5524a59b0930638413ab44b150a3e66818a34cf9.tar.bz2 |
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 57 |
1 files changed, 7 insertions, 50 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 53720ad..f47b408 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -256,31 +256,21 @@ builtin_cmp(self, args) } static object * -do_coerce(v, w) - object *v, *w; -{ - object *res; - if (is_instanceobject(v) || is_instanceobject(w)) - return instancebinop(v, w, "__coerce__", "__rcoerce__", - do_coerce); - if (coerce(&v, &w) < 0) - return NULL; - res = mkvalue("(OO)", v, w); - DECREF(v); - DECREF(w); - return res; -} - -static object * builtin_coerce(self, args) object *self; object *args; { object *v, *w; + object *res; if (!newgetargs(args, "OO:coerce", &v, &w)) return NULL; - return do_coerce(v, w); + if (coerce(&v, &w) < 0) + return NULL; + res = mkvalue("(OO)", v, w); + DECREF(v); + DECREF(w); + return res; } static object * @@ -1464,39 +1454,6 @@ initbuiltin() (void) dictinsert(builtin_dict, "None", None); } -/* Coerce two numeric types to the "larger" one. - Increment the reference count on each argument. - Return -1 and raise an exception if no coercion is possible - (and then no reference count is incremented). -*/ - -int -coerce(pv, pw) - object **pv, **pw; -{ - register object *v = *pv; - register object *w = *pw; - int res; - - if (v->ob_type == w->ob_type && !is_instanceobject(v)) { - INCREF(v); - INCREF(w); - return 0; - } - if (v->ob_type->tp_as_number && v->ob_type->tp_as_number->nb_coerce) { - res = (*v->ob_type->tp_as_number->nb_coerce)(pv, pw); - if (res <= 0) - return res; - } - if (w->ob_type->tp_as_number && w->ob_type->tp_as_number->nb_coerce) { - res = (*w->ob_type->tp_as_number->nb_coerce)(pw, pv); - if (res <= 0) - return res; - } - err_setstr(TypeError, "number coercion failed"); - return -1; -} - /* Helper for filter(): filter a tuple through a function */ |