summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-12-05 23:18:18 (GMT)
committerGuido van Rossum <guido@python.org>1996-12-05 23:18:18 (GMT)
commited0af8fe702505001c67ec5e233fb84944529f7e (patch)
treea609802456ec83f646077e604042e1b373552376 /Python/bltinmodule.c
parent150b2df6824e98ac8b073db8a82384d1a56a7849 (diff)
downloadcpython-ed0af8fe702505001c67ec5e233fb84944529f7e.zip
cpython-ed0af8fe702505001c67ec5e233fb84944529f7e.tar.gz
cpython-ed0af8fe702505001c67ec5e233fb84944529f7e.tar.bz2
Support __complex__ method on instances, for complex() conversion.
Keep gcc -Wall happy.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 142a4f7..6a81c91 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -308,6 +308,28 @@ builtin_complex(self, args)
"complex() argument can't be converted to complex");
return NULL;
}
+ /* XXX Hack to support classes with __complex__ method */
+ if (is_instanceobject(r)) {
+ static object *complexstr;
+ object *f;
+ if (complexstr == NULL) {
+ complexstr = newstringobject("__complex__");
+ if (complexstr == NULL)
+ return NULL;
+ }
+ f = getattro(r, complexstr);
+ if (f == NULL)
+ err_clear();
+ else {
+ object *args = mkvalue("()");
+ if (args == NULL)
+ return NULL;
+ r = call_object(f, args);
+ DECREF(args);
+ if (r == NULL)
+ return NULL;
+ }
+ }
if (is_complexobject(r))
cr = ((complexobject*)r)->cval;
else {
@@ -632,7 +654,7 @@ builtin_map(self, args)
/* XXX Special case map(None, single_list) could be more efficient */
for (i = 0; ; ++i) {
- object *alist, *item, *value;
+ object *alist, *item=NULL, *value;
int any = 0;
if (func == None && n == 1)